Browsing Posts in Power

Adding memory? I forgot. 16/04/13

You’d have thought that with all this learning and fun stuff happening here at Wardian Towers, that as I get further and further into this electronic ‘lark’, first with PIC’s, then I2C, then real time clock counters, then I2C input/output devices, then into iButtons and all the wonders they produce; you’d have thought that it would get easier as time went on.

Scientists do say that the brain is in fact like a giant muscle, and that the more you use it, the easier it gets as it becomes more familiar with cramming it with yet more and more knowledge.

Well, I can report that from this end, it most certainly doesn’t seem to.Before...

But then again, I guess I’m not as young as I used to be, and maybe doing this kind of stuff is really for the twenty-somethings.

But then again, if I was twenty-something again, I’d be either playing on my X-Box, or drooling over a new Porsche, or Armani suit.  BUT, I’ve been there.  Got the T-shirt; read the book.  Boring.  Shallow.


To the right here is the board before I fitted the new memory chip.  The chip itself is a Microchip device called a ’24FC512′.  This denotes it’s from the ’24’ series of serial EEPROM (Electrically Erasable Programmable Read Only Memory) chips, and it will store up to 512 K bits of information.  Note the ‘bits’ bit.  In more user-friendly language, it will store up to 64 K Bytes of 8-bit words. (As we all know, there are 8 bits to a byte.)

The datasheet tells me that I can have up to four of these little guys sat on the same I2C lines, each individually addressable, so I could have up to 256K bytes of information storage on just four chips.


Hooking the thing up was ridiculously easy, and took a matter of minutes -I just had to remember to wire the SDA (data) and SCL (clock) lines properly.  Mix them up and all kinds of exciting and unexpected stuff would happen....After

There’s also a pin which you can either wire up, or even have sat on another output pin from the PIC.  This pin is the ‘Write Protect’ pin.  With it sat at 5-volts, you can read the contents of the chip, but it won’t let you write, while tying the pin to ground gives you unfettered access to everything.  This is a pretty useful feature, and I may well use it if I get the opportunity.

And here is the chip in circuit.  As I said, ridiculously easy to wire up, and you can barely notice any other new components.  They’re there, though.

And so to programming it.

And this is where all the ‘fun‘ started.

I set up an entirely new project in the X-IDE program I use from Microchip so as not to contaminate the other stuff I’ve written.  Okay, doing it this way may take longer, but it gives you a ‘fresh canvas’ to work on, and it prevents great lumps of code being sat in the program for other functions that you will never use in this.  It also focuses the mind on just what you really need in there to get the program running.

For this program, I needed the new RS232 program I’d written the other day so I could actually see in a box on the screen what the processor was putting into the RAM and also what was coming off the RAM.  Yes, I could have done it with simple LED’s already sat on the board, but that would have been pratty.

After several hours, many cups of tea, and of course, ‘consultation chats’ with young Alfie (…He’s a bit ropy on I2C, but learning fast…), I finally nailed it when I realised that you never use the ‘Acknowledge’ pulse when you’re writing to the device, but when you read from it, you must acknowledge every byte apart from the last one where you send a ‘NotAcknowledge’ pulse.

Oh, and to be on the safe side, you need plenty of ‘IdleI2C()’s thrown around, just for good measure.

Again, last night was another late one, but I can report total success.

I can now write data to this chip, switch the whole thing off, have a cup of tea, switch it all back on, and the data is still exactly as I wrote it.

Today, I have other, much less fun stuff to do, and of course Wednesday and Thursday are ‘Plotting’ days.

But I shall return soon to this project -hopefully before I forget everything I’ve done.

Unlike the RAM I’ve just fitted and programmed, unfortunately, I do forget stuff when switched ‘off’.


The lightest of touches 15/04/13

When I wrote that last piece about the iButtons, yes, I’d got the iButton to display its unique serial number on the PC screen. I did this using an RS232 link to my PC using a free program called PuTTY which emulates the old ‘Hyperterminal’, not found on Windows 7.  This was no mean feat -I’d never programmed a PIC for RS232, so it was new territory all round.

