Getting Started with MeggyJava translation for building programs and running on the Meggy Jr Device

Important Note:Depending on your machine and OS, you may need to make modifications, such as pathnames, to these instructions. Learning how to customize to your environment is a good skill for your future. Share any modifications with the class on piazza, and we will update these instructions or add to them.

To use existing compilers to check the syntax of a MeggyJava program that you wrote:

Follow these steps:

To test MeggyJava programs without your own compiler

You can test MeggyJava programs by having them link to a testing library and passing them through the Java compiler.

To translate a MeggyJava program to AVR assembly:

In order to have MeggyJava programs run on the Meggy Jr. device they must be compiled into AVR assembly; this is the goal of your future programming assignments. We provide a few sample .s files and you will be creating additional ones as test cases for PA1.

You have two ways to translate a MeggyJava program to AVR assembly: (1) use the reference compiler (MJ.jar) which is for your convenience in testing your own work and for grading, or (2) use your own compiler that you will be creating this semester. This document describes how to use the reference compiler. To get started on the MeggyJr device without using the MeggyJava compilers, you can run existing C++ programs on the MeggyJr.

To use the reference compiler to compile a MeggyJava program down to AVR assembly, Download the reference compiler MJ.jar and place where you will be executing MeggyJava programs with the reference compiler. The reference compiler compiles MeggyJava code to AVR assembly, which is what your compilers will be doing as well. It can be helpful to use the reference compiler on your test cases to see what code it generates.

To try out the reference compiler, first download the example input PA5Cylon.java. Then do the following:

    java -jar MJ.jar PA5Cylon.java
This will generate a PA5Cylon.java.s file, which you can then compile and upload to the Meggy Jr using the above provided Makefile, or run on the MJSIM simulator.

Going from .s to Meggy

In PA2 and onward you will be compiling .java source-files and outputting .s assembly language files. To assemble and run your .s files you will use a Makefile that can translate .s files to .hex, then transfer .hex files onto the Meggy Jr. device itself.

To execute an AVR assembly (.s) file generated from the reference MeggyJava compiler or your MeggyJava compiler:

You have two ways to execute your (file.s) AVR assembly programs: (1) use the MJSIM simulator, or (2) generate a .hex file using the Makefile below and upload onto the MeggyJr using the Makefile.

AVR assembly for MeggyJava programs can be executed in one of three ways: (1) through the commandline line mode of the MeggyJava simulator, (2) through the GUI of the MeggyJava simulator, and (3) on the device itself. To run PA2bluedot and PA5movedot through the simulator:

Going from .s to Hex files run on the MeggyJr Device

In PA2 and onward, you will be compiling .java source-files and outputting .s assembly language files. To assemble and run your .s files, you will use a Makefile that can translate .s files to .hex, then transfer .hex files onto the Meggy Jr. device itself.

Running programs on the Meggy Jr connected to a linux machine

  1. Download the MeggyJrSimple.cpp, MeggyJrSimple.h, MeggyJr.cpp, MeggyJr.h, Makefile, and simple-test.cpp files.
  2. Plug the Meggy Jr device into your USB port.
  3. Follow the directions at the top of the Makefile file to compile the example and install it on your Meggy Jr device.

Running programs on the Meggy Jr connected to a Mac

Pretty much following www.evilmadscientist.com/article.php/meggyjrlib. These instructions are offered as is with NO support from the 453 instructor or TA. If you figure out how to get Arduino to work with your Windows or linux box, please consider sharing it with the rest of the class. If you find any errors in the below, please let us know.
  1. Download the Arduino software from http://arduino.cc/en/Main/Software. Copy the Arduino application to the Applications directory.
  2. It is possible that you will need to install a USB serial driver. I did in 2011, but I didn't in 2015.
  3. Make the MeggyJrLibrary accessible in Arduino.
    1. Download MeggyJrLibrary1.40.zip from http://code.google.com/p/meggy-jr-rgb/.
    2. Exit out of Arduino application.
    3. Put the unzipped folder into the Sketchbook location in a subdirectory called libraries, which is specified in the Arduino preferences and is by default /Users/yourusername/Documents/Arduino/. You will probably have to create the libraries subdirectory, /Users/yourusername/Documents/Arduino/libraries/, and place the MeggyJr folder in the libraries/ subdirectory.
    4. Restart the Arduino application.
    5. You should be able to open the MeggyJr examples. For instance, try File->Examples->MeggyJr->MeggyJr_FroggyJr in the Arduino application.
  4. Upload an example to the MeggyJr device.
    1. Under the Tools->Board menu select Arduino Duemilanove or Nano w/ ATmega328
    2. Plug the Meggy Jr device into your USB port, turn it on, and make sure /dev/tty.usbserial-* is selected under Tools-->Serial Port.
    3. Click the upload button on the example. The example should start immediately running on the Meggy Jr device.
  5. Writing your own example in C WITHOUT using the Arduino GUI.
    1. Download the MeggyJrSimple.cpp, MeggyJrSimple.h, MeggyJr.cpp, MeggyJr.h, Makefile.mac, and simple-test.cpp files.
    2. Plug the Meggy Jr device into your USB port, turn it on, and make sure /dev/tty.usbserial-** is selected under Tools-->Serial Port in Arduino (this is all you have to do in the Arduino IDE).
    3. Follow the directions at the top of the Makefile.mac file for the input file simple-test.cpp (so file=simple-test).
    4. Create your own .cpp file by copying the simple-test.cpp file. The build process in the Makefile.mac is set up for a single .cpp file of any name.

Credits: Much of this page was originally created by Michelle Strout while teaching CS 453 at Colorado State University.