Skip to content


Arduino + Liberlab = Liberino

liberinoIn this article Randall Bohn converts the Liberlab microcontroller project software so that the Arduino platform can take advantage of the great Liberlab software and experiment platform. We mentioned Liberlab here at uChobby in a recent article.

Liberlab is an excellent lab tool for learning about analog and digital control. With a programmed microcontroller and the supplied open source software you can easily make analog measurements, detect and control digital signals and even automate control functions. All this without learning to program! It truly is a great setup for teaching and simple control projects.

Randall’s conversion along with the Liberlab PC software turns the Arduino board into a very useful lab tool. It serves all the original purposes of Liberlab; Measurement, recording, conversion, control and is easy to use.

This article was submitted by Randall Bohn as part of the “Hobby parts for articles” program. Randall will receive some nice electronics parts or maybe another Arduino kit for this great article.

LiberlabSoftwareI took a look at the Liberlab project last year. The hardware was very simple, just an AVR ATMega8 chip and a RS232-to-TTL converter. I didn’t really see the point until I watched the screencast of the software in action. Liberlab is an easy way to read voltages in a circuit and graph them on the screen. It also allows you to drive 6 digital IO lines, either manually or based on the input voltages from the ADC (Analog to Digital Converter). Since I already have the Arduino hardware I decided to use that instead of building the Liberlab board. I have an Arduino shield with a light sensor and some LEDs on it, so I used that to help test my port. I smiled when I could turn the LED on and off by clicking a button on the computer, and I started laughing when I set it to turn on when it the light sensor was in the dark. Sure I could program the Arduino to do that directly, but here the decisions were all happening on the computer, with the results relayed back to the board.

There are several interesting screencast showing how easy it is to use the software for recording and controlling electronic projects. The software page on the main Liberlab site has three screencast to view.

The Liberlab firmware for the ATMega8 is about as simple as the hardware. This made it easy to figure out the protocol it uses to communicate with the computer. You can follow along at the project source code site [Link].

The ADC channels are selected using flags adc1order..adc6order. Next come some routines for serial IO (lines 75-108). Each ADC channel has a function to read it and send the result on the serial line (readandsendadc1() etc). The main() function starts at line 196. It initializes the UART, then it sends up the ADC readings and the digital port status. PORTD pins 2-7 are the digital IO lines. Finally it reads a byte from the serial port and uses that to adjust the digital IO lines. A-F turn pins on, a-f turn them off, and G or g will turn them all on or off. (It looks like you only get one character each time through the loop, and if nothing new has arrived you just reuse the last one).

So the input to the board from the computer is A-Ga-g single characters, and anything else you can ignore. Data to the computer for one ADC is A1[high][low], with all the enabled lines one after the other. Next comes the digital pins IN[byte], followed by a CRLF ("\r\n"). The ADC is 10 bits, with 0×000 = 0 Volts and 0x3FF = 5 Volts. There are 6 digital pins, so that range is 0×00 to 0x3F. One full line of input with all the inputs enabled would read:

A1..A2..A3..A4..A5..A6..IN.\r\n

(the dots above stand for raw binary values). The ADC results are sent big-Indian (most significant byte first).

To port this to the Arduino I make some different choices. I like to use bits instead of integers for flags, so I merge adcNorder() into one byte. I used the Arduino support for serial IO. I have one function to read the ADC pins and call it for each enabled input. I also read any pending characters from the serial port each time through the main loop. I also read the digital IO pins individually. The sketch is available in liberino.zip . I’ve used it on the Mega8 Arduino and the ATMega168 Bare-Bones Board.

With this sketch on the Arduino board I run the Liberlab software and connect it to port COM4 at 9600 baud. Then I click ‘Measure’ and the data starts drawing on the screen. When I wave my hand over the light sensor the trace on the screen moves up and down.

BIG COLOSSAL WARNING: Don’t connect the Arduino inputs to anything greater than 5 Volts. You will fry the chip! Always take proper precaution when working with electrical circuits.

The protocol from the Liberlab board is simple; I’m thinking about writing some Processing sketches to work with it.

Randall Bohn lives in Orem Utah with his wife and three kids. He is probably out on his snowshoes today. He is occasionally heard on the amateur radio bands as AD7NT. Randall learned the hard way that cameras with built-in-flash pack a 300 volt punch.

Posted in Arduino, Development Tools, Discovering, Ideas, Microcontroller, Workshop Tools.


