The first one is the classic Serial and is used to send commands from Arduino IDE
The second one is SoftwareSerial RX=2 and TX=3 and is used to get data from the mega.
The mega only has this SoftwareSerial RX=69 and TX=8.
Everithing works 98% of the time, but I get random ⸮ (reversed question mark) or false data when I send MEGA_UNO_Serial.println("9999");.
I Read all Serials as follow
char data_MEGA_UNO[message_len_MEGA_UNO]; :
If Serial.available()
byte m = MEGA_UNO_Serial.readBytesUntil('\n', data_MEGA_UNO, message_len_MEGA_UNO);
I think you will find that SoftwareSerial is very unreliable / not working at all at 115200 baud. Anything above 19200 baud and I think you may begin to encounter issues.
Your topic was MOVED to its current forum category as it is more suitable than the original as it has nothing to do with the installation or troubleshooting of the IDE
SoftwareSerial is vey unreliable at 115200 baud. Try reducing the baud rate
Then you have come to the right forum. We are all a bit dumb sometimes.
How are you going to solve it ?
The SoftwareSerial on the Uno and a hardware Serial port on the Mega might work. But the SoftwareSerial can have a conflict with other libraries. Avoiding SoftwareSerial is the best option.
I have 20 potentiometers that needs instant update (a 115200 speed is quite good)
So my goal is that when I say ' get potentiometer 1' to the Uno, the Mega can give me the value.
From what I've seen the softwareSerial doesn't look like the best option, I think I need to look at SPI, Wire.h and I2C, because I need at least 115200 baud, and have a lot of button, potentiometers
What is your message protocol? Maybe it has a lot of excess data overhead that you can cut out. Also what is the physical distance between the two boards?
I think, someone who considers themselves "dumb" might struggle with I2C or SPI processor intercommunication. Also those channels don't like to run long distances.
There is an overpowering smell of an X-Y problem here...
The Mega's role in this project is to provide more analog ports for the Uno, to read potentiometers? There are far better, faster, easier, cheaper ways to do that.
Here is the Uno code, and the mega is almost the same, without the USB_serial parts
The distance is less than 10cm but with cheap Amazon 'Dupont Breadboard' cables,
And when the speed is less than 115200 baud, the perfect precision is lost
#include <SoftwareSerial.h>
/*################### 6 USB_serial Analyser les entrées ##################*/
const int message_len_usb = 201;
char data_usb[message_len_usb];
/*################### 6 USB_serial Analyser les entrées ##################*/
/*################### 6 MEGA_UNO__serial Analyser les entrées ##################*/
#define rxPin 2
#define txPin 3
SoftwareSerial MEGA_UNO_Serial = SoftwareSerial(rxPin, txPin);
const int message_len_MEGA_UNO = 100;
char data_MEGA_UNO[message_len_MEGA_UNO];
/*################### 6 MEGA_UNO__serial Analyser les entrées ##################*/
unsigned long pTime = 0;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
MEGA_UNO_Serial.begin(19200);
Serial.begin(115200);
Serial.println("Uno");
delay(2000);
}
void loop()
{
read_USB_serial();
read_MEGA_UNO_serial();
}
void read_USB_serial()
{
byte n = Serial.available();
if (n != 0)
{
for (int i = 0; i < message_len_usb; i++)
{
data_usb[i] = '\0';
}
byte m = Serial.readBytesUntil('\n', data_usb, message_len_usb);
process_USB_serial();
data_usb[m] = '\0';
}
}
void process_USB_serial()
{
// Arduino IDE terminal => Mega Board
MEGA_UNO_Serial.println(String(data_usb));
pTime = micros();
}
void read_MEGA_UNO_serial()
{
byte n = MEGA_UNO_Serial.available();
if (n != 0)
{
for (int i = 0; i < message_len_MEGA_UNO; i++)
{
data_MEGA_UNO[i] = '\0';
}
byte m = MEGA_UNO_Serial.readBytesUntil('\n', data_MEGA_UNO, message_len_MEGA_UNO);
process_MEGA_UNO_serial();
data_MEGA_UNO[m] = '\0';
}
}
void process_MEGA_UNO_serial()
{
unsigned long A = micros()-pTime;
Serial.println("Megga a dit : " + String(data_MEGA_UNO) + String(A));
}
It is just a small part, but on the final project I use 'lisse set 1 99' for example, so the message length is < 20 chars
Thx a lot for the help,
Can you give me an example of how to send that ? (maybe MEGA_UNO_Serial.println())
And read that ? (maybe MEGA_UNO_Serial.readBytesUntil())
I need it to be non-blocking