Writing Code for the ATtiny10

I previously wrote about the hardware aspects of getting your code into an ATtiny10 some 7 years ago (wow that was realllyy a long time ago!).

Now, avrdude is at version 6.3 and the TPI bitbang implementation has already been integrated in. The upstream avr-gcc (and avr-libc) also have proper support for ATtiny10s now. These software components are bundled with most distributions, including the Arduino IDE, making it easily accessible for anyone. Previously a fully integrated and working toolchain only came from Atmel and it was behind a registration page.

The price of the ATtiny10 has also dropped by a lot. When I first bought this microcontroller in 2010, element14 carried it for $1.85 in single quantities. Now, they are only $0.56 each.

I thought I’d write up a short post about writing and compiling code for it.

ATtiny10 on a prototyping board

Continue reading

Making USBasp Chinese Clones Usable

I don’t have any dedicated programmers. I have been programming Atmel chips using the USB-to-serial bitbang method.

Recently, I thought I’d get one because doing a re-programming cycle is taking quite a bit of time (a disadvantage of serial port bitbanging).

A popular one on Aliexpress seems to be this “USB ISP” one, so I bought one. I chose this one because it has a nice aluminium case, and a pinout diagram imprinted on the case, which is handy. After having so many one-off projects with bare PCBs collecting dust, I now appreciate the importance of having projects in their own box or case.

USB ISP programmer with aluminium case

While it has “USBasp” in the item name, it turns out that this was not a USBasp device, and getting it to work like one takes some effort.

It identifies itself as a zhifengsoft HID device when I plug it into Linux:

usb 3-1: new low-speed USB device number 3 using ohci-platform
usb 3-1: New USB device found, idVendor=03eb, idProduct=c8b4
usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 3-1: Product: USBHID
usb 3-1: Manufacturer: zhifengsoft

avrdude does not recognize the device, even after creating an entry with the corresponding vendor/product ID. This particular device was designed to work with their Windows-based UI called ProgISP and will not work with avrdude.

And apparently you can’t just take the USBasp firmware and flash it into this device, because the circuit is somewhat different.

After some research based on the PCB markings, I found these sites that talk about them:

Disassembly

Disassembling the device is simple. While grabbing the side of the case, firmly push the USB connector inwards and the board should slide out the other end. You can then gently pull the board out by the IDC connector.

Disassembly how-to photo

The programmer seems to be based off of the popular USBasp programmer, but modified somewhat (to what end I’m not sure). It lacks some features offered by other USBasp programmers, like the ability to control the target’s clock, or to use 3.3V for certain targets. But at $2 with a nice aluminium case, what more can you ask for?

It’s powered by an ATmega88 (I read that older versions were based on ATmega8). The markings on the board indicate that this is a MX-USBISP-V4.00. You can ignore tHe date because it was never updated; the older V3.02 also has the same date. While the GreenPhotons blog was talking about V3.00, I have verified that this version suffers from the same issue.

USBISP programmer, with aluminium case

USPISP PCB rear

Note that there are provisions on the PCB to add a voltage regulator, and the PCB link marked “C” can be cut to separate USB power from the rest of the system. Link “D” can be cut if you wish to disable target power. However, none of these options were used.

The crucial difference with this clone is that the USB D- pin is additionally connected to PD3, shown here highlighted in blue:

Clone difference in schematic view

However, in the USBasp’s main() function, PORTD‘s data direction register was initialized like so:

  /* all outputs except PD2 = INT0 */
  DDRD = ~(1 << 2);

This causes the USB D- line to be actively driven from PD3, thereby impeding communication to/from the USB host.

The rest of this post will talk about (1) correcting this problem in USBasp, and (2) uploading the firmware into your zhifengsoft programmer.

Continue reading

DIY Optical Slave Flash

I found a couple of old disposable cameras in storage that I played around with 15 years ago, shorting the caps to make a loud bang, wiring up the flash trigger to a remote-controlled relay kit I had assembled. I thought I’d do something useful with them.

I decided to turn them into optical slave flashes, since on-camera flashes are not very flexible. I was thinking of a way to detect the camera flash so that the slave could be fired, maybe using an LDR with the ADC to detect an increase in light intensity? It turns out there’s an even easier way to do this – with an infrared sensor. Apparently when flash tubes are fired, they give off infrared which can be detected more reliably than light intensity changes. When I read about this, I tested it out with a simple Arduino sketch and it works as advertised.

Disposable cameras usually have metal contacts that are placed near the shutter mechanism. When the shutter opens, the contacts are closed and if the flash was charged it would fire. To control the flash firing, I replaced the contacts with an SCR.

Continue reading

My First Arduino

I finally bought myself an Arduino Uno this week.

“Wait a minute… then what have you been using?” I hear you ask. Previously I had access to an Arduino Duemilanove, and used it to burn the Optiboot bootloader onto an ATmega168 that I had. The Duemilanove board used an FTDI chip which had additional pins brought out to an unsoldered header marked as X3. Following this guide by Kimio Kosaka, I downloaded the precompiled avrdude for Windows and used it to program the ATmega168 via the X3 header.

The end result was a bare-bones Arduino that ran on a 12MHz crystal. The reason for 12MHz was because that was the maximum “safe” clock speed at 3.3V, which I used for a university project and have been using ever since. You can see it below, driving a HD47780 parallel LCD.

However, it’s a real chore to hook this up, especially since everything on the breadboard like the crystal, FTDI header and reset button and pullup resistor are all inserted like any other component. It is more convenient to have a ready-built board for prototyping, where you don’t have to worry about the Arduino components.

If you haven’t gotten an Arduino board yet, I highly suggest you get one. If you would like to hook it up on the breadboard similar to what I did, at least get the Really Bare Bones Board (RBBB) Kit.

Reducing power usage on the iCufflinks’ ATtiny4

I came across this very nice article which documents steps taken to reduce the power usage on the ATtiny4 used in the iCufflinks.

The process managed to shave off about 315 μA, which boosts battery life quite a bit:

The overall effect this has on the product is that the 24 hour time between battery changes can be upped to 38 hours. That is a pretty good power savings for the day.

It’d be great if this was incorporated into the products.

I do disagree on one thing though, which is cutting away the data points used for the PWM. Unless the output was measured with an oscilloscope and produces the same breathing pattern, I would very much keep the data since the additional space gained is not used for anything else.

If you don’t know what iCufflinks are, watch the video below.