Giter Club home page Giter Club logo

max7219's Introduction

MAX7219 Driver

Interfacing LED matrix displays with the MAX7219 driver [PDF datasheet] in Python using hardware SPI on the Raspberry Pi. The particular LED matrix I bought can be acquired for a few pounds from Banggood. Likewise 7-segment displays are available from Ali-Express. There are many other outlets selling both types of devices on Ebay and other such places.

This library has recently had a major overhaul, and is not compatible with the earlier version. It now supports:

  • multiple cascaded devices
  • LED matrix and seven-segement variants

max7219 matrix

Python Usage

For the matrix device, initialize the matrix class:

import max7219.led as led

device = led.matrix()
device.show_message("Hello world!")

For the 7-segment devce, initialize the sevensegment class:

import max7219.led as led

device = led.sevensegment()
device.write_number(deviceId=0, value=3.14159)

The MAX7219 chipset supports a serial 16-bit register/data buffer which is clocked in on pin DIN every time the clock edge falls, and clocked out on DOUT 16.5 clock cycles later. This allows multiple devices to be chained together.

When initializing cascaded devices, it is necessary to specify a cascaded=... parameter, and generally methods which target specific devices will expect a deviceId=... parameter, counting from zero.

For more information, see http://max7219.readthedocs.org/

max7219 sevensegment

Pre-requisites

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)

And that the 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

Follow the advice in the references below if the devices do not appear before proceeding.

GPIO pin-outs

The breakout board has an two headers to allow daisy-chaining:

Board Pin Name Remarks RPi Pin RPi Function
1 VCC +5V Power 2 5V0
2 GND Ground 6 GND
3 DIN Data In 19 GPIO 10 (MOSI)
4 CS Chip Select 24 GPIO 8 (SPI CE0)
5 CLK Clock 23 GPIO 11 (SPI CLK)

Building & Installing

For Raspian:

On setup while in raspbian config or post install by running 'sudo raspi-config' you must enable SPI: 8 Advanced options > A6 SPI > Yes (Would you like the SPI interface enabled?) > OK > Yes (Would you like the SPI kernel module to be loaded by default?) > OK

$ sudo apt-get install python-dev python-pip
$ sudo pip install spidev
$ sudo python setup.py install

For Arch Linux:

# pacman -Sy base-devel python2
# pip install spidev
# python2 setup.py install

Examples

Run the example code as follows:

$ sudo python examples/matrix_test.py

or

$ sudo python examples/sevensegment_test.py

NOTE: By default, SPI is only accessible by root (hence using sudo above). Follow these instructions to create an spi group, and adding your user to that group, so you don't have to run as root: http://quick2wire.com/non-root-access-to-spi-on-the-pi

References

License

See MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.