Matrix and 7-Segment LED Backpack with the Raspberry Pi



Similar documents
Adding a Real Time Clock to Raspberry Pi

Adafruit NFC/RFID on Raspberry Pi

Adafruit NFC/RFID on Raspberry Pi. Created by Kevin Townsend

Adafruit LED Backpacks

DIY Pocket LED Gamer - Tiny Tetris!

Drive a 16x2 LCD with the Raspberry Pi

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

Tiny Arduino Music Visualizer

TSL2561 Luminosity Sensor

Bob Rathbone Computer Consultancy

Character LCDs. Created by Ladyada. Last updated on :45:29 PM EDT

Preparing Raspberry Pi

2.3" Monochrome 128x32 OLED Display Module

Setting up a Raspberry Pi as a WiFi access point

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Beginner s Guide to the PI MATRIX. by Bruce E. Hall, W8BH 1) INTRODUCTION

Playing sounds and using buttons with Raspberry Pi

Raspberry Pi radio player with touchscreen

Setting up IO Python Library on BeagleBone Black

1.5" & 2.1" Monochrome 128x64 OLED Display Module

Monitor Your Home With the Raspberry Pi B+

Introducing the Adafruit Bluefruit LE Sniffer

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

Arduino Lesson 0. Getting Started

Arduino Lesson 14. Servo Motors

Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing

A REST API for Arduino & the CC3000 WiFi Chip

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Raspberry Pi Adding a Real Time Clock (RTC)

USB + Serial RGB Backlight Character LCD Backpack

Adafruit's Raspberry Pi Lesson 7. Remote Control with VNC

CAN-Bus Shield Hookup Guide

Raspberry Pi Kernel-o-Matic

8 by 8 dot matrix LED displays with Cascadable Serial driver B32CDM8 B48CDM8 B64CDM8 General Description

DS1307 Real Time Clock Breakout Board Kit

TEECES DOME LIGHTING SYSTEMS

Adafruit's Raspberry Pi Lesson 1. Preparing an SD Card for your Raspberry Pi

AR1100 Resistive Touch Screen Controller Guide

UniPi technical documentation REV 1.1

Adafruit's Raspberry Pi Lesson 3. Network Setup

Designing VM2 Application Boards

5inch HDMI LCD User Manual

1.8" TFT Display Breakout and Shield

Arduino Lesson 13. DC Motors. Created by Simon Monk

Controlling a Dot Matrix LED Display with a Microcontroller

Hardware Connections between Arduino and IMU Nori Wilkins Apr. 5, 2013

How To Connect A Raspberry Pi To The Internet On A Microsoft Moonstone 2 (Microsoft) Microsoft Powerbook 2 (Powerbook 2) (Powerboard 2) And Powerbook 3 (Powerstation 2)

PiFace Control & Display

Adafruit's Raspberry Pi Lesson 6. Using SSH

Network Interface Failover using FONA

Adafruit Si4713 FM Radio Transmitter with RDS/RDBS Support

Wireless Security Camera with the Arduino Yun

MCP4725 Digital to Analog Converter Hookup Guide

Arduino Lesson 4. Eight LEDs and a Shift Register

Install bluez on the Raspberry Pi

BeagleBone Black: Installing Operating Systems

Arduino Lesson 5. The Serial Monitor

SSH to BeagleBone Black over USB

Creating a Project with PSoC Designer

Arduino Lesson 1. Blink

Upgrading from Windows XP to Windows 7

Arduino Lesson 17. Sending Movement Detector

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

Adafruit Proto Shield for Arduino

7" Portable HDMI Monitor

Arduino Lesson 9. Sensing Light

Real Time Clock USB Evaluation Board V3.0

RGB LED Strips. Created by lady ada. Last updated on :00:18 PM EST

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

Bluefruit LE Python Library

All About Arduino Libraries

2013 G Miller. 3 Axis Brushless Gimbal Controller Manual

Battery Power for LED Pixels and Strips. Created by Phillip Burgess

Strato Pi Hardware Guide

Accessing I2C devices with Digi Embedded Linux 5.2 example on Digi Connect ME 9210

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

PN532 NFC RFID Module User Guide

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

7/Basic Input and Output

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

Adafruit ATWINC1500 WiFi Breakout

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

Copyright 2012 by Fen Logic Ltd. All rights reserved.

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

