Hi so I have been working on a serial interface for a while for my Arduino and I am basically right now just trying to set up a basic system of telling the "home" program that the Arduino is ready to start talking to it. I did that on my laptop by just creating a loop that sends one number and waits 1 second to receive another number back. I checked and my "home" program works great but I think I managed to mess up my Arduino code. I say this because it never sends any data back to my laptop. I checked using all the same parameters for serial with some generic example codes and everything works. I believe it just boils down to my improper use of the Arduino Serial type functions. So if you guys would look at my code and critique it a bit (tell me that I was a complete idiot and that I can't use that function like that) it would be greatly appreciated. As a little bit of a forewarning I am very new to programming Arduino and basically anything in general so expect some badly written code. So while doing so testing I found that the Rx led lights up when the "home" program is sending it's one number but it never goes anywhere from there. It also resets when I first open up to port like it should.
Arduino Code
int readSerial = 0;
void setup() {
pinMode(5, OUTPUT);
Serial.begin(9600);
}
void loop() {
readSerial = Serial.read();
if (readSerial == 3) {
Serial.write(4);
readSerial = Serial.read();
if (readSerial == 2) {
Serial.write(3);
readSerial = Serial.read();
Serial.print(readSerial);
}
}
}
The Important parts of the Python code
er = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
connected = 0
while connected == 0:
print("not connected") #Just debug message
ser.write("3") #Seeing if the arduino is open to com yet
if ser.read() == 4: #Arduino saying it is open to com
connected = 1 #Another debug message
print("connected")
time.sleep(1)
print("it has slept")
while connected == 1:
print("it worked")
Some random code to do fun things but we never get this far
I can never seem to get it to go p