Computing stuff tied to the physical world

Archive for December 2008

Rabbits

In AVR on Dec 21, 2008 at 15:56

Microcontrollers with attached RF transceivers are starting to multiply like rabbits around here:

2328FCA4-BD04-461B-942B-6DBE8DA17EA0.jpg

This is an Arduino Mini Pro with an RFM12B. The nice property of this combo is that the mini has on-board 3.3V regulation, which is the voltage required for RFM12B’s, and with a little tweaking of the FTDI connector the Arduino itself can be made to run at that same voltage. This avoids the need for level conversion.

That brings the total number of functioning RFM12B’s to four right now. Two have been in permanent use for monitoring energy & gas consumption for over a week now.

The other two, including this new unit, will allow me to further refine the software. A first advance has already been implemented: the receiver code is now interrupt-based, leaving the MCU free to handle other tasks at the same time.

Failure

In AVR on Dec 20, 2008 at 15:56

Failures are worth documenting too… here is one:

4DAFC86E-3DB0-4141-9797-402D7068F1B8.jpg

This was intended to become a general-purpose 868 MHz wireless solution: a low-end receiver + transmitter from Conrad, alongside an 868 MHz RFM12B which is likely to become my workhorse module. The receiver + transmitter are compatible with the FS20 wireless remote protocol, and allow listening as well as controlling these devices.

Well, most of this stuff didn’t work once hooked up. For various reasons actually – from bad sensitivity to using the wrong module (turns out that RFM12 unit was in fact for 433 MHz, doh).

In an attempt to salvage this thingamagic, I decided to replace & rewire the whole thing. It is now a 433 MHz receiver + transmitter, and an RFM12, also working on 433 MHz. The whole has been put aside for now, but maybe one day it can be made to work with some 433 MHz stuff, such as this or some cheap weather sensors.

Due to the switch to a lower frequency band, all three antennas are now 17 cm long wires.

The microcntroller is an Arduino Nano, btw. This is a 16 MHz 5V unit with a mini-USB port.

More readings

In Software on Dec 19, 2008 at 15:55

Here is the latest display showing on my screen:

7474AFF5-C9D3-4DA7-B5E3-492EE65C15DB.jpg

Updated in real time, with new readings coming in every few seconds for electricity and gas and every few minutes from the weather station (still sitting here in the office for now, so the values are bogus).

Different 868 MHz units

In AVR on Dec 18, 2008 at 15:54

Here’s a small but fairly general-purpose setup:

37DAF000-31B3-4F42-AAEB-F41E0851AF40.jpg

At the top right is the NSLU2, a very useful little NAS box with two USB ports plus Ethernet. It has been re-flashed to run a standard Debian Etch Linux system – using a 4 Gb USB stick plugged into the upper USB slot on the back. The other three connections are: ethernet, power, and an un-powered USB hub.

Plugged into the USB hub are three RF units – from left to right:

  • the RFM12B, hooked up to an Arduino Mini Pro
  • a simple 868 MHz receiver, connected to a USB Boarduino
  • the CUL plug, with its own ATmega and CC1101 transceiver

Each of these uses the same 868 MHz RF band, but with different transmission modes and protocols.

You’re looking at a micro-power 4-CPU cluster with a total power consumption of 3.5 watt. This is now a test rig for collecting various kinds of data.

This is not a mouse

In AVR, Hardware on Dec 17, 2008 at 15:53

The CUL is a small gadget which combines a CC1101 RF module with a USB-enabled ATmega processor in a very small unit:

AF108B36-7BA1-4902-AAB4-62917B0EEF16.jpg

So, yes, it has a tail and it plugs into a USB port, but it’s not a mouse. This thing can receive and decode messages from 868 MHz devices such as the FS20 home control unit, the KS300 weather sensor, and more. Technically, it could also send out such messages since the CC1101 is a transceiver, but apparently the 1.07 firmware isn’t quite there yet.

Switching stuff

In Hardware on Dec 16, 2008 at 15:51

Today, some simple “KAKU” remote switches came in. These are both by KlikOn-KlikOff – the first one is an older setup I was already using, with up to 12 different codes:

