Following on from my blog post about using the AVR Dragon to program Atmel microcontrollers, I have been building a TV-B-Gone prototype, hopefully leading to making some of these as a skill share at my local hackspace.
The TV-B-Gone was conceived by hack-hero Mitch Altman. It is designed emit the ‘OFF’ code for the majority of TVs in Europe and the US. Basically it is a TV remote control which only has the power button. It is designed to turn off inappropriate TVs, such as unwatched ones in public spaces. It is a commercial product, but Mitch has also worked with Adafruit industries to have an open-source design.
I am using v1.2 as shown on the LadyAda website. I had already programmed the ATTiny85 microcontroller, as mentioned in the previous post. This was built onto breadboard to check that it was working OK, but it did not include all the components, such as the IR LEDs.
The next stage was to build the circuit onto strip board. This would be the full design with all the components. My stripboard prototype is shown here – the layout is probably not optimal, but its small enough. I only used two IR LEDs, rather than 4 (as I only had two), but I added a red LED to show that they were working.
I have designed a PCB for this but wanted to prove that the circuit works before going too far and ordering a load of PCBs….
Top side of the prototype.
Solder side of the prototype.
I am in the UK so needed the optional 10k pulldown resistor on pin 6 of the microcontroller. This makes the EU TV codes run. If you are in the US then do not use this resistor and the US codes will be used.
I went out to find some TVs and try turning them off. I spent a while doing this but it did not work.
So now the fun fault finding begins. Firstly I have not been using exactly similar parts as the Adafruit design, due to the fact I did not have them and thought I had decent replacements. I hooked up the circuit to my oscilloscope and checked the waveform. The first thing I could see was that the power supply voltage was dipping down quite a lot when the IR LEDs were on. I helped to improve this by adding a 100uF capacitor on the power lines near the LEDs (I had only used 10uF). This helped a bit.
I checked the voltage across the IR LEDs and it was not swinging from +Vcc to ground, rather just being pulled down to around 2V (from a 4.5V supply). Hence the IR LED was probably not fully switched ON. SOLVED: This was due to the red LED used to indicate that the IR LEDs were working. The red LED would switch on at a lower voltage and then take a lot of the current and hence stop the IR LEDs working correctly. When the red LED was removed then the voltage applied to the IR LEDs was much better (in the region of 3V with a 3.8V supply (3 x AAA batteries)).
The other difference was the fact I had used different transistors: for the MPS2907A PNP, I used a BC558 PNP and for the 2N3904 NPN, I used a BC548 NPN. I checked the datasheets for differences, mainly related to the collector current.
MPS2907A can cope with 600mA of current, but the BC558 can only cope with 100mA - This could be an issue. 2N3904 can cope with 200mA, but the BC548 can only cope with 100mA - probably less of an issue?
The last issue could be that I had used a 330ohm resistor for the PNP transistor base, rather than the 1k suggested. SOLVED: Differences in the transistor make very little difference, as long as they can cope with the currents required. I swapped the BC558 for a BC640 PNP transistor, which can deal with 1A of current.
The TV-B-Gone still did not work, even with these changes.
I checked to see if the IR LEDs were working. This can be done using a digital camera as this will show the LEDs flashing a purple colour (cheaper digital cameras are sensitive to infra-red light). I did this and saw that I was getting flashes of light, so the IR LEDs were working.
Using a phone camera to see the flashing IR LEDs
Image from the phone camera – purple/violet colour flashes.
So we have a very-close-to-working circuit that still does not switch off any TVs. This needed more reading up. When I read the actual c file of the main code I hit upon one answer. Basically I had not changed any of the fuses on the microcontroller. This meant the device was still using the internal RC oscillator. In order to get accurate timings an external crystal resonator is used (on the Ladyada forum the answer is “always use a resonator or crystal”).
Also, by default, the microcontroller comes with the oscillator ‘divide by 8’ fuse set ON. This means with an 8MHz crystal we are running the code at just 1MHz. This might not matter in some situations, but here timing is critical. With both the 8MHz external oscillator used and no divide by 8 the the device worked! Great. Now to turn off TVs.
More information about fuses is available here, again from the Ladyada/Adafruit site.
To change this in AVR studio v5.0 you must set some of the fuses.
Firstly click on Tools -> AVR Programming. This will bring up the above pop-up. Set the device to ATtiny85 and using the AVR Dragon. I needed to lower the ISP clock frequency to around 64kHz to get it to work reliably, but that might have been due to the length of the programming wires (now sorted out and much shorter).
Click on ‘Memories’ and browse for the flash memory. Point this to the TV-B-Gone firmware v1.2 .hex code and click ‘program’. Hopefully it should work. If not take a break and then check your wiring (honestly the break helps).
Next click on ‘Fuses’ and then click on ‘Read’. This should show the above setting for a ‘factory fresh’ microcontroller. Note the CKDIV8 is enabled and the SUT_CKSEL is set to internal oscillator.
The above photo shows the correct fuses to set – de-select the CKDIV8 and select EXTXOSC_3MHZ_8MHZ_16KCK_14CK_65MS for the clock select drop down menu. Set the fuses after programming or else you will not be able to use the AVR dragon to directly program the microcontroller again as the fuse means it will be expecting an external oscillator. You will need to use the ISP lead onto a board with power and an actual oscillator. I set the clock to be ‘external’ on one of my Attinys which now means I cannot program it without setting up an external clock source.
Here are some pictures of the final prototype which was used to turn off the TVs in my local Argos:
I designed a PCB and ran a workshop as a soldering session at Nottingham hackspace. These kits are now available to buy.