Hello,
I am getting this error while compiling code for esp32.
Error:
Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, None"
C:\Users\bilal\AppData\Local\Temp\arduino_cache_87525\core\core_6929dad97967b40f7e760b2df9456f93.a(HardwareSerial.cpp.o):(.bss.Serial2+0x0): multiple definition of `Serial2'
sketch\sketch_may14a.ino.cpp.o:(.bss.Serial2+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board ESP32 Dev Module.
ESP32 Code: #include <HardwareSerial.h> #define RXD2 16 #define TXD2 17
HardwareSerial Serial2(2);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
Serial.print("Data Received: ");
Serial.println(Serial2.read());
delay(200);
// put your main code here, to run repeatedly:
I got this output on the serial monitor. I don't know what is wrong with the code but I want to transfer the value "50" from Arduino to ESP32 so that the value should be shown on the serial monitor of ESP32.
Any help in that?
Thank you.
Have a look at ASCII codes. You are printing the characters 5 and 0.
Please use code tags to post code. Reading codes on images in no fun and does not allow to copy code.
Also have a look at serial examples. You should check whether there are any available characters first.
As a general tip I recommend you avoid combining function calls for now. Think about the data types and store all values in local variables first and then use them. This will help you understand better what is going on and tells other more about what you think happens vs what actually happens in your code. e.g.
Serial.println( Serial2.read() ); // make this two lines of code
Thank you for the reply.
Can you also tell me that if it is possible to have bi-directional communication between Arduino and ESP32? If it is, then what code/documentation I should see for an example?
Also "myRcvChar = Serial2.read();
Serial.print(myRcvChar);"
Should I write these lines for ESP32 or Arduino?
Any help in that would be helpful.
Thank you Stefan for your help. I was able to achieve what I wanted to.
I just wanted a bit more help from you in, how can i send multiple sensor data from Arduino Uno to ESP32 via serial communication.
I have already tried sending only one value like 100 or a string like "Hello" but I want to send more than one sensor value to esp32.
Basically, I will try to send EEG and EMG data from Arduino to Esp32.
I hope you can guide me in this regards.
Thanks
There is a library called SafeString,
which has functions to make life easier about send/receive strings
and to extract parts of a string.
The variabletype String (with capital "S") is dangerous to use with the Arduino if the strings are defined global.
I guess you do not yet understand what defining as "global" means.
Well that's one of the basic things you have to learn.
The name of SafeStrings is program. They are safe to use.
What I'm gonna do for you is "teach fishing" WHich means I can show you some programming-techniques that will make you yourself able to analyse in details what a program does.
ANd based on that you can modify your code to see what happens through the modification.
There are various learning-types like learning by reading or learning by watching (videos)
here is a basic course that teaches important basic things you need to know for every program including sending single or multiple values
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
If you are not the reading-texttype of learner just say so.