Sleeping an MCP9808 on an Arduino based Pressure, Humidity & Temperature logger

As I gear up for the next round of fieldwork, I thought I would introduce the newest addition to the Cave Pearl lineup: A logger for Pressure, Relative Humidity, and Temperature

Left: MS5805-02, HTU, MCP9808  Right: MS5803-02, HTU ,TMP102

Left: MCP9808, HTDU21D, MS5805-02          [rgb LED on both]          Right: HTDU21D,  TMP102,  MS5803-02

When one of the drip sensors from the last deployment failed early, I went hunting for information to see if I could corroborate the dramatic increase in drip rate it recorded before it expired.

 The wires of the housing pass-through always push the boards into odd angles, so I level the boards with a preliminary 'underlayer" of cured epoxy while applying some top pressure with a pin to hold things in place

The pass-through wires push the breakout boards into odd angles, so I tack them down with a pea-sized bead of JB Plastic Weld while applying some top pressure to hold the board level. (takes ~15 minutes) Then I test the sensors “dry”, while they can still be removed. Potting in epoxy is the last step.

This made it clear that there really was not alot of good climate station data near our deployment site, and that even if that data was available, it still was not going to tell us much about the conditions down below. So I spent a couple of days cobbling together these mini “in-cave” sensor stations. I will try adding an anemometer to them them later, if I can find one that draws a low enough current to operate within my power budget.

These first units which will be co-deployed so that we can compare the performance of the different sensors. One uses the MS5803-02 sensor (already proven robust enough for five months at 5m in 50% marine water), and the other is using the much more affordable MS5805-02 which is only listed as ‘splash-proof”. This comparison is test was almost effortless to do, as both sensors are code compatible, with the exception of the CRC check.

 

CarefullyEpoxytheProtectiveCap

The cap fits because the HTU21D  from Measurement Specialties has a similar form factor  to the Sensirion SHT series humidity sensors. But you need to cut the legs off the cap to flush mount on the Sparkfun board as I have here.

For Relative humidity I am using the Sparkfun HTU21D with the Sensirion SF2 protective cap. The trick to installing these caps on the sparkfun board is to first bond the cap to the board with a tiny amount of epoxy applied all the way around the base of the protective cap with a toothpick. Once the cap is bonded to the board you can cover the rest of the topside of the breakout with epoxy, taking care not to let it run up to the protective fabric, where it could wick in and seal off the sensor. Hopefully this waterproof cap will protect the sensors well enough, but I am not expecting miracles because most RH sensors go a bit squirrly in caves, where the environment can be at 100% RH for a good deal of the time. I was very happy to discover that this sensor auto-sleeps after each reading, so it adds almost nothing to the power budget. The units are going into the field in a few days, so I will have to look at something like salt calibration of these humidity sensors later.

Good old JB plastiweld lets me tuck the Groove hub up out of the way, as all the real estate on my platform is taken up with the battery holders.

JB Plastic weld putty lets me tuck a trimmed Groove I2C hub up out of the way, so only one I2C jumper runs from the cap to the logger platform, taming the spaghetti monster.

For the hat-trick I am trying out two different I2C temperature sensors. Technically speaking, the pressure and RH sensors already collect temperature data, which they need for their internal calibration, but I just thought that it would be nice to do a little experiment comparing Sparkfuns TMP102 to Adafruits MCP9808.  While their precision is identical (0.0625 C), the 9808 claims much better accuracy.

I already had the TMP102’s working in one-shot mode, but even Adafruits generally good code support did not cover putting the MCP9808 into its low current shut-down mode, and this is critical for my application. A little browse through the datasheet, and it turned out to be pretty easy to do, and I thought I would post this for others wanting to use the MCP9808 for logging:

byte bytebuffer1 =0;
byte bytebuffer2 =0;
#define MCP9808_REG_CONFIG 0x01
//
void MCPshutdown() {
Wire.beginTransmission(MCP9808_I2CADDR);
Wire.write((uint8_t)MCP9808_REG_CONFIG);
Wire.endTransmission();
Wire.requestFrom(MCP9808_I2CADDR,2);
bytebuffer1 = Wire.read(); //upper bits first 15-8
bytebuffer2 = Wire.read(); //then bits 7-0//set “bit 8” to “1” to enter shut down mode
bytebuffer1 |= (1 << 0);
//x |= (1 << n); // forces nth bit of x to be 1. all other bits left alone
Wire.beginTransmission(MCP9808_I2CADDR);
Wire.write((uint8_t)MCP9808_REG_CONFIG); //register pointer
Wire.write(bytebuffer1); //
Wire.write(bytebuffer2); //this one is unchanged probably could skip it
Wire.endTransmission();
}
//
void MCPwakeup() {
Wire.beginTransmission(MCP9808_I2CADDR);
Wire.write((uint8_t)MCP9808_REG_CONFIG);
Wire.endTransmission();
Wire.requestFrom(MCP9808_I2CADDR,2);
bytebuffer1 = Wire.read(); //upper MSB bits 16-8
bytebuffer2 = Wire.read(); //then LSB bits 7-0//set bit 8 to 0 = Continuous conversion (power-up default)
// x &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone.
bytebuffer1 &= ~(1 << 0);
Wire.beginTransmission(MCP9808_I2CADDR);
Wire.write((uint8_t)MCP9808_REG_CONFIG); //register pointer
Wire.write(bytebuffer1);
Wire.write(bytebuffer2); //this one is unchanged probably could skip it
Wire.endTransmission();
}

Except for the bit-math, I use the same method here to wake up and shut down the sensor, but since the default values of the config register are all zeros, you could also use the much simpler:

void MCPwakeup() {
Wire.beginTransmission(MCP9808_I2CADDR);
Wire.write(MCP9808_REG_CONFIG); //register pointer
Wire.write(0b00000000);
Wire.write(0b00000000);
Wire.endTransmission();
}

to reset all defaults & launch continuous measurement mode.  I think the soft reset does the same thing, but I have found that some sensors make you wait much longer after a “soft reset” before they give you good data than they do if you use a sleep/wake method. When possible I let my  sensors go through a couple of conversion cycles to flush old data out of the registers before I read them.

I have also learned some hard lessons about not trying to do calculations on a limited platform like the Arduino if I can avoid it. So all the sensor data is being saved as raw output in the log files.  I always get better results when I do the conversions later with a spreadsheet.

…And just to go completely over the top, I also record the temperature register of the DS3231 RTC. While this is certainly the least capable sensor in the mix, I am curious how it tracks against the others, in terms of accuracy.

Addendum 2015-02-27

As I put the first units into the field a couple of days after they were built, I did not have a chance to really play with them. So I recently built a couple more, using the TMP102 for temperature, MS5805-02 pressure sensors. One was built with the Sparkfun HTU21D breakout, while the other used a $5 noname HTU board from eBay.  In my tests so far, both deliver identical humidity readings, and both of these mini ultra based loggers sleep at 0.08 mA, which bodes well for these guys making it to my year of operation benchmark.

Addendum 2015-06-22

After building a few more of these I ran into a problem with epoxy wicking into the RH sensors before it cured. This is impossible to see under that SF2 protective cap so the only option is to drill out the bad sensor the next day. To prevent this from happening again, I now pot the RH sensor without the caps, and then tack the cap down with plumbers putty after the epoxy is dry:

This entry was posted in Developing other sensors. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s