Creative WebWelcome to Creative Web. Discover professional articles, resources, and expert updates on our official portal.

mbed.org – Introduction & Improved MbedRPC Module For Python

Today I received my NXP mbed Design Challenge kit. At the first glance it looks like a cool piece of hardware: NXP LPC1768 (ARM Cortex-M3 Core) running at 96 MHz, 512KB flash, 64KB RAM, Ethernet, USB device/host, CAN, SPI, I2C, Analog I/O etc., but the first question was of course: How can I get my code running on this thing? On connecting the mbed via USB to your computer, a mass-storage device will appear into which you just drop your compiled files. To create this compiled files, you can use the browser-based IDE at mbed.org or build locally using arm-elf-gcc. At this point, I was really disappointed: They are only providing object files of their libraries, no source code. That sucks. But for now, ignore that fact and go on:
mbed.org – Introduction & Improved MbedRPC Module For PythonArchive Unresolved - Placeholder Asset" alt="A picture of the device itself." title="mbed-device" width="500" height="374" class="aligncenter size-medium wp-image-449"/>
The first thing I wanted to try out was interfacing the mbed using XMLRPC via USB (serial) from Python. In the mbed cookbook there is a module provided for that, but even loading that module fails:

1
2
3
4
5
6
7
>>> from mbedrpc import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mbedrpc.py", line 266
    self.mbed.rpc.(self.name, "write", [str(value)])
                  ^
SyntaxError: invalid syntax

Obviously, the loading fails because of the period in front of the bracket. After removing it the module loads. The next thing was this line in the sample code:

1
>>> x = DigitalOut(mbed, 3) # LED3

This is wrong, because DigitalOut needs either a string or a pin instance as second argument, but the module doesn't throw an exception which makes it harder to track this issue down. The code should look like this:

1
>>> x = DigitalOut(mbed, LED3) # LED3

(This is fixed in the Wiki now.)

After that, I was able to get a LED on the mbed blinking - Cool! But I was everything else then pleased by the module, so I started improving it. I replaced some stuff to make the code a bit more easy to read and modify, and I added a list called 'pins' which can be used to interface pin 0-29 using something like:

1
>>> x = DigitalOut(mbed, pins[2]) # LED3

You can find the latest version here: mbedrpc.py
Or check out the git repository at Github here.

After this starting difficulties, I'm now able to interface the mbed within my Python shell and everything works fine :-) . I hope that the guys from mbed decide to open the sources of their libraries at some point, as that would make the project MUCH more cooler, because one would actually be able to learn something about the processor by reading the implementations and could extend the libraries with own cool ideas - and I'm sure that there are a lot of people out their which have some great stuff in their head on what could be done with the mbed.