Raspberry Pi & openDAQ (I)

04 February 2013

Raspberry Pi is a board computer (SBC) the size of a credit card, which can be connected to a TV or a keyboard. It is a miniature PC with ARM processor that can be used for many of the things that a desktop PC can do, such as spreadsheets, word processors and games. You can even play HD video.

It was developed in the UK by the Raspberry Pi Foundation, intended to serve educational purposes. The board packs lots of features, Including a 700MHz processor, GPU VideoCore IV and 256 MB of RAM. And costs less than € 25!

As it is logical, it has become incredibly popular since it was launched in 2012. During the first months of sale, the shipping delays could last several months.

Interestingly, this platform uses Python as a primary development language and specially promotes its learning (Pi comes from Python!).

Here, we are all fans of Raspberry Pi, so we asked ourselves: Can Raspberry work with openDAQ? Absolutely!

In fact, they are an excellent matched couple, where openDAQ can provide a physical-analogue interface for Raspberry, which lacks on its own. In this first example, we will just teach you how to connect and perform a simple data acquisition using both of them.

We will be connecting to the raspberry through a terminal via SSH (ssh "IP address"). This is not important and you can connect with it in any other way you have on hand. In any case, you will need to have Internet access from the Raspberry, in order to download the neccessary packages.

You can use any of the USB host connectors in Raspberry to plug openDAQ. Raspberry will automatically detect CP2102 USB bridge and enumerate openDAQ.

The first step is to install the necessary Python packages (the interpreter is already natively installed). We will use the apt-get utility:

  • Install numpy
  • Install matplotlib dependencies (apt-get build-dep matplotlib)
  • Install matplotlib

From the TCP terminal you can check which ttyUSB* port is associated with openDAQ using the command dmesg. In our case it was the ttyUSB0.

[24598.036821] usb 1-1.3: New USB device found, idVendor=10c4, idProduct=ea60

[24598.036851] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3

[24598.036867] usb 1-1.3: Product: openDAQ

[24598.036878] usb 1-1.3: Manufacturer: Silicon Labs

[24598.036891] usb 1-1.3: SerialNumber: 0001

[24598.046588] cp210x 1-1.3:1.0: cp210x converter detected

[24598.124447] usb 1-1.3: reset full-speed USB device number 6 using dwc_otg

[24598.226110] usb 1-1.3: cp210x converter now attached to ttyUSB0 

Then, we must load the main library in Python for openDAQ, the module "daq.py", using scp or FTTP (scp /path/to/daq/daq.py pi@ipadress:/home/pi/). This module is included in the python-opendaq repository.

Now, you can run the Python interpreter on the same route (from the ssh terminal run: "cd/home/pi/", and then: "python").

Once imported (from daq import *) functions of the class can be freely used. In the following example lines, we set a voltage of 1.9 volts in the DAC and then read it through analog input A8:

pi@raspberrypi ~ $ python

Python 2.7.3rc2 (default, May 6 2012, 20:02:25)

[GCC 4.6.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from daq import *

>>> #here we connect to the openDAQ plugged in /dev/ttyUSB0

... dq = DAQ("/dev/ttyUSB0")

>>> #now we can set an output voltage

... dq.set_analog(1.9)

1900

>>> #if we configure properly the analog input, we can read it

... dq.conf_adc(8,0,1,20)

(-15176, 8, 0, 1, 20)

>>> # positive input 8,  negative input 0, gain 1 and 20 samples per point

… #now print read value in Volts

... print dq.read_analog()

1.88038437

>>> #Lastly print raw value

>>> print dq.read_adc()

-15287

 

As you can see, it's all very simple and intuitive. Virtually, Raspberry can run openDAQ simply by plugging it.

In next examples, we will give you a very interesting employ to the team of these two devices: we will create a web-server from Raspberry to allow remotely access to the data captured by openDAQ!