Getting Started with the AllJoyn Lighting Service Framework 14.12

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

E-Blocks Easy Internet Bundle

Upgrading from Windows XP to Windows 7

HL1606. HL1606 is a LED driver IC with SPI controlled. We can get complex mode changes by fewer data. No. Name Description No.

Set up and Blink - Simulink with Arduino

MAX5417L Evaluation Kit/Evaluation System

Qt on Raspberry Pi. Jeff Tranter Integrated Computer Solutions (ICS) Qt Developer Days

E-Loader Operation Manual

Transcription:

Matrix and 7-Segment LED Backpack with the Raspberry Pi Created by Kevin Townsend Last updated on 2014-07-09 02:30:10 PM EDT

Guide Contents Guide Contents Overview What You'll Need Related Information Configuring your Pi for I2C Hooking Everything Up Using the Adafruit Library Downloading the Code from Github Testing the Library Class Summary Adafruit_LEDBackpack Adafruit_7Segment Adafruit_8x8.py Examples 2 3 3 3 4 6 8 8 8 10 10 10 11 11 Page 2 of 12

Overview While we already have a great tutorial (http://adafru.it/aov) and Arduino library (http://adafru.it/ali) for our handy and easy to use LED backpacks, if you're wondering how you can make use of backpack-enabled LED displays on the Pi, this guide will help you get started! What You'll Need 1. A Raspberry Pi 2. A Pi Cobbler (http://adafru.it/914) to make it easy connecting things up 3. One of our many 8x8 (http://adafru.it/alg) or 4-Digit 7-Segment (http://adafru.it/alh) backpack-enabled displays Related Information If you're looking for help on how to assemble one of our backpack-enabled LED displays, have a look at our earlier guide, Adafruit LED Backpacks (http://adafru.it/aov). It contains a lot of complimentary information on these displays, including step by step soldering and assembly instructions. Page 3 of 12

Configuring your Pi for I2C The Holtek HT16K33 (http://adafru.it/amy) chip used in all of our backpacks communicates using the common I2C bus. Linux and the Pi both have native support for I2C, but you'll need to run through a couple quick steps from the console before you can use it in Python. If you are running Occidentalis and are familiar with Terminal commands, then the description below will be sufficient. If not, then to learn more about how to setup I2C with either Raspbian or Occidentalis, then take a minor diversion to this Adafruit Tutorial: http://learn.adafruit.com/adafruits-raspberrypi-lesson-4-gpio-setup/configuring-i2c (http://adafru.it/ati) sudo apt-get install python-smbus sudo apt-get install i2c-tools i2c-tools isn't strictly required, but it's a useful package since you can use it to scan for any I2C or SMBus devices connected to your board. If you know something is connected, but you don't know it's 7-bit I2C address, this library has a great little tool to help you find it: sudo i2cdetect -y 1 This will search /dev/i2c-0 for all address, and if a Holtek HT16K33 breakout is properly connected and it's set to it's default address it should show up as follows (the exact address will vary depending on whether or not you have any of the address solder jumpers set). If you happen to have one of the original first batch of Raspberry Pis, you will need to change the 1 to a 0 in the command above. Page 4 of 12

Once both of these packages have been installed, you have everything you need to get started accessing I2C and SMBus devices in Python. Page 5 of 12

Hooking Everything Up The LED backpack displays are wonderfully easy to connect to the Pi. Both the 8x8 pixel and 4-character 7-segment displays are connected the same way, with two digital pins for I2C (SDA and SCL) and two power pins (VCC and GND), as follows. If you're using a red, yellow or green backpack, you can power the backpack from 3.3V which will keep the I2C levels at 3.3V. If you have a blue or white backpack, the LEDs will be dim if powered from 3.3V. If you want them a little brighter, connect the VCC pin of the backpack to 5V. There are 10K pullups on the backpack to 5V. As long as the backpack is the only i2c device on the i2c bus with pullups to 5V this is perfectly safe for the Pi. If you have 2 or more 5V i2c devices, the 5V pullups may 'overpower' the Pi's strong 3.3v pullups, in this case you'll want to use a proper level shifter: https://www.adafruit.co m/pro ducts/757 (http://adafru.it/757) Page 6 of 12

Page 7 of 12

Using the Adafruit Library The Python code to work with Adafruit's LED Backpacks on the Pi is available on Github at https://github.com/adafruit/adafruit-raspberry-pi-python-code (http://adafru.it/aog) This code should be a good starting point to understanding how you can access SMBus/I2C devices with your Pi, and getting your blinky on. If you're running Wheezy or something-other-than-occidentalis, you will need to set up I2C first. Follow this tutorial to fully enable i2c (http://adafru.it/ati) Downloading the Code from Github The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros. Simply run the following commands from an appropriate location (ex. "/home/pi"): sudo apt-get install git git clone https://github.com/adafruit/adafruit-raspberry-pi-python-code.git cd Adafruit-Raspberry-Pi-Python-Code cd Adafruit_LEDBackpack Testing the Library Once the code has be downloaded to an appropriate folder, and you have your LED Backpack board properly connected, you can test it out with the following commands (the driver includes a few simple demo programs) For 8x8 displays, you can run a simple test with: sudo python ex_8x8_pixels.py Which should result in something like the following: For 4-character, 7-segment displays, you can run a clock demo with: sudo python ex_7segment_clock.py Which should result in the following: Page 8 of 12

Page 9 of 12

Class Summary If you're interested in writing your own code, the easy way is to start with the examples in the code repository (the.py files starting with 'ex_'), but the following information may be helpful as well. Adafruit_LEDBackpack All of the low-level IO and I2C access is passed through Adafruit_LEDBackpack.py, which is used by all of the other classes and examples in the library. This file implements a class named LEDBackpack, which has the following functions: setbrightness(brightness) Sets the display brightness with a value between 0 and 15 setblinkrate(blinkrate) Sets the optional blink rate for the display, with one of the following values for blinkrate 0 = No Blinking 1 = Blink at 2Hz 2 = Blink at 1Hz 3 = Blink at 1/2 Hz setbufferro w(ro w, value) Updates a single row of data. The HT16K33 contains an internal memory of 8 rows, with each row having 16 bits of data. Each row generally corresponds to one character on a 7-segment display or one row of pixels on an 8x8 display. getbuffer() Returns a list of 8 16-bit values representing the current state of the internal buffer, which can be used to update the display without affecting the rest of the content. clear() Clears the contents of the entire buffer Adafruit_7Segment The 7-Segment library is encapsulated in the file Adafruit_7Segment.py, and implements a class named SevenSegment (since class names can't start with a digit). It instantiates and instance of Adafruit_LEDBackpack internally, and you normally won't need to use the lower level class directly. It implements the following functions: writedigitraw(charnumber, value) This will raw a raw 16-bit value to the specified charnumber, which corresponds to a single row in the HT16K33, and one character in the 4x7-segment displays. (Note: row Page 10 of 12

2 is the colon on most 4 character displays). You can use this to display custom characters that aren't supported natively by the current library. writedigit(charnumber, value, do t=false) Writes a single decimal (0..9) or hexadecimal (0..9 and A..F) character to the display, with charnumber being the character to update, and value being the digit. You can set a third optional argument, do t, to True to set the decimal place after each character. setco lo n(state) You can pass either True of False to this function to enable or disable the colon that is usually connected to row 2 of the HT16K33. Adafruit_8x8.py The Adafruit_8x8.py file implements a class names EightByEight that can be used to drive 8x8 pixel square LED blocks. It contains the following functions: writero wraw(charnumber, value) This will update an entire row of data with the specified 16-bit value (though normally only the last 8-bits are used on one-color 8x8 displays. This is faster than setting individual pixels. setpixel(x, y, color) This function will update a single pixel within the relevant X/Y space of the display. Please keep in mind that lists in Python are zero-based, meaning to sets pixels 1..8 in each direction you actually use the values 0..7, so the following will enable the pixel 3 over and 5 down: grid = EightByEight(address=0x70) grid.setpixel(2, 4) Examples If you need a bit of help, simply looking at the provided example python code: 1. ex_7segment_clo ck.py: Displays the current time on a 4*7-segment display, changing the state of the colon every second 2. ex_8x8_pixels.py: Constantly updates every pixel on an 8x8 display, one pixel at a time. You can run these examples with the following code: sudo python ex_8x8_pixels.py Page 11 of 12

Last Updated: 2014-07-09 02:30:11 PM EDT Page 12 of 12