5178D8B8-5919-4468-89B0-B194DC94A909.jpg

The second is a newer model with up to 256 different codes – it’s heavily discounted (€14 for 2 units plus transmitter), probably because this type is being replaced by a newer model which uses unique unit codes:

47189E65-1B9A-4213-A21A-AE5585C20CFF.jpg

The drawback with both of these, as compared to the FS20 models by Conrad, is that you can’t control them at the plug – you have to locate the remote and press buttons on it. But then again, at these low prices per unit … you get what you pay for.

These units use 433 MHz signalling, there’s code for Arduinos which understands the KAKU protocol.

Energy & Gas Consumption

In Uncategorized on Dec 14, 2008 at 15:49

These last few days, a little application has been running here which tracks energy (i.e. electricity) and gas consumption in the house, in a little window of its own:

A3E7A251-C3E5-4ABD-868E-D522D66731D3.jpg

That’s 640 watt and 1.333 m3/hr. These values are normally updated a few times a minute. There are still some wrinkles in the software, such as the gas consumption not adjusting properly when the meter stops fully, i.e. when no pulse is received once the central heating turns off.

The following systems are involved in this setup:

  • some sensors and a transmitter based on an RBBB Arduino with an RFM12B
  • a USB-powered receiver based on an Arduino Mini Pro with its own RFM12B
  • a Linux server, i.e. a modified version of the Bubba/II NAS in this case
  • the Mac notebook I usually work on, though it could be anything really

Only the first 3 items above need to be always on, with a combined power usage of less than 10W. Every 3 seconds, sensor readings are transferred and stored on the server, using a trivial text format for now. This proof-of-concept setup uses rsync to transfer the log from the server to the notebook every 20 secs, so the above window isn’t yet as real-time at it could be.

But even with such a crude setup it is easy to keep an eye on consumption – and by simply switching appliances on and off one can deduce their approximate power consumption.

Better Mousetrap

In AVR on Dec 12, 2008 at 15:48

Now that RF transmissions work better, it was a small step to create a better house usage monitor. This one supports four sensors:

3E7468D6-0CFD-439D-91D9-8E41BAD8FB67.jpg

Only two sensors are being used so far (all sensor inputs are identical).

Sensor #1 watches the electricity meter rotations using the SY310 sensor:

CBCE0CCB-9B9B-4960-9F00-81FA934B304D.jpg

Sensor #2 is a QRD1114 which tracks a little mirror mounted on the last digit “0” of the gas meter:

87BF22D8-4722-46F6-A76B-2C3775CEEE14.jpg

The sensors were described in a previous post. Proper positioning turned out to be crucial, so there’s a fair bit of scotch tape to hold everything in place!

Good RF with RFM12B

In AVR, Software on Dec 11, 2008 at 15:38

Yippie. Got a simple blinking LED demo running on RFM12B’s after lots of head-scratching. Had to understand ATmega’s SPI mechanism to get there, but these two boards now talk to each other over the air, uni-directionally:

Good RF

That’s an Arduino Mini Pro (which runs at 3.3V internally, as does the RFM12B). Power comes from the FTDI cable, but with a special hack to drive the raw power input from it, not the default VCC connection. This way, the on-board 3.3V regulator is used to lower the voltage for both the MCU and the wireless module.

The other board is a bit of a mess, has the same Mini Pro, but some other stuff which is partly a left-over from earlier experiments:

Good RF

Here a USB interface is used to provide 3.3V power. It’s functionally identical to the first board: with RFM12B’s the same setup can be used as transmitter or as receiver.

The top board is the receiver – its picture shows the green LED on, i.e. correct packet reception!

The hookup is very simple, just 5 wires between RF module and MCU, and 2 power pins / 1 pull-up / 1 antenna wire on the RF module is all it takes. The 5 wires are standard SPI plus an IRQ line:

  • MOSI (MCU) –> SDI (RFM)
  • MISO (MCU) <– SDO (RFM)
  • SCK (MCU) –> SCK (RFM)
  • SS (MCU) –> nSEL (RFM)
  • PD2 (MCU) <– nIRQ (RFM)

