Saturday, 15 June 2013

Battery Powered LCD Desk Clock

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

Most of the clocks I have built have been mains or USB powered, but I had a request to build some battery powered ones, so I have been researching into the options. My basic LCD design was fairly simple, using an ATMega328P with a DS1307 Real Time Clock and an HD44780 based LCD display. I've built quite a few like this, here is one of the prototypes of this arrangement with an Arduino Uno and an adafruit RTC module:
My target was a pair of AA batteries. Of those, the micro will run happily run at 3V. The LCD should work at 3V although it is a 5V model, but the RTC requires 5V and a separate backup battery. To keep cost, size and power drain down, I have removed the RTC from the equation. It's a shame to lose the battery backed clock option. To save having to fully set the date and time each time the batteries are changed, I set it to write the date to EEPROM once a day at midnight. That at least means the date doesn't need to be set. The previous versions all used an ATMega328P running from a 16MHz crystal, but firstly that uses a lot more power, and secondly, it's only rated for that speed at 5V. I looked at running the micro from a 32768Hz crystal, but that didn't work out too well as the LCD updates were very slow. I finally went for the option of using the internal 8MHz oscillator in the micro, divided down to 1MHz, but retaining the 32768Hz watch crystal for an internal counter. This has to be set by programming the fuses in the ATMega328P microcontroller. I used avrdude and a USB Tiny ISP to set these using the following command line:
avrdude -cusbtiny -pm328p -Ulfuse:w:0x22:m -Uhfuse:w:0xd2:m -Uefuse:w:0xff:m
This sets the fuses to 22:D2:FF, selecting the internal 8MHz oscillator as the clock source, and enabling divide by 8 to get 1MHz. It also enables clock out - more on that later. This can be tricky territory as you can end up setting the clock speed to the point it isn't running fast enough to re-program. See my previous article on Reviving an unprogrammable ATMega328P. However, once set, this did reduce the current draw quite a bit from the original version running at 16MHz. The next challenge was the LCD. I went though a number of options here, I started with an MC34063 as a step up switch mode regulator. The idea was to generate 5V from the 3V input. This worked fine, but required quite a few components and took up a fair amount of space. It was also running at about 10mA, which wasn't really an option on batteries.
Having ruled that out, I looked into other options. Since the micro could run at 3V, it was only the LCD that required 5V. The next step was to look at using a voltage doubler to power the LCD. The idea is to take a square wave signal and via a couple of diodes and a couple of capacitors generate a voltage twice that of the  input. In this case, I was looking at getting up to 6V from doubling 3V. There is diode drop to consider, although with the 1N5819 schottky diodes, it's only around 100mV. To get the square wave, I had ruled out the ATMega328P PWM outputs as I'd changed the internal clocks to count the seconds (or rather 16th's of a second), so the extra fuse setting I programmed was clock out. This send the 1MHz internal clock out of PB0 (pin 14, Arduino Digital Output 8). This is a bit higher than necessary, but it's effectively free. A bit of experimenting with values gave around 5V under the load of the LCD and we were in business. There were few components to fit, so I went for mounting the circuit on a pair of small pad boards, the micro and the LCD on the front board. The crystal fits under the microcontroller to protect it. The LCD connectors via a 14 way header.
The batteries and buttons went on the second board.
I used a short ribbon cable to join the two boards, and bolted it all together.
This was using a few mA and seemed to be keeping good time, and sat nicely on the desk.
One of the tasks for this was to show the day of the week. The trouble was, it was only 8 characters, so I had to be a bit creative with Wednesday and fit 'esday' into 4 user defined characters.
I used the same 'esday' characters to allow Tuesday to be fit in the centre:
I ran this for a couple of weeks and all seemed well. As I was building another couple of these, I had another look at driving the LCD. The HD44780 chip should be able to run off 3V, the only reason the display was blank was because the contrast couldn't be turned low enough, it was already down to 0V. Various data sheets show a negative voltage as being required for this, so I made a slight modification and turned the voltage doubler into a negative voltage generator. This then generated approximately -3V from the clock signal. This was a bit high, so a switched to using standard 1N4148 diodes and 100nF capactiors (in place of 10uF) to make it less good. This ended up about -2V under load. The LCD could then be driven direct from the 3V battery supply, and the only things on the charge pump was the contrast reference of the LCD. This reduced the current consumption to less than 1mA, so should double the battery life, by just shuffling around a few components.
So there it is, a neat little desk clock / calendar that should run for many months on a pair of AA batteries.
Update:
Dave Jones over at the EEVBlog has posted some videos on charge pumps and negative voltage generators:



Wednesday, 5 June 2013

Enough Leafs to fill an autumn

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

They're multiplying! The three charging bays at work were full again today, three black Nissan Leafs. Is it 'Leafs', I don't think 'Leaves' is right, although I'm not sure there are normally enough of them in the same place for anyone to have thought about a collective noun.
Not quite all charging away, as the middle one didn't have a Type 2 charging lead, and only the post on the left had a domestic three pin socket for the 'emergency' charger supplied with the Leaf, the others have the faster Type 2 Mennekes socket. Mine (on the right) is using a type 2 cable which goes direct from the post to the car. The one on the left is using the 'emergency' charger.
I'm not keen on the box that hangs down about a foot from the plug, I'm not convinced that's going to last or be waterproof. I was hoping they would have gotten around to supplying a suitable type 2 cable with the new cars, but it appears not.
1,300 miles in and I'm still enjoying mine. I'm living with the range without a problem. A couple of occasions I've had to plan in advance when I was going to charge up, in order to make longer journeys, but nothing insurmountable. I'd still recommend one to anyone who drives less than 30 miles a day and has a place to charge up.

2022 Update: I am pleased to say when I bought my second Leaf in 2016, they did supply a Type 2 charging lead with the car.

Sunday, 26 May 2013

Arduino revival with EPROM programmer

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

One of the errors you get from time to time when working with Arduino's in general is

avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override this check.

This error covers a multitude of sins. 99% of the time it is due to the chip not being connected to the programmer correctly for whatever reason. Either it is missing, badly inserted or there is a wiring problem between the chip and the 6 pin header. To fix those sort of problem, check the wiring, and don't bother with -F, that could just lead to more trouble.
In this case, I'm in the other 1%. I know the wiring is correct because I was using a USBtinyISP plugged into an Arduino UNO board, and it had been working correctly. The error in this case is because I had been setting the fuses via avrdude on the command line and I had programmed a duff set of fuses into the chip, setting a stupidly low clock rate. In this state, the ATMega328P wasn't able to handle interfacing with the programmer (but it was probably running in a low power mode which is what I was trying to achieve).

I tried various solutions to this, apparently adding -B10 (up to -B250) is meant to help by slowing the interface down, and indeed it did, a bit. It got through the chip ID, but failed on the next step. One thing I didn't get around to trying was injecting an external clock into the chip, which might have worked. However, I was keep to get on with the battery powered LCD clock I was working on (more about that later...), so put that chip to one side.
Later I remembered I'd bought a cheap 'universal programmer' from ebay in order to program some EPROMs. After the fun I'd had with the VIC20 repair, I had concluded I needed a new one. The MiniPro programmer seemed quite widely available and had decent reviews. It has a massive list of supported chips, including some neat features like testing 74 series logic chips and SRAM chips. It also had the option to program various microcontrollers. I wasn't planning on using it to program ATMega328Ps, as I normally work in the Arduino IDE, which has no support for this, but easy support for programming using the standard bootloader on an Arduino board, or with the USBtinyISP.
Firing up the software, it read the chip correctly and showed the duff fuse settings. I was able to set them back to something more reasonable and reprogram the chip. To make sure it was OK, I changed to a known working ATMega328P and read that in, saving a copy for future reference. I then wrote the code and fuse settings from the working chip back to the dodgy one. That seemed to go alright, so I replaced the chip in the Arduino Uno board, loaded the IDE and programmed it with the blink example (what else).

The moral of the tale, when it says 'be careful when setting fuses', it means it!

Wednesday, 24 April 2013

Nissan Leaf Review - Part 4: One Month On


This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

I've now had the leaf for a month, and driven 500 miles in it. I really like it, yes there have been a few minor issues, but solving those has been quite interesting, and it's now just an automatic part of the daily ritual to plug in and charge.
I've only had to charge up at home a couple of times to make a longer journey, so that's the only time I've had to pay. All in, the 500 miles has cost me about £2. (plus £250 for the charging cable, and the initial cost of the car).

As you're driving the dashboard shows via a series of dots how much power is coming out of or going back into the batteries. Given such a clear indication of the way your driving affects how much energy you use makes it easier to make minor adjustments to the way you drive to save energy, and extend the range. Things such as thinking about when you accelerate and when you actually need to, and braking sooner to slow down more gradually, making more use of the regenerative breaking.

The main annoyance for me at the moment is a minor one, with all the instrumentation in the car and the carwings website and app, nowhere does it give the one figure that would be most useful, the actual percentage charge available. The estimates are always going to be off as they can only be based on assumptions the the type of road you're currently driving will remain the same for the next 80 miles. It won't, I know it won't, I know exactly what the roads will be like, so given the vital missing information, I would be able to get a more accurate estimate. As it is, the best I can get is either the 12 bar gague or the misleading 'percent' on the carwings website which jumps is steps rather than giving the actual figure. Hopefully they'll be able to do something about it in future.

In summary:

  • There were a few initial problems getting insurance and the correct charging cable, but those are soon forgotten about
  • It's a very nice car, roomy, well built, fast, responsive, quiet, comfortable and easy to drive
  • The range is comfortable around 60 miles driving normally (less that quoted, but perfectly workable)
  • There are probably an additional 10 or 20 miles available past where I take it to, so 80 miles tops
  • You can get a better range if you drive slower and more carefully
  • It should be fine for anyone who drives up to about 40 miles a day, and has the option to charge at home or at work
  • Once you're using it, although they are getting better, it's still wise to ignore the dashboard, app and website estimates, and just count the bars on the battery gauge
  • The battery is 24kWh, so in the UK, that's about £3 to charge from empty, so at 60-80 miles, that works out around 4p per mile if you charge at home, although many charging posts are currently free. My old diesel would do 10p per mile at best.

Here's to the next 35 months of my 3 year contract!

2022 Update: 9 years later, I am still driving a Leaf, albeit my second one. The range estimate is a lot more accurate on the 2016 model, and shows a percentage remaining, and I get between 100 and 120 miles range, depending on the weather.


Saturday, 6 April 2013

Nissan Leaf Review - Part 3: Living with a Leaf

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

I've had the Leaf for a few weeks now, and I'm starting to get the hang of working with the range. The first thing to do it seems is ignore the estimates and the quoted ranged and just see what you get from normal driving. I'm getting about 60 - 80 miles, about half of what the estimates tell me. The range of the car is estimated differently in various places, but most are over 100, so what I am getting is a little disappointing. However, it's still perfectly usable.

It's a balance, if you want a car which is nice and easy to drive, fast and responsive, you will get a lower range. If you want higher range, you need to drive in ECO mode with the aircon off and don't accelerate too often or too hard, you may be able to get into the 100 miles + range. I've been enjoying the car and getting less range, but I know if I'm getting a bit low, I can just change my driving style a little and extend the range. So you get the best of both worlds, you can have the fast, responsive, enjoyable to drive car when you want it, and drop to the economic one if and when you need to. You don't get that choice on a normal car, it's one or the other.

The range estimates on the dashboard are getting better, it is currently showing I have 100% charge and a 75 mile range (although carwings - see photo lower down - still shows a generic average of 120-149 miles).
The one piece information I've been relying on is the charge gauge. This has twelve bars, and I'm working to the following rules of thumb for these:
  • 1 bar = 5 miles of my driving on my usual roads
  • 1 bar = 10 miles at a push in ECO mode with the aircon off and driving carefully
  • 1 bar = 30 minutes to recharge from a type 2 charging post (32A rated, limited to 18A by the onboard charger)
  • 1 bar = 45 minutes to recharge from 13A standard mains socket
  • 1 bar = 2kWh = 25p (if you're at home and paying) or free at most charging posts
So from that, it works out at 5p per mile (if you're paying), and it charges at 10 miles per hour. That's what I'm getting at the moment, I'll keep an eye on those readings over the coming weeks.
The carwings website shows a percentage of charge, which I think can be a little misleading as I think it only show percentages converted from the number of bars. I've been monitoring charging and I've only ever seen it change in 7-8% jumps, as if it can only show 1/12, 2/12, 3/12 etc. It's estimate is also a generic one, and not biased by your driving style, so shows the rather optimistic range of 149 miles with the air conditioning off. The car itself, as shown above, is now showing a more realistically attainable 75 mile range, although this varies a little to frequently when you're driving. If you're in a short 30 mph zone, the range shoots up just as fast as it falls when you leave the 30 zone, so it's difficult to keep track of. Hence, I'm using the bars.

At one point, I left the car with a charge shown on carwings as 50%. The next day, without having moved the car, it was showing 42%. I initially thought it had lost 8% somewhere! However, what was seen as a jump from 50 to 42 may have been a lot less as it dropped from 6 bars (50%) to 4 bars (42%). It may have just dropped slightly, just enough to drop down to the next bar. A little misleading initially, but now I think I know how it works, less of a concern.

2022 Note: That 8% drop was probably the battery heater which kicks in when it's cold overnight. The Mark I Leaf's heater was a bit primitive, basically just a resistive wire across the high voltage battery.

Friday, 29 March 2013

Nissan Leaf Review - Part 2: First Impressions

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

Just a quick update following on from the rather long first part of this review. One of the longest journeys I regularly make is a 34 mile round trip from here in Tynemouth to an office in Houghton-Le-Spring. I've been driving that route on and off for the last five years, so I know it well. All the little twists and turns, all the places here I need to change gear, and the places where I can get away without doing so. That makes it an ideal test for Nissan Leaf on motorway (type) driving, lets see how it does on that journey.

I have to say I've very impressed, it's so easy to drive. Just press the accelerator and it goes faster. Press the brake and it goes slower. It doesn't have to be any more complicated than that! It's so easy in fact, that I'm finding it easy to be going faster than I expect. I think I must be tuned to listening for the engine noise combined with knowing which gear I was in and subconsciously judging speed from that. One nice feature the Leaf has is a speed limiter, a bit like a cruise control, but just an upper limit, with no lower one. So, if my right foot is a little enthusiastic, it holds back and only accelerates up to the set speed, thus avoiding wasting energy by accelerating up to a higher speed, realising and then decelerating  It also benefits from gravity in the mode, so driving through the Tyne Tunnel, I set it to 40 mph and it was applying the brake automatically and recharging the battery via regenerative breaking all the time it was on the downhill part, the same on the long downhill stretch of the Houghton Cut at 50.

There are charging posts at my destination, so I plugged in my hard won Type 2 lead and charged from about 15% to full capacity in under 4 hours. During that time, I was able to monitor progress via the Nissan Car Wings website:
There is also an iphone app and an app for android (although it doesn't support android 4.x devices like my Nexus 7). Not all of the buttons on the site seem to be working at the moment, but I've raised this with Nissan and they're looking into it.

All in all, a very successful test. The range estimates I'm getting are a little misleading at times, I don't know how much of the driving history it bases it's assessments on, but it's going up and down all the time. I've already found I'm more comfortable with hard(er) facts like charge capacity. It seems that journey uses about 30% of the charge each way (the way I drive), so it's much easier to calculate based on that. There are 12 bars on the charge gauge, so as long as there are 4 bars left, I should get there. In practice  I'd be wanting 6 bars+ before setting off. Although I know if it is running low, just slowing down and turning off the aircon should extend the range sufficiently to get me there, and if it doesn't, there are a number of places I can call at on the way for a topup.

So much for a quick update.

2022 Update: The phone app and website are still a bit rubbish and still work intermittently. Which is a shame.

Wednesday, 27 March 2013

Nissan Leaf Review - Part 1: Actually Getting One

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

After almost 11 years, it's finally time to replace my trusty VW Golf GT TDI. This has served me very well over the last decade or so, and even though it's now 14 years old and still solid and reliable, it's time to upgrade.
I've looked around at various options and have become very interested in the possibilities of electric cars. It's a tricky subject to get decent information on, because there seems to be a lot of bad press on them, but really when you get down to the facts, it seems to be a combination of lazy journalism or lack of understanding.

The first thing everyone says when I mention electric vehicles, is 'what happens when you run out of charge on the motor way'. When you think about it, the answer is exactly the same as 'what happens when you run out of petrol on the motor way'. The answer is this, people point and laugh and you make an embarrassed call to a recovery service. The point is, you don't get into that situation. In a petrol car, if the low fuel light was on and the gauge was low, you'd think ahead and refill before making a long journey. It's exactly the same with an electric vehicle.

The main difference is that the overall range when full on an electric vehicle is in the order of 100 miles, whereas my teenage diesel could get in the order of 600 miles with 50 miles to the gallon. So, yes, it needs charging more often, but you can charge at home, at work, various car parks, and it costs between £0 and £3 per charge. As opposed to £70 on my golf. Given that information, if you plan to take long trips or drive more than 100 miles a day, an electric vehicle isn't for you. But if you're like the vast majority of us and you commute to work and back, 10 to 20 miles, plus trips to supermarkets etc. there's no reason to consider 'range anxiety' an issue.

So, my decision was made, an electric vehicle was a good choice for me, so all I I had to do was pick one. There aren't many choices at the moment, and the Nissan Leaf seems to be the best choice for me. There is a dealer close by, so I arranged a test drive and tried it out. It was fine. It worked, I was able to drive up and down the Coast Road without a problem. I didn't run out of charge. I didn't have to push it home. I didn't have to stop half way for a charge. It just worked. I don't have much experience of driving an automatic, but it didn't take me long to retire my left foot and left hand and drive only with the accelerator and brake (although I'm still subconsciously trying to check I'm in first when I'm waiting at lights).


I'm not the slimmest of drivers, but there was plenty of space inside, probably more than the Golf, even though it was about the same size externally (so it's 'bigger on the inside'). That's because there's just less stuff in an electric vehicle, the biggest item is the battery which is beneath the floor, the charger is behind the back seat, and the motor, transmission sit in the front where the engine would normally go. Also under the bonet is a standard 12v battery to power the lights and the radio etc.. That lot takes up much less space than an internal combustion engine, gearbox, transmission, exhaust, fuel tank, etc. This is front wheel drive, so there's a bit more going on, some of the older rear wheel drives were frighteningly simple and elegant with the wheels attached directly onto the motor shafts.


Having overcome what the press had said was the main issue (that of range), and my main issue (that of interior space), I couldn't see a reason not to get one, so I ordered one. Buying outright didn't seem the best option, and there is a potential issue of battery longevity. Nissan were quoting 5-7 years I think, and Renault had opted for a different solution and were actually leasing the batteries to the driver. Although it may be seen as a downside, all that will happen in reality is the maximum range will slowly reduce. It's not like a petrol car where when the engine goes, it goes at that's it. The solution seemed to be to go for a three year contract hire rather than an outright purchase. That gives me a good long time to try it out and see if it works for me. If it does, I'll be able to look around and buy a newer, faster, better, more version in three years time. Or a Golf TDI if it hasn't worked out.

That was what seemed to be the main objection out of the way, so it should all be plain sailing from then on.... Well, no it wasn't. I hit a few snags, the ones they don't tell you about when they're too busy driving around and around Lincoln waiting to run out of charge. I think most of these will be sorted over time, but in an emerging market, there are some teething troubles.

Firstly charging. That shouldn't be a problem right, that's one of the main functions of the car? Well there are essentially three ways to charge the Leaf. One is via a supplied charger which has a standard 3 pin 13A mains plug on the end and charges the car in around 8 hours (normally overnight). The second is to plug into one of a growing number of charging posts in public and office carparks, many of which have the new Type 2 Mennekes.sockets which with 32A will charge in about 4 hours. The third is to use a rapid charger, currently mainly installed at Nissan dealers, which can charge to 80% in 30 minutes. 

The 13A plug charger is supplied with the car. The rapid chargers have cables built in, much like a petrol pump. What's missing is the cable which connects the car park charging posts to the car. Nissan are apparently going to supply one in future models, but at the moment, they couldn't source one. I found one online and reluctantly ordered it (£200 for a cable!). After a week, no sign of the cable and the car delivery date approaching, I contacted them and found it was out of stock until some time in April - I wonder when they were planning to tell me that? I then searched further and found another lead from a different supplier, more expensive (£250 for a cable!!), but looked better with a longer flexible black cable as opposed to thicker bright orange. (and yes, it is thinner, but the conductors are still 6mm squared cable, so it is rated for 32A). That was in stock and was delivered the day before the car. So that one's sorted, and probably isn't going to be a problem for future purchasers.

The next issue they don't tell you about is insurance. It seems half of the insurers I called didn't have the Leaf listed or don't do electric vehicles (0cc? ok, but is it petrol of diesel?) and the other half don't insure leased vehicles. Again, I'm sure they'll get the hang of it over time.


It was quite a struggle in the end. It took a while to get the paperwork sorted and insurance setup, and after several days of emails, and phone calls, the Nissan dealers IT problems and three hours sitting in the dealership signing things, I finally drove away in my new Nissan Leaf. Being electric, there's no engine noise, only road noise and the depressing sounds of depreciation as a new car is driven off the dealers forecourt.

So I'll leave it there for this instalment  this is going to be an experiment, it might not work, but I think it will. Time will tell. There are only a few thousand electric vehicles on the road in the UK at the moment, so it's a bit new, but get over the few teething problems, and I think it's going to work. I'll continue this review over the coming months as I get to know the Leaf and report on my progress.

2022 Note: I think the experiment worked. I had to give that Leaf back after three years, and so I bought another new one, this time with an option to buy after three years, which I did, and I still have it, and it's still a great car. And I haven't run out of electric once.