Programming Your DAQCplate

Writing Your First Program

What follows assumes that you have at least one DAQCplate Pi-Plate attached with an address of 0. In addition, it is assumed that you know a little bit about Python. If not, there’s an amazing amount of information on the web as well as some excellent books. We recommend Learning Python, 5th Edition.

No initial program would be complete without turning on an LED. Fortunately, the DAQCplate has nine LEDs for us to play with. For the first program, we’ll use the Python interpreter from the command line. Type the following at command line and hit <ENTER>:

This will launch the Python 2.7 interpreter and leave you with a prompt that looks like “>>>”. Next type the following two lines:

Congratulations! If everything went well, you should have turned on one of the green LEDs on the DAQCplate board. Go crazy and turn on some more by changing the second argument of the setDOUT function. Press the up arrow on your keyboard then backspace over the 2nd zero and type “7)” to make it look like:

Hit ENTER and the green LED on the far right should come on. When you’ve had enough fun, Press <CNTL>+D to exit the Python interpreter and return to the command prompt.


 

Writing Your Second Program

Another common first program is to write “Hello World” to the screen. But, since we don’t have a screen, we’re going to send the string “Hello World” to our LEDs using their ASCII representation. First  launch the nano editor from the command line with this statement:

Once the editor opens up, copy and paste or type the following lines. Note that the comments are unnecessary and are simply there for explanation:

 

 

When you’re satisfied with your edits, press <CNTL>-O to save your work and then <CNTL>-X to leave nano and return to the command line. Once there, type the following line to turn you DAQCplate into a single character binary teletype:

Now sit back and bask in the green glow of your software masterpiece. When you tire of it, hit <CNTL>-C to close the program. Congratulations, you just finished your second interaction with the DAQCplate!


 

Five Different Ways to Interact with Your DAQCplate

Since all of the programming used to interact with Pi-Plates is done using the Python programming language, there  are  a number of ways to interact with it.

Command Line

From the Linux command line, you can launch a pre-edited Python script by typing sudo python myprogram.py. See the Writing Your Second Program section above. Once cool thing about using the command line is that you can log into your Raspberry Pi with an SSH client and control it with your PC or even a tablet. Here’s a picture of a DAQCplate board being controlled via an application called JuiceSSH running on a Nexus 7 tablet:

Screenshot_2014-11-01-08-13-35

Command Line Interpreter

Or, you can enter the Python interactive environment by typing sudo python and talk directly to the Pi-Plate. See the Writing Your First Program section above. See the image above on doing this remotely using a tablet.

Integrated Environment

For a integrated development environment, enter the graphical user interface by typing startx at the command line. Once there, double click the Idle icon (not Idle3):

IdleIcon

 

This will bring up the Python development environment which provides an editor as well as a set of debugging tools for your programs:

IdleScreen

TKinter

We have written a small TKinter program which allows you to easily play with your DAQCplate board(s). It’s not quite finished and it’s not well documented, but it’s stable and really shows off the capabilities of the DAQCplate. To get it, execute this line of code from the command line in your home directory:

Then extract the files with:

Next, run “startx” to launch the x-windows environment, double click the LXTerminal icon, and type the following on the command line:

If all goes well the following window should pop up:

2014-08-17-203621_1920x1080_scrot

The program samples and updates the A/D channels and Digital Inputs once a second. Any changes that are made to the digital outputs or the DAC channels occur immediately. Go ahead and click some of the boxes in Digital Outputs frame – these will instantly turn on the LEDs connected to those channels. Run a wire from one of the DAC outputs to one of the A/D inputs to “close the loop” and experiment with both functions.

As stated previously, this software is a little unfinished. For example, the program is capable of addressing multiple DAQCplates in a stack, but when you change the Board Address in the upper right, all of the check marks in the Digital Outputs frame are unchanged which most likely will not reflect the state of the currently selected board. If all you do with this program is talk to a single board then you should have no problems.

So, there it is, feel free to adapt the code to your needs. We would be very interested to see what you do with it.

Streaming

If you want to plot your results, then the best thing to do is to stream your data to a third party website such as Initial State. With a single line of code you can send all of your data to their web site and then view it form any location using your web browser. Go to their web site and check out their rich feature set. Or, look at this example and see how we did it.

There are children playing in the streets who could solve some of my top problems in physics, because they have modes of sensory perception that I lost long ago. Robert Oppenheimer