Hello everyone,
I'm new to electronics and I'm currently working on a project that involves an Arduino Mega board and an ESP32. The ESP is mounted on a custom-made MEGA 2560 board and are connected by RX and TX pins.
I'm trying to send sensor data from the Arduino Mega to the ESP32, but I'm not sure how to go about it. I've done some research and read somewhere that you send the data via serial communication but not sure how...
If anyone has experience with this or knows how to accomplish this, I would really appreciate your help. Any advice, code snippets, or resources would be extremely helpful.
Heres a code snippet of the sensor readings from the mega board
#include "PinAssign.h"
#include "MyConstants.h"
#include "Variables.h"
// #include "thingProperties.h"
void SensorReadings(){
//CheckFloat
//Assign float positions
const int floatState1_1 = pcf8574.digitalRead(P0);
const int floatState1_2 = pcf8574.digitalRead(P1);
//Check Float level
if((floatState1_1 == LOW && floatState1_2 == HIGH) && !add_salt){
lowTrig1 = true;
EEPROM.update(lowaddress1,true);
Serial.println("Strong solution\n");
}
else if (floatState1_1 == HIGH && floatState1_2 == LOW){
lowTrig1 = false;
EEPROM.update(lowaddress1, false);
Serial.println("Weak solution...Turning OFF Dehumidifier\n");
dehumidifier_status = false;
add_salt = true;
}
else{
lowTrig1 = EEPROM.read(lowaddress1);
Serial.print("Float status: ");
Serial.println(lowTrig1);
}
delay(1000);
extern float ES135xx_Temp;
extern float ES135xx_Hum;
//SHT reading
//Storage SHT
//Storage room sensor
select_channel(SENSOR2_CHANNEL);
ES135xx_read_T_H();
Serial.print("Storage Temp = " + String(ES135xx_Temp) + " C " + " Storage RH = " + String(ES135xx_Hum) + "% | ");
// Utility sensor
select_channel(SENSOR2_CHANNEL);
ES135xx_read_T_H();
Serial.println("Utility Temp = " + String(ES135xx_Temp) + " C " + " Utility RH = " + String(ES135xx_Hum) + "%\n");
//DS18B20
// call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
/*float rawTempC = sensors.getTempCByIndex(0);
float calibratedTempC = rawTempC + CALIBRATION_OFFSET;
if(rawTempC == -127.00)
{
Serial.println("Error: Could not read temperature data");
}
else
{
Serial.print("Temperature: ");
Serial.println(calibratedTempC);
}*/
Serial.print("Temperature 1: ");
Serial.print(sensors.getTempCByIndex(0)); // 0 refers to the first IC on the wire
Serial.print("\tTemperature 2: ");
Serial.println(sensors.getTempCByIndex(1)); // 1 refers to the second IC on the wire
delay(1000);
}
Thank you in advance for your time and assistance!
Best,
John