Vernier sensors and the Wolfram Language

Here’s another guest post from Allison at Wolfram Research. Today we’re looking at how to interface external sensors from Vernier Software & Technology to the Pi using the Wolfram Language.

Even though we only released the Wolfram Language on the Raspberry Pi a few months ago, Bob LeSuer is already a power user. He’s an Associate Professor of Chemistry at Chicago State University and is naturally a big proponent of incorporating technology into his teaching. In his lab classes, he uses instruments from Vernier, a company that creates a wide array of sensors for collecting data, from accelerometers and barometers to CO2 and pH sensors. But what particularly piqued our interest was that Bob came up with the idea to connect these sensors to the Raspberry Pi with the Wolfram Language! So of course we had to share.

Equipment you will need:

First, download the Vernier Software Development Kit for Linux and follow the instructions for unpacking the file. A few additional lines of code will need to be added to get it to run on the Pi.

In config.in, add:

AC_CONFIG_MACRO_DIR([m4])

And to Makefile.am, add:

ACLOCAL_AMFLAGS= -I m4

The following C code and MathLink template were used to create the functions getLibVersion, getDeviceInfo, and getSimpleMeasurements, which can be used in Mathematica. Download the two files and compile them with the following command:

mcc -o vernier vernier.c vernier.tm -I/usr/include/GoIO -lGoIO

Make sure the GoIO library is linked and that the /usr/include/GoIO directory is included in the search path.

And now, switching to the Wolfram Language, you can dynamically update the readings from your sensor with the following code:

link = Install["/mnt/documents/Pi/vernier/Vernier"]

Dynamic[{Column[{Row@StringSplit[getDeviceInfo[], ","][[{4, 5}]],
getSimpleMeasurement[]}], Clock[{1, 1}, 2]}]

The code will even continuously update with the appropriate readings as you swap sensors!

Similarly, you can make a plot update in real time, as shown below using a light sensor:

info = StringSplit[getDeviceInfo[], ","]

Dynamic@ListPlot[data, PlotLabel -> info[[4]],
Frame -> {True, True, False, False}, FrameLabel -> "Time (s)",
"Light " <> info[[5]]]

And this is just the start! There are an infinite number of ways now for this data to be analyzed and optimized with the Wolfram Language. You tell us—where would you go from here?

Bob’s web page also has some more great ideas for using the Wolfram Language and the Raspberry Pi for experiments (like building a spectrometer using Lego!).

16 comments

Avatar

I think this is an excellent use of the Raspberry Pi, some people have much interest in do this type of applications (specially Physics professors )

Avatar

This is very interesting, but with over 650 sensors/components listed and prices from the hundreds to thousands of dollars, it’s all pretty overwhelming. It’s not clear who can afford this beyond well-heeled universities and private primary/secondary schools. I can’t see how any public primary/secondary school could afford to equip a single class, let alone a campus lab, with a reasonable collection of these instruments, which apparently are of world-class quality (at least I certainly would hope so for the prices asked). I did notice that integration with required standards has been performed, which is very helpful to educators as that’s the first thing administrators ask to see.

It’s going to take quite a while to plow through what appear to be subject-oriented kits/packages that I hope offer significantly-increased value over buying components individually. If anyone has extensive experience with many of these components and can provide pointers to what are the most appropriate to acquire, in what order, and how they’re best used that would be greatly appreciated.

Does anyone have recommendations for sources of grants or other funding for U.S./California schools that tend to support schools in acquiring this sort of equipment? For a start, I’m going to buy the cheapest set of probes for the most common things measured that can’t be readily rigged using parts available from electronics suppliers.

In any case, it will be interesting to try out some of these things with Mathematica. Given that the SDK is from Vernier, can what’s shown here be used with self-built sensors/probes or those from other suppliers, or only those from Vernier?

Thanks Allison and Bob!

Avatar

I tend to agree that when financial considerations are incorporated into the equation, Vernier/RPi loses some of its attraction. My interest in the project originated with “I’ve got these parts lying around the house, can I build something” and the answer was a surprisingly rapid-fire yes. If you or your institution have the dollars to purchase Vernier sensors, then you undoubtedly have the money for the Vernier hand-held computer which does the same thing that my Mathematica/RPi implementation does, only with better graphics and fewer bugs.

I doubt the Vernier SDK would be of much use to non Vernier probes; the biggest advantage of the SDK is that it saves the end-user from having to parse the information being sent from a Vernier USB sensor. That said, the source may be of use to someone more knowledgeable in low-level driver programming to implement custom solutions.

Avatar

Exactly my feelings, Jim.

My father was a secodary-scool Physics teacher, and (back in the 80;s) also ran ‘Electronics’ modules as well (are such modules even available in modern-day syllabi?). He saw my BBC Micro(s), he saw the Computer Rooms stacked with BBCB’s back in the day, and he set out to build a suite of simple interfacing projects that could be used in his Electronics and Physics labs – but at the lowest possible price.

After all, education budgets are ridiculously low at the best of times (despite the nonsense we are supposed to believe from Westminster).

And then it is folk like me who, when it comes time to try and find ‘electronics engineers’ to fill business vacancies, realise just how small the pool of ‘good’ engineers really is. (By the way, my classification of a ‘good’ electronics engineer has now had to be reduced to those applicants who do not calssify an op-amp as an ‘8-legged diode’ !!)

