That is driving me nuts so I need your help.
Master : PC with Ubuntu, a USB to serial converter (chipset CP2102), connected to Arduino Uno Pin 10, 11 and GND. The Arduino Uno is plugged in the same PC.
Port for the converter is /dev/ttyUSB1
Port for the Arduino is /dev/ACM0
I tried to communicate by Serial through the converter (I do not want to use ACM0 as it is buggy and sometimes suddenly change to ACM1, messing up my big testing program).
On Arduino side :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int inByte = 0; // incoming serial byte
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (mySerial.available()) {
char inByte = mySerial.read();
mySerial.println(inByte);
Serial.println(inByte);
}
delay(10);
}
The Python script (simple one to debug)
import serial
arduino = serial.Serial('/dev/ttyUSB1', 9600)
arduino.timeout=0.5
arduino.bytesize=8
arduino.stopbits=1
code=49 #ASCII Code for 1
arduino.write(chr(code).encode('utf-8'))
print(chr(code))
print(chr(code).encode('utf-8'))
print(arduino.readline())
print("done")
arduino.close()
When I run it, I have on Arduino Serial monitor a g
and Python script output
1
b'1'
b'Ly\x00'
done
By the way, the very same code over /dev/ttyACM0
and standard serial rather than Softwareserial works perfectly (as long as the port remains ACM0 of course)