1

My Problem: I've got an Arduino connected to my Pi via /dev/ttyUSB0 and I always have to initialize the connection via screen, otherwise I cannot send any values via Bash or Python.

What I'm doing: From the Arduino I receive sensor values like this:

<43.30,43.50>
<43.30,43.70>
<43.50,43.70>
<43.60,43.30>
<43.50,43.60>
<43.50,43.60>
<43.50,44.10>
<43.50,43.60>
<43.30,43.60>
<43.50,43.70>

That data I'm parsing via Python and later Java...

I also can send data to the Arduino: 0 and 1 to turn a switch on and off.

When I connect via screen I can see the input values and send values. Then, when I close screen, I can also use my script, eg this one:

#!/usr/bin/python

import serial, time

ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("1")
ser.close

But the every time I reboot my Pi, the script doesn't work until I connect via screen to /dev/ttyUSB0. Does anybody know why?

1

I think you need to create a SYMLINK (alias) for ttyUSB0 via /etc/udev/rules.d.

See here

  • I am not sure about that. On my current Archlinux ttyUSB0 is available right from scratch. So maybe the OP can check first. – Ghanima Sep 4 '14 at 6:20
0

You may need to add a time.sleep(0.5) right after your write. Not sure why, but I think that will get it to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.