Unable to connect to Firmata

If you need technical help with anything you've bought from Dawn Robotics, please post here.

Unable to connect to Firmata

Postby arnoldbail » Fri Jun 20, 2014 11:49 am

Hi,

I installed the Pi Co-op as per the simple install instructions. I'm also new to the Arduino. I have the latest Raspian. When I execute the Blink sketch I get a "program not responding" error. When installing Pymata, I get a:
"Please wait while Arduino is being detected. This can take up to 5 seconds ...
Board Auto Discovery Failed!"

At the end I get:

" File "/home/pi/PyMata/PyMata/pymata.py", line 148, in __init__
raise Exception( "Unable to connect to Firmata" )
Exception: Unable to connect to Firmata"
arnoldbail
 
Posts: 7
Joined: Thu Jun 19, 2014 4:40 pm

Re: Unable to connect to Firmata

Postby Alan » Sat Jun 21, 2014 11:45 am

Hi Arnold,

Welcome to the forum. :) Sorry to hear you're having problems with your Pi Co-op, and also, sorry for the delay in replying to you.

Could you try a couple of things for me please?

[*] With the Pi powered on, can you press the white reset button on the Pi Co-op please? Do you see the green LED on the Pi Co-op flash?
[*] Likewise, when you try to program the Pi Co-op from the Arduino IDE or with Pymata, does the LED flash then.
[*] If possible, could you try to download our SD card image and flash it to an SD card please? This has the Arduino environment and all required programs installed, so it'd be interesting to see if you have the same problems with that.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: Unable to connect to Firmata

Postby arnoldbail » Mon Jun 23, 2014 11:35 am

Hi,

1) Pressing the reset button did not turn the green led on.
2) The green led never flashes,

I downloaded the image and it worked. Then, I booted up with an SD card that had previously failed. Without making any changes to the card, the IDE and PyMata Blinks worked. I did not reseat the Pi Co-op or anything. Perplexing.

Thanks for your response,

Just a note: I originally looked for an image I could try; but, I couldn't find a link to it.

Arnold
arnoldbail
 
Posts: 7
Joined: Thu Jun 19, 2014 4:40 pm

Re: Unable to connect to Firmata

Postby Alan » Mon Jun 23, 2014 12:21 pm

Hi Arnold,

Glad you got it to work, although it's odd that it didn't work in the first place. :? The sequence should be that behind the scenes, a program called avrdude is started to program the Pi Co-op, and as part of this a small Python script resets the Pi Co-op ready for the program download to start. This slightly convoluted process is needed because the UART on the GPIO pins doesn't have a hardware reset line.

I'm thinking now that there could perhaps be a timing issue with the reset signal being sent out, which I'll look into in case I need to make a software fix.

Also, good point about the image, I'll add a link to the Pi Co-op product page.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: Unable to connect to Firmata

Postby Maximus789 » Mon Dec 29, 2014 11:22 am

Alan,

I have managed to get an potentiometer reading (analogue) to print onto python. However this usually works twice before getting the code:
Exception: Unable to connect to Firmata

I have rebooted the pi and sometimes it works, but majority of the time it doesn't.

I can paste my code here if you want, but not convinced there is an issue with my code as it has worked in the past.

Any assistance will be appreciated.

Max
Maximus789
 
Posts: 7
Joined: Thu Dec 11, 2014 10:22 am

Re: Unable to connect to Firmata

Postby Alan » Mon Dec 29, 2014 1:24 pm

Hi Max,

If you could post the code so that I could have a look, then that would be very helpful.

I have occasionally seen connection problems with the Pi Co-op which I believe may be due to timing issues when the Pi resets the Pi Co-op or perhaps it's due to problems with the serial communication. The problem is that I've only seen the problem very infrequently, it's tough to get a repeatable test case and rebooting does seem to solve the problem. If you've got a program which encounters the problem repeatedly then it could be very useful for resolving it.

Alternatively, the other thing that could be going wrong is that your program may not have exited cleanly one of the previous previous times it ran. This would mean that it might still be sitting there, interfering with any serial communication you later try to do with the Pi Co-op.

You can check for this by running
Code: Select all
ps aux | grep python


which should show you all of the Python scripts running on your computer. You can kill them to shut them down completely by running

Code: Select all
sudo kill -9 PID


where PID is the ID of programs process (number displayed in the 2nd column when you run the ps command).

Hope that helps.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: Unable to connect to Firmata

Postby Maximus789 » Mon Dec 29, 2014 3:27 pm

Afternoon,

This is the code that I have been trying to get to work. It seems to work a few times as it is, but wont work at all if I remove the # before the GPIO lines.


Code: Select all
import time
from PyMata.pymata import PyMata
#import RPi.GPIO as GPIO