Yes, the PC would display the list of numbers, but the problem was, it would only do it occasionally!Before...

By its very nature, 1-wire communications with the iButton is shaky, even at the best of times, so getting the thing to display the proper numbers consistently was something of a challenge.

In the end, I had to read seemingly thousands of pages of dry-as-a-bone documentation, both from Microchip (the makers of the PIC processor) and from Dallas Semiconductors (the makers of the iButton).

A very long and very boring story later, and very late last night, I finally cracked it.

Initially, the PC would read the correct number maybe only once in thirty button touches.  Now, it’ll do it between eight and nine times out of ten.  Okay, still not ‘production’ quality, and I’m sure I can improve it further, but you’ll agree, it’s a Big Lot better.

Up to the right here is my board.  You’ll remember the ‘flying board’ of the I2C real time clock sat there on its piece of card, attached with gaffer tape. The iButton is the red thing at the side, while the iButton reader is to the left of that, joined by its two wires....and after.

To the left here is the same board, but this is after I’d gently touched the iButton to the reader, and you can see the white LED towards the back of the board, lit to show that the button has been recognised.

I’ve also programmed it such that different iButtons will light different LED’s, while tapping an ‘unknown’ iButton illicts no response whatsoever.

So, we can safely say that this is now a ‘Job Done’.  iButtons are now recognised, and more importantly, different iButtons produce different responses, while ‘new’ iButtons, until programmed in, aren’t recognised at all.The result!

To the right here is a pretty poor picture of what the screen says when a valid iButton is touched to the reader.  Pretty neat, eh?  And yes, the black ear behind the box on the screen is that of my cat, Alfie.

And the next job, Wardo?


That’ll be the I2C non-volatile RAM I mentioned seemingly weeks ago.

With this in circuit, I’ll be able to record, using the RTCC clock for reference, just when an iButton was touched to the system, and it won’t ‘forget’ once the power is turned off.

And after that?

Ah, Dear Reader, therein lies the ‘challenge’.  After that, I plan to design and build a monitoring circuit that will measure -and record- battery usage as the unit is working.  This board will be a ‘hybrid’ board, combining both digital circuits with an analogue ‘front-end’ that will monitor the currents going both into and out of the battery, but it will also ‘time-slice’ this data into usable ‘chunks’ with an integrator.  It is this integrator that has proved most troublesome, but thanks to the excellent ‘Khan Academy‘, a free Internet maths revision site, I think I’ve got it cracked.

Tie this to iButton usage, and I’ll have a permanent record of just who was using the bike, when they were on it, and most importantly, how much juice they put into the battery.

This data could then be used as the basis for the strict rationing of the ever-popular LEAF chocolate biscuits!

No, seriously, this could have a profound effect on how we might approach possible funders, and on what basis we apply for the ever-shrinking pot of public monies.

But to be honest, I’m not thinking quite that far ahead just yet.

One problem at a time, and the current problem is the non-volatile (NV) RAM.

Then I’ll look at the challenge of power monitoring.

All clean, healthy fun.

iButton madness

For those of you not in the know, an iButton, funnily enough, is not from those wonderful boys and girls who make the phones, computers, and seemingly everything else ‘i…’.

The iButton is actually made by Dallas Semiconductors.  If you’ve ever been in a bar, then odds-on, the barperson would have had one of these little things that they simply touch to the till to identify them as your server.  Yeah?


Well, Dear Reader, I’ve known about iButtons for years -we used them in the electronics department at Sheffield University for access control into areas that undergraduates are normally not allowed.

They’re dead cute, and can fit on any keyring.

But, the best thing about them is that each one is unique.  They have a laser-imprinted 64-bit serial number that is impossible to fake or hack (…they’ve tried, believe me…), so when you touch your iButton onto the piece of gear, it checks from a list of known users, and as nightclub bouncers are so fond of saying- ‘If your name’s not on the list, you’re not coming in!’

