Communicating via COM port


so, trying send character python program arduino program via com5 serial port. however, wont let me run both @ same time because says port busy.

this python code:
code: [select]

import serial
import time
try:
    arduino = serial.serial()
    arduino.port = 'com5'
    time.sleep(2)
   
except exception e:
    print(e)

arduino.open()
arduino.write(b'a')
time.sleep(2)
arduino.close()


this arduino code exact same of robin2's serial basics code.
code: [select]

char receivedchar;
boolean newdata = false;

void setup() {
 serial.begin(9600);
 serial.println("<arduino ready>");
}

void loop() {
 recvonechar();
 shownewdata();
}

void recvonechar() {
 if (serial.available() > 0) {
 receivedchar = serial.read();
 newdata = true;
 }
}

void shownewdata() {
 if (newdata == true) {
 serial.print("this in ... ");
 serial.println(receivedchar);
 newdata = false;
 }
}


can tell me doing wrong? thanks.

you can have 1 thing connected serial port @ time.  the solution use 1 port serial monitor , python port.  you connecting usb ttl converter (ftdi) different serial port , pc python port.  some arduinos have hardware serial ports (mega) or can use software serial library create port (uno).


Arduino Forum > Using Arduino > Programming Questions > Communicating via COM port


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts