Setup AVR Development Environment
This page will help you setup the programming environment for designing the low level firmware of individual Molecube actuators. After finalizing and compiling the actuator program, the resulting binary files will be transferred to the ATmega324P/644P processors embedded into the interface boards of the actuator Molecubes. These processors are responsible for physically executing commands issued by the controller Molecube, according to the list of commands given in the hardware protocol definition document.
Recommended Order of Installation
- Install Microsoft Visual Studio with all updates.
- Install WinAVR-20070525 preferably to the default location
C:\WinAVR. Unfortunately, the most recent WinAVR version does not appear to be immediately compatible with our Molecubes firmware. Any help making our code compatible with the most recent WinAVR version is most welcome.
NOTE: On one occasion, WinAVR installation resulted in emptying the "Path" environment variable. For safety, we recommend backing up the contents of "Path" variable prior to installation and then restoring it after WinAVR has been installed.
- Extract AVRLib (slightly modified from the original version to support ATmega324P and ATmega644P) in WinAVR directory so the avrlib root is located at
- Set the following 2 environment variables:
AVR = C:\WinAVR\bin
AVRLIB = C:\WinAVR\avrlib
- Install AVR Studio 4.13 (build 528) with service packs: AVR Studio 4.13 SP1 (build 557) and AVR Studio 4.13 SP2 (build 571). This Integrated Development Environment is supplied with drivers for the AVRISP mkII in-system programmer. Once you connect the programmer to the USB port of your computer, the drivers will be installed automatically.
- Download the AVR project files from GitHub, and open
AVRProject.dswwith Visual Studio. The project should compile now.
Minor Corrections Introduced into AVRLib:
Line 34 of
avrlib/make/avrproj_make changed to:
all: $(TRG).elf $(TRG).bin $(TRG).hex $(TRG).ok
#ifdef additions to add in support for ATmega324P and ATmega644P processors throughout
Recommended Programming Sequence
|Step 1: Update your local repository files. Start Microsoft Visual Studio and open the "AVRProject" project and build it (by pressing F7). If AVR tools have been installed successfully, the project should compile.|
|Step 2: Sroll down to line 25, and find a block of #define items. By commenting in and/or out the individual lines in this block, we configure the AVR firmware contents and functionality. When programming any particular Molecube AVR controller, observe the type of the target Molecube and which part of a robot it is installed into: these can be either North or South half for Actuator, Triplet or Duet half for Controller and Battery (these are distinguished by the number of circuit boards installed in a given half). Gripper only has one ATmega324p controller installed. In the first block of lines, select one item matching your firmware target. Keep device address allocation to 0x00 unless you mean to change it and fully realize the consequences. Some of the modules may need to go through the initialization routine, such as servo angle measurement calibration or gripper position calibration. Servo calibration routine is necessary for all new actuators, gripper initialization is optional. If either of these procedures is required, un-comment the corresponding line and compile the project. If you program the robot with one of these initialization routines, keep in mind that this routine will need to be removed from the robot's memory before it can be a part of a Molecube assembly. So, if you are going through the final round of programming before assembling the modules into a Molecube assembly, comment out any initialization routines. Build your solution once the necessary selections have been made (by pressing F7).|
|Step 3: Connect AVRISP-MKII to your computer with a USB cable. Attach the target robot to the power supply module or a battery module. Connect AVRISP-MKII to the target Molecube processor board. Before switching on the power on the Molecube power bus, we recommend testing the resistance between the communication line and the high voltage line. Having an accidental short circuit between these two lines has the potential of permanently damaging all communication buffers of Molecubes connected to the communication bus. Resistance between the communication bus and 14..24 VDC bus should be at least 15-20 kOhm. The communication bus terminals are innermost on the Molecube electrical interconnection interface (any of the four radially spaced pins closest to the LED), and the 14..24 VDC bus terminals are the farthermost.|
|Step 4: Once the resistance between COM and +18V has been confirmed above 15 kOhm, switch on the power, and the formerly red LED of the AVRISP-MKII should change to green. If not, check the wiring between AVRISP-MKII and the Molecube circuit board.|
|Step 5: Start AVR Studio and click the "Con" button to display the "Connect" dialog. In the "Select AVR Programmer" window, select "AVRISP mkII", type of connection "USB", and click "Connect".|
|Step 6: In the Main tab of the ISP mode dialog, click "Settings", and set the ISP clock frequency to 250 kHz, click "Write". Select the processor type (AImega324P), and you should be able to read the processor signature.|
|Step 7: In the "Fuses" tab, make sure that the fuses are set as shown, otherwise, re-program the fuse settings. CAUTION!!! Wrong fuse settings can render the processor defunct, be very careful when programming fuses.|
|Step 8: Now we need to specify to the AVR Studio, which of the binary files it should place into the flash memory of the processor. In the "Flash" section of the "Program" tab, choose the "main.hex" file, by navigating to |