You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the Atom Lite is NOT receiving data, it transmits data to the computer without an error.
When the Atom Lite IS simultaneously receiving data, many errors appear in the data sent to the computer.
To reproduce
Here is an Arduino sketch. Serial is configured at baud 115200. It simply puts any received data in a array and it sends out the values 0 to 255 in a loop constantly.
//#include <M5Atom.h>unsignedlong monChronoMessages;
int inBuffer[256];
int inBufferIndex;
int outBufferIndex;
voidsetup() {
// put your setup code here, to run once:// M5.begin(false, false, false);
Serial.begin(115200);
delay(5000);
}
voidloop() {
// put your main code here, to run repeatedly:// À CHAQUE 20 MS I.E. 50x PAR SECONDEif (millis() - monChronoMessages >= 20) {
monChronoMessages = millis();
for (int i = 0; i < 33; i++) {
Serial.write(outBufferIndex);
Serial.flush();
outBufferIndex = (outBufferIndex + 1) % 256;
}
}
while (Serial.available()) {
inBuffer[inBufferIndex] = Serial.read();
inBufferIndex = (inBufferIndex + 1) % 256;
}
}
Here is a Python test program that checks that all incoming data is the sequence of numbers 0 to 255. If a number falls out of sequence it means that there is was an error while transmitting the data.
Install Serial for Python first: pip install pyserial
importserialimporttimeimportthreadingimportsysimportselectdefsend_sequence(ser, batch_size=33, delay=0.1, stop_event=None):
try:
whilenotstop_event.is_set():
forstartinrange(0, 256, batch_size):
# Generate the batch of 33 numbers (or fewer if at the end of the sequence)batch=list(range(start, min(start+batch_size, 256)))
ser.write(bytes(batch))
#print(f"Sent batch: {batch}")time.sleep(delay)
ifstop_event.is_set():
breakexceptserial.SerialExceptionase:
print(f"Serial error in sender: {e}")
exceptKeyboardInterrupt:
print("Stopping sender...")
defcheck_sequence(ser, stop_event=None):
try:
expected_value=0# Start expecting from 0ignore_first=Truewhilenotstop_event.is_set():
ifser.in_waiting>0:
byte=ser.read(1)
received_value=int.from_bytes(byte, byteorder='big')
ifignore_first==True:
expected_value= (received_value+1) %256ignore_first=Falseelse:
ifreceived_value==expected_value:
#print(f"Received correct value: {received_value}")expected_value= (expected_value+1) %256else:
print(f"Sequence error! Expected {expected_value} but got {received_value}")
expected_value= (received_value+1) %256exceptserial.SerialExceptionase:
print(f"Serial error in receiver: {e}")
exceptKeyboardInterrupt:
print("Stopping receiver...")
defmain():
serial_port='COM3'# Replace with your actual serial portbaud_rate=115200stop_event=threading.Event() # Create an event to control stopping the threadstry:
# Instantiate the serial connection onceser=serial.Serial(serial_port, baud_rate)
print(f"Connected to {serial_port} at {baud_rate} baud.")
# Create and start the sending and receiving threads with the shared ser instancesend_thread=threading.Thread(target=send_sequence, args=(ser, 63, 0.1, stop_event))
receive_thread=threading.Thread(target=check_sequence, args=(ser, stop_event))
send_thread.start()
receive_thread.start()
# Wait for any key press to stop the threadsprint("Press ctrl+C to stop...")
input() # Wait for user input# Set the stop event to signal both threads to exitstop_event.set()
# Join threads to wait for them to finishsend_thread.join()
receive_thread.join()
exceptserial.SerialExceptionase:
print(f"Could not open serial port {serial_port}: {e}")
exceptKeyboardInterrupt:
print("Exiting program...")
finally:
ser.close()
print("Serial port closed.")
if__name__=="__main__":
main()
Expected behavior
Replace COM3 with your serial port in the Python code:
serial_port='COM3'# Replace with your actual serial port`
The expected behavior is that the Python code should receive all the values 0 to 255 in a loop sequentially. If you run the Python code you will see that some values received are out of sequence.
What is strange is that if you disable the sending of values from Python (by commenting the following lines) THERE ARE NO MORE ERRORS IN THE VALUES RECEIVED:
Describe the bug
When the Atom Lite is NOT receiving data, it transmits data to the computer without an error.
When the Atom Lite IS simultaneously receiving data, many errors appear in the data sent to the computer.
To reproduce
Here is an Arduino sketch. Serial is configured at baud 115200. It simply puts any received data in a array and it sends out the values 0 to 255 in a loop constantly.
Here is a Python test program that checks that all incoming data is the sequence of numbers 0 to 255. If a number falls out of sequence it means that there is was an error while transmitting the data.
Install Serial for Python first:
pip install pyserial
Expected behavior
Replace
COM3
with your serial port in the Python code:The expected behavior is that the Python code should receive all the values 0 to 255 in a loop sequentially. If you run the Python code you will see that some values received are out of sequence.
What is strange is that if you disable the sending of values from Python (by commenting the following lines) THERE ARE NO MORE ERRORS IN THE VALUES RECEIVED:
Screenshots
No response
Environment
Additional context
No response
Issue checklist
The text was updated successfully, but these errors were encountered: