Hey everyone,
This is my first post here, so hopefully I am complete enough in my question.
I am trying to send and read an incremented value via serial communication (Teensy 3.6 to Python3 on laptop).
void setup()
{
// Initialise serial communication
Serial.begin(115200);
}
void loop()
{
for (int d = 15000000; d <= 16000000; d++) {
Serial.println(String(d));
}
}
I get an issue that at some point the incrementation becomes faulty.
My python code is as follows.
import serial
ser = serial.Serial(port = "COM3", baudrate=115200)
while True:
data = ser.readline().decode('ascii')
data = data.strip()
print(data)
As can be seen below, at some (random?) point it reads a longer value and also shifts the incrementation.
Does anyone have a clue as to why this is happening? Baud rates are matched, so that can't be it.
I would really appreciate the help!
Cheers,
Rens
Thanks for the quick response!
I changed this, but it did not really matter.
Could it be that the serial communication is not fast enough for this type of transfer? I explicitly did not use a delay in the loop to have the fastest cycling as possible.
(Why this impacts the perceived value of d, I do not know)
Actually, it seems like something is falling behind. If I add a significant delay, say 10 ms, I get no more errors but the cycling seems a bit slow. Is there a trick to keep high 'sweep' rate and transfer this data efficiently?
I am no pro at communication protocols, but could it be that the microprocessor is pumping out a ton of values and that some other part has trouble keeping up? It seems like it makes some sort of backlog and at some point the backlog overflows. Is this something that can happen in serial communication? E.g. my computer can't process the signal fast enough and thus has to store some data in a place that eventually overflows.
Actually, it seems like something is falling behind. If I add a significant delay, say 10 ms, I get no more errors
Please post your latest programs in your next Reply so we can see exactly what you have done.
It is completely impractical to expect an Arduino to be able to send serial data as often as loop() can repeat. Serial data is relatively slow even at a high baud rate.