September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

A TinyXML library for the Arduino

A lot of devices use XML these days – and parsing the XML by hand is quite complex. I use a CurrentCost CC128 power monitor and also Twitter. Both of these have an XML interface.

Over the last couple of months I have been developing a simple XML parser as an Arduino library – it is table driven and so compact and easily modified. This is now ready for release – you can download it here. The CC-128 example compiles at less than 9kB.

I have included a Twitter API example and also a CurrentCost CC-128 example.

The CC-128 example is being used to provide a data concentrator for CC-128. I am using an Arduino (Mini Pro 328) to take the cpu burden off the main Arduino, processing serial data at 57600 baud takes up most of the power of an Arduino.

Connect the Mini Pro to the CC-128 using GND and CC-128 Tx to Mini Pro pin digital 1. The Mini Pro acts as an I2C slave for the main Arduino (simple connection – just link up GND, A4 and A5 – also 5V if you don’t have a separate power supply).

I have three current cost devices feeding the CC-128 – Electricity, Gas and a light sensor. It should be quite easy to modify the example for your configuration.

Master code to read from the CC128 I2C slave is roughly as follows

CC128Data cc128data; // structure definition is held in the .h file

Wire.beginTransmission(I2CADDR);
Wire.send(COMMAND);
Wire.send(SNAPSHOT | READALL);
Wire.endTransmission();
delay(5); // give the I2C transmission and the slave time to deal with request
// 2mS does not work - 3 does - give it 5 to be safe
Wire.requestFrom(I2CADDR, sizeof(CC128Data)); // request data structure bytes from slave device
byte* b = (byte*)&cc128data;
for (int i = 0; i<sizeof (CC128Data); i++)
{
*b++ = Wire.receive(); // receive a byte as character
}

I will be writing up another post about the CC-128 data concentrator and the main Arduino, describing how to set up multiple I2C slaves all linked to a central Arduino CPU.

Christmas day 2009



Christmas day 2009, originally uploaded by jcrouchley.

Presents under the tree all ready to be opened after scrambled egg and smoked salmon brunch, with bucks fizz. Nom nom. Despite appearances the tree is vertical – just a weird branch at upper right.

Updated blog to use Ingoal’s Twitter Updater

Playing with Arduino Nokia 3310 shield

The Arduino Nokia 3310 shield come from NuElectronics. I have been using this shield with an Arduino Ethernet shield together with Andrew Lindsay’s Nokia 3310 library. I upgraded the library to be compatible with multiple SPI components, you need to bend digital pin 10 so that it does not make contact and then connect it to another spare pin.
Andrew has updated the library based upon my changes, you can download it from here.

Block diagram of current home monitoring system

This is the current state fo my home monitoring system.
Home monitoring
I am working on integrating a camera (pictures visible on a web site), sms and email.

Vacation over

Just got back from Hungary – blogged here.
Now unpacking and back to work.

Somerset for the weekend

We spent the weekend staying a the George Hotel in Castle Cary.
George Hotel Castle Cary somerset
Maria was making a bear with Gregory Gyllenship at a Bear Basics workshop. The hotel was comfortable and the food was good, but there was very little parking. Whilst Maria was at the course I went for a walk around the area.
Castle Cary market hall
Castle Cary somerset
All Saints Church Castle Cary somerset
Castle Cary somerset
Castle Cary somerset
Castle Cary somerset
I then waited at the hotel to meet Claire who came over from Swansea for the day. Claire ran into traffic on the M4 and again in Bristol – she was 2 hours late! We had a late lunch and then picked up Maria. Street is nearby so we had a shopping trip to the Clarks Village. On Sunday I had a quiet day looking for a cider farm and then watching the F1 Hungarian Grand Prix, it was a good race and Hamilton won.
This is the bear that Maria made – he is called Gerald.
Gerald

Arduino code for Currentcost/XPORT/Pachube

The code I have been developing for my Current Cost meter updating to Pachube via Arduino with XPORT is ready for sharing.
You can download the code from this link.
Current cost sensors are
0) Main electricity sensor – clamp on incoming live cable
1) Gas pulse sensor – see entry below
2) light sensor – photo resistor (about 2M ohms dark to 100 ohms bright light) as sensor across the channel inputs on the Current Cost dev board.
Current Cost sensors are read by Arduino, displayed on 4×20 lcd module and uploaded to Pachube via Adafruit XPort shield every 15 minutes.

XBee wireless programming of Arduino

Succeeded today in remote wireless programming a Funnel IO Arduino clone.

I had previously followed the instructions from LadyAda and got a very flaky program load – particularly with large files. Now following the Funnel IO route I have a reliable and solid way of remotely programming the board. I am using the Arduino IDE to upload the code. This also works well with direct use of avrdude.
The secret lies in the XBee configuration – this works for me.

Command Coordinator (i.e. a PC side) End device (i.e. a FIO side)
ATRE – Reset to defaults
ATBD 4 4
ATID 1234 1234
ATMY 0 1
ATDL FFFF 0
ATD3 3 5
ATIC 8 -
ATIU - 0
ATIA - FFFF
ATRR 3 -
ATRO 10 10
ATWR – Write the changes
ATCN – Exit command mode

I think the main difference from my first attempts lies in the destination address (ATDL). I will test further to see what is needed – also how well this works for other Arduino types.

Gas meter to CurrentCost to Arduino to Pachube up and running

Built to circuit and connected it all up. Bluetacked reed switch to meter and board + cc dev board + 2 AA batteries into small container.
CurrentCost dev board with gas meter circuit
P7122949
P7122950
CurrentCost meter connect to Pachube via Arduino. In order to try and get some idea of energy usage and comparison with the electricity usage I am logging KW. The calculations are:
Gas KWhours = cubicmeters * correctionfactor * calorificvalue / 3.6
1 pulse is 0.01 cubic meters
correctionfactor is 1.022646 (from gas bill)
calorificvalue is 39.4 (from gas bill)
So 1 pulse is 0.1119223 KWh.
Average KW = totalKWh * 3600 / measurementperiod(seconds)
I have set the measurement period to 5 minutes – this gives a reasonable resolution. At peak use I seem to get about 1 pulse every 18 seconds. Latest – I now update every 15 minutes – that way Pachube displays every update.

Last 24 hours Gas KWatts

Why the diode in the circuit?

When the switch opens the falling edge will cause a negative pulse on the 4013 input. The diode removes that negative pulse.

Input to 4013 without diode – one pulse (on/off) – zero volts is the centre line. The signal goes negative to minus 1.44 volts. Positive pulse comes from direct connection to +3 volts, negative pulse is smaller because capacitor has to discharge through 1M resistor.
P7112944

Input to 4013 with the diode – the negative signal is almost totally removed. The signal goes negative to minus 0.35 volts.
P7112945