At my work I need to measure various things every now and then. I mostly use a DAQ card of a Linux computer with comedilib.
Today I also needed to store the values of a multimeter (HP 34401A) that measured the voltage over something the DAQ card also measured (PCI-DAS4020/12) measurement – I wanted to see how the values change during a longer period of time so I plot the data from both the DAQ card and the multimeter and see how the correlate.
Version 0.1 – the old fashion way..
I take pen & paper and write down the reading of the multimeter at the same time when I run the DAQ measurement. It’s time consuming and requires me to stay at the setup all the time. I also have to use time to move my notes from paper to the computer. Works for shorter measurements.
Version 0.2 – the simple digital way
I write the numbers directly to the computer. Makes it easier to start processing the data, but still requires me to stay around the whole time.
Version 0.3 – half-automated
We connected a Canon SX100IS camera with a USB cable on the Linux computer. Then we wrote a small script to run the DAQ card measurement every 30s – and using gphoto2 to tell the camera to take a photo of the multimeter Gphoto2 is an awesome tool to control about any digital camera! Then when the measurement was done, I wrote the values from the photos to a text file and was ready to analyze the data. I don’t have to stay around the whole time waiting for the next 30s period, the camera does the work for me.
Here’s the script:
#gphoto2 --delete-all-files -R # this removes all files from camera.. be careful..
#
for i in {1..40};
do
echo "#################"
echo "MEASUREMENT $i"
date
echo "#################"
#
#capture a photo
gphoto2 --capture-image &
#
#run the DAQ measurement
/home/administrator/comedilib-0.7.22/demo/mmap > mittaus$i
#
sleep 30
done
#
#download all photos and rename them to photo1.jpg photo2jpg etc..
gphoto2 --get-all-files -R --filename=photo%n.jpg
But I still have to copy manually the multimeter values from the photos. Doesn’t work for long measurements, say 2000 photos or more..
Version 0.5 – automated version
We were discussing already earlier today the option of using GPIB to read the numbers. There’s linux-gpib package available as well as python-visa so it shouldn’t be too bad. However since I’ve never done anything on python nor GPIB I decided to try the RS-232 aka. serial interface. Google gave me the HP34401A manual that told me what kind of commands the multimeter understands and how to connect there. After playing around a while I had a bash script to do the work for me. It uses standard linux commands like echo, head, sleep, for and stty so it should work on any Linux box with no additional software or hardware required.
delay=30
measurements=240
#
#Initialize the serial port
stty -F /dev/ttyS0 ispeed 9600 ospeed 9600 -echo cs8
#
#Set the multimeter to remote mode:
echo "SYST:REM" > /dev/ttyS0
#
#Reset the multimeter
echo "*CLS" > /dev/ttyS0
echo "*RST" > /dev/ttyS0
#
#Show 'LOADING..' text on the screen
echo "DISP:TEXT 'LOADING..'" > /dev/ttyS0
sleep 5
#
echo "########" >> values
date >> values
echo "Points $measurements" >> values
echo "Delay $delay" >> values
#
for ((i=1;i<=$measurements;i+=1));
do
#
echo "#################"
echo "Measurement $i/$measurements"
date
echo "#################"
#
#Show text on multimeter screen
echo "DISP:TEXT 'MEASURING..'" > /dev/ttyS0
#
sleep 1
#
#Measure the DC voltage with the multimeter
echo "MEAS:VOLT:DC?" > /dev/ttyS0
#
sleep 2
#
#Read the value
head -n 1 /dev/ttyS0 >> voltit &
#
#Run the DAQ measurement
/home/administrator/comedilib-0.7.22/demo/mmap > mittaus$i
#
#Show counter
echo "DISP:TEXT '$i/$measurements'" > /dev/ttyS0
#
sleep $delay
done
#
#Clear display
echo "DISP:TEXT:CLEAR" > /dev/ttyS0
#
#Return to local mode
echo "SYST:LOC" > /dev/ttyS0
Now I had it all automated. This simple bash script controls both the DAQ card and the multimeter and saves the multimeter values in a text file. No need for me to wait at the setup nor write or copy the values anywhere. It also shows the number of the current measurement on the screen of the multimeter. The commands to send to the multimeter are very simple, SCPI commands so the same commands work for ~any hardware. The same commands also work with GPIB.
I know the same could be done with ‘real’ programming languages like Python or C or GUI tools like LabView (starting from 780€). But 30 simple lines of bash (the rest’s comments & empty space) does it for me. I just love Linux.
Related posts:
- Matlab image save speed I use Matlab at my work to analyze measurements. This...
- 19.12. Tämä viesti on osa vuoden 2008 adventtikalenteria. This post is...
What accuracy? What speed? For <$30, an Arduino Diecimila will give you 10bits x6chans and 100 reads in <40 seconds. Output is spreadsheet-ready, scaled to mV. Also 12 pins for IO (6 for PWM) with a GUI via xdialog. Get the script package at user.cavenet.com/rolandl.
@Roland
Accuracy is high and depends on ly on the multimeter capabilities. Speed is of course not good (RS-232..) – I had to add those extra sleeps there to give the multimeter some time before the next operation to stop writing to it’s output buffer. But at the moment I only need to measure every 30 seconds.
Yes, I’ve heard of Arduino, some of my friends use it. It’d be nice to get to know it better. But still, it’s additional hardware to run the measurement :)
Pingback: Time lapse photography: Ice flowers | Risto H. Kurppa