Transcript
Page 1: Hands On Embedded Linux with BeagleBone Black

HANDS ON EMBEDDED LINUX WITH BEAGLEBONE BLACK Daniele Costarella

Ex Carcere Borbonico (Avellino) – October 25th, 2013

Page 2: Hands On Embedded Linux with BeagleBone Black

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.

Page 3: Hands On Embedded Linux with BeagleBone Black

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

Page 4: Hands On Embedded Linux with BeagleBone Black

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

Page 5: Hands On Embedded Linux with BeagleBone Black

Advantages?

5

Filesystem

Timekeeping Built-in

networking

Multitasking Linux

software

USB Size

Community

Remote access

October 25th, 2013 Linux Day 2013

Page 6: Hands On Embedded Linux with BeagleBone Black

BeagleBone Black: Ready to use

6 October 25th, 2013 Linux Day 2013

Page 7: Hands On Embedded Linux with BeagleBone Black

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

Page 8: Hands On Embedded Linux with BeagleBone Black

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

Page 9: Hands On Embedded Linux with BeagleBone Black

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

Page 10: Hands On Embedded Linux with BeagleBone Black

10

Expansion Headers

Each digital I/O pin has 8 different modes that can be selected, including GPIO

October 25th, 2013 Linux Day 2013

Page 11: Hands On Embedded Linux with BeagleBone Black

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

Page 12: Hands On Embedded Linux with BeagleBone Black

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

Page 13: Hands On Embedded Linux with BeagleBone Black

LED blinking: wiring Positive to pin 10 and negative to GND

13 October 25th, 2013 Linux Day 2013

Page 14: Hands On Embedded Linux with BeagleBone Black

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

Page 15: Hands On Embedded Linux with BeagleBone Black

LED blinking: writing the program …and execute it

15

# python blink.py

Easy!

October 25th, 2013 Linux Day 2013

Page 16: Hands On Embedded Linux with BeagleBone Black

Measuring Temperature: wiring

16 October 25th, 2013 Linux Day 2013

Page 17: Hands On Embedded Linux with BeagleBone Black

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

Page 18: Hands On Embedded Linux with BeagleBone Black

Using a Push Button

Energy Harvesting Demoboard 18 October 25th, 2013

Page 19: Hands On Embedded Linux with BeagleBone Black

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

Page 20: Hands On Embedded Linux with BeagleBone Black

Fade Effect with PWM: wiring

20 October 25th, 2013 Linux Day 2013

Page 21: Hands On Embedded Linux with BeagleBone Black

PWM?

21 October 25th, 2013 Linux Day 2013

Page 22: Hands On Embedded Linux with BeagleBone Black

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

Page 23: Hands On Embedded Linux with BeagleBone Black

DEMO

Page 24: Hands On Embedded Linux with BeagleBone Black

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

Page 25: Hands On Embedded Linux with BeagleBone Black

Thank you

25

@dcostarella

danielecostarella.com

Linux Day 2013 October 25th, 2013


Top Related