Thursday, 18 July 2013

Python Arduino DAQ on the Mac

Kevin Hughes created a basic DAQ system in python to read Arduino analog voltages and display them on screen. He told me it should be platform independent, so I decided to try it on my mac. Steps to getting there [including mistakes where I slipped up]:

Get the arduino sketch running. This was simple, although I dropped the serial data rate to 57600 because that works with all the other stuff in my ecosystem.

[This was probably a huge mistake, as it looks like many libraries only work with python 2.7. Restored machine state and started again. Install python 3.3.2 for the mac, because that's the latest. After the install I still got python 2.7.2 from a terminal command line, even after a restart, but 'python3' gets 3.3.2.]

Serial Communications

Rely on the installed python 2.7.2 on the mac and install pySerial using Adafruit tutorial.

tar -xzf pyserial-2.6.tar.gz
cd pyserial-2.6
sudo python install

I confirmed pyserial was functioning by creating

import time
import serial

ser = serial.Serial('/dev/tty.usbmodemfa13131', 57600)

while True:
    message = ser.readline()

and it echoed output being written by the Arduino with Serial.println.


[The packaged matplotlib doesn't seem to work with the Apple release of Python. ( from gives an error saying "matplotlib 1.2.1 can't be installed on this disk. matplotlib requires System Python 2.7 to install.]

Following (or maybe better and some of provided alternatives after installing the xcode command line tools:

ruby -e "$(curl -fsSkL"
brew doctor

brew install pkg-config
brew install freetype
brew install libpng

sudo easy_install pip
sudo pip install matplotlib

The matplotlib install produced a huge number of warnings, but reported successful installation at the end.


Install wxPython (wxPython2.8-osx-unicode-py2.7) from To get the install to work you need to allow installs from anywhere in system settings. see and


After all that installing, still works. Got the Arduino running Kevin's ArduinoDAQ on a fresh port tty.usbmodemfa13141. Changed the port in  and ran, but it fails on loading wxPython 2.8 with no 64 bit environment. wxPython 2.9 claims to be OK with both 32 and 64 bit, so I installed it and then python runs!

It generates repeating warnings if the Arduino environment is still running, but quitting it and rerunning python works great.

No comments:

Post a Comment