​ ​ ​ ​ Picaxe control of Adafruit 8x8 LED matrix with i2c backpack
Results 1 to 3 of 3

Thread: Picaxe control of Adafruit 8x8 LED matrix with i2c backpack

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Location
    London
    Posts
    244

    Default Picaxe control of Adafruit 8x8 LED matrix with i2c backpack

    I couldn't find any Picaxe Basic code examples for controlling this display, but this thread described how to control a 4-digit, 7-segment display that uses the same backpack.

    8x8 matrix LED.jpg

    Building on the information in that thread, I have produced the following code that demonstrates how to turn on/off, dim or flash the display and control which pixels are lit up. By giving it its own thread, people searching on the Internet for information on how to control this module (as opposed to the 7-seg version) will find it more easily.

    1. After initialising, the starting address ($00) is sent, then (in brackets in the example below), the string of data containing the value for each of the 8 columns, where the "value" is the row value in binary, MSB first. However, the row value is a 16 bit value and only the first 8 bits are physically connected. So, every other byte is ignored. I have put $AA into each of these in the example below, just so they are not confused with anything else.
    2. For some reason, the physical row 0 (at the top if you look at the display with the Adafruit logo at the bottom) is wired as the MSB so all the other rows are shifted down.

    Code:
    picaxe 08m2	' Define PICAXE 08M2
    #no_data		' Ignore EEPROM data - loads program faster
    
    Initialise:				' Initialise pins and set up variables
    LET dirsC = %00000110		' Make pins C.1 & C.2 outputs; rest as inputs
    LET pinsC = %00000000 		' Turn off all outputs on port C
    Hi2cSETUP  i2cmaster,%11100000, i2cfast, i2cbyte
    PAUSE 1 ; wait 1 ms for the display chip to initialise
    Hi2cOUT ($21) ; start clock/oscillator
    ' $00 turns off the whole row
    
    Main:
    Hi2cOUT ($80) ; clear the display
    
    
    ' turn on all LEDS in each column (%11111111=$FF)
    ' x = don't care (not connected) but I have used $AA
    '    start !  col0 x  , col1 x  , col2 x  , col3 x  , col4 x , col5 x  'col6 x  , col 7 x
    Hi2cOUT $00, ($FF, $AA, $FF, $AA, $FF, $AA, $FF, $AA, $FF,$AA, $FF, $AA, $FF,$AA, $FF, $AA) 
    Hi2cOUT ($81) ; turn on the display
    pause 1000
    
    ' now draw a smiley face
    '  xxxx  
    ' x    x
    'x x  x x
    'x      x
    'x x  x x
    'x  xx  x
    ' x    x
    '  xxxx
    
    
    
    '    columns
    '7 6 5 4 3 2 1 0
    '0 0 1 1 1 1 0 0 row0
    '0 1 0 0 0 0 1 0 row1
    '1 0 1 0 0 1 0 1 row2
    '1 0 0 0 0 0 0 1 row3
    '1 0 1 0 0 1 0 1 row4
    '1 0 0 1 1 0 0 1 row5
    '0 1 0 0 0 0 1 0 row6
    '0 0 1 1 1 1 0 0 row7
    
    'Adafruit logo at bottom
    
    'MOVE TOP ROW (ROW0) TO bottom (MSB) AND SHIFT EVERYTHING ELSE DOWN=>BIT0->BIT7, BIT7->BIT6, BIT6->BIT5
    
    ' becomes....
    
    '    columns
    '7 6 5 4 3 2 1 0
    '0 1 0 0 0 0 1 0 row0
    '1 0 1 0 0 1 0 1 row1
    '1 0 0 0 0 0 0 1 row2
    '1 0 1 0 0 1 0 1 row3
    '1 0 0 1 1 0 0 1 row4
    '0 1 0 0 0 0 1 0 row5
    '0 0 1 1 1 1 0 0 row6
    '0 0 1 1 1 1 0 0 row7
    
    'Adafruit logo at bottom
    
    'for example, after shifting row 0, column 0 becomes %00011110 or $1E
    '    start !  col0 x  , col1 x  , col2 x  , col3 x  , col4 x , col5 x  'col6 x  , col 7 x
    Hi2cOUT $00, ($1E, $AA,$21, $AA, $CA, $AA, $D0, $AA, $D0,$AA, $CA, $AA, $21,$AA, $1E, $AA)
    Hi2cOUT ($81) ; turn on the display
    pause 1000
    
    Hi2cOUT ($E0) 'dim the display (range $E0 to $EF)
    pause 1000
    Hi2cOUT ($EF) ' full brightness again
    pause 1000
    Hi2cOUT ($83) 'blink the display ($83=2Hz blink, $85=1Hz, $87=0.5Hz)
    pause 3000
    Hi2cOUT ($80) ; turn off the display
    pause 1000
    goto main

  2. #2
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,083

    Default

    Steve, there's been quite a lot of code on the forum about driving the 8x8 displays, but not the particular Adafruit i2c display that you are referring to.

    I have built a double-digit display using a 20X2 with I/O via i2c. Adafruit might have made that job a bit easier for me.

    EDIT: You might also find some inspiration at this link: http://www.picaxeforum.co.uk/showthr...ent-LED-Driver
    Last edited by Texasclodhopper; 05-02-2017 at 15:51. Reason: Added link to MAX7219
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Location
    London
    Posts
    244

    Default

    I found the 8x8 matrix tricky until I worked out what was going on. I think they must have designed the backpack for 7-seg plus decimal point then, when porting to 8x8 matrix found that row0 was connected to the backpack on the same line that the decimal point from the 7-seg was connected to. Not very intuitive!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •