Fading a RGB LED on BeagleBone Black

Similar documents
Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

CamJam EduKit Robotics Worksheet Six Distance Sensor camjam.me/edukit

Adafruit 16-Channel Servo Driver with Arduino

Arduino Workshop 01. AD32600 Physical Computing Prof. Fabian Winkler Fall 2014

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

LEVEL A: SCOPE AND SEQUENCE

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

CodeBug I2C Tether Documentation

INA169 Breakout Board Hookup Guide

Adafruit SGP30 TVOC/eCO2 Gas Sensor

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Adafruit 16-Channel Servo Driver with Arduino

OM29110 NFC's SBC Interface Boards User Manual. Rev May

Pololu DRV8835 Dual Motor Driver Kit for Raspberry Pi B+

Adafruit 16 Channel Servo Driver with Raspberry Pi

Lab 2: Blinkie Lab. Objectives. Materials. Theory

PWM Guide: Zen Buzzer and Tri-Colour LEDs For Linux Kernel 4.1+ Table of Contents. by Brian Fraser Last update: November 17, 2017

LEDs and Sensors Part 2: Analog to Digital

Project Kit Project Guide

Gravity: 12-Bit I2C DAC Module SKU: DFR0552

Motor Driver HAT User Manual

Lab 12: Timing sequencer (Version 1.3)

Adafruit 16-channel PWM/Servo Shield

MAKEVMA502 BASIC DIY KIT WITH ATMEGA2560 FOR ARDUINO USER MANUAL

Smart Circuits: Lights On!

Moto1. 28BYJ-48 Stepper Motor. Ausgabe Copyright by Joy-IT 1

Adafruit 8-Channel PWM or Servo FeatherWing

J. La Favre Controlling Servos with Raspberry Pi November 27, 2017

ZIO Python API. Tutorial. 1.1, May 2009

CamJam EduKit Robotics Worksheet Nine Obstacle Avoidance camjam.me/edukit

Adafruit 16-Channel Servo Driver with Arduino

가치창조기술. Motors need a lot of energy, especially cheap motors since they're less efficient.

Electronic Components

Internet of Things Student STEM Project Jackson High School. Lesson 3: Arduino Solar Tracker

Demon Pumpkin APPROXIMATE TIME (EXCLUDING PREPARATION WORK): 1 HOUR PREREQUISITES: PART LIST:

RGB LED Strips. Created by lady ada. Last updated on :21:20 PM UTC

ZX Distance and Gesture Sensor Hookup Guide

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

introduction to Digital Electronics Install the Arduino IDE on your laptop if you haven t already!

Welcome Show how to create disco lighting and control multi-coloured NeoPixels using a Raspberry Pi.

Pololu Dual G2 High-Power Motor Driver for Raspberry Pi

Chroma. Bluetooth Servo Board

Arduino Lesson 1. Blink. Created by Simon Monk

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

Adafruit 16-channel PWM/Servo Shield

Chroma Servo Board v3 for Raspberry Pi. (Firmware 0.1 and 0.2)

RGB Driver click. PID: MIKROE 3078 Weight: 28 g

Getting Started with Blinkt!

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

POLOLU DUAL MC33926 MOTOR DRIVER FOR RASPBERRY PI (ASSEMBLED) USER S GUIDE

Lab 4 Rev. 1 Open Lab Due COB Friday April 6, 2018

Congratulations on your purchase of the SparkFun Arduino ProtoShield Kit!