Same kind of thing, but without the badly-fitting suits or tattoos.

Well, to be honest, like the dreaded (no longer!) I2C that I mentioned previously, iButtons were things that I’d kind of been putting off for years.  In reality, they’re pretty difficult to program for, because everything is so dependent on timings and all other kinds of fun stuff.

The thing is, for the electric bikes to move forward, I needed a simple system -like an iButton- that regular riders could simply tap onto the top of the box, and it would instantly know who they were.  iButtons seemed ideal, but as I said, they’re a real drag to get right.

Well no longer!

Just a few minutes ago, with the help of my trusty feline (?!?), I finally cracked it.

As young Alfie so kindly reminded me from his position on my knee, the reason it wasn’t reading was that I hadn’t unset the bloody analogue inputs from PORTA, so it wasn’t reading it properly.

Well, now it is!

Now, the long-suffering Mr Ward Senior will not be around for our regular Sunday brunch tomorrow morning, so I’ve got all day to get the program working as I want.  Little things like the unit sensing when an iButton has been touched, interrupting what it’s doing, then reading the number from it.

Then I can program in the list of my six iButtons, so it will know exactly which one has been touched, and give an appropriate message.

All tremendously good fun, and it keeps me off the streets.

Oh, and there’ll be a ‘regular’ LEAF blog entry up first thing in the morning after I’ve processed all the photos and thought of just what to write.

Doing it properly.

On Wednesday, I went down to Maplin’s to get just a couple of really, really pratty push-buttons that with only minor tweaking can be made to fit into standard 0.1-inch Veroboard.

Armed with these, I hurried home, and because the session down The Plots was cancelled what with the awful weather and all, I popped the kettle on, and planned my next attack on this little i2c board.

And the next attack just had to be those inputs I mentioned last post.  I could hear the board, laughing at me, challenging me to solder up the two buttons and go for it.

Well, I can report good progress on Wednesday and Thursday afternoon/evening!

By last night, I had it so it not only showed the correct time, but when I pressed one, or both, of the buttons, the corresponding LED’s would light.  I’m not saying it was easy -it wasn’t, but I finally managed to get the i2C to read the values of the buttons into the main PIC processor.  The only ‘problem’ (…if you could call it that…) was that I was doing this by polling the input pins every few milliseconds, then displaying any changes as they happened.  So yes.  It worked, but not properly.

This morning, after the usual chores, I sat down again with a fresh cup of tea, deciding to do it the right way.

The right way, is to have the little input/output chip produce an interrupt when a button is pressed.  This interrupt then temporarily stops the processor from what it’s doing -namely displaying the clock.  In the interrupt service routine, the i2c chip is then read, the processor then does a little magic to get the numbers right, then whacks it back out on the i2c bus, this time writing to the chip to tell it to display on the LED’s.

Now, this all sounds terribly simple to do, but really, it isn’t.

Anyway, long, boring and tedious story shorter: It now FULLY works.  With interrupts!

Yes, you press a push-button, and the corresponding LED comes on, and yes, you could do that simply with a switch.

But that’s not the point!

The point is that I’ve managed to get the i2c reading and writing and interrupting the PIC when something happens.

(…mutter… …mutter… …mutter…)

Onwards and upwards!

What’s next?

Why, another cup of tea, of course!

Sunday and Monday, it’ll be that cute new LCD panel I bought the other day.  It’s sat in my drawers, laughing at me.

Ha!  I’ll have you, you little swine!

…to LED clocks.

After that last posting last night, I bit the bullet and went for it.  After all, I’d got the RTCC showing sensible numbers.  Why not make it show correct numbers?A few minutes ago...

To the right here is a photo I took of it just a few minutes ago.

Well, 5:03pm, to be precise!

The little blue board towards the bottom of the shot, sat on a piece of white card, held on by black insulation tape, is the RTCC, joined to the main board by that thick piece of black wire.  That’s actually four-core flex, so it carries not only the SDA and SCL lines I mentioned yesterday, but also the +5 volts and ground connection.

