Programming Meggy Jr RGB


Last week we released an Arduino environment library for the Meggy Jr RGB. The code is an open source project here, and the downloadable package comes several example programs, ranging from very simple to moderately complex. (One of the examples is a new game called Froggy Jr, where you help your a little round green frog cross the street and then a river.)


Today, to make it all a bit more useful, we are releasing the Meggy Jr RGB Programing guide, which you can download Here (600 kB PDF file).

Programming Meggy Jr RGB: How to Get Started


  1. Download Arduino 0015 (or newer) and install.
  2. Download latest Meggy Jr RGB Arduino Library from here.
  3. Unzip the library, and place it…


    [For Arduino 16 or older] in a sub-directory of the hardware/libraries sub-directory of the Arduino application directory. T

    [For Arduino 17 or newer], in the “libraries” subdirectory of your sketch folder. (See this blog post for additional details.)

  4. Launch the Arduino environment; you should see the library in the Sketch>Import Library menu.

  5. Make sure that the correct menu option under Tools>Board> is selected. Board type should be Duemilanove (or Diecimila) with ATmega168 or with ATmega328P selected, depending on which your kit came with.

  6. Load an example program from your menu: File>Sketchbook>Examples>Library-MeggyJr>MeggyJr_MeggyBrite
  7. Verify (compile) the program by pressing the Verify button in the upper-left of the Arduino window; it has the “play” symbol, a right facing triangle.
  8. Connect your USB-TTL cable to your computer and Meggy Jr. The black and green ends of the Meggy side connector are labeled on the circuit board.
  9. To program Meggy Jr, press the “Upload to I/O Board” button at the top of the Arduino program window (the other “right arrow”). It typically takes about 15 seconds.


One of the demo programs included with the library, MeggyJr_MeggyBrite is a pixel art drawing program that shows off simple functions that make drawing pixels and making sounds surprisingly easy. These functions are documented in the programming guide.

To go forward, try out the other demo programs too and look through their code. Start small, by modifying these programs to make them still work but do different things. Once you understand that basic process, you’re good to go!






The Meggy Jr Library


The function of the Meggy Jr Library is to provide a software interface to the Meggy Jr RGB hardware. One of the things that it does is to allocate a chunk of the AVR microcontroller’s RAM to act as Display Memory, analogous to the video memory in a desktop computer system. The Display Memory is a sizeable array of data that fully describes the state of all 200 LEDs on the Meggy Jr RGB. The LED display is constantly redrawn at a rate of 150 times per second, fully reading out the contents of that Display Memory and using it to control the LEDs.


The Meggy Jr Library provides interface calls to directly set and read values in the Display Memory. While this can give you great control over the LEDs, it can also involve unwieldy data manipulation. In most cases the Meggy Jr Simplified Library is a much better place to start, so we will save discussion of the Display Memory for later.






The Meggy Jr Simplified Library


The Meggy Jr Simplified Library (MJSL) is a set of macros and functions on top of the Meggy Jr Library that let you get started quickly without
deep knowledge of the Display Memory or how the hardware works.
It also removes the excess complexity that is normally
associated with libraries in the Arduino environment, so you can just use the darned thing. And it really works well.


(Note: the MJSL is *fully compatible* with
the main library, since it is built on top of that. Any of the main library functions
can be made to work here as well, however it is usually not necessary to do so.)

Under the hood, the Meggy Jr Simplified Library uses the (full) Meggy Jr
Library, with its Display Memory and internal functions,
to constantly refresh the screen at 150 Hz.

The Simplified Library also adds an additional memory
array that makes drawing to the LED display more intuitive. Besides the Display Memory already mentioned,
the MJSL uses a second off-screen drawing space called the “Game Slate,” where we actually perform the drawing.
(You don’t have to use it for games, that’s just the name of it.) The
Game Slate is an 8×8 array of memory locations– one for each
pixel on the LED display– and in each position we store the name of a pre-defined color that will be drawn in the corresponding pixel. Because the Game Slate is not part of the actual Display Memory, we can take our time drawing a new image without affecting what appears on the LED display. When we’re finished drawing, we copy the Game Slate data to the Display Memory, looking up the color definitions in a look-up table.


For complete documentation, please see the Meggy Jr RGB Programing guide, which you can download here as a 600 kB PDF file.




Quick Links

EmailFacebookTwitterGoogle+tumblrPinterestRedditStumbleUpon

5 thoughts on “Programming Meggy Jr RGB

  1. I have an intel mac/osx, and I can not get past step 2 above– where is the hardware/libraries subdir on a mac? (the application folder does not have anything like it nor the ~/Library/Aruino). Any help appreciated brewster@archive.org

    Download latest Meggy Jr RGB Arduino Library from
    http://code.google.com/p/meggy-jr-rgb/downloads/list
    To install, unzip the library to a sub-directory of the hardware/libraries sub-directory of your
    Arduino application directory. Then launch the Arduino environment; you should see the
    library in the Sketch>Import Library menu.

    • found it– it is in Applications/Arduino (then control click it to say open package contents) then Contents/Resources/Java/hardware/libraries

      and it all worked. yippie

  2. I can’t seem to find one single file on the library’s site. Am I supposed to select all and download?

Comments are closed.