Skip to content

Latest commit

 

History

History
89 lines (49 loc) · 6.54 KB

README.md

File metadata and controls

89 lines (49 loc) · 6.54 KB

Led Scroller Matrix atmega48-based

This is the firmware for a led scroller matrix I made using an atmega48p and some charliplexing techniques (check my page on hackaday.io for more info about the project and the board itself; also here's a video with the demo program!).

Led scroller 1

Usage

  • make all to compile
  • make flash to upload
  • make fuses to set the fuses

Device starts DISABLED by default

(so use the 0x11 command - ENABLE - to start displaying things)

Device address

0x42 (set on __/firmware/twi.h)

Commands

See the example on /host for more info and examples about the different commands and modes.

  • 0xA1, DIAGNOSTIC MODE (changes to diagnostic mode: a single glowing led that iterates over all "pixels")

  • 0xB1, LETTERS MODE + INIT + STRING LENGTH + [MULTIPLE BYTES]: changes to letters mode and receives a buffer offset + byte count + some chars to be set on the letters buffer

  • 0xC1, BUFFER MODE + INIT + STRING LENGTH + [MULTIPLE BYTES]: changes to buffer mode and receives a buffer offset + byte count + some chars to be set on the leds_status buffer

  • 0x11, ENABLE (enables the matrix output; otherwise the device will perform "as usual" - modes and flags can be changed- but without displaying anything)

  • 0x10, DISABLE (disables the matrix output; by DEFAULT this is the initial state when powering up the display)

  • 0x20, SPEED + SPEED_VALUE (send a value between 0x00 and 0xFF to set the step function for the modes. The bigger the number, the longest the mode step intervals will be triggered - this is directly wired to the timer0 used to trigger those step functions. By DEFAULT this value is set to 2 when powering up the display)

  • 0x30, DISPLAY REGULAR (shows the display in regular mode: "0" pixels are off and "1" pixels are on; this is the initial DEFAULT behaviour when powering up the display)

  • 0x31, DISPLAY INVERT (shows the display in inverse mode: "1" pixels are off and "0" pixels are on)

  • 0xB2, LETTERS SCROLL (When in letters mode, the scroll will be ACTIVE; this is the initial DEFAULT behaviour when powering up the display)

  • 0xB3, LETTERS STATIC (When in letters mode, the scroll will be INACTIVE - showing text from left to right, with some cropped characters if those are longest than the display size)

Buffer sizes

  • leds_status buffer (the whole grid): 47 bytes (fixed size)
  • letters buffer (the whole grid): 300 bytes (fixed size)

Examples on /host

On the /host folder there's a sample program for an attiny85 wired as a primary device that will control and show different options and modes from an attached board.

Info

/firmware

Contains the firmware for an atmega48p properly wired in order to control the matrix and also act as a secondary I2C device.

The main program is an endless loop of constant led updating (charlieplexing_step() on charlieplexing.h, controlling all the turn-on / turn-off led stuff), reading the status from each "pixel" (or led) from a leds_status main buffer. This main buffer will be modified by different modes and actions in order to "change" whatever needs to be displayed.

Those modes (on the /modes folder) triggers an init function when switching to them and a "mode step" that will be executed according to a timer set on the micro. On each step the mode usually modifies the leds_status buffer, like when "scrolling" some text on each step according to the scroll speed.

In addition to the modes there's also a twi.h file that handles the I2C communication: this device will act as a secondary device that will listen to different commands that will modify the buffers or some options.

Some commands will change the mode, others will change the leds_status buffer and there's a bunch of options that will modify small flags and variables like speed, inverted colors, etc.

modes

The mode wrapper takes a couple of defined functions for each mode: *_init and *_step. Adding new modes is a matter of updating the numeric constants and set the new function pointers in order to be able to execute the proper mode change. Notice those changes are usually handled by the twi communication.

twi

Using the Two-Wire Interface capabilities on the atmega48 here we handle the different commands and stuff we can receive and properly handle.

Notice we're answering with an ACK or NACK depending on the circumstances: usually a NACK will be sent at the end of the whole transaction, but single bytes commands cannot return a NACK since the default state is to return an ACK (setting the TWEA bit to 0 will indicate a NACK on the NEXT byte transaction, not that one)

buffer mode

By controlling the whole buffer we're just modifying leds_status on-the-fly (notice the buffer.h mode file itself it's almost empty!): we're receiving an index + byte length + that amount of bytes to directly override that specific part of the buffer.

letters mode

Similar to buffer mode but with a different letters buffer: instead of storing "pixels" on the matrix we're dealing with ascii characters that are later translated into differnent columns (there's a letters_constants.h file with the ascii fonts and a small JS tool I made to design them on the /tools folder).

The scrolling is handled on the letters.h mode file (it iterates over and over if the lt_scroll flag is active - otherwise just display the text from left to right).

The letters buffer has a 300 bytes fixed size, meaning strings up to 300 chars can be displayed. In order to stop scrolling over all the buffer when dealing with smaller ones, a \0 char terminator must be used to set the end of the current string (this way the scrolling method will stop at that point and iterate only over the small subset and not the 300 chars).

game of life mode

A work in progress, yet not finished nor added into the whole code.

A classic Conwell's Game Of Life implementation using the matrix as an infinite grid. Adding it to the whole modes system will create a larger-than-4k firmware file and won't upload to the micro.