PI and Arduino usb/serial trouble - Raspberry Pi Forums


hi all,

facing trouble when trying make pi2 communicate arduino uno thru serial ttyacm0 automatically created when plugged usb pi (in fact plugged thru powered usb hub).

test basic : pi sends request arduino thru serial port, arduino gets request , sends answer, pi has display answer.

to wrote following .py file i'm launching "python myfile.py"

code: select all

import serial, time ser=serial.serial('/dev/ttyacm0',9600,timeout=1) ser.write('?') time.sleep(0.5) print ser.readline() ser.close()
arduino code:

code: select all

void setup() {   serial.begin(9600); } void loop() {   if (serial.available()) {     if (serial.read() == '?') serial.print('hello');   } }
easy, no ?
problem : got nothing when launching "python myfile.py"
but, if type these same commands directly in python shell (2.7.3), working !
better : if after launch again "python myfile.py", working !!? shell opening or initializing else serial ??

wonder if problem on pi or arduino's side ?

tryed arduino (nano) : same
tryed arduino connected directly pi without usb hub : same

have got idea ???
thanks

i think python serial.readline(...) waits see newline character in serial data should using serial.println(...) in arduino code. it's not clear how give symptoms you've described there may issue.

debugging technique, might try toggling gpio connected led when arduino receives character. tell whether or not pi arduino path working.


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code