HiPi
Perl Modules for Raspberry Pi
Version 0.92 - released 28 March 2024

HiPi::Interface::MAX7219

This module provides an SPI interface to the MAX7219 8 digit LED display drive

It uses HiPi::Device::SPI as a backend.

The module supports

Methods

Create a new instance of the class

use HiPi qw( :max7219 );
use HiPi::Interface::MAX7219;

my $dev = HiPi::Interface::MAX7219->new( );

$value between 0 and 7 - how many registers are scanned.

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->set_scan_limit(7);

$value between 1 and 15 for the intensity of the display.

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->set_intensity(3);

Wake up the MAX7219

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->wake_up();

Set the display_test mode on and off

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->set_display_test(1);  # ON

Shutdown the MAX7219

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->shutdown();

Set the decode mode on or off.

The MAX7219 has a built in map for digits and a very limited number of additional chars.

If you set decode mode on, you can user the method 'write_code_char' to display numbers without any external char mapping.

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->set_decode_mode( 1 );
$dev->write_code_char( 1, '1' );
<

The MAX7219 has a built in map for digits and a very limited number of additional chars.

If you set decode mode on, you can user the method 'write_code_char' to display numbers without any external char mapping.

You can use the optional flags parameter to declare that this matrix should have the decimal point set.

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

# Write 9.8
use HiPi qw( :max7219 );
.......
$dev->set_decode_mode( 1 );
$dev->write_code_char( 0, '8' );
$dev->write_code_char( 1, '9', MAX7219_FLAG_DECIMAL );

Send a raw $byte to the $matrix number.

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->send_segment_matrix( 3, 0x3d );

Send a raw MAX7219 command consisting of a register and a data byte.

The following constants are exported:

  • MAX7219_REG_NOOP
  • MAX7219_REG_DIGIT_0
  • MAX7219_REG_DIGIT_1
  • MAX7219_REG_DIGIT_2
  • MAX7219_REG_DIGIT_3
  • MAX7219_REG_DIGIT_4
  • MAX7219_REG_DIGIT_5
  • MAX7219_REG_DIGIT_6
  • MAX7219_REG_DIGIT_7
  • MAX7219_REG_DECODE_MODE
  • MAX7219_REG_INTENSITY
  • MAX7219_REG_SCAN_LIMIT
  • MAX7219_REG_SHUTDOWN
  • MAX7219_REG_TEST

$cascade - If you have several MAX7219 controllers chained together,use $cascade to specify the MAX7219 that should accept this command.

$dev->send_command( MAX7219_REG_SHUTDOWN, 0x00 ); # shutdown
$dev->send_command( MAX7219_REG_SHUTDOWN, 0x01 ); # wake up

Send @bytes directly to the MAX7219

$dev->send_raw_bytes( @bytes );