Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
Python on a Chip [Phyton-on-a-Chip]

Python on a Chip [Phyton-on-a-Chip]

Ratings: (0)|Views: 2,398|Likes:
Published by MC. Rene Solis R.
python on a chip, Good example HOWTO´s (MbedCookbook-PyMite)
python on a chip, Good example HOWTO´s (MbedCookbook-PyMite)

More info:

Published by: MC. Rene Solis R. on Mar 19, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/05/2011

pdf

text

original

 
2009/04/20 07:28PyMite – cookbook – TracPage 1 of 4http://mbed.co.uk/projects/cookbook/wiki/PyMite
PyMite
PyMiteis a flyweight Python interpreter.PyMiteruns bytecode-compiled Python programs or an interactive prompt. This project runsPyMiteininteractive mode. This project is also a rough draft, so it runsPyMitejust fine,but does not have the entire Mbed API wrapped and callable from Python. Intime the API will grow to allow you to control all Mbed peripherals fromPython.
Hardware
Connect to the Mbed via USB (same port that you use for programmingthe Mbed)The LEDs are hardwired and ready to go.Optionally, follow theTextLCDrecipe, if you want to print to LCD.
Software
PyMiteHardwareSoftwarePythonPySerialPyMiteMbed FirmwareHello World!Resources
 
2009/04/20 07:28PyMite – cookbook – TracPage 2 of 4http://mbed.co.uk/projects/cookbook/wiki/PyMite
Python
You need the official Python 2.5 (2.6 might work but is untested) on your computer.
PySerial
PyMite's interactive mode requires that you install the PySerial package
PyMite
You will need to get a copy of thePyMitesource tree so you have the tools to run the interactive hostsoftware.OPTION: If you want to zip your own project source tree:Results in
pymite_mbed.zip
in the current directory. Load
pymite_mbed.zip
into the on-line Mbedcompiler, compile and download.
Mbed Firmware
PyMiteon Mbed is alpha quality: you can get things to work, but there are known and unknowndefects.Install the
pymite_mbed.bin
binary built in the previous section, OR download and use this binarypymite_mbed.bin
Hello World!
Connect to the Mbed via USB (same port that you use for programming the Mbed). Run thePyMiteinteractive host software on your desktop or laptop computer (note: your serial port name will varydepending on your OS):Now you may type Python source at the prompt, just like you would with Python's interactiveenvironment. Here is the list of modules that you may import:Here is the list of builtin functions that you may call:All the stuff to control the Mbed is inside the
plat
module:The items that start with capital letters are class-like objects (PyMitedoesn't have real classes yet)Here is how to use them:
http://www.python.org/download/$ easy_install pyserial$ svn co http://svn.pymite.python-hosting.com/trunk pymite$ cd pymite/src/platform/mbed$ make zip$ pymite/src/tools/ipm.py --serial=/dev/cu.usbmodem1912 --baud=19200This is the interactive PyMite command line.Just type the code that you want the target device to run.Type another return if you see no prompt to exit multiline mode.Type Ctrl+C to interrupt and Ctrl+D to quit.ipm> print "Hello World!"Hello World!sys, list, dict, string, platchr, dir, eval, globals, len, map, ord, range, sum, type, ismainipm> from plat import *ipm> dir()['__doc__', 'AnalogIn', 'AnalogOut', 'DigitalIn', 'DigitalOut', 'PwmOut', 'Textipm> adc15 = AnalogIn(15)ipm> adc15.read_u16()11595ipm> adc16 = AnalogIn(16)
 
2009/04/20 07:28PyMite – cookbook – TracPage 3 of 4http://mbed.co.uk/projects/cookbook/wiki/PyMite
MorePyMiteExamples
This demonstrates the use of basic datatypes in PythonThis example defines a function with one default argument and calls the function. Press <Enter>twice to end a multi-line input:Press Ctrl+D to exit the interactive interpreter.
Resources
PyMite
More aboutPyMite
# Doing the above will let you use adc16, but adc15 will now refer to adc16.# This 1 instance limit applies to all other classes.ipm> dac = AnalogOut(18)ipm> dac.write(0x100) # This method will be renamed to write_u16() in the futipm> din = DigitalIn(5)ipm> din.read()0ipm> dout = DigitalOut(30)ipm> dout.write(1)ipm> dout.read()1ipm> pwm21 = PwmOut(21)ipm> pwm21.period_us(1000)ipm> pwm21.pulsewidth_us(500)ipm> lcd = TextLCD()ipm> lcd.printf("PyMite on Mbed!")ipm> lcd.cls()ipm> set_led(1,1) # LED1 onipm> set_led(3,1) # LED3 onipm> set_led(1,0) # LED1 offpm> 40+242ipm> 6 * 742ipm> 2**416ipm> a = 10ipm> a + 3242ipm> foo = range(5)ipm> foo[0, 1, 2, 3, 4]ipm> foo[3] = aipm> import listipm> list.append(foo, "a string")ipm> foo[0, 1, 2, 10, 4, 'a string']ipm> d = {}ipm> d["foo"] = fooipm> d[0] = "zero"ipm> d['1'] = 1ipm> import string; dir(string)['find', 'count', 'atoi', 'letters', 'hexdigits', 'digits', '__doc__']ipm> d{'1':1, 0:'zero', 'foo':[0, 1, 2, 10, 4, 'a string']}ipm> def bar(n=42):return ["bar",] * nipm> print bar(4)['bar', 'bar', 'bar', 'bar']ipm> ^D

Activity (6)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
munnagnekar liked this
manojram18 liked this
smartkiwi liked this
ALi liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->