hands on embedded linux with beaglebone black
DESCRIPTION
Slide from my talk at Linux Day 2013 in Avellino (Italy). Getting started with BeagleBone Black and Python library by AdafruitTRANSCRIPT
HANDS ON EMBEDDED LINUX WITH BEAGLEBONE BLACK Daniele Costarella
Ex Carcere Borbonico (Avellino) – October 25th, 2013
What is BeagleBone Black?
October 25th, 2013 Linux Day 2013 2
BeagleBone Black is a $45 MSRP community-supported development platform for developers and hobbysts. Boot Linux in under 10 seconds and get started on development in less than 5 minutes with just a single USB cable.
Hardware
3
Processor: AM335x 1GHz ARM® Cortex-A8 • 512MB DD3 RAM • 2GB 8-bit eMMC on-board flash storage • 3D graphics accelerator
Connectivity • USB client for power and communications • USB host • Ethernet • HDMI • 2x46 pin headers
Software Compatibility • Ångström Linux • Android • Cloud9 IDE on Node.js w/ BoneScript Library and more…
October 25th, 2013 Linux Day 2013
Embedded Linux for Makers • Embedded Linux System blur the definition between
computer and device • Powerful tools in the hands of “regular” people, not just those who
design electronics for a living • More powerful and capable than a “simple” microcontroller like
ATMEGA 328 (Arduino) • Perfect for those projects too complex to be executed on a MCU
4 October 25th, 2013 Linux Day 2013
Advantages?
5
Filesystem
Timekeeping Built-in
networking
Multitasking Linux
software
USB Size
Community
Remote access
October 25th, 2013 Linux Day 2013
BeagleBone Black: Ready to use
6 October 25th, 2013 Linux Day 2013
Browsing Your BeagleBone • Firstly, just test that the
connection is active by trying to connect to the BBB with a browser.
• Connect to the URL http://192.168.7.2
• You should see a helful introductory web page served by the BeagleBoard itself
7 October 25th, 2013 Linux Day 2013
Go with SSH • On Linux or Mac simply open a terminal window and
type the following command:
8
ssh 192.168.7.2 –l root
October 25th, 2013 Linux Day 2013
Using Python Using GPIO, PWM and more with Python! Available functionality: • 7 Analog pins • 65 Digital Pins at 3.3V • 2xI2C • 2xSPI • 2x CAN Bus • 4 Timers • 4x UART • 8x PWM • A/D Converter
9 October 25th, 2013 Linux Day 2013
10
Expansion Headers
Each digital I/O pin has 8 different modes that can be selected, including GPIO
October 25th, 2013 Linux Day 2013
Install Adafruit_BBIO Commands needed to install the library. Access via SSH and execute (on Angstrom Linux):
11
opkg update && opkg install python-pip python-setuptools python-smbus pip install Adafruit_BBIO
You can test your installation simply trying to load one of the modules:
import Adafruit_BBIO.GPIO as GPIO; print GPIO #you should see this or similar: <module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>
October 25th, 2013 Linux Day 2013
Using the library Open a Python console and import the library. Example:
12
import Adafruit_BBIO.GPIO as GPIO
You can access the channels by either referencing the pin “key” or the name.
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_10", GPIO.OUT)
GPIO.output("P8_10", GPIO.HIGH)
GPIO.setup("P8_14", GPIO.IN) if GPIO.input("P8_14"): print("HIGH") else: print("LOW")
October 25th, 2013 Linux Day 2013
LED blinking: wiring Positive to pin 10 and negative to GND
13 October 25th, 2013 Linux Day 2013
LED blinking: writing the program Back to the Linux/Mac prompt and create the executable file
14
# nano blink.py
Write the simple program:
import Adafruit_BBIO.GPIO as GPIO import time GPIO.setup("P8_10", GPIO.OUT) while True: GPIO.output("P8_10", GPIO.HIGH) time.sleep(0.5) GPIO.output("P8_10", GPIO.LOW) time.sleep(0.5)
October 25th, 2013 Linux Day 2013
LED blinking: writing the program …and execute it
15
# python blink.py
Easy!
October 25th, 2013 Linux Day 2013
Measuring Temperature: wiring
16 October 25th, 2013 Linux Day 2013
Measuring Temperature …and write the program
17
# nano temperature.py
Write the simple program: import Adafruit_BBIO.ADC as ADC import time sensor_pin = 'P9_40' ADC.setup() while True: reading = ADC.read(sensor_pin) millivolts = reading * 1800 # 1.8V reference = 1800 mV temp_c = (millivolts - 500) / 10 temp_f = (temp_c * 9/5) + 32 print('mv=%d C=%d F=%d' % (millivolts, temp_c, temp_f)) time.sleep(1)
October 25th, 2013 Linux Day 2013
Using a Push Button
Energy Harvesting Demoboard 18 October 25th, 2013
Writing the code …and write the program
19
# nano button.py
Write the simple program: import Adafruit_BBIO.GPIO as GPIO import time GPIO.setup("P8_12", GPIO.IN) old_switch_state = 0 while True: new_switch_state = GPIO.input("P8_12") if new_switch_state == 1 and old_switch_state == 0 : print('Do not press this button again!') time.sleep(0.1) old_switch_state = new_switch_state
October 25th, 2013 Linux Day 2013
Fade Effect with PWM: wiring
20 October 25th, 2013 Linux Day 2013
PWM?
21 October 25th, 2013 Linux Day 2013
Fade Effect with PWM: code …and write the program
22
# nano led_fade.py
import Adafruit_BBIO.PWM as PWM import time led_pin = "P9_14" PWM.start(led_pin, 0) while True: for i in range(0, 100): PWM.set_duty_cycle(led_pin, i) time.sleep(0.05) for i in range(0, 100): PWM.set_duty_cycle(led_pin, 100-i) time.sleep(0.05)
October 25th, 2013 Linux Day 2013
DEMO
Recommended readings
24
Getting Started with BeagleBone Black Make By Matt Richardson
October 25th, 2013 Linux Day 2013
Building Embedded Linux System O’Reilly By Karim Yaghmour, Jon Masters, Gilad Ben Yassef, and Philippe Gerum
Embedded Linux System Design and Development By P. Raghavan, A. Lad, S. Neelakandan, Auerbach
Thank you
25
@dcostarella
danielecostarella.com
Linux Day 2013 October 25th, 2013