Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **System Initialization**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-10-20 23:16:10
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* merge code. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <TinyGPSPlus.h>
- #include "ACS712.h"
- #include <WiFi.h>
- #include <ESPAsyncWebServer.h>
- #include <SPIFFS.h>
- #include <ArduinoJson.h>
- #include <EEPROM.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include "X9C10X.h"
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Access Point credentials
- char ssid[] = "pleasedontcode.com"; // your network SSID (name)
- char pass[] = "prova1234"; // your network password (use for WPA, or use as key for WEP)
- // Create an instance of the web server
- AsyncWebServer server(80);
- // Instantiate library objects
- TinyGPSPlus gps;
- ACS712 ACS(current_pin, 3.3, 4095, 40); // Current sensor
- X9C10X pot(10000); // Digital potentiometer
- // Define constants and global variables...
- #define VELOCITA_SOGLIA_HIGH 75.0 //km/h
- #define VELOCITA_SOGLIA_LOW 65.0 //km/h
- #define VELOCITA_SOGLIA_0A_HIGH 20.0 //km/h
- #define VELOCITA_SOGLIA_0A_LOW 10.0 //km/h
- // Pins and global variables...
- const int water_level_pin = 18;
- const int voltage_pin = 35;
- const int current_pin = 34;
- const int tempSensor1_pin = 33;
- const int tempSensor2_pin = 32;
- const int ONE_WIRE_BUS_Temp1 = 19; // Temperature sensor 1
- const int ONE_WIRE_BUS_Temp2 = 21; // Temperature sensor 2
- const int DIGPOT_INC = 4; // pin INC - X9C103S
- const int DIGPOT_UD = 5; // pin UD - X9C103S
- const int DIGPOT_CS = 15; // pin CS - X9C103S
- const float PWM_output_percentage_0A = 0.0; //0%
- const float PWM_output_percentage_9A = 20.0; //20% --> 1V/5V
- const float PWM_output_percentage_5A = 13.0; //13% --> 0,65V/5V
- // Global data
- float PWM_output_percentage = 0.0;
- float velocita = 0.0;
- float voltage_output_value = 0.0;
- bool waterLevelEmpty = true;
- float voltage = 0.0;
- float current = 0.0;
- float temperature1 = 0.0;
- float temperature2 = 0.0;
- unsigned long powerOnTime = 0; //minutes
- boolean startRegeneration = false;
- unsigned int set_current = 0;
- unsigned int set_timer = 0;
- // Configuration for ACS712
- unsigned int ADC_Offset = 1930;
- // Setup a OneWire instance for temperature sensors
- OneWire oneWire1(ONE_WIRE_BUS_Temp1);
- OneWire oneWire2(ONE_WIRE_BUS_Temp2);
- DallasTemperature sensor1(&oneWire1);
- DallasTemperature sensor2(&oneWire2);
- /****** DEFINITION OF ANALOG INPUTS CHARACTERISTIC CURVES *****/
- const uint8_t SEGMENT_POINTS_voltage_Temperature = 10;
- const float voltage_Temperature_lookup[2][SEGMENT_POINTS_voltage_Temperature] =
- {
- {0.0, 1.2, 1.9, 5.0, 10.0, 14.5, 17.0, 20.0, 30.0, 35.0}, // voltage [V]
- {0.0, 5.0, 7.0, 13.0, 22.0, 29.0, 33.0, 37.0, 56.0, 65.0} // percentage [°C]
- };
- // Initialize SPIFFS for file storage
- void initSPIFFS() {
- if (!SPIFFS.begin(true)) {
- Serial.println("An error occurred while mounting SPIFFS");
- return;
- }
- Serial.println("SPIFFS mounted successfully");
- }
- void setup() {
- // Start Serial for debugging
- Serial.begin(115200);
- delay(1000);
- Serial.println("ciao");
- pot.begin(DIGPOT_INC, DIGPOT_UD, DIGPOT_CS); // Initialize digital potentiometer
- // Initialize ACS712 sensor
- ACS.setMidPoint(ADC_Offset);
- // Initialize temperature sensors
- sensor1.begin();
- sensor2.begin();
- // Initialize SPIFFS
- initSPIFFS();
- // Set up WiFi Access Point
- WiFi.mode(WIFI_AP); // Set the ESP32 to access point mode
- if (!WiFi.softAP(ssid, pass)) {
- Serial.println("Soft AP creation failed.");
- while(1);
- }
- // Print the IP address of the access point
- IPAddress IP = WiFi.softAPIP();
- Serial.print("Access Point IP Address: ");
- Serial.println(IP);
- // Serve the JPEG image
- server.on("/background.jpg", HTTP_GET, [](AsyncWebServerRequest *request){
- request->send(SPIFFS, "/background.jpg", "image/jpeg");
- });
- // Serve the HTML page
- server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
- request->send(SPIFFS, "/index.html", "text/html");
- });
- // Start the server
- server.begin();
- }
- void loop() {
- // No logic in the loop; the server works asynchronously
- readGPSAndCheckSpeed();
- readCurrent();
- readVoltage();
- readWaterTank();
- readTemp1();
- readTemp2();
- updateMinutesCounter();
- checkRegeneration();
- }
- // Function implementations...
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement