Every single simple sketch works correctly with its setting (switch mode selection)!
Unfortunately, there is no output generated by the serial monitor when I connect the 2 microcontrollers with the switch mode selection setting selection indicated.
1|1|0|0|0|0|0|0| -> comunicaion between ATmega328P+ESP8266
Thankyou
// Simple code on ATMega328p
/*
Switch status and mode selection on Arduino UNO ATMega328p
----------------
1|2|3|4|5|6|7|8|
0|0|1|1|0|0|0|N| -> upload sketch
----------------
*/
void setup() {
Serial.begin(9600);
Serial.println("ATmega328P ready");
}
void loop() {
Serial.println("Hello from ATmega328P");
delay(1000);
}
// Simple code on ESP8266
/*
Switch status and mode selection on ESP8266
----------------
1|2|3|4|5|6|7|8|
0|0|0|0|1|1|1|N| -> upload sketch
0|0|0|0|1|1|0|N| -> connect sketch
1|1|0|0|0|0|0|0| -> comunicaion between ATmega328P+ESP8266
----------------
*/
void setup() {
Serial.begin(9600);
Serial.println("ESP8266 ready");
}
void loop() {
if (Serial.available()) {
String message = Serial.readStringUntil('\n');
Serial.println("Received: " + message);
} else {
Serial.println("Waiting for data...");
}
delay(1000);
}
3
Note
The Mega version of your board has a selector allowing you to use one of the additional UARTs (Serial3) of the Mega2560 to communicate with the ESP8266 instead of Serial.
Thank you Guys for the valuable input you have given me!
Without Forum I could not have understood.
My intent was to take sensor values with the ATMega328p , then pass them to the ESP2866 and send them to a webserver. I had already done this with a much more expensive board. Instead with this low-cost one I had to split the code because the ESP8266 does not detect the sensor values.
Is there a possibility to send the values read by the sensors, between the two microcontrollers, bypassing the serial, with other functions or methods?
Which sensors do you use? What does "does not detect" mean? Which code did you use to come to that conclusion?
In which case you have no need for the USB serial
You probably can. There is a block of 3x4 pins in the right top of the board; you will have to figure out the functionality of those pins and take it from there. You can e.g. try to use the I2C bus by wiring the relevant pins; or wire some of those pins to the Uno pins and use SoftwareSerial at both sides. I don't have much experience with the ESP8266 but it sounds feasible to me.
(sterretje wrote) Which sensors do you use? What does "does not detect" mean? Which code did you use to come to that conclusion?
I tried this simple code to test the digital and analog pins of esp8266 and avoid using the combination of both microcontrollers; but the output is not correct:
18:01:48.352 -> -------------get_DHT11_sensor_data()
18:01:48.416 -> Temperature C° :0.00
18:01:48.416 -> Humidity % : 0
18:01:48.448 -> Status Read DHT11 Sensor : FAILED
18:01:48.480 -> -------------
18:01:48.480 ->
18:01:48.480 -> -------------get_Moisture_sensor_data()
18:01:48.544 -> - Moisture n.1 % : 100
#include <DHT.h>
//======================================== DHT sensor settings (DHT11).
#define DHTPIN 4 //--> Defines the Digital Pin connected to the DHT11 sensor.
#define DHTTYPE DHT11 //--> Defines the type of DHT sensor used. Here used is the DHT11 sensor.
DHT dht11_sensor(DHTPIN, DHTTYPE); //--> Initialize DHT sensor.
//========================================
//======================================== Variables for DHT11 sensor data.
float send_Temp;
int send_Humd;
String send_Status_Read_DHT11 = "";
int moisture_01;
// int global = 3; //test sd card connection ( 0 = disconnect / 1 = connect)
void setup() {
Serial.begin(9600);
Serial.println("ESP8266 ready");
dht11_sensor.begin();
}
void loop() {
Serial.println();
Serial.println("-------------get_DHT11_sensor_data()");
// Read temperature as Celsius (the default)
send_Temp = dht11_sensor.readTemperature();
// Read Humidity
send_Humd = dht11_sensor.readHumidity();
// Check if any reads failed.
if (isnan(send_Temp) || isnan(send_Humd)) {
//Serial.println("Failed to read from DHT sensor!");
send_Temp = 0.00;
send_Humd = 0;
send_Status_Read_DHT11 = "FAILED";
} else {
send_Status_Read_DHT11 = "SUCCEED";
}
Serial.println((String) "Temperature C° :" + send_Temp);
Serial.println((String) "Humidity % : " + send_Humd);
Serial.println((String) "Status Read DHT11 Sensor : " + send_Status_Read_DHT11);
Serial.println("-------------");
Serial.println();
Serial.println("-------------get_Moisture_sensor_data()");
int sensorvalue_01 = analogRead(A0); //Legge il valore analogico proveniente dal sensore
moisture_01 = map(sensorvalue_01, 195, 525, 100, 0);//Rimappa il valore sensorValue
moisture_01 = constrain(moisture_01, 0, 100);
Serial.println((String) "- Moisture n.1 % : " + moisture_01);
Serial.println("-------------");
delay(1000);
}