It took some work to get the software working. The trouble with this stuff is that until you get both transmitter and receiver working properly, it all remains a bit hard to debug. And there are quite a few registers to set up on the RFM12B to make it do its magic.

But after some tweaking, the rfm12xmit and rfm12recv sketches for the Arduino IDE started working. First with bit-banged SPI coding, but then also with the ATmega168’s built-in SPI hardware. Which is nice, because all exchanges now take place at 1..2 MHz (i.e. 8..16 µsec per 16-bit command). All I/O with the RF module uses simple busy polling for now.

The RF range and quality of reception with the RFM12B is considerably better than my earlier 868 MHz AM setup. Packets now easily get across 3 layers of stone/concrete and all of them appear to be arriving properly.

Update – here’s the C source code for the xmit and recv sides.

Update 2 – the connections for MISO and MISO as listed above were reversed – many thanks to José Xavier for pointing this out. The text above has been fixed.

Wireless RFM12B Module

In Hardware on Dec 10, 2008 at 15:36

A new 868 MHz module came in today, which uses FSK as modulation method:

388C7E29-2302-4882-B86E-33B3CC8060AF.jpg

This is a tiny 16×16 mm RFM12B module. It contains a transceiver and can be connected with a 4-pin SPI bus plus an IRQ pin to send/receive bytes using interrupts. Documentation is a bit sketchy, but there are a few different code samples on the net.

This version is for SMD mounting (with 2mm pins, again). But it’s easy to add a few wires and use this in a 0.1” grid breadboard. The antenna used here is an 82 mm straight wire.

IR Sensors

In Uncategorized on Dec 8, 2008 at 15:35

Here are two new home-made sensors, improving on this one they will soon replace:

8CF78CD3-58D0-48C5-9A03-97A964CB0317.jpg

The top one uses a QRD1114 sensor, which produces an analog signal, whereas the lower one is based on the SY310 with a built-in comparator to generate a digital output. The intended range is around 5..15 mm, hopefully just right to detect the 0-digit reflector on the gas meter and the the rotations of the energy meter, respectively.

Both of these sensors are connected to a 3-wire audio jack cable: shield = ground, ring = +5V, and pin = signal. Both sensors use a 330..470 Ω resistor to drive the IR-LED and a second one of 10..100 KΩ as pull-up for the output signal.

Home Control

In Hardware on Dec 7, 2008 at 15:34

The FS20 system by Conrad is a simple RF-based set of modules to turn various appliances on and off. The transmitter looks like this:

E7ABA8B9-8392-407F-A9F8-226F4C0E230A.jpg

The most basic on/off remote control switches are as follows, shown with central European power plugs:

4CF33024-50D4-4DB4-A610-0A6087235D4B.jpg

They have an on/off toggle on the unit, which is a big plus over simpler units. The other useful aspect of these units is that they operate over the 868 MHz band, and that the details of the FS20 protocol are available. Several projects exist which can receive and/or transmit the corresponding signals.

Definitely not the most beautiful design, but hey, they get the job done…

Timer Interrupts

In AVR, Software on Dec 6, 2008 at 15:33

Here is some new interrupt-driven receiver code. This receiver is considerably better at identifying correct packets, regardless of what other bit patterns are coming in. The new code is based on a state machine which takes pulse times and gaps into account, detecting all valid sequences of pulse widths and rejecting all outliers. The main code is:

AA4D1C74-E3E3-41B7-BD67-90E432711496.jpg

Then, in the main loop, this code picks up the results:

EFC8BB55-ECC5-4553-9C8D-17CB1F9A92CC.jpg

Also, with an interrupt driven design the receiver no longer depends on timing loops and is free to spend its time in other logic. It is now possible to run multiple state machines in parallel, decoding a variety of different signal patterns.

Bad Reception

In AVR, Hardware on Dec 5, 2008 at 15:32

This is a USB Boarduino with an 868 MHz receiver connected to it:

A6EB094C-7303-4B2F-BC23-8568A44B55F1.jpg

The antenna is a short 82 mm wire. Just like the one used in this setup. Given the same software, it receives the same signals.