So – when I see these commercial sensors being offered to the educational market, I realise that nothing much has changed in the last thirty years. The products on offer are simply too expensive (and, unjustifiably so).

Why, when the Pi Foundation can offer a ‘full-blown computer’ more less than most of these sensor prices, would anybody be able to justify their purchase?

I would be far more interested in Wolfram and the likes of Adafruit (other sensibly-priced vendors are available) working together.

Sorry – but Vernier may have great intentions, but affordability is obviously not one of them.

Cheers,
Niall

Avatar

Elegant, beautiful and very useful. Thanks for bringing this to our attention- & I’ll certainly look at the ‘system’.

I’d echo Jim, though. The Pi world has a major dichotomy between experts with high & appropriate skills, and often big budgets- and the Foundation’s audience of children with pocket money.
In another section of the forum it happens I’d just posted Python code to smooth readings from sensors. An LDR+capacitor, and timing of a GPIO pin, and a few lines of code turns your screen into a scrolling analogue display understandable to even Python beginners. The scale is of course non-linear and arbitrary, not in absolute values of light intensity.

Keep this kind of reference coming, guys, but remember too which target audience a particular posting may appeal to!

Avatar

The Wolfram folk get to pick what they guest-post about – I agree that there’s going to be a limited audience for this particular application, but it *is* interesting; and believe it or not, we do have readers who will be using Vernier sensors in their labs at universities and in business.

Avatar

Don’t mind me, I’m just another educator spoiled by the Pi effect: drastically increased expectations for devastatingly decreased prices for tech – and hence non-existent profits for suppliers. TBH, the Vernier prices are in line with those for high-quality professional sensors and probes, but it seems like an area ripe for some DIY Maker projects and Kickstarter/IndieGoGo campaigns.

Accuracy past three decimal places is way overkill for primary/secondary school if that’s what these are capable of (still plowing through the products list), so a line of modestly accurate and priced sensors/probes and A/D input interfaces would be very well-received from those of us at the low end of the food chain (I introduce visitors to the Monterey Bay Aquarium to zooplankton all the time – I just never realized I was one! :lol: ).

Avatar

Yes again Jim – my heart-beat monitor on the Beeb was a torch bulb and a Light Dependent Resistor, connected to the Beeb’s Analogue I/P Port – with the ‘guinea-pig’s’ finger shoved in-between the two (and a vague promise of “don’t worry, it won’t hurt (much)”.

A few lines of code (more difficult on the Pi, because of the hurdles needed to be overcome to get on-screen graphing up and running), and a very simplistic Kalman-based filter:
new_value= ((smoothing * old_value) + new_reading) / (smoothing + )
old_value = new_value

And that was it – a scrolling ‘heart-beat monitor’ easily as impresive as anything on “Casualty”!!

Total cost – less than a fiver !!(and, that’s probably in today’s prices!!).

And all the (many) other sensors were basd on similar ‘chewing gum and gaffer tape” approach.

So – it CAN be done!

Cheers,
Niall

Avatar

I notice the last reported value of the “CO2 High(ppm)” sensor in the animated gif is small negative value, something like -7E-45. Perhaps they can comment on the physical meaning of a negative concentration :-).

Avatar

Negative concentration is what I experience when I’m trying to read the tripe that some people pass off as source code. My mind would much rather being doing anything else! :lol:

Avatar

I am still encountering some timing problems with my Wolfram/RPi setup, and this applies to both USB and GPIO style sensors. The negative readings occur when Mathematica tries to read from the sensor but the sensor doesn’t want to send the information. I’m still in the process of diagnosing this issue.

Avatar

Interesting use, we are looking to use the Rasberry Pi system with an ambient light sensor to adjust brightness of LED’s based on different lighting conditions. Anyone have some experience doing that?

Avatar

I can’t find “config.in” or is it “configure.in”? And where can I find the “C code and MathLink template” ? The links go nowhere.

Avatar

It looks like those links didn’t transfer over to this blog entry. If you look at the post on my website here you will find the active links. And you are correct, configure.in is the file that should be changed.

Avatar

Hi Bob,
I can’t contact you from your Home page Bobthechemist.com, then I’m posting from this page.

I had tried to compile the SDK adding the lines to ‘configure.in’ and ‘Makefile.am’ as your comment, but I got an error message.
The following is the system message. Could you please advise it?

———————————————————————————–
$ sudo ./build.sh
Useless use of /d modifier in transliteration operator at /usr/share/automake-1.9/Automake/Wrap.pm line 60.
autoreconf: Entering directory `.’
autoreconf: configure.in: not using Gettext
autoreconf: running: aclocal -I m4
aclocal: couldn’t open directory `m4′: No such file or directory
autoreconf: aclocal failed with exit status: 1
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target ‘dist’. Stop.
make: *** No rule to make target ‘install’. Stop.
———————————————————————————–

Avatar

The plot in real time with my Go!Temp:
link = Install[“/home/pi/Vernier/vernier”]
info = StringSplit[getDeviceInfo[], “,”]
data = {{t0 = AbsoluteTime[], getSimpleMeasurement[]}};
data[[1,1]] -= t0;
Dynamic[{AppendTo[data, {AbsoluteTime[]- t0,
getSimpleMeasurement[]}];,Clock[{1,1},2]}]

Dynamic@ListPlot[data, PlotLabel -> info[[4]],
Frame -> {True, True, False, False},
FrameLabel -> {“Time (s)”, “Temperature ” info[[5]]}]

Leave a Comment

Comments are closed