Using Adafruit Fona GSM/GPRS breakout to log data to Xively

Collecting and logging sensor data automatically is one of the most useful “sciencey” things you can do with programmable microprocessors like Arduino and Raspberry Pi. One problem with this is what to do with the data you are collecting. You can store it locally to the device, for example Arduinos can log temperatures or movement signals from PIR sensors to SD cards. However, you have to turn the device off and remove the card, put it into a laptop and copy the data off it before you can access it. Alternatively you can send the data over a serial connection or wirelessly to another device which will store the data for you for easier retrieval or even real-time plotting. Recently small GSM/GPRS modules have become available which are essentially the guts of a mobile phone with no screen, battery or keyboard. These enable you to use mobile phone networks to send data to the internet using protocols such as GPRS and 3G. This is very useful for science as field experimental sites rarely sport ethernet ports or wireless routers through which to transmit data from long-term monitoring sites.

The Adafruit Fona is one of these devices and I obtained one with the intent of monitoring the temperatures in some of our more critical freezers and fridges in case one of them broke down, imperilling the irreplaceable scientific samples stored within. I’ve already set up one device using a GPRS shield from Elecrow. You can see the feed from it here. Its logging temperatures from three freezers in a shed on AUT’s North Campus where various valuable samples are stored. The Fona is a little smaller and a little cheaper and I wanted to make another couple of devices to deploy in our labs to keep an eye on the freezers there. These contain not only valuable samples but, in our molecular labs, thousands of dollars worth of reagents for the MiSeq, our next generation sequencing platform. The idea here is not just to keep an eye on the functionality of the freezers but to get notified if the power goes down. Freezers are well insulated so if the power goes off the temperature won’t immediately rise. If the power goes off on Friday evening, however…

In setting up the Fona I ran into problems getting code to work. The Fona code examples for GPRS access were limited to simple website recovery and not sending HTTP PUT requests, which is what is required to log data to Xively. Frustratingly the code I’d adapted from my previous GPRS logger didn’t work and I could find no indication as to why. Even more frustratingly the Arduino Xively libraries didn’t work either, probably because they had been written for use with WiFi or ethernet and not GPRS. Instructions are sent to the GPRS shields from your microprocessor using a special set of text commands, called AT commands. These commands need to be sent to the shield over a serial connection. The HTTP PUT requests sent to Xively must conform to something called REST, which is explained in somewhat inadequate detail in Xively’s API docs. So, to summarise: I had to use my Arduino to send AT commands to the Fona over serial that would instruct it to send PUT requests conveying my data to Xively. Three different communication protocols. Simples!  >_<

To cut a long story short I managed to use a Python library to send updates from my laptop to Xively by HTTP PUT requests. Using more Python I then managed to log the text of those HTTP requests and use that as a template that I could deconstruct and send to the Fona from my Arduino, inserting real-time data from sensor reads. The result is the code linked at the bottom of this post, which logs temperature, pressure and humidity data from an Adafruit BME280 sensor as well as the battery voltage of the Li-Ion cell connected to the Arduino and Fona. Credit to Limor Fried/Ladyada and Chip McLelland, whose example sketches I adapted to create this.

Here’s a quick pic of my setup. Its a Feather 32u4 LoRa, a uFL Fona and a BME280, all from Adafruit Industries. The Fona must have a lithium battery connected to it so I’ve added an 18650 Li-ion cell which is connected to both the Feather, which charges it, and the Fona. If the power does go out at work then the device will run for several hours on this battery, even without any low-power optimisation of the code. The enclosure is lasercut from 3mm acrylic. Its a beta version as I’ve yet to add mounts and an enclosure for the BME280. Ultimately I want this sketch to read three DS18B20 temperature sensors too, which will be in the freezers, but that’s a work in progress.

img_20161203_231247

Download this code: Adafruit_Feather_Fona_BME280.ino

Advertisements

how not to replace your kids’ quadrocopter toy batteries

I bought my daughter one of those little quadrocopters from eBay. It was a lot of fun but the battery seems to have died. I found a replacement on eBay for a couple of dollars, which arrived today. Unfortunately it was slightly larger than the original.

IMG_20160906_204447.jpg

I thought this wouldn’t be a problem so I just cut some bits out of the chassis of the quadrocopter and jammed it in.

IMG_20160906_204133.jpg

I think I might have underestimated how narrow the performance envelope of the thing is, because instead of zipping around the room it now does this.  😦

Making Size Exclusion Chromatography columns

My summer student, Kalita, has been digesting oligosaccharides, derivatising them and injecting them into the mass spectrometers in an effort to derive structural information from these complex molecules. We had hoped to use acrylamide gel electrophoresis to visualise the performance of our digests, in the way of Pomin et al (2005).

Screenshot from 2016-03-03 20:30:41.png

