Summary of Running PYTHON (pymite-09) on an Arduino MEGA 2560 using atmega16 micrcontroller
The article reviews the Arduino Mega 2560, highlighting its 256KB flash, 8KB RAM, and 54 digital I/O pins. The author demonstrates running Python via the Pymite interpreter on this board using avr-gcc and avrdude. Additionally, an Ethernet shield with a micro SD slot is tested for network connectivity and data storage.
Parts used in the Arduino Mega 2560 Project:
- Arduino Mega 2560 board
- Atmega2560 chip
- Atmega16 chip (USB to UART converter)
- 16MHz crystal oscillator
- Python (pymite) software
- avr-gcc compiler
- avrdude programmer
- Arduino Ethernet shield
- Micro SD card
Now it is the first time I am using an arduino board. Arduino mega 2560 is really a great product. The chip got a flash of 256KB, RAM of 8KB and EEPROM of 4KB. Also, the data sheet of Atmega2560 says that we can extend the RAM (by external) upto 64KB. Another most important feature of this stuff is that it have 54 Digital I/O pins (of which 14 provide PWM output). It is clocked with a 16MHz crystal osc.
Also the board contains another atmega16 (just above the crystal) which is pre-programmed as a USB to UART converter which enables a serial communitation between the atmega2560 and PC via USB. The product is shipped with a bootloader inside which make it easy to program it via the same USB-UART channel. So the channel got two functions, ie programming the chip and serial communication with PC. From the arduino home page we can download the arduino IDE for appropriate OS.
- extract it. (tar -xvf pymite-xx.tar.gz)
- ‘cd’ into the directory of pymite folder
- now, cd into src/platform/arduino_mega and open the Makefile
- edit the platform configuration MCU to atmega2560
- now cd back to the pymite folder (cd ../../../)
- now type “make PLATFORM=arduino_mega”
- now if you see any error as below:
avr-gcc -c -mmcu=atmega2560 -I. -gstabs -DF_CPU=16000000UL -I../../vm -I/home/vinod/pymite-09/src/platform/arduino_mega -Os -Wall -Wstrict-prototypes -Werror -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums main_nat.c -o main_nat.o In file included from main_nat.c:20:0: /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h: In function 'nat_05_avr_delay': /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:153:28: error: __builtin_avr_delay_cycles expects an integer constant. /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:153:28: error: __builtin_avr_delay_cycles expects an integer constant. make[1]: *** [main_nat.o] Error 1 make[1]: Leaving directory `/home/vinod/pymite-09/src/platform/arduino_mega' make: *** [all] Error 2
- if the above error occur, then open the file src/platform/arduino_mega/
- Now add below function under the #include <util/delay.h>
//-------------------
void delay_MS(unsigned int n){
unsigned int x;
while(n--){
x=2600;
while(x--);
}
}
-
- Now edit the function nat_05_avr_delay(pPmFrame_t *ppframe) in the opened file. Replace the _delay_ms( with delay_MS( and save it.
- Now go back to pymite (cd ../../../) and type “make PLATFORM=arduino_mega” or type simply “make” from the current folder and if no errors, we could see a main.elf file generated in the arduino_mega folder.
- Now convert it to hex using below command.
- avr-objcopy -j .text -j .data -O ihex main.elf python.hex
- Now we obtained the hex file and we need to burn it to arduino mega 2560, for that we can use avrdude command as below.
- sudo avrdude -V -F -c stk500v2 -p m2560 -b 115200 -P /dev/ttyACM0 -U flash:w:python.hex
- Now the hex is loaded into arduino and we can test it. For that, cd into the directory of the arduino_mega (cd src/platform/arduino_mega) and type ../../tools/ipm.py -f pmfeatures.py –serial /dev/ttyACM0 –baud=57600
Now if every thing is okay, then we could see an ipm prompt and we can test simple python codes. Below is some of my test codes and screen shots.





- I got one more product from element14, an arduino ethernet shield. I tried the basic examples of google search, twitter etc on it and it is working fine. Also there is a micro sd card slot which is very much helpful to easily interface a micro sd card to the arduino.. It is a cool stuff….
- What are the memory specifications of the Arduino Mega 2560?
The chip has 256KB of flash, 8KB of RAM, and 4KB of EEPROM. - How many digital I/O pins does the board have?
The board contains 54 Digital I/O pins, with 14 providing PWM output. - Can the RAM be extended externally?
Yes, the data sheet states that external RAM can be extended up to 64KB. - What function does the Atmega16 chip serve?
It acts as a pre-programmed USB to UART converter for serial communication between the main chip and PC. - How do you resolve the delay.h build error when compiling Pymite?
Add a custom delay_MS function and replace _delay_ms calls with delay_MS in the source code. - What command converts the generated elf file to hex format?
Use the command avr-objcopy -j .text -j .data -O ihex main.elf python.hex. - Which tool is used to burn the hex file to the board?
The avrdude command with the stk500v2 programmer is used to load the firmware. - How do you test the Python environment after loading the hex file?
Run the ipm.py script with specific serial and baud parameters to access the prompt. - What features does the Arduino Ethernet shield offer?
It supports network examples like Google and Twitter and includes a micro SD card slot.