10 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. DU says

    Awesome! I found the liberlab thing a while ago and wanted to use it for my next measuring project (multiple temperatures). I’m glad someone already ported it to the Arduino for me.

  2. francois says

    Hi guys and thanks for the two articles on Liberlab (I’ve just seen them on my RSS reader)

    Liberlab is not really active these days (lack of time) and since Arduino is now such an great project, and easily available, I “””planed””” (a while ago) to adapt Liberlab to it. So, I’m really glad Randall actually did it :)

    For information, the Liberlab firmware (I wrote 2.5 years ago) is not the most clean/efficient code and there is plenty of space for improvement. In particular I think the protocol is way too long to increase the actual data acquisition speed (100/150 measures/sec on the Liberlab board at 57600 bauds). For example there’s no real need for these extra “A1″ “A2″ “A3″ “A4″ characters (if we know where the data is in the string) and also the firmware shouldn’t need to process and send the four ADC channels if the user just use one.
    I began few months ago to make these changes in a firmware for the Arduino (and reading the data sent using the Liberlab python module). It was much quicker (over 1000 measures/sec, not sure of the baudrate anymore) but each few seconds I had a slowdown for a fraction of a second and didn’t investigate more. I’ll try to digg up that code for those interested.

    Apart from the GUI software there are interesting things to do with the Python module:
    http://pcsm1.u-strasbg.fr/liberlab/englishversion/logiciels/module-liberlab/document_view

    A fun example is to have three photo-resistors and one thermistor linked to the four ADC so you can play with the light to deform the x,y,z length of a 3D cube and heat the thermistor to change the color of the cube:
    http://www.flickr.com/photos/frenchy/100834508/
    http://liberlab.cvs.sourceforge.net/liberlab/liberlab-module/liberlab-demo-vpython.py

    Another example is to see a board live on the web and have the measures in real time and command the output in the browser (I’ll try to digg up the code and put it online):
    http://www.flickr.com/photos/frenchy/175546610/in/set-72057594057698650/

    Anyway, thanks, I think Arduino is the way to go. I’ll try to make some time for Liberlab software on the Arduino :)

    francois

  3. Sebastien CELLES says

    Hello,

    Arduino and Liberlab are both two very interresing project.
    I believe that some improvements could be made.

    To increase the bandwidth, the uC should store data in memory (a buffer) and send the buffer to the computer using the serial com.
    The speed for acquiring data and the speed for sending data to the computer will be differents so if buffer is full, the aquistion will stop (or the beginning of the buffer overwritten)

    This kind of mode is called “burst” by opposition of “sample” mode
    http://www.google.com/search?hl=en&q=data+acquisition+burst+sample&spell=1

    An over usefull feature could be to add a triggered scope
    http://en.wikipedia.org/wiki/Oscilloscope#Trigger

    About Arduino… instead of using a FTDI chip they should use a USB harwared capable uC such as PIC18F2550, PIC18F4550, ATMEL AVR USB http://www.atmel.com/products/AVR/usb/

    an other idea could be to use a software implementation of USB such as http://www.obdev.at/products/avrusb/index.html

    Best regards

    Sebastien CELLES

  4. dfowler says

    The Liberlab site is down for a bit for some maintanence. I have talked with the author and it will be back soon.

  5. Roland Latour says

    I use an Arduino Diecimila under linux, using shell
    scripts I developed. See my website, 207.14.167.161.
    Not 24/7, only works when my PC is booted. Full IO
    & PWM control, A/D readings scaled to mV & formatted
    for import to most spreadsheets. Requires Simple
    Message System firmware, available from arduino.cc.

  6. Bob Ryan says

    Randall- Your code is working great for me on the A0-A5 pins but I am unable to enable/disable any digital pins, I looked at the code but I am still a noob and didn’t see anything obvious. I was trying to use the automation menu in liberlab to enable/disable some outputs. Any ideas?

  7. jono says

    Hi,

    on line 50, should that be a “G” or a “g”. I ask because line49 is “G”.

  8. jono says

    woops, i forgot to add that this refers to the liberino.pde file

    Cheers

  9. rsbohn says

    @jono Right, the second one should be a ‘g’. Sorry about that! @Bob Ryan this might be the problem with the digital pins.

  10. Larry says

    Great artical. I down loaded the liberlab application and the sketch in this artical. I’ve only had my Arduino a week now, but projects like this are sure to keep me buzy in retirement.
    I had to modify one function in the sketch to get the digital readback function to work correctly in liberlab:

    uint8_t readDigital8() {
    uint8_t temp = 0;
    uint8_t result = PIND; // Read feedback of six digital outputs, pins 2 through 7
    // The following swap the bit order as needed by liberlab

    if (result & 128) temp = temp + 1;
    if (result & 64) temp = temp + 2;
    if (result & 32) temp = temp + 4;
    if (result & 16) temp = temp + 8;
    if (result & 8) temp = temp + 16;
    if (result & 4) temp = temp + 32;
    result = temp;
    return result;
    }