ANN: Python-on-a-Chip ported to Arduino Mega

Hello, I'd like to announce that I've ported Python-on-a-Chip (p14p) to the Arduino Mega. This is for the Mega only as p14p needs roughly 4K for the VM and the remaining 4K for whatever app you create.

p14p development is completely separate from the Arduino IDE and libraries, and the p14p libraries available are limited at this point. But by far the best feature is that you can run an interactive command prompt to create and run Python code immediately, without the compile/flash/test cycle.

This project is not for beginners. You need to know how to check out code from subversion, have avr-gcc installed, run a makefile, etc.

Link to this project shall go in a reply below (forums prevented a URL in my first post).

!!Dean

Link to project http://www.pythononachip.org

This IS nice ::slight_smile:
Maybe I try it next weekend.
The original implementation had been done here http://mbed.org/
This is an ARM/Cortex board for around the same cost as a Mega board, but runs 10 to 20 times faster... Not to mention things like Ethernet, 512KB Flash and 64kB RAM ;D
http://www.sparkfun.com/commerce/product_info.php?products_id=9564

yeah, shame the mbed isn't open source.

Great! I'm just getting started with python, and have done a few real simple python serial connections to an Arduino board and a few simple python connections using a python FTDI library (that I compiled from source) to an FT245 interface to 12 and 16-bit A/D converters. Going the other way by having python running on the Arduino mega sounds like "just the ticket."

So...

I downloaded pymite-08.tar.gz, verified the sha1sum, and unzipped it on my Centos 5.5 Linux system.

Then I did a "make" to get the workstation version compiled for testing. (GNU gcc version 4.1.2). The build process was uneventful, so I did "make check" to make sure it could work as advertised on the workstation before trying the cross compile.

Well, it got through all of the unit tests OK, but...

When it got to src/tests/system/t047, here's the message


../../tools/pmImgCreator.py -c -u -o t047_img.c --native-file=t047_nat.c t047.py 
cc -Os -Wall -Wstrict-prototypes -Werror  -I../../vm -I/home/dave/cprogs/pymite/pymite-08/src/tests/system  -o t047.out t047_nat.c t047_img.c t047.c plat.o ../../vm/libpmvm_desktop.a
./t047.out
Error:     0xE5
  Release: 0x08
  FileId:  0x00
  LineNum: 0
Traceback (top first):
  t047()
  <module>.

I looked at src/tests/system/t047.py and found the line line that (I think) caused it to choke. Here's line 55:

assert string.count("","") == 0

I ran the following line through python 2.4 and python 2.6 on the workstation.


>>> import string
>>> print 'string.count("","")  =', string.count("","")
string.count("","")  = 1

The lines 55-60 in t047.py look like this:

assert string.count("","") == 0
assert string.count("","a") == 0
assert string.count("a","") == 0
assert string.count("","\0") == 0
assert string.count("\0","\0") == 0
assert string.count("\0","") == 0

So I created a little python program to show the values of the counts

import string
print ' 1:  string.count("","")      =', string.count("","")
print ' 2:  string.count("","a")     =', string.count("","a")
print ' 3:  string.count("a","")     =', string.count("a","")
print ' 4:  string.count("","\\0")    =', string.count("","\0")
print ' 5:  string.count("\\0","\\0")  =', string.count("\0","\0")
print ' 6:  string.count("\\0","")    =', string.count("\0","")

Here's what I got with python 2.4 and python 2.6:


 1:  string.count("","")      = 1
 2:  string.count("","a")     = 0
 3:  string.count("a","")     = 2
 4:  string.count("","\0")    = 0
 5:  string.count("\0","\0")  = 1
 6:  string.count("\0","")    = 2

Since I am a novice in python, I didn't want to change anything in t047.py to try to "get it to work" because I wanted to ask the questions:

Have you verified that the tarball is valid for building and testing?

What should the count values be? Are they really all supposed to be zero?

What version of python is it supposed to be compatible with?

Have you run "make check" on your workstation?

What is your workstation operating system?

What version of python is on your workstation?

Regards,

Dave

Footnote:
When I bypassed t047, I got errors from other files (t102, t110, t136 and t160), but I didn't want to go any farther without getting some understanding of what went wrong with the first one.

davekw7x: Don't use release 08, use the latest from subversion.

davekw7x: Use Python 2.6 on the desktop.

use the latest from subversion

Ahhh---I should have realized. that.

Python 2.6

OK. Thanks for that.

Much better, however, for your reference, there was one (easily-fixable) problem:

With make PLATFORM=arduino_mega, I got the following error:


make -C src/platform/arduino_mega
make[1]: Entering directory `/home/dave/cprogs/pymite/pymite_trunk/src/platform/arduino_mega'
avr-gcc -c -mmcu=atmega1280 -I. -gstabs -DF_CPU=16000000UL -I../../vm -I/home/dave/cprogs/pymite/pymite_trunk/src/platform/arduino_mega -Os -Wall -Wstrict-prototypes -Werror -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  plat.c -o plat.o 
cc1: warnings being treated as errors
plat.c: In function 'plat_reportError':
plat.c:379: error: pointer targets in passing argument 2 of 'strncpy_P' differ in signedness
make[1]: *** [plat.o] Error 1
make[1]: Leaving directory `/home/dave/cprogs/pymite/pymite_trunk/src/platform/arduino_mega'
make: *** [all] Error 2

Changed line 378 in
from

                      pframe->fo_func->f_co->co_filename,

to

                      (char *)pframe->fo_func->f_co->co_filename,

Now it builds with no errors. (GNU gcc version 4.1.2, Python 4.6.5)

Haven't had a chance to cross-compile and upload anything to the mega, but will try it "real soon now."

Could you give a complete example (source code and compile instructions) that creates a hex file that I can upload?

Regards,

Dave

Dave, thanks for the defect reports. The ones in t047 still exist and I've created a ticket for them. The other one requiring the cast is because your avr-gcc is more up-to-date than mine (3.4.6); and I just mainlined that change. BTW, I'm very envious of your version of Python: 4.6.5

Everybody, I don't frequent the Arduino forums. If you want to talk about p14p, please consider joining our google group: http://groups.google.com/group/python-on-a-chip

Python: 4.6.5

Oops. By the pseudo-smiley, I perceive that you know that was a typo. It's actually 2.6.5.

Centos 5 comes with Python version 2.4.3. As I was trying to learn Python from books code on the web, I found too many examples that didn't work, so I built 2.6.5 from source. I see that, as of a week ago, 2.6.6 has been released, so maybe I'll try that.

Anyhow, thanks for coming over here to share your contribution to the Arduino cause.

I realize that Python details don't really belong here, so maybe I'll start hanging around the python-on-a-chip group (in my so-called spare time). I see the "step-by-step" there as a starting point.

Regards,

Dave