#Set GPIO pins
#GPIO.setmode(GPIO.BOARD)
#GPIO.setup(8,GPIO.OUT)

# Set co-op pins
BOARD_LED = 13
POTENTIOMETER = 0

#  Creat a PyMata instance using the Arduino COM Port as the input parameter
SERIAL_PORT = "/dev/ttyS0"
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )

#  set digital pin 13 to be an output port
firmata.set_pin_mode(BOARD_LED, firmata.OUTPUT, firmata.DIGITAL)
firmata.set_pin_mode(POTENTIOMETER, firmata.INPUT, firmata.ANALOG)
sensorvalue = firmata.analog_read(POTENTIOMETER)

#read anologue input
print "Blinking LED 13 10 times"
print firmata.analog_read(POTENTIOMETER)


#if sensorvalue<500:
 #       for i in range(0,10):
  #          print '< 500'
   #         print "iteration " + str(i+1)
    #        GPIO.output(8,True)
     #       print 'high'
      #      time.sleep(0.05)
       #     GPIO.output(8,False)
        #    print 'low'
         #   time.sleep(0.05)

#  blink for 50 times
for x in range(50):
    print x+1
    print firmata.analog_read(POTENTIOMETER)
    firmata.digital_write(BOARD_LED, 1)
    #  wait a half second between toggles.
    time.sleep(.5)
    firmata.digital_write(BOARD_LED, 0)
    time.sleep(.5)

# close PyMata when we are done
firmata.close()


Perhaps I have made an error trying to initialize the GPIO pins?
Maximus789
 
Posts: 7
Joined: Thu Dec 11, 2014 10:22 am

Re: Unable to connect to Firmata

Postby Alan » Mon Dec 29, 2014 3:46 pm

Hi there,

Do you get an error message? You need super user privileges in order to use the GPIO pins. So you'll need to run the program using sudo. If you're already using sudo then there may be a clash somewhere in the PyMata library. I'll have a look to see if I can see anything.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: Unable to connect to Firmata

Postby Maximus789 » Mon Dec 29, 2014 4:03 pm

Alan,

I run this script using
Code: Select all
sudo python filename.py


I have successfully run this code once:

Code: Select all
import time
from PyMata.pymata import PyMata
import RPi.GPIO as GPIO



# Set co-op pins
BOARD_LED = 13
POTENTIOMETER = 0

#  Creat a PyMata instance using the Arduino COM Port as the input parameter
SERIAL_PORT = "/dev/ttyS0"
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )

#  set digital pin 13 to be an output port
firmata.set_pin_mode(BOARD_LED, firmata.OUTPUT, firmata.DIGITAL)
firmata.set_pin_mode(POTENTIOMETER, firmata.INPUT, firmata.ANALOG)
sensorvalue = firmata.analog_read(POTENTIOMETER)

#Set GPIO pins
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8,GPIO.OUT)

#read anologue input
print "Blinking LED 13 10 times"
print firmata.analog_read(POTENTIOMETER)
print sensorvalue


#if sensorvalue<500:
 #       for i in range(0,10):
  #          print '< 500'
   #         print "iteration " + str(i+1)
    #        GPIO.output(8,True)
     #       print 'high'
      #      time.sleep(0.05)
       #     GPIO.output(8,False)
        #    print 'low'
         #   time.sleep(0.05)

#  blink for 50 times
for x in range(20):
    print x+1
    print firmata.analog_read(POTENTIOMETER)
    firmata.digital_write(BOARD_LED, 1)
    #  wait a half second between toggles.
    time.sleep(.5)
    firmata.digital_write(BOARD_LED, 0)
    time.sleep(.5)

# close PyMata when we are done
GPIO.cleanup()
firmata.close()


But if I try to do it a second time I get the following error code

Code: Select all
Opening Arduino Serial port /dev/ttyS0
Please wait while Arduino is being detected. This can take up to 5 seconds ...
Error: Caught exception in command handler - pop from an empty deque
Board Auto Discovery Failed!
Traceback (most recent call last):
  File "pymata_anologue.py", line 13, in <module>
    firmata = PyMata( SERIAL_PORT, max_wait_time=5 )
  File "/usr/local/lib/python2.7/dist-packages/PyMata/pymata.py", line 148, in __init__
    raise Exception( "Unable to connect to Firmata" )
Exception: Unable to connect to Firmata


Hope this is helpful.
Maximus789
 
Posts: 7
Joined: Thu Dec 11, 2014 10:22 am

Re: Unable to connect to Firmata

Postby Alan » Tue Dec 30, 2014 10:52 pm

Hi there,

Thank you for this.

I can't see anything obvious after a quick look at the code, but I'll try running it when I get back in to the office next week (5th January) and let you know if I find anything.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Next

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 0 guests