Page 1 of 1
Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 1:10 am
by keldos
I'm trying to interface with an Arduino using Nanpy and the program always gets stuck at this line:
Code: Select all
a = ArduinoApi(connection=connection)
When I press control-C I get the following output:
Code: Select all
Traceback (most recent call last):
File "nanpy_test.py", line 10, in <module>
a = ArduinoApi(connection=connection)
File "build/bdist.linux-armv6l/egg/nanpy/classinfo.py", line 22, in getinstanc
File "build/bdist.linux-armv6l/egg/nanpy/classinfo.py", line 59, in __init__
File "build/bdist.linux-armv6l/egg/nanpy/memo.py", line 21, in __call__
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 55, in wrapper
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 123, in wrappe
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 46, in _call
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 16, in return_
File "build/bdist.linux-armv6l/egg/nanpy/serialmanager.py", line 92, in readli
File "build/bdist.linux-armv6l/egg/serial/serialposix.py", line 461, in read
KeyboardInterrupt
Here is the source:
Code: Select all
from nanpy import (ArduinoApi, SerialManager)
from time import sleep
dev = '/dev/ttyACM0'
baud = 9600
print "starting"
connection = SerialManager(device=dev, baudrate=baud)
a = ArduinoApi(connection=connection)
a.pinMode(13, a.OUTPUT)
while True:
print "on"
a.digitalWire(13, a.HIGH)
time.sleep(1)
print "off"
a.digitalWire(13, a.LOW)
time.sleep(1)
The baudrate I have set in the code matches what is set in my cfg.h file. I have also tried it with the default baudrate and the empty SerialManager constructor.
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 9:06 am
by B.Goode
How is the Arduino connected to the RPi?
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 1:37 pm
by keldos
The Arduino is connected to the RPi by USB. When the program is run the 'L' LED will flash a bit and the RX light will blink once very briefly but the program will never display anything after the "starting" print statement.
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 10:02 pm
by B.Goode
dev = '/dev/ttyACM0'
That looks like the definition of the UART on the GPIO header.
If you are using a usb serial dongle I would expect the virtual serial port to have a name something like /dev/ttyUSB0
So I think your code is failing because it does not get a response from the Arduino.
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 10:44 pm
by keldos
With that I get the output:
Code: Select all
starting
Traceback (most recent call last):
File "nanpy_test.py", line 10, in <module>
a = ArduinoApi(connection=connection)
File "build/bdist.linux-armv6l/egg/nanpy/classinfo.py", line 22, in getinstance
File "build/bdist.linux-armv6l/egg/nanpy/classinfo.py", line 59, in __init__
File "build/bdist.linux-armv6l/egg/nanpy/memo.py", line 21, in __call__
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 55, in wrapper
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 123, in wrapper
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 27, in _call
File "build/bdist.linux-armv6l/egg/nanpy/arduinoboard.py", line 9, in _write
File "build/bdist.linux-armv6l/egg/nanpy/serialmanager.py", line 82, in write
File "build/bdist.linux-armv6l/egg/nanpy/serialmanager.py", line 75, in open
File "build/bdist.linux-armv6l/egg/serial/serialutil.py", line 282, in __init__
File "build/bdist.linux-armv6l/egg/serial/serialposix.py", line 289, in open
OSError: [Errno 2] No such file or directory: '/dev/ttyUSB0'
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 10:54 pm
by keldos
Using connection = SerialManager() I get the same output as I do using dev = '/dev/ttyACM0' and connection = SerialManager(device=dev, baudrate=baud)
Re: Program stuck when using Nanpy
Posted: Tue Nov 11, 2014 11:10 pm
by DirkS
Have you checked that your serial device is present with 'lsusb'.
Have you checked whether /dev/ttyUSB0 and / or /dev/ttyACM0 are present? (just use ls for that).
Gr.
Dirk.
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 12:45 am
by keldos
lsusb outputs the following:
Code: Select all
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 008: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 12:20 pm
by DirkS
And the ttyxxx ports?
Gr.
Dirk.
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 1:23 pm
by scruss
B.Goode wrote:That looks like the definition of the UART on the GPIO header.
No, the GPIO UART is /dev/ttyAMA0. ACM0 is one of the standard ones.
It might be a groups/permissions issue. Try these two commands:
Code: Select all
pi@mince ~ $ ls -l /dev/ttyACM0
crw-rw---T 1 root dialout 166, 0 Dec 31 1969 /dev/ttyACM0
pi@mince ~ $ groups
pi adm dialout …
If groups doesn't return ‘dialout’ in the response, then you likely can't read or write to the device.
Firmata, though elderly and not able to support some fancy devices, is better maintained, and has a userbase who understand and can explain its quirks. Nanpy doesn't have that kind of traction.
cheers,
Stewart
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 1:49 pm
by keldos
Sorry DirkS forgot that part.
Code: Select all
/dev/tty /dev/tty19 /dev/tty3 /dev/tty40 /dev/tty51 /dev/tty62
/dev/tty0 /dev/tty2 /dev/tty30 /dev/tty41 /dev/tty52 /dev/tty63
/dev/tty1 /dev/tty20 /dev/tty31 /dev/tty42 /dev/tty53 /dev/tty7
/dev/tty10 /dev/tty21 /dev/tty32 /dev/tty43 /dev/tty54 /dev/tty8
/dev/tty11 /dev/tty22 /dev/tty33 /dev/tty44 /dev/tty55 /dev/tty9
/dev/tty12 /dev/tty23 /dev/tty34 /dev/tty45 /dev/tty56 /dev/ttyACM0
/dev/tty13 /dev/tty24 /dev/tty35 /dev/tty46 /dev/tty57 /dev/ttyAMA0
/dev/tty14 /dev/tty25 /dev/tty36 /dev/tty47 /dev/tty58 /dev/ttyprintk
/dev/tty15 /dev/tty26 /dev/tty37 /dev/tty48 /dev/tty59
/dev/tty16 /dev/tty27 /dev/tty38 /dev/tty49 /dev/tty6
/dev/tty17 /dev/tty28 /dev/tty39 /dev/tty5 /dev/tty60
/dev/tty18 /dev/tty29 /dev/tty4 /dev/tty50 /dev/tty61
and it looks like I have dialout:
Code: Select all
pi@raspberrypi ~ $ ls -l /dev/ttyACM0
crw-rw---T 1 root dialout 166, 0 Nov 11 16:41 /dev/ttyACM0
pi@raspberrypi ~ $ groups
pi adm dialout ...
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 6:36 pm
by B.Goode
scruss wrote:B.Goode wrote:That looks like the definition of the UART on the GPIO header.
No, the GPIO UART is /dev/ttyAMA0. ACM0 is one of the standard ones.
Happy to be factually corrected. Thanks for clarifying.
Re: Program stuck when using Nanpy
Posted: Wed Nov 12, 2014 11:23 pm
by keldos
Thank you all very much for your help. I was able to get it working using Firmata as Stewart suggested.
Re: Program stuck when using Nanpy
Posted: Thu Nov 13, 2014 7:30 am
by B.Goode
I am pleased this has been resolved for @keldos, using an alternative solution.
For anyone who hits this thread looking for advice on NanPy, there is a previous extensive thread elsewhere on this forum by Tony Goodhew (@tonygo2) which includes a very detailed setup tutorial for NanPy on Raspbian.
http://www.raspberrypi.org/forums/viewt ... py#p546921