You’ll also notice that none of the LED’s are lit tonight.  This isn’t because that bit of the circuit has broken:  Far from it, it’s working too well, in that the LED’s are too bright to work around!  Trying to focus on something when there are little green dots in your eyes is a little off-putting!

When I came to check the time this morning as I switched my computer on, it disagreed with the computer by about four seconds, until the computer logged into for Internet time, then the two agreed completely.

It works -better than my PC clock!  Whether it will still work up at The Plots, given the extremes in temperature, and being kicked around in the top shed, well, we’ll have to see, but so far, it’s looking good.

The little chip about halfway down on the right hand side is the MCP23008 i/o chip that was controlling those LED’s, while the big black one towards the bottom is the PIC.

Now, this MCP23008 is an 8-channel device, and I’ve only used four of the pins as outputs for the LED’s.  This means I have up to four spare pins, which I’ll be using shortly to make the input circuit I mentioned last night.

All good, harmless fun!

More soon…

From flashing LED’s…

No photos tonight, I’m afraid.  The camera battery is flat, and anyway, in this light, they probably wouldn’t have come out.

So you’re going to have to take my word for this…

After long, long hours of head scratching, and moments of seeming madness, I’ve finally cracked this i2c lark.

Saturday’s missive was all about how I’d managed to write data down the i2c bus.

As it turns out, this was the easy part.  Apparently, even my cat could have done it, if he’d been bothered.

Getting i2c to receive coherently and on time is apparently quite a big beef amongst the electronics fraternity, and Microchip -the makers of the PIC’s I’m using, haven’t done themselves many favours. Briefly, the way they’ve implemented it is, well, decidedly pratty.

A very long and boring story shorter, but just suffice to say I’ve now got the little board you saw on Saturday not only flashing the LED’s if I want to, but I’ve whacked on an RTCC (Real Time Clock Counter) onto the i2c bus too.

The input/output chip and the clock are quite happily sat on the same two lines (SCL and SDA if you’re that bothered), because they have different i2c addresses.  Before you talk to a chip, you have to give it the right address, which kind of makes sense.

SO, I’ve now got that same board, and you’ll remember it has those four displays left over on it.  Well, these are now coded up so the display simply reads minutes and seconds from the RTCC.  I haven’t set the clock properly, so the numbers are pretty meaningless, but the fact is that even if I completely unplug the board to switch it off, this little clock keeps on ticking -in much the same way as your PC clocks does when you power it down at night.

So, when I come to switch it on again, not only has the clock advanced, but it’s advanced properly to show the correct minutes and seconds that it was when it was on previously.

I guess I’m not explaining this very well, I guess I’m a little tired, but I’ll get some proper photos tomorrow to explain.

Hells, I may even set the clock properly so it shows the correct time!

The next job will be to work with that little input/output chip to get it to input, rather than simply lighting LED’s.

This shouldn’t be quite as difficult as today’s marathon effort, but I have the added ‘fun factor’ of having to set it up so that a button press will interrupt the processor.  This will then send out a command to find out just which button was pressed.


Well, this vastly saves on processor time.  Rather than the processor having to ‘poll’ the inputs every few milliseconds, and all the bother that entails, this way, it’ll only do something when it’s interrupted.

There’s even a possibility of being able to ‘wake’ the processor from ‘sleep mode’ with a button press.  This then does away with a whopping great on/off switch -it’ll just be a button press to turn on.  …Maybe, we’ll see…

I guess it all sounds dead simple, but take it from me -it’s not!

This is One Tired Wardo, signing off!

Ladies and Gentlemen…

…And cats.

At about midday today, there was great jubilation here at Wardian Towers.

Yup, you guessed it.  I got a couple of LED’s to light.Two LED's.

‘No Big Deal,’ you may think.  ‘Surely, a switch and a battery would achieve the same thing?’

And you’d be dead right.  ‘Why use microprocessors and the ‘C’ programming language, when all you need is a switch?’

