my current project requires an Arduino Uno to communicate via serial with an Arduino Mega and I would like to improve the data transfer rate.
This Arduino Uno is extracting information from a strain gauge through a bridge circuit using analogRead()
(which I have already tested). It then sends this information through Serial to the Mega, which then sends it to a computer using a USB cable and serial communications.
This Mega board is required because the Uno is placed on a rotating axis, and the communication between it and the Mega is done through a circular optocoupler, which I have tested and is also working.
With this out of the way, I'm currently reading data from the rotating Uno at 190Hz. I believe most of the problem is due to a delay(5);
present in the code, but even lowering it to 3ms is enough for the data to arrive with missing characters.
The Uno code:
void setup() {
Serial.begin(19200);
}
void loop() {
Serial.println(analogRead(A0));
delay(5);
}
The Mega code:
char t;
void setup() {
Serial.begin(9600);
Serial1.begin(19200);
}
void loop() {
if (Serial1.available()>0)
{
t = Serial1.read();
Serial.print(t);
}
}
The data being sent is always an integer from 0 to 1023, since it comes from analogRead()
, so maybe I could encode it better, but I'm not sure how to do it or if that would fix the bigger problem of the necessary delay(5);
Thank you very much
println();
and I get this data 190 times a second. The dropping data I mentioned is not happening if I keep the delay at 5ms, but, as far as I understand, I can't get more than 200 data samples a second due to this delay. – Tu 123ip