Saturday, 27 April 2013

Arduino Leonardo based ZX81 USB keyboard

Last year, I had a ZX81 case and wanted to turn it into a ZX81 USB keyboard. At the time the option I chose was initially developed on an Arduino Uno, and then built up onto a board using just the ATMega328P. I've build several versions of this now, many of which sat alongside Raspberry PI's inside their ZX81's and ZX Spectrum's, and I'd refined the circuit and the presentation a bit since the orignal.
A couple of days ago, I had a request for more information on the keyboard, and I mentioned that if I were doing it now, I would have looked at using an Arduino Leonardo. These are Ardunios based on the ATMega32U4, which has built in USB support, and there are libraries to turn the Leonardo into a USB Keyboard / Mouse etc. as part of the Arduino IDE.
So I got my self a Leonardo and tried out some of the samples and it seemed to work fine, so I adapted my original code to use the Leonardo USB Keyboard object and tried that out, and it worked remarkably well. One of the things I'd noticed about the Leonardo was that it was available to buy without the headers, and the IO pins were arranged in a way that I could get the 8 and 5 pin headers for the keyboard directly over IO pins 0-7 and 9-13.
So it was simply a case of soldering the keyboard connectors in place where the headers would have been.
Then installing it in the ZX81, on the underside of the top of the case.
And there it is, an incredibly simple way of making a ZX81 USB keyboard. There are 20 available IO pins on the Leonardo, so a similar approach could be used on most matrix keyboards, up to 100 keys. It should also work with any of the other ATMega32U4 based Arduino boards (such as the Micro).
The code is available below, in two versions. The first is the standard keyboard mapping, all the letters and numbers work as usual, and with shift held, the letters are upper-cased and the top row gives escape, ", #, arrow keys, !, and delete. The alternate version has the top acting like that by default and requires shift to get the numbers. This is the version I use to drive my myth tv frontend box, so I can navigate the menus without having to hold shift.
Creative Commons Licence
ZX81 USB Keyboard by Dave Curran is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Note: I have stopped using Leonardo based boards and moved onto my own custom PCBs and firmware for ZX81, ZX Spectrum and Commodore computers. There seem to be some issues using the Leonardo keyboard library with things like the Fuse emulator. If you plan to use an emulator, either see my Etsy store, or try the older V-USB based design.

Wednesday, 24 April 2013

Nissan Leaf Review - Part 4: One Month On


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 inital 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!

Saturday, 6 April 2013

Nissan Leaf Review - Part 3: Living with a Leaf

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.