Milli Developer Kit Reference Application Published on Silver Spring Networks STAGE (

Guide to LED and Hobby Lighting Projects Documentation

Grove - Collision Sensor

02 Digital Input and Output

Project Final Report: Directional Remote Control

USBLMC_CUH_ IPG_V1(4) IPG Board

Lab 2.4 Arduinos, Resistors, and Circuits

LED + Servo 2 devices, 1 Arduino

Figure 1. CheapBot Smart Proximity Detector

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

THE INPUTS ON THE ARDUINO READ VOLTAGE. ALL INPUTS NEED TO BE THOUGHT OF IN TERMS OF VOLTAGE DIFFERENTIALS.

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

Pi-Cars Factory Tool Kit

Class #25: Digital Electronics and Software Python2.7-Based Control and Data Acquisition

EFX IO84 Input/Output Module

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

16X PWM LED Fader v1.1 Specifications: Available at CuriousInventor.com

Patton Robotics, LLC.

Assembling the board. Getting started with Enviro phat

Pi Servo Hat Hookup Guide

APDS-9960 RGB and Gesture Sensor Hookup Guide

MAX11300PMB1 Peripheral Module and Munich (USB2PMB1) Adapter Board Quick Start Guide

ScaleRCHelis.com Light Controller Users Manual

Embedded Control. Week 3 (7/13/11)

9DoF Sensor Stick Hookup Guide

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Microcontrollers and Interfacing

µpad: Proto Base Manual

I2C Demonstration Board LED Dimmers and Blinkers PCA9531 and PCA9551

Aim: To learn the resistor color codes and building a circuit on a BreadBoard. Equipment required: Resistances, millimeter, power supply

LaserPING Rangefinder Module (#28041)

Workshops Elisava Introduction to programming and electronics (Scratch & Arduino)

Adafruit PCA9685 Library Documentation

INA3221 Breakout Board

DuoDrive Nixie Bargraph Kit

Arduino Intermediate Projects

mclr boot 3R GND stat chg pwr GND 3.3V GND 5V GND VIN 5-15V SIKIO GUIDE Your guide to the SparkFun Inventor s Kit for IOIO-OTG

Product overview. Features. Product specifications. Order codes. 1kΩ Resistance Output Module

CMSC838. Tangible Interactive Assistant Professor Computer Science. Week 11 Lecture 20 April 9, 2015 Motors

DEMO CIRCUIT 976 LT3476EUHF. Quadruple High Power LED Driver in Buck Mode DESCRIPTION. PERFORMANCE SUMMARY Specifications are at TA = 25 C

Graphical Control Panel User Manual

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

RAPID PROTOTYPING OF CONTROL SYSTEMS FROM ELECTROMAGNETIC TRANSIENT SIMULATOR PROGRAM

USBLMC_CUH_DIGIT_V1(2)_EN. Digital Board

Embedded Control. Week 1 (6/29/11)

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

La Malinette is an open source project by Reso-nance Numérique Programming Interactivity Kit

I2C Encoder. HW v1.2

Transcription:

Fading a RGB LED on BeagleBone Black Created by Simon Monk Last updated on 2018-08-22 03:36:28 PM UTC

Guide Contents Guide Contents Overview You will need Installing the Python Library Wiring Wiring (Common Cathode LED) Wiring (Common Anode LED) The Python Console Writing a Program PWM Next Steps 2 3 4 5 6 7 8 9 10 13 14 Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 2 of 14

Overview In this tutorial, you will learn how to control the color of an RGB LED using a BeagleBone Black (BBB). Because the BBB runs Linux, there are many ways in which it can be programmed. In this tutorial we show how to control the power output of a GPIO pin and hence control the color of an RGB LED using Python. The tutorial uses a technique called PWM (Pulse WIdth Modulation) to vary the brightness of each color channel between 0 and 100. Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 3 of 14

You will need To make the project described in this tutorial, you will need the following: BeagleBone Black Diffused 10mm RGB LED common cathode or common anode 3 x appox. 470Ω resistors - you can use 220Ω to 1KΩ Half-sized Breadboard Male to male jumper leads Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 4 of 14

Installing the Python Library This tutorial uses Ångström Linux, the operating system that comes pre-installed on the BBB. Follow the instructions here, to install the Python IO BBIO library. http://learn.adafruit.com/setting-up-io-python-libraryon-beaglebone-black (https://adafru.it/cgh) Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 5 of 14

Wiring This tutorial is compatible with both common cathode and common anode LEDs. Common anode LEDs have the positive connections of the red, green and blue LEDs connected together to one lead (the longest lead). A common cathode LED has the negative connections connected together (again, the longest lead). Select the next step according to the type of RGB LED that you have. Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 6 of 14

Wiring (Common Cathode LED) Wire up the breadboard using the header leads as shown below. Push the LED leads into the breadboard, with the longest (common negative) lead on the second row of the breadboard. It does not matter which way around the resistors go. The top two connections on the BBB expansion header we are using (P8) are both GND. The three outputs to control the brightness of the red, green and blue channels are connected to sockets P8_13, P8_19 and P9_14 of the BBB. The pins are numbered left to right, 1, 2 then on the next row down 3,4 etc. You can also use the pin P9_16 for PWM output. You can find out about all the pins available on the P8 and P9 connecters down each side of the BBB here: http://stuffwemade.net/hwio/beaglebone-pin-reference/ (https://adafru.it/cgi) Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 7 of 14

Wiring (Common Anode LED) Wire up the breadboard using the header leads as shown below. Push the LED leads into the breadboard, with the longest (common positive) lead on the second row of the breadboard. It does not matter which way around the resistors go. The common anode of the LED is connected to 3.3V. The three outputs to control the brightness of the red, green and blue channels are connected to sockets P8_13, P8_19 and P9_14 of the BBB. The pins are numbered left to right, 1, 2 then on the next row down 3,4 etc. You can also use the pin P9_16 for PWM output. You can find out about all the pins available on the P8 and P9 connecters down each side of the BBB here: http://stuffwemade.net/hwio/beaglebone-pin-reference/ (https://adafru.it/cgi) Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 8 of 14

The Python Console Before writing a Python program to control an LED, you can try some experiments from the Python console to control the LED's color and make sure that everything is working. To launch the Python Console type: # python Python 2.7.3 (default, Apr 3 2013, 21:37:23) [GCC 4.7.3 20130205 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> First, we need to import the library, in particular its PWM feature that will allow us to control the brightness of the three color channels. so enter the command: >>> import Adafruit_BBIO.PWM as PWM To turn on the red component of the LED type: >>> PWM.start("P8_13", 0) Next turn on the Green by doing: >>> PWM.start("P8_19", 0) The LED should now look yellow / orange. Finally lets turn on the blue channel using: >>> PWM.start("P9_14", 0) The LED should now be whitish in color as all three color channels are at full brightness. Lets now turn all the LEDs off again by sending the following commands: >>> PWM.stop("P8_13") >>> PWM.stop("P8_19") >>> PWM.stop("P9_14") Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 9 of 14

Writing a Program To make the LED cycle through a range of colors, we can write a short program. First, exit the Python console by typing: >>> exit() This should take you back to the Linux prompt. Enter the following command to create a new files called fade.py nano fade.py Now paste the code below into the editor window. import Adafruit_BBIO.PWM as PWM import time red = "P8_13" green = "P8_19" blue = "P9_14" PWM.start(red, 0) PWM.start(blue, 0) PWM.start(green, 0) def fade(colora, colorb, ignore_color): PWM.set_duty_cycle(ignore_color, 100) for i in range(0, 100): PWM.set_duty_cycle(colorA, i) PWM.set_duty_cycle(colorB, 100-i) time.sleep(0.05) while True: fade(red, green, blue) fade(green, blue, red) fade(blue, red, green) Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 10 of 14

Save and exit the editor using CTRL-x and the Y to confirm. To start the program, enter the command: $ python fade.py When you want to stop the program, use CTRL-c. You will notice that the LED will remain frozen in its last color. Since we are not stopping the PWM channels, they will run in the background. The program fades colors in pairs. First from red to green, then from green to blue and finally from blue to red, before continuing the cycle again. The set_duty_cycle changes the brightness of the led color. In the Adafruit_BBIO.PWM library, brightest is 0 and 100 means the LED for that color is off. The program above assumes that you are using a common cathode LED. If you are using a common anode LED, then change these lines: PWM.set_duty_cycle(ignore_color, 100) PWM.set_duty_cycle(colorA, i) PWM.set_duty_cycle(colorB, 100-i) to look like this: Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 11 of 14

PWM.set_duty_cycle(ignore_color, 0) PWM.set_duty_cycle(colorA, 100-i) PWM.set_duty_cycle(colorB, i) Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 12 of 14

PWM Pulse Width Modulation (or PWM) is a technique for controlling power. We also use it here to control the brightness of each of the LEDs. The diagram below shows the signal from one of the GPIO pins on the BBB. Every 1/5000 of a second, the PWM output will produce a pulse from 3.3V down to 0V. The length of this pulse is controlled by the 'set_duty_cycle' function. If the output is high for 90% of the time then the load will get 90% of the power delivered to it. We cannot see the LEDs turning on and off at that speed, so to us, it just looks like the brightness is different. Adafruit Industries https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black Page 13 of 14

Next Steps You could try using analog readings, say from light or temperature to control the color of the LED. Perhaps, just set the red channel to 50% duty cycle and use a temperature reading to control the blue channel and the light reading to control the duty cycle of the green channel. You can find tutorials for sensing temperature and light here (https://adafru.it/cis) and here (https://adafru.it/cit). About the Author. As well as contributing lots of tutorials about Raspberry Pi, Arduino and now BeagleBone Black, Simon Monk writes books about open source hardware. You will find his books for sale here (https://adafru.it/cah) at Adafruit. Adafruit Industries Last Updated: 2018-08-22 03:36:22 PM UTC Page 14 of 14