Grove Temperature and Humidity sensor

Grove are a fun concept, lots of cheap, little sensors, buttons, etc. on little PCBs with a universal 4 wire connector system (e.g. gnd, vcc, rx, tx or gnd, vcc, sda, scl). Making projects becomes more like lego but it's a bit less heavyweight than the "shields" or "hats" ideas, and a lot cheaper!

I got a mixed bag recently, about £12 worth, plus a "seeduino", which is Seeed Studios' *duino clone. The price quite recently dropped from something like $19 to something like $6.90! To be honest, most retailers, like the one I went to, are still selling nearer the old price, but I guess you can't blame them if that's what they paid for the stock. I think I forked out £18 in the end, plus the 12 for bits, making about 30... plus postage, etc.

I got:

An IR distance interrupter - single bit detects if a person (or thing) gets close, obviously great for robotics, although many other applications

PIR (passive IR) motion detector - security lights, etc... detect if someone comes near...

Button - with pull down resistor, simple input

Buzzer - on/off or PWM

Temperature and Humidity sensor - cheap (£2 or so) and not super accurate 2C


By accident the first one I picked to test was the temp/humidity sensor.

Wouldn't you know it, it was the only one with a proprietary comms protocol!

It seems to contain a DHT11 sensor from Aosong.  The blog on Seeed Studios was good for beginners I think, with lots of photographs and some sample code to cut and paste, but it didn't contain a link to the actual datasheet (there was one elsewhere on the site) and I found it frustratingly lacking in detail.

So I went to two sources, the Adafruit open source library (link on the Seeed wiki page) and their python code. Both seemed to have been sort of played with until they worked.

So my second source was the hardware! I wrote a simple program in S4A to output high-low-high on the one wire protocol wire to the sensor and hooked up my Saleae to see what came back. That was much more useful and informative!

I quickly figured out a program to read each of the 40 bits, then with a little tweaking got numbers out.

One other note, from my experiments, you can't read too often. 500ms or less between reads and you'll get some misreads.

Here's the video:


Swift was perfectly fast enough to handle the signals coming back from the sensor. The readings take about 4ms to transmit, which isn't exactly blistering.

Generally I've had no problem bit banging with swift except in super fast, very tight tolerance protocols like the one wire neopixel protocol (which I had to make some special hand tuned assembly for).

The logic analyser tracks:

and

There you can see the protocol as described in the datasheet.

Here's the code in question:




Comments

Popular posts from this blog

Halloween LED lights on a plastic trick or treat cauldron

All about bootloaders

code signing, entitlements, bundles, sandboxes, hardened runtime, notarisation, app store security