1.Find firmata code in arduino examples in arduino IDE,
2.Then, upload standard firmata code into arduino,
3.Now, its time to download python library for firmata using command
$ pip install pyfirmata
and its documentation and full source code can be found on github.Now we are all set lets get started,
Open up terminal and open python,
>>> from pyfirmata import Arduino, util #importing library for firmata
>>> board = Arduino('/dev/ttyACMA0') #'/dev/ttyACMA0' may be different for your OS, you can find that under tools tab of arduino IDE
>>> board.digital[10].write(1) #writing 1 or 'HIGH' to pin 10 of arduino
>>> it = util.Iterator(board) #making iterator object
>>> it.start() #starting iterator object
>>> board.analog[0].enable_reporting() #you need to enable reporting to read analog value
>>> board.analog[0].read() #reading value from channel zero of analog port
0.661440304938
>>> analog_0 = board.get_pin('a:0:i')
>>> analog_0.read()
0.661440304938
>>> pin3 = board.get_pin('d:3:p')
>>> pin3.write(0.6)
It is very usefull. I will definetly try this.
ReplyDeletenice job nidi sir
ReplyDelete