Leon Anavi
IT Tips && Tricks

Mobile & Embedded

Created: 22.01.2016 01:27 Last Modified: 06.03.2017 03:12 Views: 13348
Keywords: C, example, LED, LED matrix, Linux, opensource, Python, Raspberry Pi, Raspian, SPI

Getting started with Red LED Matrix Module for Raspberry Pi

Introduction

This is an add-on board with LED red matrix for Raspberry Pi from icstation. By the time of writing this post it costs less that 10 USD including shipping. It is based on MAX7219 driver and has two cubes with 64 red common cathode LEDs on each of them. The matrix is 16 dots wide and 8 dots high. It is compatible with any Raspberry Pi model and version.

Enable SPI

SPI must be enabled to use the LED matrix. The easiest way to do it, if you are using the Raspian GNU/Linux distribution is through raspi-config:

  • Go to Advanced Settings, select SPI and reboot your Raspberry Pi.
  • Ensure that the SPI kernel driver is enabled:
  • dmesg | grep spi
    [    3.769841] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
    [    3.793364] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
    
  • Verify that devices are successfully installed in ⁄dev:
  • ls -l /dev/spi*
    crw------- 1 root root 153, 0 Jan  1  1970 /dev/spidev0.0
    crw------- 1 root root 153, 1 Jan  1  1970 /dev/spidev0.1
    

Examples

Execute the following command to get my open source examples and to control the LED matrix on your Raspberry Pi:

cd ~
git clone https://github.com/leon-anavi/raspberrypi-matrix-led-max7219.git

Python

  • In order to you my Python example for the LED red matrix for Raspberry Pi you need to install several additional packages on your Raspberry Pi. Execute the following commands if you are using Raspbian:
  • git clone https://github.com/rm-hull/max7219.git
    cd max7219
    sudo apt-get install python-dev python-pip
    sudo pip install spidev
    sudo python setup.py install
    
  • Run as root the example Python script which displays the CPU temperature of Raspberry Pi on the LED matrix:
  • cd ~/raspberrypi-matrix-led-max7219
    sudo python python/matrix-cpu.py
    

C

The second example is written n the C programming language. Follow the steps below to build and run it:

  • Install C library for Broadcom BCM 2835.
  • wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.49.tar.gz
    tar xf bcm2835-1.49.tar.gz
    cd bcm2835-1.49
    ./configure
    make
    sudo make check
    sudo make install
    
  • Build the example application
  • cd ~/raspberrypi-matrix-led-max7219/c
    make
    
  • Run the example application to print text on the red LCD matrix for Raspberry Pi:
  • sudo ./led-max7219-text hello


  Home | About | Contact | Disclaimer | Sitemap © 2009-2022 Leon Anavi. All rights reserved.