0% found this document useful (0 votes)
17 views5 pages

Arduino and Genuino 101 Development Workshop - Agus Kurniawan Part 017

Arduino and Genuino 101 Development Workshop - Agus Kurniawan

Uploaded by

SANTOSH KHANAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Arduino and Genuino 101 Development Workshop - Agus Kurniawan Part 017

Arduino and Genuino 101 Development Workshop - Agus Kurniawan

Uploaded by

SANTOSH KHANAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

9.

1 Getting Started
In this scenario we build a desktop application to control sensor/actuator devices on
Arduino board. Several methods can be used to implement this case. In this chapter, we
use Firmata protocol to access Arduino board from Computer. I use Python as example
which accesses Arduino board.
Further information about Firmata, please it
on http://firmata.org and https://github.com/firmata/protocol .
9.2 Installing Firmata Firmware
To implement Firmata on Arduino board, you should install Firmata program on Arduino.
You can get it by clicking menu File -> Examples -> Firmata -> StandardFirmata .

After that, you get program codes for Firmata.


Configure board and port for Arduino 101. Then, upload the program into the board.
Now you’re ready to develop Firmata program.
9.3 Demo
In this demo, we use three LEDs as actuator devices on Arduino. We will control these
LEDs from Python program.
Let’s start.

9.3.1 Wiring
We connect three LEDs on Digital pin 10, 9 and 8 from Arduino/Genuino 101.
The following is my wiring.

9.3.2 Firmata Program on Arduino Board


You can install Firmata on Arduino board. Please read section 9.2 to deploy Firmata on
Arduino.

9.3.3 Writing Python Program


There are several options to use Firmata library for Python. In this section, I use
pyfirmata, https://github.com/tino/pyFirmata .
You can install pyfirmata via pip.
$ pip install pyfirmata

You also can install it from source code.


$ git clone https://github.com/tino/pyFirmata
$ cd pyFirmata
$ python setup.py install

After installed pyfirmata, you can write Python program as below.


from pyfirmata import Arduino
import time

board = Arduino('/dev/cu.usbmodem1411')
led1_pin = 10
led2_pin = 9
led3_pin = 8

def turn_off_all():
board.digital[led1_pin].write(0)
board.digital[led2_pin].write(0)
board.digital[led3_pin].write(0)

# turn on LED sequentially


try:
while 1:

print('LED1 is ON')
board.digital[led1_pin].write(1)
time.sleep(1)
turn_off_all()

print('LED2 is ON')
board.digital[led2_pin].write(1)
time.sleep(1)
turn_off_all()

print('LED3 is ON')
board.digital[led3_pin].write(1)
time.sleep(1)
turn_off_all()

except KeyboardInterrupt:

You might also like