But somehow, it’s considerably less sensitive – so far this unit won’t pick up the (faint) transmissions from the energy monitor nearly as reliably as the first setup. It’s not a matter of noise signals, antenna placement, or any hardware differences (all physical variations give the same result). Must be moon phases, or something. I’m going to let it rest and focus on other RF options instead.

The original polling setup has been working fine for several days now, btw.

Contraption

In AVR on Dec 4, 2008 at 15:31

This watchamacallit is a hookup to the electricity meter downstairs:

89248D86-7166-454D-88C8-7C711912A943.jpg

It has a sensor concocted from an ultra-bright LED and a phototransistor, which senses when the black marker on the rotating wheel passes underneath it.

This sensor is tied to an RBBB Arduino which tracks and transmits the rotation count every 3 seconds on 868 MHz, using the previously created setup:

D73BA4B6-ECFD-4CE5-84F9-BDDDA6DD129F.jpg

The green transmitter PCB is in front at the top. The whole thing is powered by a 9V adapter.

To deal with quick rotations, the sensor is read out about 100 times per second, also during each 100 msec transmission. These were rough calculations and the transmissions no doubt have considerable jitter due to inaccurate timing. A timer- / interrupt-driven version will probably improve accuracy and transmit range. But for now this crude setup appears to provide acceptable readings.

This Tcl script saves the results to file on MacOSX:

2C7654DB-52CF-40EF-A4CC-D1B16FD14023.jpg

And this is an extract of that log file (showing roll-over and some missed packets):

41E4D41F-D6B3-4FA7-9FEC-9EA8277E47CA.jpg

The 94..97 values are the rotation count. This also shows that the log remains usable even when packets are missed.

Success @ 868

In AVR, Software on Dec 3, 2008 at 15:29

As expected, a lot of the bit-level reception problems with the 433 & 868 MHz wireless issues can be resolved with better packet framing and reception logic. Here’s part of the latest reception log, alll the way across those elusive 3 stone/concrete walls:

93E74FE4-4BB6-4209-A2EE-7700D52833DF.jpg

There are still times when proper reception stutters, but as long as reception recovers within a minute or so that’ll be fine for the purpose of low-rate data logging.

The send format now includes an old-fashioned SYN-bytes-plus-SOH header:

176528F4-75FD-4BB2-B7CA-5CF5EA7105A9.jpg

Reception takes a bit more code, here’s the basic frame reception loop:

86C83486-9950-4FB9-B4BE-8D5FB482ED49.jpg

And here’s the bit-level decoder:

23F292A5-C471-4C4E-A654-96D7A5E10263.jpg

The receiver + serial debugging code takes a mere 3208 bytes so far.

CC2500

In Hardware on Dec 2, 2008 at 15:27

The nice part of this transceiver by Ideetron is that it’s cheaper yet more advanced than the 433 & 868 MHz radio modules by Conrad:

5B1A8AD7-20F8-4ACF-8901-679A993B5432.jpg

I does have that awkward 2mm pin header, but Ideetron most generously threw in a few female headers for free.

This modules uses a CC2500 chip operating at 2.4 GHz. The interface is via SPI commands, which provides various registers to exchange data both ways. All the bit manipulation and byte synchronization is handled, and the communication is bi-directional, allowing for a packet-oriented design with positive acknowledgement.

Unlike the iDwarf kit there is relatively little sample software to get started with this module, so it will take more work to get this going. Having an on-board antenna just like the iDwarf and XBee and using the same 2.4 GHz frequency band, the range might again be insufficient to pass through a few stone walls, but that’s just guessing for now.

From 433 to 868

In AVR, Hardware on Dec 1, 2008 at 15:26

These are the 868 MHz modules from Conrad – receiver on the left, transmitter on the right:

5874AE0B-77D9-48C2-8B90-B01D31126300.jpg

Worked as straight replacements in the 433 MHz setup, but there seems to be some problem with noise. It got a bit better when the receiver was tied to an 82 mm wire as antenna (as shown), i.e. exactly 1/4 wavelength. And that funny transmit antenna wire/coil probably isn’t optimal either…

Still, a bit noisy, lots of spurious pulses, and only occasional CRC-valid reception. It looks like much of the problem is caused by the crude bit-start synchronization software. Needs more work, clearly.