I’ve been using pyFirmata to power my PiPodCorder project that uses a RaspberryPi and an Arduino to read a load of sensors and display them to an LCD screen. However, I’ve been noticing that there are a few alternatives. I’m going to try and do a little on-paper evaluation of the three I’ve found so far.
Warning: This might be a little rambling.
First of all, there is pyFirmata which relies on the StandardFirmata sketch (or other sketch) being uploaded to the Arduino. pyFirmata is easy enough to use as it’s a Python library on the Pi. It also has the advantage of being a standard sketch issued with the Arduino IDE. The one issue I find with the Firmata sketch on the Arduino is that it does some weird-arse conversions between digital and analog readings. Take a sensor reading. As I understand it, normally on the Arduino a reading is taken from 0-1023. However, Firmata then converts this to a figure from 0-1. Which means that you then have to re-convert it on the Pi if you want the original reading. Obviously, 0-1 gives you a handy percentage reading, but I’d much rather do that conversion myself on the Pi.
Secondly, there’s nanpy. I covered it previously but have not yet used it. There is a firmware side and a client-side for the Pi, but it is not fully developed yet and it’s slightly unclear as to what it offers apart from the basics. Of course, the “basics” are what I will be using, so I’m going to give it a go!
And now, there’s PiSerial. PiSerial is interesting because it’s not a fully-fledged library. There’s no client-side at the moment (although the author is working on a Python implementation) and it’s basically a parser that sits on the Arduino waiting for commands over the serial line. Now, I’m not sure how efficient this is. The author of PiSerial says that Firmata communicates using binary, whereas PiSerial is (as the name infers) strictly text-based over the Serial line. I’m not so sure this is a big problem in terms of performance. The pyFirmata library must communicate over serial, as there is no other way of communicating between the Pi and the Arduino, it’s just the format of the commands that differs, I would have thought. In fact, thinking about it, if Firmata does use binary, there must be a fair amount of packing and unpacking of the commands on both sides… which surely must introduce overhead. Anyway, I haven’t got the tools and ability to test out that overhead yet, so I’m hoping Code and Life will do this in time.
The most important difference between Firmata and PiSerial, however, is that you control the code on the Arduino. That’s right: the PiSerial is merely a framework on which you hang your own command parser. I don’t want to replicate all the text from Code and Life here, so I suggest you read it yourself to find out how the communication is achieved.
In summary, Firmata is quite a beast for what I want it to do for the PiPodCorder project. Essentially, all I want it to do is to do sensor readings and I’m not sure that it’s the best solution for that, what with the 0-1023 conversion it does. So, I think I will try to convert my PiPodCorder Python code to use nanpy and then, when the client-side is written on PiSerial, try that as well. Hopefully that will give me an insight into which one is ‘best’ for my needs and which one is more educational/interesting to use.