pyFirmata icon indicating copy to clipboard operation
pyFirmata copied to clipboard

Can't read Arduino pins (returning "None") using Raspberry & TX/RX pins

Open David-Lor opened this issue 8 years ago • 2 comments

I'm trying the pyFirmata library with a Raspberry Pi, and an Arduino Mega 2560 board attached to it, using the TX and RX (0 and 1) pins of the Mega board and the TX/RX pins of the Raspberry.

Can this be done with pyFirmata? pyFirmata "connects" to the Arduino Mega without problems, and the board.digital[13].write(1) function works fine, I can turn on/off leds, blink... But the problem comes with the reading functions.

Tried on both digital and analog pins and it doesn't work. No errors are given, but the read function just returns "None". This is an example of the complete instructions I executed:

`>>> import pyfirmata

board=pyfirmata.ArduinoMega("/dev/ttyAMA0") it = pyfirmata.util.Iterator(board) it.start() board.analog[0].enable_reporting() board.analog[0].read() print board.analog[0].read() None board.digital[2].enable_reporting() #I suppose the "enable_reporting" is for analog reads only? Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/pyfirmata/pyfirmata.py", line 487, in enable_reporting raise IOError("{0} is not an input and can therefore not report".format(self)) IOError: Digital pin 2 is not an input and can therefore not report print board.digital[2].read() None v=board.digital[2].read() print v None a0=board.get_pin("a:0:i") a0.read() print a0.read() None pin3=board.get_pin("d:3:i") pin3.read() print pin3.read() None `

Tried using USB instead of the TX/RX pins and the read functions works fine, so I though if pyFirmata might not be able to use that communication.

David-Lor avatar Mar 30 '17 11:03 David-Lor

The fact is you need to program a correct code to the Arduino first. pyFirmat only do communication, it do not program the Arduino.

dynamictoys avatar Aug 28 '18 03:08 dynamictoys

I don't understand what do you mean I uploaded pyFirmata's sketch beforehand to the Arduinp

David-Lor avatar Aug 28 '18 08:08 David-Lor