Ah, but there lies the rub.

Those two humble (…but very, very bright…) LED’s are being controlled by the black chip just down and to the right of them.  For the more technically minded, it’s a Microchip MCP23008e i2c input/output chip.

However, the key bit of that information is ‘i2c’.

After what seems like years of half-heartedly trying to ‘get into’ i2c, then giving up, I’ve now finally achieved i2c communication across two chips in the programming language ‘C’.

Even though I’d studied it extensively with Bang & Olufsen many years ago, I’d never built and programmed an i2c system from scratch until this lunchtime.And the other two lit!

The proof here is to the left.  I changed one byte of information sent to the MCP23008, and the other two LED’s are now lit.

Okay, not earth-shattering in itself, but you may remember my excitement all those years ago when I got my first ever LED to light when programmed from a PIC?

The same feeling, but better.

These four little LED’s now pave the way for the really fun stuff as I whack the RTCC (Real Time Clock Counter) into it. This will then tell the PIC the exact time and date whenever it switches on.  This paves the way for ‘workouts’ on the bike to be correctly time and date stamped, so I’ll know just how much was put in, or taken out, of the battery over a given period.

Then, I’ve got the excitement of adding the cute little LCD display panel that also runs from i2c.  Different chip, but same protocol.

So, you can see, Dear Reader, things at Wardian Towers are moving forward.

…Even if the weather isn’t!

Second Box? Collected!

Yesterday, Phil from Trade Base came over to pick up his shiny new Electric Bike Box from us.

Okay, so it’s only months late, but as he himself admitted, they didn’t have anywhere secure to store it until a few days ago.

In the meantime, I’m working on the mkII version of ‘The Box’.

This version does away with all the confusing 7-segment displays, and makes do with a single larger LCD display.  At the touch of a button, this will show what the rider needs to know, but more importantly, because the display unit is almost self-contained, it relieves the main processor of all the work of updating all 20 7-segment displays.  All this unit needs are four wires to connect it to the processor -all the communications are handled serially via I2C.

I’ve also got a ‘Real Time Clock Counter’ on order from eBay as well.  This will mean the unit knows what time it is, and even what day of the year it is.  Again, this communicates via I2C.

If, like me, you’re of the ‘Propellor Head’ persuasion, you’ll find this pretty exciting.

More news as it happens…

Second Box? Done! 02/02/13

Yes, yes, yes, I know, Dear Reader.  You’re about to faint.

But it is true.  The second box for TradeBase is actually finished.  What isn’t finished is the A-frame bit that the bike sits in.

But I will finish it, come Hell or high water.  It only needs the wheel sensor whacking on, and if I get a clear run at it (HA!), it’ll only take me a morning or an afternoon.

This second box now has much brighter LED’s than the original ‘demo’ box -bright enough to be easily visible even in direct sunshine.  And it only took another 16 transistors and 30 resistors on one board to achieve this.  Piece of cake!

Other news is that since Ian (no relation) gave me that little TV with the HDMI input socket, I’ve been ‘playing’ with the Raspberry Pi, and having a Big Lot of fun in the process.

I ordered a tiny little ‘wireless dongle’ for it -so I can use it on the Internet at home running wirelessly from my router. This really was a little swine to get going, and it took me a full half-day to get there, but it’s now working fine and very fast when you consider it’s a full computer the size of a credit card for less than £30.00.

“So what?” you quite rightly shout.

Ah, I actually plan to have a Pi down on The Plots in the top shed.  Because it’s so small, I can easily hide it away -probably behind somewhere or even under something, so any potential thieves won’t be able to find it.

I may take an old, empty PC case, and put that in there, complete with a couple of bricks in the bottom.  A scabby old 14″ CRT monitor (…which won’t work…), and a knackered keyboard and mouse will finish off my ‘stage set’.  If any thieves do break in, they see these, and take them.

I can imagine them picking up the empty PC case (…plus two bricks), and saying to each other;-

