Arduino I2C Wire library

I’ve spent most of the evening trying to get I2C working between the Arduino and a couple of I2C devices (a LCD output and a relay board) from Robot Electronics. I finally had to look at the source code for the Wire library that implements the TwoWire serial protocol for the Arduino, and found that the library correctly bit shifts the address one bit towards the MSB, but that means that you have to do the reverse bit shift to quote the address on the bus when making the library calls. It all has to do with the fact that it’s a 7 bit addressing system.

I did finally manage to get it to work by dividing all the addreses by two, so that’ll make it easier when I actually get the 6-7.2V supply working for the servo board for controlling the turnouts on the layout.

Bedtime now.

Arduino model railway control

I’ve been playing with a couple of Arduinos for the last week, and doing some physical computing, interfacing with real devices from the microcontroller. It’s been interesting doing some low level electronics again, and it was a great feeling about half an hour ago to have the model railway running under computer control – using the laptop to send commands over the USB port to the Arduino, which then does PWM to control the speed of the train.

There were a few hiccups along the way – not least of which the Arduino crashed repeatedly when the train started moving – it appears that the power pack I was using didn’t like having its load being PWMed, causing voltage problems. I resorted to running the Arduino off the USB supply, disconnecting the common 12V power input to the board, and just using that external power pack to provide power for the direction change relay and output to the loco. Make sure that you keep the ground connected though, as the Darlington TIP120s need that to be common in order to work.

The eventual use for this project is to automate the model layout in the Corris Railway Museum, and allow visitors to put coins in a slot and the train will then run for a number of returns depending on the coin put in. More coins – the train runs a little quicker. The software allows for reed switches at either end of the line for reversing, as well as reed switches for stations.

The hardware driver circuit is shown here in the schematic below (I know it’s pretty rough, but it’s as good as I can do at short notice), and photo of the really dodgy looking breadboard prototype.

The diodes are 1N4004s and the caps are 0.1μF to protect against reverse current from the inductive loads.

MRCC1Breadboard MRCC1

Computer Errors – in Haiku

Three things are certain:
Death, taxes, and lost data.
Guess which has occurred.

Everything is gone;
Your life’s work has been destroyed.
Squeeze trigger (yes/no)?

Windows NT crashed.
I am the Blue Screen of Death.
No one hears your screams.

Seeing my great fault
Through darkening blue windows
I begin again

The code was willing,
It considered your request,
But the chips were weak.

Printer not ready.
Could be a fatal error.
Have a pen handy?

A file that big?
It might be very useful.
But now it is gone.

Errors have occurred.
We won’t tell you where or why.
Lazy programmers.

Server’s poor response
Not quick enough for browser.
Timed out, plum blossom.

Chaos reigns within.
Reflect, repent, and reboot.
Order shall return.

Login incorrect.
Only perfect spellers may
enter this system.

This site has been moved.
We’d tell you where, but then we’d
have to delete you.

Wind catches lily
Scatt’ring petals to the wind:
Segmentation fault

ABORTED effort:
Close all that you have.
You ask way too much.

First snow, then silence.
This thousand dollar screen dies
so beautifully.

With searching comes loss
and the presence of absence:
“My Novel” not found.

The Tao that is seen
Is not the true Tao, until
You bring fresh toner.

The Web site you seek
cannot be located but
endless others exist

Stay the patient course
Of little worth is your ire
The network is down

A crash reduces
your expensive computer
to a simple stone.

There is a chasm
of carbon and silicon
the software can’t bridge

Yesterday it worked
Today it is not working
Windows is like that

To have no errors
Would be life without meaning
No struggle, no joy

You step in the stream,
but the water has moved on.
This page is not here.

No keyboard present
Hit F1 to continue
Zen engineering?

Hal, open the file
Hal, open the damn file, Hal
open the, please Hal

Out of memory.
We wish to hold the whole sky,
But we never will.

Having been erased,
The document you’re seeking
Must now be retyped.

The ten thousand things
How long do any persist?
Netscape, too, has gone.

Rather than a beep
Or a rude error message,
These words: “File not found.”

Serious error.
All shortcuts have disappeared
Screen. Mind. Both are blank.

Program aborting:
Close all that you have worked on.
You ask far too much.

Your file was so big.
It might be very useful.
But now it is gone.

Chip and pin just as fallible as old system?

A Guardian article about how chip and pin is not really any more secure than the old system, and the only change is that banks are now not paying claims, instead blaming the card owner for giving their cards and pins out. Their argument – you can’t copy these chips!

The article raises some important security concerns. Also, do you believe that reported card crime is down, now that you don’t report it to the police, the bank does that for you after they decide if it’s worth reporting?

And rather than make another post, I just have to link to this article about airport and airline security, and how completely absurd the whole thing is.
Personally, I fell that they’ve already won, by getting us to allow our government to take away civil liberties, whilst most of the voting public either encourage it, or just lay down and take it.
One of the comments near the top of the page, made by a pilot who is also subject to these security checks puts it quite succinctly:

Let’s think about something. I am in my pilot uniform and going through security and about to fly an aircraft and passengers from point A to B. I and my co-pilot will be sealed in the cockpit in front of a security door that cannot be opened from the outside. I will have in my hands the only “lethal” weapon used on 9/11, – the control yoke. So just what is it the TSA is checking me for? A gun? A knife? What? If I had been recuited by ‘the bad guys’ do I need to carry ANYTHING lethal? Of course not! Therefore, I should not have to go through security at all!