32-bit PIC programming in Python!

PIC32MX4 Micromedia Python Demo

It has been a long journey for me to learn about modern interpreted object oriented programming languages, first on the desktop (see post here), later on industrial control and data acquisition applications (see post here) and now I feel like I have finally closed the circle: Python programming on an embedded control (32-bit) microcontroller thanks to the “Python-on-a-chip” project!

Dean Hall has been working at this project for several years now. He has demonstrated the possibility to run a small Python interpreter even on 8-bit architectures and others before me have ported the (well written) code to 16-bit microcontrollers like the PIC24. But since all Python interpreters have a huge thirst for RAM, it is only in the flat an (virtually) unlimited addressing space of a 32-bit microcontroller that Python starts really to make sense in my opinion.

So I have created a clone of the project (Mercurial) repository for the purpose (link)  and developed a new PIC32 port for the v10 revision of the project. While describing the whole project would take a while, it is interesting to note that the time I spent to “port” the PIC32 code in itself (from pull to first successful build) was less than an hour!

Actually most of the time for me went into figuring out how to use Python effectively to wrap existing libraries and get a useable,  or I should say a useful, package to develop applications on the PIC32 MX4 Micromedia Board.

At the moment I have demonstrated good real time support for the following features:

  • QVGA Graphics Primitives
  • Touch screen input
  • Joystick input
  • LED output
  • Serial input/output
  • Accelerometer input
  • Temperature sensor input
  • Audio (work in progress)

Eventually the project begs to be recompiled for a PIC32MX7 Micromedia board (128K of RAM!) where I could even dream to attempt a port of the PyGame libs to make development of little interactive applications real fast…

Please feel free to review the code and send your comments… but beware this is not a project for the faint of heart!

You will be required to master the following tools/application libraries:

  • MPLAB X
  • C32 Compiler
  • PIC32 peripheral libs
  • Microchip Application Libraries (GFX, MDD File System…)
  • Scons project manager
  • Mercurial versioning tools
  • Doxygen automated documentation generator/manager

Enjoy!

The Sinclair ZX Spectrum turns 30!

St. George

Happy Birthday ZX Spectrum!

Today Google UK  dedicates the daily doodle to  the 30th birthday of the ZX Spectrum.

I am part of that generation that learned to love computers/programming playing games like Manic Miner on an 8-bit little console with rubbery keys. The machine was so simple and ingenuous that you could get the entire schematic at a single glance and you could literally know every single line of code in the BASIC rom.

My tribute  to that lost (romantic?) era: an emulator for the PIC32 written entirely in C from scratch that runs the original games in almost real time (a bit faster actually) on a Mikroe Multimedia  Board.

Dmitry Grinberg

Single chip Audio Player

There are rare times when you realize unmistakably that you are in the presence of true genius. Visiting Dmitry’s web site today was one of them!

Check out this project and you will get the picture!

Now genius and madness are often separated by a thin line, here is a second example that will remove any last doubt!

I cannot wait to see what he will do next!

Codecademy

Last night, I was cleaning up (managing) my notes (I use Evernote for pretty much everything in my life) and I stumbled upon a reference to “codecademy”.  For as much as I tried I could not remember what it was about or where I had gotten this, so I did what we all do nowadays, I googled it! The result a misterious link to a web site: http://www.codecademy.com

Codecademy

You must take a look! This is one of those things that make you say: ” Why did I not think of it?”

My head is spinning with ideas for courses, if only there was a nice way to apply it to Embedded Programming too…

MPLAB X

MPLAB X

So it is done! After more than two years from my first hopeful post I have completed the transition. I have severed all my connections with Windows. MPLAB  was the last strong chain keeping prisoner but with the latest release of MPLAB X (1.10 just a couple of days ago) I can finally say I am free.

No, it is not perfect yet, but I can definitely say that the advantages/features of the new (Netbeans based) IDE surpass the few remaining squawks and occasional annoyances/frustrations.

I love the new navigation capabilities, the call tree, the local history, the … it’s a long long list of sometimes little things that add up and can make your development time so much more productive.

It has been more than a year since I started using it (from the very early betas while re-writing many of the PIC24 book chapters for the second edition) and it is several weeks now that I am not firing up MPLAB 8 anymore. I guess this is the signal. Eventually MPLAB X has reached a level of familiarity for me such that I feel comfortable developing exclusively with it. Or perhaps there is a natural amount of time that our mind requires to accept a new tool, especially when it impacts so much our daily work.

MPLAB (8.x) is dead, long live MPLAB X!

Virgil

Virgil

I was reading recently about the (slow) adoption of object oriented programming languages in the embedded world. There is quite a sad situation, while in the mainstream, OOP languages are pretty much a standard, in the embedded world, they are just starting to show up, why?

