Maintenance notice: These forum archives are read-only, and will be removed shortly. Please visit our forums at their new location,

Connecting 2 Peggy II boards and increasing the number of commands to execute.s

edited November 2012 in General

I am using  a Peggy 2 to drive individual LEDs for a Railroad Museum display.
I have cut the number of rows driven by the board to increase brightness in the leds.

Would like to add another Peggy 2 to increase the number of points illuminated.  Doing this would include the requirement that the 2 boards communicate so each Peggy board could do part of a display and hand off the other part of it to the 2nd Peggy.

The current code (1 Peggy board) looks like this;
...code snipped from source file ...
CUT.RefreshAllFast(dly2) ;
    CUT.ClearPoint(N32) ;
CUT.RefreshAllFast(dly2) ;
CUT.RefreshAllFast(dly2) ;
Where the coordinates are 'defined' in an include file, and the variable(s) dly2 are initialized early in the code.

I want to increase the overall size of the program to increase running time beyond the capacity of the on-board memory.

Can an EPROM, or equivilant device, be added to hold the additional commands?
Perhaps a serial feed from another m


  • I hate this keyboard!

    Perhaps a serial feed from another microcontroller with the EPROM.

    Any suggestions are appreciated.

  • First off, I'm not sure how much you need to expand, but you can actually get a fair number of extra LEDs with the hardware that you have.   The Peggy 2 has 25 rows and columns on board, but the LED driver chips actually support 32 columns.  The extra seven columns are broken out on the PCB as A0 - A6, by U5.   So, if you have six rows, using these extra pins will get you 42 extra LEDs.  The only downside is that you'll have to modify the code to include those extra locations. 

    It is not possible to expand the program memory of the AVR microcontroller directly. While I suspect that it's possible to use the code more efficiently-- I've almost never filled up the full 32 kB! -- I'll try to suggest a few workarounds.

    - Use a larger AVR, for example the ATmega1284, which has 128 kB of program memory.   This could be used as the "brain" of the Peggy, with some code changes.   You could also use it as a "master" that sends serial commands to the two Peggy units over TWI (I2C).   

    - Use a larger-AVR-based Arduino board, such as the Arduino Mega with the ATmega2560 processor-- which has 256 kB of program space. 

    - Use an off-board Arduino, with an appropriate shield, to read commands from an SD card and transmit them to the Peggy board(s) over TWI.

    - Store the commands on the computer, and stream them to the Peggy board(s) through a serial or TWI interface.

  • The idea of using a processor with additional memory is the easiest method, so far, to increase run time.
    More Memory = More Run Time.
    To illustrate how I am applying the Peggyboard I will give an overview in pseudo-code.
    The code snippet, in the first post, is a true representation of the program structure.  I am only using the following verbs; ~.SetPoint(), ~.ClearPoint(), and ~.RefreshAllFast().  Is there a better way to code this?  The application is to recreate the appearance of the Railroad Track Layout Status Board for the Cincinnati Union Terminal Control Tower.  Each led illuminates 1 indicator showing Track Occupancy or Signal indications.  A sequence illustrates the movement of trains in the Terminal 'Yard'

    A typical sequence is:
    Set(N1) ;
    Refresh(3 seconds) ;
    Set(N2) ;
    Refresh(2 Sec) ;
    Clear(N1) ;
    Refresh(2 Sec) ;
    Set(N3) ;
    ad infinitum

    Is there a better way to code this?
    Can there be Functions, or Macros, for repetative code sequences?
  • Yes, you can use functions to simplify the operation and reduce the code usage.  You could even define each of the "tracks" as an array that specifies the location of each dot, and then use loops to say something like:

    For each light on track XYZ:
      Turn on light
      refresh 2 seconds
      clear light
  • As you refer to functions, am I correct in hoping that the syntax would be something like:
    void setup()
        CUT.HardwareInit();    // Call this to init the hardware.
        CUT.Clear();        // Erase the entire frame buffer.

    void to_Eng_Yard()
    ~Set(S5) ;
    ~.Refresh(3 sec) ;
    ~.Set(s4) ;
    ~.Refresh(3 sec) ;

    void loop()

    to_Eng_Yard() ;

     {more code}

    I have not tried it yet, nor have I found any evidence of this technique in the examples I have found.
    It would be a Huge help if it works.


  • The Peggy 2 runs Arduino code, and there are a wealth of examples of how to create functions and other types of program features on the Arduino site: 

    For the most part, we'd recommend using the Peggy 2 specific functions for I/O (rather than the individual pin commands from within Arduino), but for everything else, you can follow the guides to structuring your program, using arrays and variables, and so forth.
Sign In or Register to comment.