“Eh, Wayne!  Feel the weight of this!  Must cost a fortune, one of these!”

Ha!  Wait ’til they get it all home and try to plug it in.

Okay, an idle, but very fun thought…

So last Friday morning, I was all fired up, looking forward to testing a slow cooker on the new bike box through the 240 Volt output.

You’ll remember I said that a slow cooker takes much less power than say, a kettle.  It does.  Whereas a kettle takes a full 13 Amps at 240 Volts -that’s a little over 3 thousand Watts, a slow cooker, on the other hand, takes a mere 200 Watts.

But doing the math, 200 Watts @ 12 Volts still draws 16.66 Amps.  This would completely drain a fully-charged, standard car battery of 50 Amp/Hours in 3 hours.  Not good.

I also found by experiment that turning the slow cooker on, even to ‘low’ made the inverter squeal in disgust, while my multimeter, rated at a mere 10 Amps had a not-so-quiet fit.  The leads to it got pretty warm as well!

So, a bit of a dilemma going on here…

…Enter a 400 Watt, 240 Volt mains lighting dimmer, freshly purchased from ‘Wickes’ -our not-so-local DIY store.  (B&Q, my preferred choice, hadn’t got any.)

I built a ‘rig’, consisting of a standard 13 Amp plug, a piece of wire, the dimmer switch and a spare 13 Amp mains socket.  I then connected it up so the new dimmer circuit was between the box and the slow cooker.  This meant I could ‘dim’ (i.e. Reduce the power to) the slow cooker by turning the ‘brightness’ up and down.  …Tremendous fun!

(…Of course, I felt completely safe doing this.  The slow cooker has no electronics to speak of inside it, so I wasn’t running the risk of blowing, say, a switch mode power supply by giving it lower power than it was used to.  Switch modes can get very, very upset if you try this…)

…And the results were encouraging!

I found I could wind up the dimmer to about 85% before things started complaining, and that was taking a mere 9.1 Amps at 12 Volts.  This works out at a snitch under 110 Watts.

Would it be enough to heat a stew or soup?

Well, to be honest, I can’t answer that because I didn’t have it on long enough, but when I put the cooker onto ‘warm’ (…i.e. ‘Keep Warm’…), even without my Heath-Robinson power control, that took only 4 Amps.

This tells me that it should be able to warm up a pot full of stew quite nicely.

By reducing the current to the cooker, it increases the battery life to about 5 1/2 hours.

Of course, this is if no-one is cycling and putting power back into the battery at the same time.

When I finally get this box and the slow cooker down to LEAF, you can bet your life there’ll be cyclists!

(Even if I have to drag them from the road nearby.)

…And back to the new box…

…I mentioned that it ‘just needed a FET’ to be complete.

Ha!  How wrong can one man be?  Yes, I changed the FET and made some other additions to the earthing circuit, but realised that the displays were nowhere near bright enough for outdoor use.  This has meant that I’ve had to build another, much smaller board only having 16 transistors and about 40 resistors on.  This board takes the +5 Volt output from the PIC and converts it into a +12 Volt signal coming directly from the battery.

This means there is now no ‘stress’ on the PIC, and I can adjust the brightness accordingly.  If it’s still too dim, then I’ll wind the current up some more.

Of course, this has brought further ‘challenges’.

The ‘Reset’ button, at the moment, merely stops the processor, then when the button is released, sets it going ‘from the top’ again.

As you hold the reset button down, one, or more, of the LED’s are on.

But, if I’m whacking too much current down the LED’s for too long a time, then these will blow.


This means I have to rewire -and reprogram- the reset button to be on another leg of the PIC.  When the PIC realises that this leg has gone low, then it will simply halt everything -including the display routines- then start ‘from the top’ again.

So, while the second box is not quite done, it’s certainly a couple of steps nearer.

Tomorrow, I plan to carry on, and don’t worry.  I have photos of the new board to show you.

(* In answer to the question posed in the title:  Because then it wouldn’t be fun.)

SEO Powered By SEOPressor