Интернет вещей: возможности Intel Galileo Gen2 и Intel Edison
The Hands on Intel Edison Manual Lab
Transcript of The Hands on Intel Edison Manual Lab
-
7/21/2019 The Hands on Intel Edison Manual Lab
1/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
2/157
Copyright
e Hands-on Intel Edison Manual Lab
us Kurniawan
BN: 978-1-312-73697-9
Edition, 2014
pyright 2014 Agus Kurniawan
-
7/21/2019 The Hands on Intel Edison Manual Lab
3/157
Table of Contents
pyright
eface
Preparing Development Environment
Intel EdisonGetting Hardware
Development Tools
Electronics Devices
Intel Edison Boxing
Connecting Intel Edison to Computer
.1 Windows Platform
.2 Linux Platform
Updating The Latest Intel Edison Firmware
Yocto Embedded Linux-based OS
Getting Started
Configuring Intel Edison: Hostname and Password
.1 Change Hostname
.2 Change root Password
Connecting to Wi-Fi Hotspot
SSH
Change Date/Timezone
Web Server
.1 Adding HTML File
SFTP
Development on Yocto Linux
.1 Python
.2 Node.js
.3 C/C++ with GCC
Reboot and Shutdown
0 Updating Software
-
7/21/2019 The Hands on Intel Edison Manual Lab
4/157
1 Installing Nano - Text Editor
2 Intel Edison Unofficial Repository
Working with Arduino IDE Software
Intel Edison and Arduino IDE Software
Hello Intel Edison and Arduino
.1 Hardware Configuration
.2 Building Application
.3 Testing
Demo: Seven-Segment Display
.1 Getting Started with 7 Segment Display
.2 Deploying Hardware Wiring
.3 Building Application
.4 Testing
Working with Serial Communication (UART)
Reading Analog Input
.1 Hardware Configuration
.2 Writing Application
.3 Testing
Working with Analog Output.1 RGB LED
.2 Hardware Configuration
.3 Writing Application
.4 Testing
Working with SPI
Intel Edison I/O Programming using Python
Getting Started
GPIO
Analog I/O - Reading Analog Input
UART
SPI
I2C/TWI
Intel Edison Development using C/C++
-
7/21/2019 The Hands on Intel Edison Manual Lab
5/157
Getting Started
GPIO
Analog I/O - Reading Analog Input
UART
SPI
I2C/TWI
Intel Edison Development using Node.js
Getting Started
GPIO
Analog I/O - Reading Analog Input
UART
SPI
I2C/TWI
Bluetooth Low Energy (BLE) and iBeacon
Bluetooth Low Energy (BLE)
Pairing BLE Devices
BLE Development and iBeacon
Further Reading
Working with XBee IEEE 802.15.4XBee IEEE 802.15.4
Getting Hardware
Connecting XBee IEEE 802.15.4 to Intel Edison
XBee with AT Command
Demo Chatting Program
.1 Hardware Configuration
.2 XBee Configuration
.3 Writing Python Program for Intel Edison
.4 Testing
XBee with API Mode
Further Reading
urce Code
ntact
-
7/21/2019 The Hands on Intel Edison Manual Lab
6/157
Preface
his book was written to help anyone wants to get started in Intel IoT and Intel Edison. It describe
l the basic elements of the Intel IoT and Intel Edison with step-by-step approach. Several code
amples are be provided to illustrate how to work with Intel Edison.
gus Kurniawan
erlin, December 2014
-
7/21/2019 The Hands on Intel Edison Manual Lab
7/157
1. Preparing Development Environment
1 Intel Edison
e Intel Edison development platform is designed to lower the barriers to entry for a range of
ventors, entrepreneurs, and consumer product designers to rapidly prototype and produce Interne
ings (IoT) and wearable computing products. You can read a brief description about Intel Edison
ps://communities.intel.com/docs/DOC-23139.
r evaluation, we use Intel Edison kit for Arduino expansion board. It is designed to be hardware
tware pin-compatible with Arduino shields designed for the Uno R3. Please read about this brea
ard on https://communities.intel.com/docs/DOC-23161.
https://communities.intel.com/docs/DOC-23161https://communities.intel.com/docs/DOC-23139 -
7/21/2019 The Hands on Intel Edison Manual Lab
8/157
2 Getting Hardwarew to get Intel Edison?
ficially you can buy it from the official distributor
Amazon, http://www.amazon.com/Intel-Edison-Arduino-Components-EDI1ARDUIN-AL-
K/dp/B00ND1KH42/
Sparkfun, https://www.sparkfun.com/products/13097
Maker shed, http://www.makershed.com/products/intel-edison-kit-for-arduino
Exp-Tech, http://www.exp-tech.de/Mainboards/Arduino/intel-edison-arduino-breakout-kit.htm
Mouser, http://www.mouser.com/Intel/_/N-1yy6lwu?Keyword=edison&FS=True
u can buy Intel Edison kit for Arduino expansion board on your local electronics store. In additio
u also buy Intel Edison peripheral devices for instance, power adapter, micro USB and micro dis
3 Development Toolsthis book, you use any development tool to write program with Intel Edison target.
e will explore these development tools on next chapters.
4 Electronics Devices
e need electronic components to build our testing, for instance, Resistor, LED, sensor devices an
http://www.mouser.com/Intel/_/N-1yy6lwu?Keyword=edison&FS=Truehttp://www.exp-tech.de/Mainboards/Arduino/intel-edison-arduino-breakout-kit.htmlhttp://www.makershed.com/products/intel-edison-kit-for-arduinohttps://www.sparkfun.com/products/13097http://www.amazon.com/Intel-Edison-Arduino-Components-EDI1ARDUIN-AL-K/dp/B00ND1KH42/ -
7/21/2019 The Hands on Intel Edison Manual Lab
9/157
ecommend you can buy electronic component kit. You find them on your local electronics shops
u can buy Intel IoT edition kit, for instance starter kit from Seeedstudio
p://www.seeedstudio.com/depot/intel-iot-c-143/.
http://www.seeedstudio.com/depot/intel-iot-c-143/ -
7/21/2019 The Hands on Intel Edison Manual Lab
10/157
u also can use additional sensor and actuator devices to evaluate Intel Edison board.
5 Intel Edison Boxing
ter you bought Intel Edison kit for Arduino, you got the following box.
en, you open it. You will find Intel Edison board and its shield.
-
7/21/2019 The Hands on Intel Edison Manual Lab
11/157
this case, we are missing:
Power adapter
Micro USB cable
USB cable
w you can plug the Intel Edison on shield. If success, you can see green light on the board, show
gure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
12/157
6 Connecting Intel Edison to Computer
stly, your Intel Edison is be connected to power and then it's be connected to computer via micro
B.
-
7/21/2019 The Hands on Intel Edison Manual Lab
13/157
6.1 Windows Platform
connect your Intel Edison kit for Arduino to computer, based on this site
ps://communities.intel.com/docs/DOC-23147, you can do the following steps:
Install FTDI driver, http://www.ftdichip.com/Drivers/VCP.htm. Download this driver based y
Windows platform edition. Run setup file as Administrator level
Intel Edison driver, https://communities.intel.com/docs/DOC-23242
t follow installation instructions.
https://communities.intel.com/docs/DOC-23242http://www.ftdichip.com/Drivers/VCP.htmhttps://communities.intel.com/docs/DOC-23147 -
7/21/2019 The Hands on Intel Edison Manual Lab
14/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
15/157
w you can connect the power adapter and then micro USB. See Figure below.
ter connected to computer, open Device Manager. You will see on Intel Edison on Ports, shown
gure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
16/157
metime you may get a problem especially for x64 edition about digital signature of Intel Edison
ver. Configure to ignore the digital signature settings on your Windows. Normally you can do it
ssin F8 key on restarting Windows. Then choose Disable Driver signature Enforcement.
r Windows 8, you can do by clicking Restart menu and pressing SHIFT key. Select Troubleshoo
en select Advanced options.
Advanced options display, select Startup settings, shown in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
17/157
ck Restartbutton. Then Windows 8 will restart. After that, select Disable driver signature
forcement.
6.2 Linux Platform
r Ubuntu Linux, please the following document on https://communities.intel.com/docs/DOC-23
7 Updating The Latest Intel Edison Firmware
stly, you can download Intel Edison image on https://communities.intel.com/docs/DOC-23242.
n see Edison Yocto Complete Image. Download it.
https://communities.intel.com/docs/DOC-23242https://communities.intel.com/docs/DOC-23149 -
7/21/2019 The Hands on Intel Edison Manual Lab
18/157
r instance, you have download Intel Edison Yocto Image, edison-image-rel1-maint-rel1-ww42
zip.
w you can plug the power adapter to board and micro USB to computer, shown in Figure below
-
7/21/2019 The Hands on Intel Edison Manual Lab
19/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
20/157
tract Edison image file, edison-image-rel1-maint-rel1-ww42-14.zip, to this to Edison flashdisk
lowing is a sample output.
-
7/21/2019 The Hands on Intel Edison Manual Lab
21/157
w change your micro USB cable to another micro USB, see Figure below.
Windows platform you can see Intel Edison board which attached to computer. See it using Dev
anager.
-
7/21/2019 The Hands on Intel Edison Manual Lab
22/157
Linux, it will show as /dev/ttyUSB0 .
r Windows, you can use PuTTY on
p://www.chiark.greenend.org.uk/~sgtatham/putty/download.htmlto access Intel Edison board. F
ial port with speed 115200 and select Serial for Connection type.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html -
7/21/2019 The Hands on Intel Edison Manual Lab
23/157
ck Openbutton if done. Then, you get PuTTY dialog. If you get a blank screen, please press Eny until show messages on screen.
ter edison logon: root . Then, click Enter key. No password on Yocto.
-
7/21/2019 The Hands on Intel Edison Manual Lab
24/157
r Ubuntu Linux, you can use Screenprogram. You can install it by typing the following comman
$ sudo apt-get install screen
rmally Intel Edison kit for Arduino is be recognized as /dev/ttyUSB0. Now you can connect it u
following command.
$ sudo screen /dev/ttyUSB0 115200
ter connected, you can type this command to update Intel Edison firmware.
$ reboot ota
e following is a sample output.
-
7/21/2019 The Hands on Intel Edison Manual Lab
25/157
w your Intel Edison has the latest firmware.
te: After update your the latest firmware by this approach, our current configuration will be dele
e must reconfigure our Edison board. Please read section 2.2 to configure Edison board.
ase logon using root user. Then, verify Edison firmware version using the following command.
$ cat /etc/version
$ configure_edison --version
u will get the current firmware version.
-
7/21/2019 The Hands on Intel Edison Manual Lab
26/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
27/157
2. Yocto Embedded Linux-based OS
is chapter explains how to work with Yocto Linux on Intel Edison board.
1 Getting Started
the previous chapters we setup Intel Edison and operate it. In this chapter, we use Yocto Linux
ich already installed for basic operations.
2 Configuring Intel Edison: Hostname and Password
fore doing the lab, please upgrade your Edison firmware. Read section 1.7.
stly, we connect Intel Edison for Arduino to computer via micro USB, see Figure below.
eck serial port which Intel Edison is be attached. After that, open PuTTY (select Serial) for Win
Screen for Ubuntu.
-
7/21/2019 The Hands on Intel Edison Manual Lab
28/157
gon using root user without password.
e can configure our Edison OS using configure_edisoncommand. Type this following command
information about Edison command.
$ configure_edison --help
-
7/21/2019 The Hands on Intel Edison Manual Lab
29/157
2.1 Change Hostname
pe the following command.
$ configure_edison --name
ter your device name. It will be hostname for Edison device.
-
7/21/2019 The Hands on Intel Edison Manual Lab
30/157
2.2 Change root Password
rthermore, we can change our password for root user. Type this command.
$ configure_edison --password
ter password for root user.
3 Connecting to Wi-Fi Hotspot
ter changed password, we can setup Wi-Fi. Type the following command to setup our Wi-Fi.
-
7/21/2019 The Hands on Intel Edison Manual Lab
31/157
$ configure_edison --wifi
will scan Wi-Fi hotspot automatically. Select which hotspot you want to connect.
elected, you will be asked to entry password if Wi-Fi needs password (WPA). If success, you wormation about your IP Address.
-
7/21/2019 The Hands on Intel Edison Manual Lab
32/157
verify it, you can open a browser and navigate to your Edison's IP Address.
u also can use ping to Edison's IP Address from your local computer.
4 SSH
-
7/21/2019 The Hands on Intel Edison Manual Lab
33/157
el Edison firmware has been installed SSH server so you can access Intel Edison via SSH client.
ustration, I use PuTTY tool to access SSH protocol. Firstly, fill Intel Edison IP address and select
Connection type.
inished, click Openbutton. If success, you obtain a terminal. By default, username is rootand
rent password.
-
7/21/2019 The Hands on Intel Edison Manual Lab
34/157
w you can do activities normally .
5 Change Date/Timezone
your Wifi has Internet connection, Intel Edison will synch Date configuration. You can read the
rent date and time on Yocto Linux using command date. Then, if you want to change time, for
tance, we change time to 12 October 2014 07:18 AM.
$ date
$ date 1012071814
6 Web Server
el Edison doesn't installed web server such as Lighttpd, http://www.lighttpd.net/ , Apache, Nginxhen you type http://ip_address_edison/ you will redirect to node.js server.
u can test using browser. Open your browser and navigate to IP address of Intel Edison. A sampl
put is shown in Figure below.
http://www.lighttpd.net/ -
7/21/2019 The Hands on Intel Edison Manual Lab
35/157
6.1 Adding HTML File
r demo, we can add new HTML file to web server. The default web folder is
r/lib/edison_config_tools/public.
you open edison-config-server.js, you get the following script.
-
7/21/2019 The Hands on Intel Edison Manual Lab
36/157
w you can add a new HTML file, called test.html. Navigate to public
r/lib/edison_config_tools/public. Type the following command.
$ vi test.html
ite the following script like this Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
37/157
ve this script and then quit from vi application.
w you can open browser on computer. Navigate to test.html. If success, you can obtain a respon
m Linux.
7 SFTP
w to transfer file from local computer to Intel Edison? Yocto Linux on Intel Edison provides SF
ecure FTP). By default, it has already installed on Intel Edison image.
se WinSCP tool, http://winscp.net/, to access SFTP on Intel Edison. Entry all authentication
ormation on WinSCP app.
http://winscp.net/ -
7/21/2019 The Hands on Intel Edison Manual Lab
38/157
ter that, click Loginbutton. If success, you can see the following dialog.
-
7/21/2019 The Hands on Intel Edison Manual Lab
39/157
w you can transfer your file to Yocto Linux.
8 Development on Yocto Linux
cto Linux provides several development compilers and tools. For text editor, Yocto provides vi e
this section, we explore various development tools in Yocto Linux.
8.1 Python
e can use Python on Yocto Linux. It has already installed. You can type the following script for d
$ python --version
$ python
>> 5*7
>> exit()
-
7/21/2019 The Hands on Intel Edison Manual Lab
40/157
8.2 Node.js
de.js has already installed in Yocto Linux. You can type the following script for illustration.
$ node -v
$ node
> 4*9
> .exit
8.3 C/C++ with GCC
-
7/21/2019 The Hands on Intel Edison Manual Lab
41/157
CC has already installed in Yocto Linux. You can check GCC version using the following comma
$ gcc -v
y to create a file, called hello.c, and write this code.
#include
main()
{
printf("Hello World\n");
}
ve and try to compile and run.
$ gcc -o hello hello.c
$ ./hello
-
7/21/2019 The Hands on Intel Edison Manual Lab
42/157
9 Reboot and Shutdown
u can reboot your Intel Edison using the following command.
$ reboot
u can turn on your Intel Edison using shutdown command.
$ shutdown -h -P now
ait until all lights are turned off on Intel Edison board. Normally it takes a minute to turn all systeter that, you can unplug the power from the board.
10 Updating Software
update and upgrade the latest library, you can type the following command.
$ echo"src intel-iotdk http://iotdk.intel.com/repos/1.1/intelgalactic" > /
en, try to update and upgrade.
$ opkg update
$ opkg upgrade
-
7/21/2019 The Hands on Intel Edison Manual Lab
43/157
ake sure your board is be connected to Internet network.
11 Installing Nano - Text Editor
you want to install nano, text editor, on your Intel Edison. You can type the following command.
$ wget http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz
$ tar xvf nano-2.2.6.tar.gz
$ cd nano-2.2.6
$ ./configure
$ make
$ make install
ter installed, you can use it, for instance,
$ nano test.txt
-
7/21/2019 The Hands on Intel Edison Manual Lab
44/157
u will get your nano editor.
12 Intel Edison Unofficial Repository
we add additional repository to Intel Edison image. Firstly, edit/etc/opkg/base-feeds.confusing
vi.
$ nano /etc/opkg/base-feeds.conf
en, add the following repository.
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
-
7/21/2019 The Hands on Intel Edison Manual Lab
45/157
ve this file.
w you can update our repository.
$ opkg update
u can install the new package using the following command.
$ opkg install
te: is package name.
-
7/21/2019 The Hands on Intel Edison Manual Lab
46/157
3. Working with Arduino IDE Software
is chapter explains how to work Intel Edison and Arduino IDE software.
1 Intel Edison and Arduino IDE Software
this chapter, we explorer Arduino software to develop application for Intel Edison target. FYI, In
ison has pin-compatible with a wide range of Arduino Uno R3 shields. To download Arduino
tware for Intel Edison, you can visit on https://communities.intel.com/docs/DOC-23242.
ter you downloaded Arduino software for Intel, for instance, arduino-windows-1.0.4.7z, extract
e into a specific folder. A sample of extracted file for Arduino Intel is shown in Figure below
indows platform).
https://communities.intel.com/docs/DOC-23242 -
7/21/2019 The Hands on Intel Edison Manual Lab
47/157
w you can install Arduino Intel on Windows platform. Then, you can run Arduino Intel.
e following is a sample of Arduino Intel app.
-
7/21/2019 The Hands on Intel Edison Manual Lab
48/157
r Ubuntu Linux, you can execute Arduino Intel by typing the following command.
$ ./arduino
u may run as Administrator (sudo) due to device security issue, for instance, accessing USB driv
-
7/21/2019 The Hands on Intel Edison Manual Lab
49/157
2 Hello Intel Edison and Arduino
this section, we learn how to get started to write a program for Intel Edison. We can use 3 LEDs
ustrate our case.
2.1 Hardware Configuration
nnected your 3 LEDs to Intel Edison digital pins: 10, 9, 8. Another pin is connected to GND pin
lowing is hardware schema.
-
7/21/2019 The Hands on Intel Edison Manual Lab
50/157
ase connect your Intel Edison from Micro USB (J16) to computer.
en, check which COM is used by Intel Edison. In Windows platform, you can find it via Device
anager. Otherwise, it presents as /dev/ttyACM0 in Linux.
-
7/21/2019 The Hands on Intel Edison Manual Lab
51/157
y Intel Edison shows as COM16. It will be used to Arduino software.
2.2 Building Application
e can turn on/off for LEDS using digitalWrite(), http://arduino.cc/en/Reference/DigitalWrite, whi
nds HIGH or LOW value to digital pin of Intel Edison.
eate new application on Arduino software and write the following code.
intled1 =8;
intled2 =9;
intled3 =10;
http://arduino.cc/en/Reference/DigitalWrite -
7/21/2019 The Hands on Intel Edison Manual Lab
52/157
voidsetup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
voidoffAll(){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
voidloop() {
digitalWrite(led1, HIGH);
delay(1000);
offAll();
delay(100);
digitalWrite(led2, HIGH);
delay(1000);
offAll();
delay(100);
digitalWrite(led3, HIGH);
delay(1000);
offAll();
delay(100);
}
ake sure your Arduino software has configured to Intel Edison target. You can do it by clicking m
ols->Board and then select your board.
-
7/21/2019 The Hands on Intel Edison Manual Lab
53/157
u must configure board COM too. You can click menu Tools->Serial Port and then select your b
OM.
-
7/21/2019 The Hands on Intel Edison Manual Lab
54/157
ve this code.
2.3 Testing
run application to Intel Edison board, you must deploy program. You can do it by clicking icon
ow (upload).
-
7/21/2019 The Hands on Intel Edison Manual Lab
55/157
uccess, you can see 3 LEDs are blinking.
-
7/21/2019 The Hands on Intel Edison Manual Lab
56/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
57/157
e following is a sample physical of 7 segment display.
-
7/21/2019 The Hands on Intel Edison Manual Lab
58/157
3.2 Deploying Hardware Wiring
e next step, we must connect our 7 segment to Intel Edison.
re is pin configuration from 7 segment display to Intel Edison.
Digital 2 --> pin DP
Digital 3 --> pin c
Digital 4 --> pin d
Digital 5 --> pin e
Digital 6 --> pin b
Digital 7 --> pin a
Digital 8 --> pin f
Digital 9 --> pin g
GND --> pin GND (center pin of 7 segment / Unlabeled pin)
e following is a hardware implementation for connecting 7 segment display to Intel Edison.
-
7/21/2019 The Hands on Intel Edison Manual Lab
59/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
60/157
intpin_f =8;
intpin_g =9;
intpin_dp =2;
voidsetup() {
pinMode(pin_a, OUTPUT);
pinMode(pin_b, OUTPUT);
pinMode(pin_c, OUTPUT);
pinMode(pin_d, OUTPUT);
pinMode(pin_e, OUTPUT);
pinMode(pin_f, OUTPUT); pinMode(pin_g, OUTPUT);
pinMode(pin_dp, OUTPUT);
}
voiddisplaynull(){
digitalWrite(pin_a, LOW);
digitalWrite(pin_b, LOW);
digitalWrite(pin_c, LOW);
digitalWrite(pin_d, LOW);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, LOW);
digitalWrite(pin_g, LOW);
digitalWrite(pin_dp, LOW);
}
voiddisplay(intnum){
switch(num){
case0:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH); digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, HIGH);
digitalWrite(pin_f, HIGH);
digitalWrite(pin_g, LOW);
digitalWrite(pin_dp, HIGH);
break;
case1:
digitalWrite(pin_a, LOW);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, LOW);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, LOW);
digitalWrite(pin_g, LOW);
digitalWrite(pin_dp, HIGH);
break;
case2:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, LOW); digitalWrite(pin_d, HIGH);
-
7/21/2019 The Hands on Intel Edison Manual Lab
61/157
digitalWrite(pin_e, HIGH);
digitalWrite(pin_f, LOW);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
case3:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, LOW); digitalWrite(pin_f, LOW);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
case4:
digitalWrite(pin_a, LOW);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, LOW);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, HIGH);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
case5:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, LOW);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, HIGH); digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
case6:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, LOW);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, HIGH);
digitalWrite(pin_f, HIGH);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
case7:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, LOW);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, LOW);
digitalWrite(pin_g, LOW); digitalWrite(pin_dp, HIGH);
-
7/21/2019 The Hands on Intel Edison Manual Lab
62/157
break;
case8:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, HIGH);
digitalWrite(pin_f, HIGH);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break; case9:
digitalWrite(pin_a, HIGH);
digitalWrite(pin_b, HIGH);
digitalWrite(pin_c, HIGH);
digitalWrite(pin_d, HIGH);
digitalWrite(pin_e, LOW);
digitalWrite(pin_f, HIGH);
digitalWrite(pin_g, HIGH);
digitalWrite(pin_dp, HIGH);
break;
}
}
voidloop() {
displaynull();
delay(1000);
display(0);
delay(1000);
displaynull();
delay(1000); display(1);
delay(1000);
displaynull();
delay(1000);
display(2);
delay(1000);
displaynull();
delay(1000);
display(3);
delay(1000);
displaynull();
delay(1000);
display(4);
delay(1000);
displaynull();
delay(1000);
display(5);
delay(1000);
displaynull();
delay(1000);
display(6); delay(1000);
-
7/21/2019 The Hands on Intel Edison Manual Lab
63/157
displaynull();
delay(1000);
display(7);
delay(1000);
displaynull();
delay(1000);
display(8);
delay(1000);
displaynull();
delay(1000);
display(9); delay(1000);
}
ve this code as 7segment file.
3.4 Testing
w you can run this application by uploading program to Intel Edison board. The following is sam
puts for 7 segment on Intel Edison board.
-
7/21/2019 The Hands on Intel Edison Manual Lab
64/157
4 Working with Serial Communication (UART)
this section we work with serial communication (UART) which we can use Serial object,
p://arduino.cc/en/reference/serial. To illustrate our case, we access Intel Edison UART using
rial.write() to write and Serial.read() to read.
en Arduino software for Intel Edison and write this code.
intled =13;
voidsetup() {pinMode(led, OUTPUT);
http://arduino.cc/en/reference/serial -
7/21/2019 The Hands on Intel Edison Manual Lab
65/157
Serial.begin(9600);
}
voidloop() {
digitalWrite(led, HIGH);
Serial.write("LEAD is HIGH\n");
delay(1000);
digitalWrite(led, LOW);
Serial.write("LEAD is LOW\n");
delay(1000);
}
ve this code and then try to upload to the Intel Edison board. If success, you can see LED on pin
nking, shown in Figure below (red arrow).
u also can verify by opening Serial Monitor. You can do it by clicking menu Tools->Serial Moni
sample output can be seen in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
66/157
5 Reading Analog Input
this section, we learn how to read analog input on Intel Edison. For illustration, I use Potentiome
analog input source. Let's start!.
5.1 Hardware Configuration
understand Potentiometer, you see its scheme in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
67/157
u can connect VCC to Intel Edison VCC 5V. Vout to Intel Edison Analog input A0. In addition,
Intel Edison GND. The following is hardware implementation.
-
7/21/2019 The Hands on Intel Edison Manual Lab
68/157
5.2 Writing Application
e can use analogRead(), http://arduino.cc/en/Reference/AnalogWrite, to read analog input in Inte
ison.
w open Arduino software and write this code.
intled =13;
intpotentiometer =0;
intval =0;
voidsetup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
}
http://arduino.cc/en/Reference/AnalogWrite -
7/21/2019 The Hands on Intel Edison Manual Lab
69/157
voidloop() {
val =analogRead(potentiometer);
Serial.print("Analog value: ");
Serial.println(val,DEC);
delay(1000);
}
ve this code as potentiometer file.
5.3 Testing
mpile and upload the program to Intel Edison board. Then, open Serial Monitor. You will see an
ut value on this dialog.
sample output can be seen in Figure below.
6 Working with Analog Output
e last section, we learn how to work with analog output on Intel Edison. We use RGB LED whic
s colors by giving R, G and B values on its pins. We use Intel Edison Analog output (PWM). If y
-
7/21/2019 The Hands on Intel Edison Manual Lab
70/157
the board, PWM pins are idenitified by 2 sign. You can see PWM pins on the following Figure
ow.
6.1 RGB LED
this scenario we build an application to control RGB LED color using Intel Edison Analog outpu
WM). RGB LED has 4 pins that you can see it in Figure below.
understand these pins, you can see the following Figure.
-
7/21/2019 The Hands on Intel Edison Manual Lab
71/157
te:
Pin 1: Red
Pin 2: Common pin
Pin 3: Green
Pin 4: Blue
w we can start to build an application and hardware implementation.
6.2 Hardware Configuration
connect RGB LED pins to Intel Edison, we can configure the following schema.
RGB LED pin 1 (red) is connected to Intel Edison PWM pin 9RGB LED pin 2 is connected to Intel Edison VCC 5V
RGB LED pin 3 (green) is connected to Intel Edison PWM pin 6
RGB LED pin 4 (blue) is connected to Intel Edison PWM pin 5
te: you can use resistor to handle voltage issues.
rdware implementation can be seen in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
72/157
6.3 Writing Application
e can generate a color by combining R, G, and B values. This value can be 0 until 255. In this ca
will generata colors: red, green, blue, yellow, and purple.
ite this code on Arduino software.
intredPin =5;
intgreenPin =6;
intbluePin =9;
-
7/21/2019 The Hands on Intel Edison Manual Lab
73/157
voidsetup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
voidloop()
{
setColor(255, 0, 0); // red Serial.println("red");
delay(1000);
setColor(0, 255, 0); // green
Serial.println("green");
delay(1000);
setColor(0, 0, 255); // blue
Serial.println("blue");
delay(1000);
setColor(255, 255, 0); // yellow
Serial.println("yellow");
delay(1000);
setColor(80, 0, 80); // purple
Serial.println("purple");
delay(1000);
setColor(0, 255, 255); // aqua
Serial.println("aqua");
delay(1000);
}
voidsetColor(intred, intgreen, intblue)
{ analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
ve this code as rgb file.
6.4 Testing
w you can compile and upload program to Intel Edison board. A sample output for RGB LED c
n in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
74/157
u can also verify it using Serial Monitor.
-
7/21/2019 The Hands on Intel Edison Manual Lab
75/157
7 Working with SPI
e Serial Peripheral Interface (SPI) is a communication bus that is used to interface one or more s
ipheral integrated circuits (ICs) to a single master SPI device; usually a microcontroller or
croprocessor of some sort.
defaults, Intel Edison has SPI with 25 MHz Master mode and 16.67 MHz slave mode. While Ed
s a native SPI controller, it will act as a master and not as an SPI slave. We can use Intel Edison S
s for Arduino breakout.
Pin 10 (SS)
Pin 11 (MOSI)
Pin 12 (MISO)
Pin 13 (SCK).
r illustration, we test our SPI on Intel Edison using SPI loopback which we connect MOSI to MI
e can use SPI library to access this I/O. The following is hardware implementation.
-
7/21/2019 The Hands on Intel Edison Manual Lab
76/157
w you open Arduino software for Intel Edison. Write the following code.
#include
intval =50;
voidsetup() {
// initialize SPI:
SPI.begin();
Serial.begin(9600);
}
voidloop() {
Serial.print("send: ");
Serial.println(val);
intrecv =SPI.transfer(val);
Serial.print("recv: ");
Serial.println(recv);
delay(1000);
val =val +1;
if(val>60)
val =50;
}
e verify it using Serial Monitor. You will send sent and received values.
-
7/21/2019 The Hands on Intel Edison Manual Lab
77/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
78/157
4. Intel Edison I/O Programming using Python
is chapter explains how to work and write program using Python for accessing Intel Edison I/O f
nux.
1 Getting Started
stly, we must understand Intel Edison board schema. You can find information about the board ops://communities.intel.com/docs/DOC-23161. The following is a board schema for Intel Edison
e can verifiy GPIO on processor using the following command.
https://communities.intel.com/docs/DOC-23161 -
7/21/2019 The Hands on Intel Edison Manual Lab
79/157
$ cat /sys/kernel/debug/gpio
this section, we learn how to write Python program to access GPIO Intel Edison. We use libmraa
rary, http://iotdk.intel.com/docs/master/mraa/python/mraa.html. It has installed for you.
test libmraa library, you can check its version using Python console.
$ python
>> import mraa
>> mraa.getVersion()
sample output can be seen in Figure below.
http://iotdk.intel.com/docs/master/mraa/python/mraa.html -
7/21/2019 The Hands on Intel Edison Manual Lab
80/157
2 GPIO
this section, we will work with digital I/O on Intel Edison and write Python program to access it
e libmraa library which has installed on IoT OS. To write HIGH/LOW on GPIO, we use Gpio.wr
you want to read digital input, you can use Gpio.read().
r illustration, we use demo from section 2.4. Connected your 3 LEDs to Intel Edison digital pins
8. Another pin is connected to GND pin.
-
7/21/2019 The Hands on Intel Edison Manual Lab
81/157
w you can create a file, called hello.py, and write the following script.
importtime
importmraa
led1 =10
led2 =9
led3 =8
pin_led1 =mraa.Gpio(led1)
pin_led2 =mraa.Gpio(led2)
pin_led3 =mraa.Gpio(led3)
# set GPIO mode
pin_led1.dir(mraa.DIR_OUT)
pin_led2.dir(mraa.DIR_OUT)pin_led3.dir(mraa.DIR_OUT)
try:
whileTrue:
print'LED 1 ON'
pin_led1.write(1)
pin_led2.write(0)
pin_led3.write(0)
time.sleep(2)
-
7/21/2019 The Hands on Intel Edison Manual Lab
82/157
print'LED 2 ON'
pin_led1.write(0)
pin_led2.write(1)
pin_led3.write(0)
time.sleep(2)
print'LED 3 ON'
pin_led1.write(0)
pin_led2.write(0)
pin_led3.write(1)
time.sleep(2)
exceptKeyboardInterrupt:
pin_led1.write(0)
pin_led2.write(0)
pin_led3.write(0)
u can execute this program to Intel Edison. Type the following command.
$ python hello.py
uccess, you will obtain responses as below.
u also see LEDs are blinking on Intel Edison.
-
7/21/2019 The Hands on Intel Edison Manual Lab
83/157
3 Analog I/O - Reading Analog Input
e can read analog input using mraa library. For illustration, we use the same scenario from sectio
ich uses Potentiometer as analog input source.
nnect Potentiometer pins to VCC and Vout to Analog input A0 on Intel Edison board.
e following is hardware implementation.
-
7/21/2019 The Hands on Intel Edison Manual Lab
84/157
aa library provide a class, Aio, to manipulate analog processing. To read analog input, we can u
o.read() with specific analog pin.
r illustration, we create a file, called analog_read.py, and write this code.
importtime
importmraa
a0 =mraa.Aio(0)a0.setBit(10)
try: whileTrue: val =a0.read()
print"analog val: " +str(val) time.sleep(2)
-
7/21/2019 The Hands on Intel Edison Manual Lab
85/157
exceptKeyboardInterrupt: print"done"
ve this code and try to execute by typing the following command.
$ python analog_read.py
uccess, you can see analog value in Terminal. Try to change Potentiometer value so you get a ne
alog value from Intel Edison board.
4 UART
this section we learn how to access UART on Intel Edison board. By default, Inte Edison has six
ART on the board. You can check them by typing the following command.
$ ls /dev/tty*
-
7/21/2019 The Hands on Intel Edison Manual Lab
86/157
sample output of command response can be seen in Figure below.
e following is a list of Intel Edison UART which we can use.
/dev/ttyGS0 is be connected to Micro USB Client which is connected to PC
/dev/ttyMFD1 is be connected to Arduino pins, digital pin 0 (Rx) and digital pin 1( Tx)
/dev/ttyMFD2 is be connected to Micro USB Client which is connected to PC for debugging
-
7/21/2019 The Hands on Intel Edison Manual Lab
87/157
r accessing UART on Arduino pins from Linux, I used pyserial library, http://pyserial.sourceforg
urthermore, you can install it via easy_install. The following is a command for installing pyseria
$ easy_install -U pyserial
you don't install easy_install yet, you can install by typing the folllowing command.
$ wget https://bootstrap.pypa.io/ez_setup.py --no-check-certificate -O - | p
sample output of installation of pyserial can be seen in Figure below.
r testing, I use a UART on /dev/ttyMFD2. We need a micro USB cable which is connected to a
mputer.
xt step is to write program using Python. Create a file, called uart.py, and write this code.
http://pyserial.sourceforge.net/ -
7/21/2019 The Hands on Intel Edison Manual Lab
88/157
importserial
importtime
serialport ='/dev/ttyMFD2'
print'open ' +serialport
ser =serial.Serial(serialport, 115200)
counter =0
whileTrue:
try:
print'writing: ' +str(counter)
ser.write(str(counter))
print(counter)
counter +=1
ifcounter >10:
counter =1
time.sleep(1)
except(KeyboardInterrupt, SystemExit):
ser.close() raise
print"done"
write data to UART, we can use serial.write() from pyserial library. Otherwise, we can use
ial.read() to read incoming data from UART. Save this code and try to execute it to Intel Edison
minal.
$ python uart.py
is program will send data from 0 to 10 and back to 1. On local computer, we use PuTTY to read
Serial. Firstly, check which a serial port is used via Device Manager if you are working on Wind
tform, for instance, COM6.
-
7/21/2019 The Hands on Intel Edison Manual Lab
89/157
en, you put COM6 to PuTTY.
-
7/21/2019 The Hands on Intel Edison Manual Lab
90/157
you are working on Linux, you can use miniterm. You can see a sample output in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
91/157
Intel Edison, the following is program output.
5 SPI
e can verify installed SPI on Intel Edison by the following command.
$ ls /dev/spi*
u can see my SPI on Intel Edison is installed on /dev/spidev1.5 .
-
7/21/2019 The Hands on Intel Edison Manual Lab
92/157
r illustration, we build a program to write and read data to/from Intel Edison SPI. We build a SPI
pback which digital pin 11 (MOSI) is be connected to digial pin 12 (MISO). Hardware
plementation can be seen in Figure below.
e will use mraa library to access SPI. To write data to SPI, we can use Spi.write(). Then, we recei
oming data from returning Spi.write().
eate a file, called spi.py, and write this code.
importtimeimportmraa
spi =mraa.Spi(5)
counter =100
whileTrue:
try:
n =len(str(counter))
recv =spi.write(str(counter))
printrecv[:n]
time.sleep(1)
counter +=1
ifcounter >110:
break
except(KeyboardInterrupt, SystemExit):
raise
print"done"
-
7/21/2019 The Hands on Intel Edison Manual Lab
93/157
is code will send counter data which is started from 100. If it reaches counter 110+, it will be
pped.
w you can run it by typing the following command.
$ python spi.py
sample output can be seen in Figure below.
6 I2C/TWI
e I2C (Inter-Integrated Circuit) bus was designed by Philips in the early '80s to allow easy
mmunication between components which reside on the same circuit board. TWI stands for Two W
erface and for most marts this bus is identical to IC. The name TWI was introduced by Atmel a
er companies to avoid conflicts with trademark issues related to IC.
el Edison has two I2C interfaces which are connected via I2C1 on Analog A4 (SDA) and A5 (SC
s and I2C6 on Digital SDA and SCL pins. We can obtain a list of installed I2C on Intel Edison u
detect with passing -l parameter.
ping the following command.
$ i2cdetect -l
-
7/21/2019 The Hands on Intel Edison Manual Lab
94/157
uccess, you see a list of installed I2C as below.
alog A4 (SDA) and A5 (SCL) pins are represented as i2c-1. For illustration, we will build I2C
plication. We need an Arduino board as I2C source. I use Arduino Uno.
r wiring scenario, we implement the following hardware schema:
Arduino A4 (SDA) to Intel Edison A4 (SDA)
Arduino A5 (SCL) to Intel Edison A5 (SCL)
Arduino GND to Intel Edison GND
u can see the hardware implementation in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
95/157
e first step is to build a program for Arduino Uno. We define I2C address 0x15. Arduino will sen
dom number to requester on I2C channel.
e create a program for Arduino, called arduino_i2c_write, and write this code.
#include
constbyte SLAVE_ADDRESS =0x15;
intled =13;
byte x;
// source:
// http://forum.arduino.cc/index.php?topic=197633.0
byte randomDigit() {
unsignedlongt =micros();
byte r =(t %10) +1;
for(byte i =1; i
-
7/21/2019 The Hands on Intel Edison Manual Lab
96/157
voidsendData(){
byte data =randomDigit();
Wire.write(data);
Serial.print("send: ");
Serial.println(data,DEC);
}
voidsetup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
Wire.begin(SLAVE_ADDRESS);Wire.onRequest(sendData);
}
voidloop() {
delay(100);
}
this program, we use Wire library, http://arduino.cc/en/reference/wire, to implement I2C on Arduw you compile and deploy it to Arduino board. Then, you can connect your Arduino to Intel Ed
I2C wiring.
e next step is to write a program for Intel Edison using Python. We will read data on I2C channe
th address 0x15. The data will generated by Arduino.
eate a file, called i2c.py, and write the following code.
importtimeimportmraa
i2c =mraa.I2c(1)
i2c.address(0x15) # change it based on I2C on Arduinop
counter =0
whileTrue:
try:
data =i2c.read()
print">>> " +str(data)
time.sleep(1)
counter +=1
ifcounter >10:
break
except(KeyboardInterrupt, SystemExit):
raise
print"done"
http://arduino.cc/en/reference/wire -
7/21/2019 The Hands on Intel Edison Manual Lab
97/157
ve this code and try to run on Intel Edison Terminal.
$ python i2c.py
uccess, you can see the data from I2C channel.
u also can verify on Arduino using Serial Monitor. Make sure your Arduino is connected to PC s
u can see data using Serial Monitor tool.
-
7/21/2019 The Hands on Intel Edison Manual Lab
98/157
5. Intel Edison Development using C/C++
is chapter explains how to work and write program using C/C++ to access Intel Edison I/O fromnux.
1 Getting Started
el IoT distro provides mraa library which can be used for C/C++ development. In this chapter, w
l focus on C development with GCC compiler. If you use C++, you can read this document,
p://iotdk.intel.com/docs/master/mraa/.
e will explore several scenario to illustrate how C work with Intel Edison board. The following isscenario:
GPIO
Analog I/O
UART
SP
I2C/TWI
t's start working with mraa library. We will check mraa library version using mraa_get_version
ite the following code.
#include
#include
#include
intmain(intargc, char**argv)
{ mraa_result_tret;
ret =mraa_set_log_level(LOG_DEBUG);
fprintf(stdout, "Mraa version: %s\n", mraa_get_version());
mraa_deinit();
returnret;
}
ve this code into a file, called testversion.c.
http://iotdk.intel.com/docs/master/mraa/http://iotdk.intel.com/docs/master/mraa/ -
7/21/2019 The Hands on Intel Edison Manual Lab
99/157
w you can compile this file by typing the following command.
$ gcc -lmraa -o testversion testversion.c
en, try to execute.
$ ./testversion
uccess, you can obtain mraa library version.
2 GPIO
this section, we learn how to access GPIO on Intel Edison using C. For illustration, I use 3 LEDs
ich are connected to digital input on the board. Please read section 4.2 for hardware configuratio
access GPIO using C, we must declare header file, gpio.h. The following is a list of steps to acc
IO.
Initialize GPIO by calling mraa_init()Getting mraa_gpio_contextobject by calling mraa_gpio_init()with passing GPIO pin. This
parameter is similiar as digital I/O on Intel Edison. For instance, we connect to digital I/O 10.
Then, we pass 10 value to mraa_gpio_init(10)
We decide I/O direction which is possible as input or output. You can do it by calling
mraa_gpio_dir()
To write value to digital Intel Edison, we can use mraa_gpio_write(). Otherwise, we can use
mraa_gpio_read()
If you finish working with GPIO, you can close it by calling mraa_gpio_close()
-
7/21/2019 The Hands on Intel Edison Manual Lab
100/157
w we can start to write a program. Create a file, called gpiodemo.c, and write this code.
#include
#include
#include
#include
sig_atomic_tvolatileisrunning =1;voidsig_handler(intsignum);
intmain()
{
signal(SIGINT, &sig_handler);
mraa_init();
mraa_gpio_context led1;
mraa_gpio_context led2;
mraa_gpio_context led3;
led1 =mraa_gpio_init(10);
led2 =mraa_gpio_init(9);
led3 =mraa_gpio_init(8);
mraa_gpio_dir(led1, MRAA_GPIO_OUT);
mraa_gpio_dir(led2, MRAA_GPIO_OUT);
mraa_gpio_dir(led3, MRAA_GPIO_OUT);
while(isrunning){
fprintf(stdout, "LED 1\n"); mraa_gpio_write(led1,1);
mraa_gpio_write(led2,0);
mraa_gpio_write(led3,0);
sleep(1);
fprintf(stdout, "LED 2\n");
mraa_gpio_write(led1,0);
mraa_gpio_write(led2,1);
mraa_gpio_write(led3,0);
sleep(1);
fprintf(stdout, "LED 3\n");
mraa_gpio_write(led1,0);
mraa_gpio_write(led2,0);
mraa_gpio_write(led3,1);
sleep(1);
}
// reset all LEDS to 0
mraa_gpio_write(led1,0);
mraa_gpio_write(led2,0);
mraa_gpio_write(led3,0);
-
7/21/2019 The Hands on Intel Edison Manual Lab
101/157
// close all gpio pins
mraa_gpio_close(led1);
mraa_gpio_close(led2);
mraa_gpio_close(led3);
fprintf(stdout, "\nDone\n");
returnMRAA_SUCCESS;
}
voidsig_handler(intsignum)
{
if(signum ==SIGINT)
isrunning =0;
}
ve this code and try to compile.
$ gcc -lmraa -o gpiodemo gpiodemo.c
done, you can execute this program by typing the following command.
$ ./gpiodemo
uccess, you can see the output as below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
102/157
u also can see 3 LEDs are blinking.
3 Analog I/O - Reading Analog Input
this section, we learn how to read analog input on Intel Edison. We use the same problem on
tion 4.3. To read analog input we can use mraa_aio_read(). This function is a part of aio.hfile
e following is the algorithm to read analog input:
Initialize aio mraa library by calling mraa_aio_init()
Set bit value for reading by callingmraa_aio_set_bit()
Read analog input using mraa_aio_read()
Call mraa_aio_close()to release aio object usage
w you can write the program by creating a file, called analog_read.c, and write this code.
#include
#include
#include
#include
sig_atomic_tvolatileisrunning =1;
voidsig_handler(intsignum);
-
7/21/2019 The Hands on Intel Edison Manual Lab
103/157
intmain()
{
signal(SIGINT, &sig_handler);
mraa_aio_context adc_a0;
uint16_tadc_value =0;
adc_a0 =mraa_aio_init(0);
if(adc_a0 ==NULL) {
return1; }
mraa_aio_set_bit(adc_a0,10);
while(isrunning){
adc_value =mraa_aio_read(adc_a0);
fprintf(stdout, "ADC A0 value: %X - %d\n", adc_value, adc_value);
sleep(1);
}
mraa_aio_close(adc_a0);
fprintf(stdout, "\nDone\n");
returnMRAA_SUCCESS;
}
voidsig_handler(intsignum)
{
if(signum ==SIGINT)
isrunning =0;
}
ve this code and try to compile by the following command.
$ gcc -lmraa -o analog_read analog_read.c
n the program.
$ ./analog_read
sample output can be seen in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
104/157
4 UART
this section, we will access Intel Edison UART using C. To access UART, we can implement ter
p://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html. For illustration, we use the s
nario on section 4.4.
eate a file, called uart.c, and write this code.
#include
#include
#include
#include
#include
#include
#include #include
void*handling_uart(void*arg)
{
intlength, value;
unsignedcharbuffer[256];
int*uart0 =(int*)arg;
value =70;
errno =0;
http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html -
7/21/2019 The Hands on Intel Edison Manual Lab
105/157
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
while(1)
{
pthread_testcancel();
sprintf(buffer,"%d",value);
printf("Write to UART: %d\n",value);
fflush(stdout);
// write to UART
length =write((*uart0), buffer, 2); if(length 80)
value =70;
}
printf("\r\n");
}
intmain(void)
{
intuart0 =-1;
pthread_tthread;
intret, status;
charserial_port[] ="/dev/ttyMFD2"; errno =0;
uart0 =open(serial_port, O_RDWR |O_NOCTTY );
if(uart0 ==-1)
{
printf("\nopen() failed with error [%s]\n",strerror(errno));
return-1;
}
// configure UART
// check http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.h
structtermios options;
tcgetattr(uart0, &options);
// set 115200 baud both ways
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
// 8 bits, no parity, no stop bits
options.c_cflag &=~PARENB;
options.c_cflag &=~CSTOPB;
options.c_cflag &=~CSIZE; options.c_cflag |=CS8;
-
7/21/2019 The Hands on Intel Edison Manual Lab
106/157
// inter-character timer unused
options.c_cc[VTIME] =0;
// blocking read until x chars received
options.c_cc[VMIN] =1;
// Canonical mode
options.c_lflag |=ICANON;
// save the serial port settings
tcflush(uart0, TCIFLUSH); tcsetattr(uart0, TCSANOW, &options);
// create a thread for handling data on UART
ret =pthread_create (&thread, NULL, handling_uart, &uart0);
if(ret)
{
printf("\npthread_create() failed with error [%s]\n",strerror(errn
return-1;
}
charc =getchar();
status =pthread_cancel(thread);
if(status)
{
printf("\npthread_cancel() failed with error [%s]\n",strerror(errn
return-1;
}
close(uart0);
return0;
}
is code will write data to UART /dev/ttyMFD2 . We use a thread for asynchronous writing.
w you can compile this file as follows.
$ gcc -pthread -o uart uart.c
u can run the program.
$ ./uart
uccess, you get program output, shown in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
107/157
se PuTTY to connect /dev/ttyMFD2 from computer. The following is output of serial data usingTTY.
5 SPI
e can implement the solution for problem on section 3.7 and 4.5 using C. Basically we can use
aa_spi_write()to write data and get a response on SPI channel.
w you can write the program by creating a file, called spi.c, and write this code.
-
7/21/2019 The Hands on Intel Edison Manual Lab
108/157
#include "mraa.h"
#include
#include
intmain(intargc, char**argv)
{
mraa_init();
mraa_spi_context spi;
spi =mraa_spi_init(5);
unsignedintresponse =0;
uint8_tdata[] ={0x00, 000};
uint8_t*recv;
printf("Reading and Writing SPI\n");
inti;
for(i =10; i
-
7/21/2019 The Hands on Intel Edison Manual Lab
109/157
6 I2C/TWI
this section we build a program as explained on section 4.6. We use Arduino as I2C source. To r
a on I2C channel, we can use mraa_i2c_read().
w you can start by creating a file, called i2c.c, and write this code.
#include
#include
#include
#include
#define I2C_ADDR 0x15 // you can change it
sig_atomic_tvolatileisrunning =1;
voidsig_handler(intsignum);
intmain()
{
signal(SIGINT, &sig_handler);
uint8_t*buff;
mraa_init();
-
7/21/2019 The Hands on Intel Edison Manual Lab
110/157
mraa_i2c_context i2c;
i2c =mraa_i2c_init(1);
intn =0;
mraa_i2c_address(i2c, I2C_ADDR);
while(isrunning){
intlen =mraa_i2c_read(i2c,buff,1);
if(len>0){
fprintf(stdout, "Received: %x\n", buff[0]);
}else{ fprintf(stdout, "no data\n");
}
n++;
if(n>=10){
isrunning =0;
}
sleep(1);
}
mraa_i2c_stop (i2c);
fprintf(stdout, "\nDone\n");
returnMRAA_SUCCESS;
}
voidsig_handler(intsignum)
{
if(signum ==SIGINT)
isrunning =0;
}
planation:
Initialize mraa library by calling mraa_init()
Access I2C using mraa_i2c_init()
Set I2C address by calling mraa_i2c_address()
Read I2C data using mraa_i2c_read()Release all resource usage using mraa_i2c_stop()
ve this code and try to compile.
$ gcc -lmraa -o i2c i2c.c
-
7/21/2019 The Hands on Intel Edison Manual Lab
111/157
en, you can execute this program.
$ ./i2c
uccess, you can get response on Terminal. The following is a sample output.
u can verify this output on Arduino via Serial Monitor.
-
7/21/2019 The Hands on Intel Edison Manual Lab
112/157
6. Intel Edison Development using Node.js
is chapter explains how to work and write program using Node.js to access Intel Edison I/O fromnux.
1 Getting Started
el IoT distro provides mraa library which can be used for Node.js development. In this chapter, w
l focus on Node.js development to access Intel Edison from Linux. We will use mraa library in o
plementation. You can read mraa source code on https://github.com/intel-iot-devkit/mraa.
e will explore several scenario to illustrate how Node.js work with Intel Edison board. The followour lab scenario:
GPIO
Analog I/O
UART
SPI
I2C/TWI
el also provides a tool, called Intel XDK IoT edition, https://software.intel.com/en-us/html5/xdku can use this tool to write JavaScript. To access Intel Edison from Node.js, we can use mraa lib
ich has already installed for you.
u can test mraa version by writing the following code.
varm =require('mraa');
console.log('MRAA Version: ' +m.getVersion());
ve this code into a file, called testversion.js. Now you can execute it.
$ node testversion.js
uccess, you can see mraa version.
https://software.intel.com/en-us/html5/xdk-iothttps://software.intel.com/en-us/html5/xdk-iothttps://github.com/intel-iot-devkit/mraa -
7/21/2019 The Hands on Intel Edison Manual Lab
113/157
xt section we explore several scenario to access Intel Edison using mraa library.
2 GPIO
this section, we learn how to access GPIO on Intel Edison using Node.js. For illustration, we use
me problem on section 5.2. To start to write a program, you can create a file, called gpiodemo.js
ite this code.
varm =require('mraa');
varled1 =newm.Gpio(10);
varled2 =newm.Gpio(9);varled3 =newm.Gpio(8);
led1.dir(m.DIR_OUT);
led2.dir(m.DIR_OUT);
led3.dir(m.DIR_OUT);
varledon =1;
setInterval(function(){
blinkLED();
ledon++;
if(ledon>3) ledon =1;
},1000);
functionblinkLED() {
switch(ledon){
case1:
led1.write(1);
led2.write(0);
led3.write(0);
break;
-
7/21/2019 The Hands on Intel Edison Manual Lab
114/157
case2:
led1.write(0);
led2.write(1);
led3.write(0);
break;
case3:
led1.write(0);
led2.write(0);
led3.write(1);
break;
} console.log("LED " +String(ledon) +" ON");
}
process.on('SIGINT', function() {
led1.write(0);
led2.write(0);
led3.write(0);
console.log("\nDone");
process.exit();
});
planation:
Open GPIO pin using mraa.Gpio()
Set I/O direction via mraa.dir()
To write data to GPIO, we can use mraa.write()
ve this code and try to run.
$ node gpiodemo.js
sample output is shown in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
115/157
3 Analog I/O - Reading Analog Input
this section, we solve a problem on section 5.3 using Node.js. We can use mraa.Aio()to read an
ut from Intel Edison board. Call Aio.read()to read incoming data on analog input pin.
r illustration, create a file, called analog_input.js, and write this code.
varm =require('mraa');
vara0 =newm.Aio(0);a0.setBit(10);
console.log("reading analog input>>>");
setInterval(function(){ readAnalog()
}, 1000);
functionreadAnalog() { varval =a0.read(); console.log(">> Analog A0 value: " +String(val));
}
en, run this program.
$ node analog_input.js
-
7/21/2019 The Hands on Intel Edison Manual Lab
116/157
uccess, you will get analog input value on Terminal.
4 UART
access UART, we can use node-serialport library, https://github.com/voodootikigod/node-serialppe the following command to install node-serialport.
$ npm install serialport
https://github.com/voodootikigod/node-serialport -
7/21/2019 The Hands on Intel Edison Manual Lab
117/157
e use the same scenario on section 5.4. The program will write data to serial port, /dev/ttyMFD2,ery a second.
eate a file, called uart.js, and write this code.
varSerialPort =require("serialport").SerialPort;
varport ="/dev/ttyMFD2";
varserialPort =newSerialPort(port, {
baudrate:115200
},false);
console.log("Open port: " +port);
serialPort.open(function(error) {
if(error) {
console.log('failed to open: '+error);
} else{
// write data to serial port every a second
varcounter =90;
setInterval(function() { serialPort.write(String(counter) +"\r\n", function(err) {
if(err){
console.log('err ' +err);
}else{
console.log('Write data ' +counter);
}
});
counter++;
if(counter>100)
counter =90;
-
7/21/2019 The Hands on Intel Edison Manual Lab
118/157
}, 1000);
}
});
ve this code and try to run.
$ node uart.js
ogram output can be seen in Figure below.
en serial monitor, for instance PuTTY. Navigate to serial port which be connected to /dev/ttyMF
icro USB).
-
7/21/2019 The Hands on Intel Edison Manual Lab
119/157
5 SPI
aa library provides Node.js interface to access SPI on Intel Edison. We can use mraa.Spi()to ge
aa object. Then, we can use Spi.read()to read data on SPI channel.
r testing, we implement a problem on section 3.7, 4.5 and 5.5 using Node.js. Create a file, called
.js, and write this code.
varm =require('mraa');
varspi =newm.Spi(5);varcounter =0;
console.log("Writing and Reading SPI..");
setInterval(function(){
readAnalog()
}, 1000);
functionreadAnalog() {
varrecv =spi.write(String(counter));
console.log(">> SPI sent value: " +String(counter));
console.log(">> SPI received value: " +String(recv));
-
7/21/2019 The Hands on Intel Edison Manual Lab
120/157
counter++;
if(counter>=10)
counter =0;
}
n the program.
$ node spi.js
sample output is shown in Figure below.
6 I2C/TWI
e last demo is to write a program to access I2C on Intel Edison. This is problem based on section
ug in your Arduino I2C to Intel Edison I2C. Then, write the following code.
-
7/21/2019 The Hands on Intel Edison Manual Lab
121/157
varm =require('mraa');
vari2c =newm.I2c(1);
i2c.address(0x15); // change it based on I2C on Arduinop
console.log("Reading I2C..");
setInterval(function(){
readAnalog()
}, 1000);
functionreadAnalog() {
varval =i2c.read();
console.log(">> I2C value: " +String(val));
}
planation:
Open GPIO pin using mraa.I2c()
Set I2C address using i2c.address(0x15). Assume I2C address is 0x15
To write data to GPIO, we can use mraa.write()
ve this code into a file, called i2c.js, and run it.
$ node i2c.js
u can see the sample output in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
122/157
verify the result on Arduino, you can use Serial Monitor from Arduino software.
-
7/21/2019 The Hands on Intel Edison Manual Lab
123/157
7. Bluetooth Low Energy (BLE) and iBeacon
is chapter explains how to work with Bluetooth Low Energy on Intel Edison.
1 Bluetooth Low Energy (BLE)
uetooth low energy or Bluetooth LE is a wireless personal area network technology designed and
rketed by the Bluetooth Special Interest Group aimed at novel applications in the healthcare, fitn
acons, security, and home entertainment industries.
this chapter, we explore how to work with Bluetooth low energy on Intel Edison. By default, Int
ison disables this device. To enable BLE, you can type the following command on Terminal.
$ rfkill unblock bluetooth
2 Pairing BLE Devices
r the first demo, we try to connect our Intel Device to another device via BLE. In this case, I use
xus 7 2013, running Android 5, which will be connected to Intel Edison.
e use bluetoothctl to pair BLE devices. Type the following command.
$ bluetoothctl
en, you will get a prompt, shown in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
124/157
get a list of command, you type help.
you want to know BLE controller in the board, you can use showcommand.
-
7/21/2019 The Hands on Intel Edison Manual Lab
125/157
connect to BLE device, firstly we scan to find BLE devices using command scan on.
ter you get BLE device name, you can use paircommand.
pair D8:50:E6:7E:CB:87
-
7/21/2019 The Hands on Intel Edison Manual Lab
126/157
uccess, you will get notification on BLE device. A sample notification from Nexus 7 2013. Tap
IR.
ter that, Intel Edison will get notification.
-
7/21/2019 The Hands on Intel Edison Manual Lab
127/157
sample output on Android Nexus 7 2013.
-
7/21/2019 The Hands on Intel Edison Manual Lab
128/157
e can use hcitool to check Bluetooth LE devices. Type the following command.
$ hcitool lescan
here is BLE device, hcitool will detect it.
-
7/21/2019 The Hands on Intel Edison Manual Lab
129/157
ter paired and connected, you can communicate among BLE devices.
3 BLE Development and iBeacon
develop BLE program in Intel Edison, you must install bluez25-dev. Firstly, configure your repo
e section 2.12. Then, type these commands.
$ opkg update
$ opkg install bluez5-dev
-
7/21/2019 The Hands on Intel Edison Manual Lab
130/157
ter that, we test our Intel Edison bluetooth for iBeacon using bleno,
ps://github.com/sandeepmistry/bleno, and noble, https://github.com/sandeepmistry/noblelibrari
$ npm install -g async
$ npm install noble
$ npm install bleno
e can run test file, for instance, test-ibeacon.js, from bleno.
$ node node_modules/bleno/test-ibeacon.js
w you can test it using iBeacon app, for instance, I use iBeaconDetector from Google Play store
ns on my Nexus 7 2013 and detects Intel Edison iBeacon. A sample output is shown in Figure be
https://github.com/sandeepmistry/noblehttps://github.com/sandeepmistry/bleno -
7/21/2019 The Hands on Intel Edison Manual Lab
131/157
so test it using iBeacon Scanner on Android app.
-
7/21/2019 The Hands on Intel Edison Manual Lab
132/157
4 Further Reading
learn more BLE programming, you can read BLE resources on books and websites. I'm finishin
w book about Bluetooth Low Energy (BLE) Programming by Example. I hope it will release on
15.
-
7/21/2019 The Hands on Intel Edison Manual Lab
133/157
8. Working with XBee IEEE 802.15.4
is chapter explains how to work with XBee IEEE 802.15.4 on Intel Edison and write program usthon.
1 XBee IEEE 802.15.4
gi International provides XBee products with specific features. You can see product comparison
Bee on this document, http://www.digi.com/pdf/chart_xbee_rf_features.pdf.
this book, we will focus on XBee IEEE 802.15.4. XBee-PRO 802.15.4 modules are embedded
utions providing wireless end-point connectivity to devices. These modules use the IEEE 802.15working protocol for fast point-to-multipoint or peer-to-peer networking. They are designed for
oughput applications requiring low latency and predictable communication timing.
u can read XBee product with IEEE 802.15.4 protocol on this website,
p://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/point-multip
modules/xbee-series1-module. The following is a sample picture of XBee 802.15.4.
http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/point-multipoint-rfmodules/xbee-series1-modulehttp://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/point-multipoint-rfmodules/xbee-series1-modulehttp://www.digi.com/pdf/chart_xbee_rf_features.pdf -
7/21/2019 The Hands on Intel Edison Manual Lab
134/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
135/157
2 Getting Hardware
w to get XBee IEEE 802.15.4 device?
ficially you can buy it from Digi International, http://www.digi.com/howtobuy/. You can buy th
oduct from official distributor, http://www.digi.com/howtobuy/find-a-distributor.
u also can buy these products on the following electronics online store:
Sparkfun, https://www.sparkfun.com/. You can see a list of XBee IEEE 802.15.4 product on
https://www.sparkfun.com/categories/223
Amazon, http://www.amazon.com/or your local Amazon website
Cooking-hacks, http://www.cooking-hacks.com/Watterott electronic, http://www.watterott.com/index.php?page=manufacturers&mnf=22
Exp-tech, http://www.exp-tech.de/index.php?manu=m35_Digi.html
Ebay, http://www.ebay.com/
uggest you to find local electronics store which sells XBee IEEE 802.15.4.
http://www.ebay.com/http://www.exp-tech.de/index.php?manu=m35_Digi.htmlhttp://www.watterott.com/index.php?page=manufacturers&mnf=22http://www.cooking-hacks.com/http://www.amazon.com/https://www.sparkfun.com/categories/223https://www.sparkfun.com/http://www.digi.com/howtobuy/find-a-distributorhttp://www.digi.com/howtobuy/ -
7/21/2019 The Hands on Intel Edison Manual Lab
136/157
3 Connecting XBee IEEE 802.15.4 to Intel Edison
default, you can't connect your XBee module to computer and breadboard directly. You need sh
order to connect to computer or breadboard. The following is a list of sample of XBee shield wh
can connect it via USB.
XBee Explorer USB, https://www.sparkfun.com/products/8687
XBee Explorer Dongle, https://www.sparkfun.com/products/9819
UartSBee V4, http://www.seeedstudio.com/depot/UartSBee-V4-p-688.htmlFoca, http://imall.iteadstudio.com/im120525005.html
e following is a sample of XBee shield with USB.
http://imall.iteadstudio.com/im120525005.htmlhttp://www.seeedstudio.com/depot/UartSBee-V4-p-688.htmlhttps://www.sparkfun.com/products/9819https://www.sparkfun.com/products/8687 -
7/21/2019 The Hands on Intel Edison Manual Lab
137/157
u also can connect it directly from XBee pins so you need XBee regular shield,
ps://www.sparkfun.com/products/11373, or you add additional pins on your shield.
other approach, you can use XBee shield for Ardunio, http://www.cooking-cks.com/communication-shield-xb-bt-rfid. You can buy it in your local store. A sample shield ca
n in Figure below.
http://www.cooking-hacks.com/communication-shield-xb-bt-rfidhttps://www.sparkfun.com/products/11373 -
7/21/2019 The Hands on Intel Edison Manual Lab
138/157
this chapter, I connect my XBee to USB so I need an adapter for Micro USB to USB,
p://www.amazon.com/SANOXY-Micro-USB-OTG-Adapter/dp/B005QX7KYU/, and a cable fo
B to mini USB, http://www.amazon.com/AmazonBasics-USB-Male-Mini-Cable/dp/B00E9IF9R
u can find them on your local/online electronics store.
http://www.amazon.com/AmazonBasics-USB-Male-Mini-Cable/dp/B00E9IF9RI/http://www.amazon.com/SANOXY-Micro-USB-OTG-Adapter/dp/B005QX7KYU/ -
7/21/2019 The Hands on Intel Edison Manual Lab
139/157
w you can connect these items to Intel Edison via USB Host. The following is hardware
plementation, shown in Figure below.
-
7/21/2019 The Hands on Intel Edison Manual Lab
140/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
141/157
$ ls /dev/ttyUSB*
u will see Intel Edison doesn't detect because FTDI driver doesn't install yet. Firstly, you update
ository with unofficial repo, see section 2.12.
w you can install FTDI driver for Intel Edison.
$ opkg update
$ opkg install kernel-module-ftdi-sio
y to check your USB now.
$ ls /dev/ttyUSB*
u will see XBee on USB, for instance, my XBee shows on /dev/ttyUSB0.
-
7/21/2019 The Hands on Intel Edison Manual Lab
142/157
w your XBee Explorer USB is be connected to Intel Edison for Arduino breakout and ready for
iting program.
4 XBee with AT Command
Bee IEEE 802.15.4 provides a communication mechanism through AT command. It can be achiev
opening serial communication to XBee. In this section, we explore how to access XBee IEEE
2.15.4 using Python from Linux on Intel Edison. There are many AT commands for XBee. You c
d these commands on the following document, http://examples.digi.com/wp-
ntent/uploads/2012/07/XBee_802.15.4_AT_Commands.pdf. Each command begins with "AT".
CTU software is useful tool to manage XBee device. Unfortunately, this tool is be provided only
ndows Platform. You can emulate it on Linux using Wine,http://www.winehq.org/. You can
wnload X-CTU software on http://www.digi.com/support/productdetail?pid=3352. After installe
u can run it. The following is a sample of X-CTU application.
http://www.digi.com/support/productdetail?pid=3352http://www.winehq.org/http://examples.digi.com/wp-content/uploads/2012/07/XBee_802.15.4_AT_Commands.pdf -
7/21/2019 The Hands on Intel Edison Manual Lab
143/157
e explore several commands to illustrate how to work with XBee through AT command. See sect
.
5 Demo Chatting Program
e objective of this demo is to illustrate how to work XBee through AT command. In this scenario
ed:
Two XBee IEEE 802.15.4
Two XBee shield (XBee Explorer) with USB connector
-
7/21/2019 The Hands on Intel Edison Manual Lab
144/157
t's start to execute our demo.
5.1 Hardware Configuration
configure hardware for this scenario, we connect XBee 1 to computer and XBee 2 to Intel Ediso
Bee 2 adapter is connected to Intel Edison via USB Host.
-
7/21/2019 The Hands on Intel Edison Manual Lab
145/157
5.2 XBee Configuration
stly, we must configure two XBee so they can communicate each other. The following is XBee
nfiguration.
Bee 1:
PAN ID (ID): 3001
Address (MY): 1
Destination address high (DH): 0
Destination address low (DL): 3
API Enable (AP): 0
Bee 2:
PAN ID (ID): 3001Address (MY): 3
Destination address high (DH): 0
Destination address low (DL): 1
API Enable (AP): 0
te: (XX) is AT command name.
configure these settings, we execute using AT command or via X-CTU. Don't forget to save the
nfigurations to XBee firmware.
-
7/21/2019 The Hands on Intel Edison Manual Lab
146/157
-
7/21/2019 The Hands on Intel Edison Manual Lab
147/157
5.3 Writing Python Program for Intel Edison
Intel Edison board, we create a program to read incoming data from XBee. Create a file, called
ee_reader.py, and write this code.
importserial
importtime
port ='/dev/ttyUSB0'
baudrate =9600
-
7/21/2019 The Hands on Intel Edison Manual Lab
148/157
print'open ' +port
xbee =serial.Serial(port, baudrate)
print'waiting incoming message...'
whileTrue:
try:
out =''
whilexbee.inWaiting() >0:
out +=xbee.read(1)
ifout !='': printout
time.sleep(1)
except(KeyboardInterrupt, SystemExit):
xbee.close()
raise
ve this code.
5.4 Testing
w you can execute Python program on Intel Edison Terminal.
$ python xbee_reader.py
computer, we use a serial application. For serial application, I used CoolTerm. You can downlo
olTerm application on http://freeware.the-meiers.org/.
http://freeware.the-meiers.org/ -
7/21/2019 The Hands on Intel Edison Manual Lab
149/157
w to use and connect to XBee?
stly, we connect XBee to computer via USB. On CoolTerm, click menu Connection -> Options.
u obtain this dialog.
-
7/21/2019 The Hands on Intel Edison Manual Lab
150/157
l Port of your XBee, Baudrate 9600, Data Bits 8, Parity none and Stop Bits 1. If you can't find y
Bee port, you can re-scan by clicking Re-Scan Serial Portsbutton.
ter that, click Terminal on left menu side. Checked Local Echo.
-
7/21/2019 The Hands on Intel Edison Manual Lab
151/157
done, click OKbutton.
w you can write message on CoolTerm.
-
7/21/2019 The Hands on Intel Edison Manual Lab
152/157
thon program will receive this message. A sample output is shown in Figure below.
6 XBee with API Mode
Bee can be programmed via API Mode. To achieve this, you must configure our XBee with API
ng X-CTU.
-
7/21/2019 The Hands on Intel Edison Manual Lab
153/157
e of Python implementation for XBee with API Mode is Python XBee,
ps://pypi.python.org/pypi/XBee. You can find Python XBee source code on Source:ps://code.google.com/p/python-xbee/. Download and install this library into your computer.
wnload this library and store to Intel Edison. After that, you can install it.
$ wget --no-check-certificate https://pypi.python.org/packages/source/X/XBe
$ tar -xvzf XBee-2.1.0.tar.gz
$ cd XBee-2.1.0
$ python setup.py install
https://code.google.com/p/python-xbee/https://pypi.python.org/pypi/XBee -
7/21/2019 The Hands on Intel Edison Manual Lab
154/157
r illustration, we configure our previous demo, section 9.4, using API Mode. Please configure th
th API enable W/PPP. Now on Intel Edison board side, we write a program to access XBee. Crea
e, called at_command_demo.py, and write this code.
fromxbeeimportXBee
importserial
port ='/dev/ttyUSB0'
baudrate =9600
print'open ' +port
ser =serial.Serial(port, baudrate)xbee =XBee(ser, escaped=True)
# VR command
xbee.send('at', frame_id='A', command='VR')
response =xbee.wait_read_frame()
printresponse
# ID command
xbee.send('at', frame_id='B', command='ID')
response =xbee.wait_read_frame()
printresponse
# MY command
xbee.send('at', frame_id='C', command='MY')
response =xbee.wait_read_frame()
printresponse
xbee.halt()
ser.close()
-
7/21/2019 The Hands on Intel Edison Manual Lab
155/157
ve this code. Try to execute this code.
$ python at_command_demo.py
uccess, you can see response from XBee.
7 Further Reading
write a book about XBee IEEE 802.15.4 Programming. This book helps you how to get started w
EE 802.15.4 programming through XBee device. All sample codes were written in Python to
ustrate how to work with IEEE 802.15.4. If you're interest with this book, you can visit on my bl
p://blog.aguskurniawan.net/post/XBee-IEEE-802154-Programming.aspx.
http://blog.aguskurniawan.net/post/XBee-IEEE-802154-Programming.aspx -
7/21/2019 The Hands on Intel Edison Manual Lab
156/157
Source Code
urce code can be downloaded on http://www.aguskurniawan.net/book/edisoncode.zip.
http://www.aguskurniawan.net/book/edisoncode.zip -
7/21/2019 The Hands on Intel Edison Manual Lab
157/157
Contact
you have question related to this book, please contact me at [email protected] . My blog:p://blog.aguskurniawan.net.
http://blog.aguskurniawan.net/