This figure from the paper shows the effect of their hydrolysis technique upon the molecular weight of the oligomer. Note the banding patterns resulting from selective hydrolysis of certain glycosidic bonds. This produces a regular reduction in size of the fragments. We wanted to use this feature to produce polymeric fragments in the <10kDa size rage. These would be amenable to LC-MS/MS, as in Lang et al (2014), allowing us to infer the sequence, functionalisation and bonding of the monomers within the oligomer.

As it turned out our acrylamide gels got lost somewhere amidst The Great Bureaucracy and so, with time running out we cast around for alternate technologies. Enter Yang, et al (2009), who used a similar technique in their paper, but also deployed Size Exclusion Chromatography to illustrate the size-class of fragments produced.

Screenshot from 2016-03-03 21:11:31.png

The thing is we didn’t have any GPC or SEC columns.  😦

 

So we decided to try making our own!  😀

 

Fortunately or chemical store had a shelf of old bottles of dextran and other GPC or ion-exchange substrates. We dug up a protocol from an MSc thesis by Wilfred Mak in which he’d used an anion exchange substrate to determine the molecular weight of intact sulfated fucan oligosaccharides, rifled through the stores to find some substrates that looked about right and away we went!

We started out with a biuret:

IMG_20160302_172848.jpg

At the bottom, hidden by the blue compression screw, is a plug of deactivated glass wool with a few mL of sand on top of that and then the white dextran gel. This was the first addition of substrate and settling. After topping it up we have a column of about 40cm length. This type of column is purely gravity-fed. You add sample and running buffer at the top and wait for the head of fluid to pass through the column, collecting fractions through the tap at the bottom. This can take hours.

While Kalita was putting this together I was looking at some of the old silica particle LC columns I had and wondering if I might dismantle them, remove the packing and repack them with the dextran to give a real, high-pressure column. This could be plumbed into one of our conventional LC setups, allowing us to push samples through at a faster rate and giving the option of automated sample injection, data and fraction collection. I had something of a brain wave and realised that I had some Swagelok fittings which would allow me to fit a piece of 1/4″ polypropylene air line with pressure-tight caps and LC fittings at either end to fulfil exactly that function. A couple of hours later Kalita and I were the proud parents of monstrous creation on the left!

IMG_20160303_162725.jpg

The white tube held between the two clamps on the left hand retort is the air line packed with hydrated dextran. The line at the top comes from the Shimadzu LC pump on the right, which is pumping Tris buffer through the column to settle the packing material. We can get a flow of 2 mL/min through the column with a back pressure of about 5 bar. Plenty for LC!

For now our creation is parked until we can get round to doing something cool with it on Monday but watch this space to see the outcome. Our intention is to add an autosampler to the front for sample injection, a Refractive Index Detector and maybe even an electrochemical detector on the outflow to detect what came off the column and possibly even a fraction collector for downstream LC-MS/MS analysis of the fractions! Fun!

Our first goal is to validate the SEC function by injecting a range of proteins stained with Bradford Reagent. We can also try some di- and tri-saccharides along with our oligo digests.

 

References cited

Lang et al (2014). Applications of Mass Spectrometry to Structural Analysis of
Marine Oligosaccharides. Mar. Drugs 2014, 12, 4005-4030
doi:10.3390/md12074005

Pomin et al (2005). Mild acid hydrolysis of sulfated fucans: a selective 2-desulfation reaction and an alternative approach for preparing tailored sulfated oligosaccharides. Glycobiology vol. 15 no. 12 pp. 1376–1385, 2005
doi:10.1093/glycob/cwj030

Yang et al (2009). Mechanism of mild acid hydrolysis of galactan polysaccharides with highly ordered disaccharide repeats leading to a complete series of exclusively odd-numbered oligosaccharides. FEBS Journal 276 (2009) 2125–2137
doi:10.1111/j.1742-4658.2009.06947.x

Bee hive mass logger

11-03-2016: This project hit a problem. See update at the bottom.

Following on from my bathroom scales hack I spent this evening sawing and screwing together the platform for it to sit on. This was an urgent task as the bee hive is being moved to a new location tomorrow and so this would be an ideal opportunity to get the scales in place without having to arrange another movement of the hive. Bees are incredibly precise creatures, I am discovering. If you move their hive a just a few meters away when foragers are out, they will return to the location they are familiar with and won’t be able to find their way home! If beekeepers have to move their hives such a short distance they’ll move them a couple of kilometers away for a week and then move them to the new spot.

The scales will sit on a plywood deck raised off the roof’s surface to provide a thermal insulation gap for the hive. I drew up the rough schematic below to illustrate this.

beehive mass monitor schematic