The problem is not the lack of say C++ compilers or Java environments for the architectures used in the embedded world, it is more a matter of dealing with the runtime overhead and code bloating often produced by those solutions. But independently from the language of your choice, not all OOP is bad (as in bloating and runtime heavy…) there are some constructs in each language that are worse than others.

Ben L. Titzer, Jens Palsberg and other researchers at UCLA have been working for years on the subject and they have distilled a list of good and “bad” features that impact so much more heavily the typical embedded application. Their recipe, a new language called “Virgil“, designed from the ground up to provide you with the best of OOP without the worst of OOP.

Virgil is compiled to native (like C++) but is also strongly typed (like Java) and shares a syntax that is certainly familiar to programmers of both origin. There are also provisions for low level management including interrupt handling, special function registers and bit manipulation!

The only problem is that new languages’ adoption is always very slow, even when there are strong sponsors… (anybody used “GO” recently?), so if we wanted to accelerate the adoption of OOP, introducing a new language is not exactly a quick option…

Nonetheless, take a look at Virgil and see if you like what it has to offer…

Maximite

I have to confess that, if I had not already done so in the past,  when I wrote some of the material for the PIC24″flying” book such as the composite video and the keyboard interface examples, I had a bigger project in mind. Eventually I was hoping to be able to put them together and (re-) create some sort of a mini personal computer. Unfortunately the early PIC24 models proved to have too little RAM for that purpose, but when the PIC32 came out, I gave the whole project a second try.

This time though I took a completely different route, using a USB keyboard interface (in place of the PS2) and using a TFT display in place of the PAL video output. FreeRTOS gave me the ability to put various other pieces together with some agility, including a Z80 interpreter/emulator and even a tape emulator (using SD Cards instead). The result has been the ZX Spectrum project running on the MikroElektronika MMB-MX4 boards. With it, you can run Sinclair Basic programs but also play old videogames in almost perfect real time.

Unfortunately, in the process the simplicity of the original idea got somewhat lost. The ZX Spectrum simulator is composed of several layers (FreeRTOS, USB, Graphics libs, Z80 emulator, SD Card file system) each eventually requiring of a certain level of knowledge to handle and maintain.

Maximite

Geoff Graham took a different approach and assembled instead a neat little board, the size of a credit card, to create a very agile little computer programmable in BASIC: the MAXIMITE. The project was the center of a series of articles he wrote for the magazine Silicon Chip where he described how he ended up writing almost from a scratch a BASIC interpreter for the PIC32. He has since posted the complete Maximite project on his web site and gathered a significant community around it.

I love his idea and I will keep checking his web site for news and future developments….

Atypical Curiosity

Actually I am typically pretty curious, especially when it comes to programming languages.

Atypical is a programming language that I discovered recently almost by mistake.

It was designed for the PIC and around the PIC assembly (midrange, 14-bit core) by Michael Park, with all the limitations and quirks of the PIC core, but with the intention to add a little structured programming and improve readability (quite a bit). Atypical flies very low, adding only a very thin layer of pre-processing to your source code. No fancy optimizations, if you are a hard core assembly wizard, you will appreciate how all the power is still in your hands…

As the author says, take a look and see if Atypical piques your interest! (link)

PIC32MX7 PIM, RB5 pin conflict (solved)

I need to thank Martin K. for bringing to my attention an issue that appears to be affecting quite a few of the readers of my PIC32 book when they attempt to use one of the new MX7 PIMs on the Explorer 16 board.

On the PIC32MX7 models the VBUSON and FVBUSONIO, are multiplexed with RB5 where the Explorer 16 connects instead the potentiometer. That could in fact cause an issue if it was not for the fact that the PIM sockets are NOT a 1 to 1 match to the PIC pins!.

See the document that comes with the PIC32MX7 PIM:
http://ww1.microchip.com/…n/DeviceDoc/51949A.pdf

and you will find that pin 20 on the Explorer16 (the pin actually connected to the potentiometer), is instead connected to pin 23 on the device, which corresponds to AN2.

So in the examples of Day 10, just read out AN2 instead (remember to adjust AD1PCFG and AD1CHS accordingly)  and you will get a perfect representation of your potmeter’s position!

MikroE Mini-32 Board

Mini-32

The guys at MikroElektronika have done it again!

Here is another brilliant new development board for the PIC32: the Mini-32

This board makes a PIC32MX5 fit in the exact form factor of a standard PIC16 or PIC18 40-pin DIP with full pin-out compatibility (with approximately 80 PIC models), but it operates at about 10 to 40 times the speed.

Of course you get 64K (+12K) of FLash memory and 16K of RAM too. A CAN interface complements a number of serial ports and the USB port is already there for you to bootload new code into it without having to use any additional hw development tool.

At USD 25 a piece, it looks ideal for breadboard-ing and quick (classroom) experimentation.