In 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.
I 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:
(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.