My final design was slightly different, with the pallet being a little smaller than the plywood shelf. This is because, as well as the four strips of ply that keep the shelf securely fitted over the scales, I also added a plywood curtain around the edge of the shelf that hung down below the pallet to prevent rain being driven in to the scales. The ply is 12mm and very solid. I sized it to be ever so slightly smaller than the footprint of the hive so that it will fit perfectly on top. Here’s some build pics:

shelf (upside down), scales, pallet

IMG_20160229_201128.jpg

scales on the pallet

IMG_20160229_201230.jpg

This next one is upside down but illustrates how the four strips of ply keep the top shelf secure. You can also see the curtains. The notches at the back are for wires to exit.

IMG_20160229_201303.jpg

final assembly

IMG_20160229_201403

 

Looking forward to testing this!

 

Update, 11-03-2016

Unfortunately there is a major flaw with my design. When Matt went to put the bee hive on top of it it turned out to be unstable due to the small footprint of the scales relative to the hive. The hive is only one box at the moment but Matt intends to add another soon and that would definitely make it vulnerable to being blown over by a gust of wind! Not a desirable situation. I am going to have to look at designing a larger platform to the corners of which I can attach the load cells. This is contrary to the advice on the MakeZine blog that inspired this project, however I cannot see any other solution besides buying an industrial-size set of scales. I want to try the DIY option first before I spend a couple of hundred dollars.

Hacking bathroom scales with an HX711 breakout

Hopefully this will be the start of a series of posts on the Internet of Bees, or the #IOBee. In case you didn’t realise, this is a play on the Internet of Things, or IoT. My intent with the IOBee is to document my application of some basic sensor technology to monitoring the health of bee hives.

There is an excellent writeup here of a conversion of a set of luggage scales to a real-time bee hive mass monitor. I have been wondering if I can do the same thing to monitor the mass of experimental bee hives in some research I’m planning looking at the effects of neonicotinoids upon honey bee colonies. In order to test this out I ventured onto eBay and bought a couple of HX711 breakouts, which you can get for just a couple of dollars.

HX711 breakout

I also bought a cheap set of bathroom scales from the Warehouse, despite the advice on MakeZine, which advised not to skimp. I intended this to be a proof-of-concept so I wasn’t going to be spending big bucks just yet.

bathroom scales

This turned out to be an excellent hacking subject. After taking the back off I found a circuit board carrying the integrated circuit, some components and some wires.

IMG_20160221_155644

The two black pads you can see are the rubber feet on the bottom of the load cells. I prised one out to show you the other side.

IMG_20160221_155936.jpg

The red white and blue wires coming from each of the four load cells needed to be joined together carefully according to the first image in this excellent post on StackExchange that I located after a modest amount of googling. I also found this how-to from SparkFun to be informative.

Once I had soldered the blue and white wires together to mimic the pattern shown and the red ones to the appropriate pads on the HX711 breakout I was left with this:

IMG_20160221_175642

I also soldered the wires from a length of USB cable from an old mouse to the other side of the breakout. The four tabs and their wires were to VCC (red), GND (black), CLK (white) and SDA (green). I drilled a hole in the plastic chassis to pass the cable through and put a cable tie around it on the inside to prevent the wires being pulled off the board. The mount holes in the breakout board ( I love mount holes!) happened to be just the right width to allow me to screw it to the chassis through two of the holes that the original PCB was mounted on. The white thing is a piece of polyethylene milk bottle wall that I cut out and used to insulate the connections of the breakout and to hold it down as the screw heads were nearly as small as the holes. This arrangement allowed the breakout to be seen through the glass window where the LCD used to be. A nice touch. 😀

IMG_20160221_204630.jpg

Having wired everything together I needed an electronic brain for my creation to talk to so I hooked it up to the Arduino Nano I’ve been using as a receiver for my solar-powered, wireless monitoring testbed. Ignore the BME280 and the NRF24 coming off it. VCC went to 5V, GND to GND, SCK to D4 and SDA to D5.

IMG_20160223_212825.jpg

I downloaded the HX711 library written by bogde (thanks!) and also the HX711 breakout sketches from the SparkFun how-to linked above. I was pretty impressed to see numbers appear straight away on the serial monitor although this turned to mild disappointment when I placed a mass on the scales and the number went negative! Apparently I had got the polarity of the signal wires the wrong way around. 😦

Five minutes of soldering later I was back reading numbers and this time they went up with the mass on the scales. According to the instructions on the test sketch I kept adjusting the calibration factor until the scales read the correct mass for the object I’d put on it. Then came the acid test: now it was calibrated, would it get my mass right?

IMG_20160221_210139.jpg

As you can see it worked almost perfectly. And I am somewhat overweight. :-/

A useful edit I made to the SparkFun code was to change the line

Serial.print(scale.get_units(), 1);

To

Serial.print(scale.get_units(), 3);

