keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Program stuck when using Nanpy

Tue Nov 11, 2014 1:10 am

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.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 9:06 am

How is the Arduino connected to the RPi?

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 1:37 pm

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.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 10:02 pm

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.

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 10:44 pm

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'

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 10:54 pm

Using connection = SerialManager() I get the same output as I do using dev = '/dev/ttyACM0' and connection = SerialManager(device=dev, baudrate=baud)

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Program stuck when using Nanpy

Tue Nov 11, 2014 11:10 pm

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.

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 12:45 am

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)

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 12:20 pm

And the ttyxxx ports?

Gr.
Dirk.

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 1:23 pm

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
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 1:49 pm

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 ...

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 6:36 pm

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.

keldos
Posts: 7
Joined: Tue Nov 11, 2014 12:39 am

Re: Program stuck when using Nanpy

Wed Nov 12, 2014 11:23 pm

Thank you all very much for your help. I was able to get it working using Firmata as Stewart suggested.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Program stuck when using Nanpy

Thu Nov 13, 2014 7:30 am

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

Return to “Automation, sensing and robotics”