Sunday, 26 May 2013

Arduino revival with EPROM programmer

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 commandline 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 acheive).

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, 1 May 2013

ZX Spectrum USB Keyboard

Following on from the ZX81 USB keyboards I've been building, next comes the Spectrum. The Spectrum has a lot in common with it's predecessor, but there are a few differences to the keyboard. The main difference from a software point of view is that there are now two shift keys. What was the ZX81's shift key is now caps shift, and what was the . / , key is now symbol shift, and there are various symbols dotted around the keyboard in red.
From a hardware point of view, it uses the same 5x8 keyboard matrix giving 40 keys, but the two membrane tails are now at opposite ends of the keyboard, meaning it's not as neat as the ZX81 worked out. I've done a few of these in the past in a similar way to the original ZX81 keyboard, just with a long, thin board. Here I went for a thin strip to take the connections to the Arduino Leonardo.
Other than that, it was plain sailing, and I soon had a Sinclair ZX Spectrum USB Keyboard to add to the collection. Note that due to the internal layout, it doesn't look like there would be sufficient space for a Raspberry Pi, the Pi would be too tall. One option would be to remove the USB connector and the RJ45 Magjack, or alternatively, use a model A - even with 256MB, it's still 5,461 times more than the Spectrum originally had.
Note: I have stopped using Leonardo based boards and moved onto my own custom PCBs and firmware for ZX81ZX 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 Tindie store, or try the older V-USB based design.

I now sell a ZX Spectrum USB  keyboard keyboard conversion kit in my Tindie store.