This gave me three decimal places instead of one and significantly more information. I was particularly pleased to see that these scales read quite consistently. The numbers for my weight jump about quite a lot because I wasn’t too worried about keeping still to get a stable reading but when I placed a fixed mass on the scales the second decimal place was pretty stable and only the third flicked up and down by 1-3 units. These scales were advertised as being accurate to +/- 100g so my results indicate I can do much better than that. And that’s without any of the tricks you can use with microprocessors to improve the accuracy of otherwise low resolution tools, such as polling them and taking a moving average.

More on the application of this very cool hack another day, once I’ve validated the calibration as described on MakeZine.

Scraping molecular information from ChemSpider using Processing.

I’ve spent the evening knocking out this little sketch to scrape molecular information from ChemSpider to inform my mass spectrometry. Until now I’ve been doing this by hand or getting the students to, when they are able, but this is the start of my attempt to automate the process. Ultimately I will just want to feed it a text file of compound names and it will parse the output into a document.

Open a Processing window, copy the code below into it, edit the first string to contain the name of the compound of your choice and click run. Here’s an image of example output.

Processing ChemSpider sketch output

// sketch to grab molecular information from a named compound from ChemSpider
// AUT School of Applied Science
// June 2015
// drchrispook@gmail.com
// released under GPLv3 licence – https://gnu.org/licenses/quick-guide-gplv3.html

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// enter the compound name you want information for
String compound = “caffeine”;
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

// sketch continues
PImage webImg;

String URL = “http://www.chemspider.com//Search.aspx?q=&#8221;;
String nameURL = URL + compound;
String[] html1 = loadStrings(nameURL);

String CSID = “CSID”;
String formula = “formula”;
String MIM = “MIM”;
String solubility = “solubility”;
String logKow = “logKow”;
int imageSize = 400;
void setup() {
size(imageSize, imageSize);

for(String i:html1) { // iterate through each string in the array
// println(i);
int line = i.indexOf(“CSID:”); // identifies CSID line by searching for this string

if(line > 0) { // if you find that string
String[] trim1 = split(i, ‘,’); // split off the junk
// for(int i = 0; i < trim1.length; i++) { // println(trim[i]); // } String[] trim2 = split(trim1[0], ‘:’); // split off more junk CSID = trim2[1]; // set the CSID break; } } String imageURL = “http://www.chemspider.com//ImagesHandler.ashx?id=&#8221; + CSID + “&w=” + imageSize + “&h=” + imageSize; webImg = loadImage(imageURL, “jpg”); String CSIDURL = “http://www.chemspider.com//Chemical-Structure.&#8221; + CSID + “.html”; // use the CSID to construct the url to that molecule’s entry String[] html2 = loadStrings(CSIDURL); // grab the html //println(html2); for(String i:html2) { // this is the main part of the macro // println(i); int MIMLine = i.indexOf(“Monoisotopic mass”); // identifies MIM line int formulaLine = i.indexOf(“Molecular-Formula”); // identifies the formula line int solubilityLine = i.indexOf(“Solubility at 25 deg C (mg/L):”); // etc int logKowLine = i.indexOf(“Log Kow (KOWWIN”); // etc if(formulaLine > 0) {
String[] trim1 = split(i, ‘/’);
// for(int e = 0; e < trim1.length; e++) { // println(trim1[e]); // } String[] trim2 = split(trim1[2], ‘”‘); formula = trim2[0]; } if(MIMLine > 0) {
String[] trim1 = split(i, ‘>’);
// for(int e = 0; e < trim1.length; e++) { // println(trim1[e]); // } String[] trim2 = split(trim1[3], ‘ ‘); MIM = trim2[0]; } if(solubilityLine > 0) {
String[] trim1 = split(i, ‘ ‘);
// for(int e = 0; e < trim1.length; e++) { // println(trim1[e]); // } solubility = trim1[12]; } if(logKowLine > 0) {
String[] trim1 = split(i, ‘ ‘);
// for(int e = 0; e < trim1.length; e++) {
// println(trim1[e]);
// }
logKow = trim1[11];
}
}
print(“the formula for ” + compound + ” is “);
println(formula);

print(“the monoisotopic mass of ” + compound + ” is “);
println(MIM + ” Da”);

print(“the estimated log Kow of ” + compound + ” is “);
println(logKow);

print(“the solubility of ” + compound + ” at 25C is “);
println(solubility + ” mg/l”);
}
void draw() {
background(0);
image(webImg, 0, 0);
}

Arduino GSM shield

This week’s project: setting up this Arduino with GSM shield to monitor the UPS that powers my mass specs. If we get a power cut (or when- this is Auckland after all) it will send me an SMS so I can race in and shut the mass specs down before they crash. Full write up when I’ve managed to make it all work.

🙂

NB Apologies for the repost but tumblr didn’t want to load the image for yesterday’s post.