DigiSpark with 6 input/output pins, homebrew fuse-programmer

Arduino projects on the go
User avatar
Phil_G
Posts: 596
Joined: 15 Feb 2018, 23:32
Contact:

DigiSpark with 6 input/output pins, homebrew fuse-programmer

Post by Phil_G »

One of the advantages of the old 8-pin PIC chips was that other than pos & neg, all six remaining pins
were available for I/O. This isnt the case for the Atmel ATTiny chips: as supplied the DigiSpark has five
I/O pins, as does the bare ATTiny85 on which its based. The sixth terminal, P5 on the DigiSpark board and
pin 1 on the Attiny85 chip is the 'Reset' pin used by the programmer.

However.... in fact this pin has two functions, it can be 'Reset' or it can be another I/O pin, with
interrupt, analogue and digital modes, and can be configured with 'pullup' just like any other pin.

In a nutshell, to program the board P5 must be configured as a Reset pin, and this is how its supplied
by default. To use P5 as I/O just like any other pin, it has to be set to I/O. This setting is determined by
one single bit of the high-fuse. For DigiSpark users, the only hfuse values of interest for this purpose
are DF which means P5 is a reset pin, and 5F which means its I/O.

To change any of the fuses requires a special high-voltage programmer, which few people have access to.

So after all this preparatory waffle, here's a project specifically designed to flip the DigiSpark P5
between Reset and I/O. Whilst the fuse-programming routines are by Paul Willoughby and Jeff Keyzer,
I've condensed the project into a small hand-held, stand-alone device and added an OLED display.
Being stand-alone means its self-contained, you dont need to plug it into your PC.

Its powered from something very near to 12v, I use a small 3S lipo which is perfect. It has to be close to 12v as thats the fuse programming voltage.
Initially the screen displays the current DigiSpark fuses. The one we're interested in is the hfuse, and
the hfuse values of DF and 5F. After showing the current fuse settings, if the power is held on,
then hfuse is set to DF. If the power is still held on, then hfuse is set to 5F. The programmer only powers up the DigiSpark for the duration of the fuse-setting - you can see the DigiSpark power LED going on/off.

An hfuse value of DF means P5 is RST and the DigiSpark can be programmed, 5F means P5 is I/O. Simply remove the power when desired setting is shown. I use a tiny 12v battery via a momentary push-button, so to read the DigiSpark I press and then read the screen. If hfuse is as required then the button can be released. If hfuse needs to be changed, just keep the button pressed until the desired value is shown.
I've done it this way to avoid any 'reset/io' switches, its easier to make and easier to use - but you could
add a selection switch if you prefer - though it really doesnt matter on an 'occasional use' tool.
You could make it even simpler by replacing the screen with a red/green bicolour LED - red is reset, green is go for i/o!

Of course this is all quite separate from normal Arduino IDE programming. Lets say as a test you want
to load 'blink' set to flash D5. In order to load the sketch "blink_D5" P5 needs to be a reset pin, hence hfuse
needs to be DF as it is when the DigiSpark is supplied. The sketch will load fine, but won't flash P5
yet as its not an I/O pin - its 'reset'.

So after loading 'blink_D5' you pop the DigiSpark into the fuse programmer and set hfuse to 5F.
The DigiSpark will now flash P5 as expected with D5 (P5) behaving just like any other I/O pin*.
But in this state, you cant reprogram it as the programmer needs a reset pin! So, if you need to make
changes, pop it back into the fuse programmer and set hfuse to DF. Now 'blink_D5' wont work, but
the DigiSpark is programmable again. Its a juggling act, so its best to be sure that P5's job is tested &
working, maybe temporarily using an 'easier' pin before moving the task onto P5.
Since it optionally has a pull-up, its ideal as a button input, an option switch or configuration link.

* though it doesnt have the full 20mA current capacity of other pins

Here's the project, I'll upload the sketch and do a vero layout (its very easy to make) and maybe a
video of it in use. Its much easier & quicker to use than to explain :D

... and a 20% increase in I/O capability is well worth having ;)

I've posted a few pics so the stripboard layout can be seen. Note the cut between vcc and ground on the 2-pin DigiSpark header.

IMG_5245[1].JPG

IMG_20190416_014654.jpg

fprog1.jpg

fprog2.jpg

fuseprog_vero_32x17.jpg

fprog3.jpg

fprog4.jpg

fprog5.jpg

fprog6.jpg


The two resistors nearest the transistor are both 1k, and the two leading to the DigiSpark P5 and Vcc are zero-ohm links. The transistor is a 2N3904, the same NPN as we use as a buzzer-buffering tranny.
The 12v battery will be replaced by a 27A 'fob' battery in a holder, On the two-pin header, the 12v rail is nearest the edge of the board. The link in the top-right corner connects 12v from the 2-pin battery header to the Raw input of the Nano - its not necessary, a solder bridge will do. I just used the link in testing.





Code: Select all

/*
  Blink P5 For Kickstarter ATTiny85. Use a 5v LED to avoid the need for a resistor.
*/

#define led 5      // Long leg (pos) of a 5v LED connected to P5
#define ground 4   // use P4 as a convenient 'negative' for the 5v LED short leg

void setup() {
  pinMode(led, OUTPUT);
  pinMode(ground, OUTPUT); // use P4 as a convenient 'ground' for the 5v LED short leg
  digitalWrite(ground, LOW);
}

void loop() {
  digitalWrite(led, HIGH);   // make P5 high
  delay(300);                // wait
  digitalWrite(led, LOW);    // make P5 LOW
  delay(700);                // wait
}
Attachments
fuse_resetter_oled5.ino
(11.09 KiB) Downloaded 401 times
User avatar
Wayne_H
Posts: 808
Joined: 17 Feb 2018, 05:26
Location: Temora, NSW. Australia
Contact:

Re: DigiSpark with 6 input/output pins

Post by Wayne_H »

Phil,

Does this mean that the ATtiny85 board(s) are a viable basis for a basic 3 ch propo encoder?
Cheers,

Wayne
Once a Retrobate, always a Retrobate............ ;)
User avatar
Phil_G
Posts: 596
Joined: 15 Feb 2018, 23:32
Contact:

Re: DigiSpark with 6 input/output pins

Post by Phil_G »

Hi Wayne, yes, one of the functions of P5 is "A0" in Arduino-speak - just another analogue input like the others.
In fact you could have four stick pots on analogue inputs, and one digital output for the PPM, leaving one you could use as a digital input to select an option like a V-tail mixer or whatever.

EDIT: Done! DigiSpark full 4-channel propo encoder with S/C mix
User avatar
Mike_K
Posts: 669
Joined: 16 Feb 2018, 06:35
Location: Hertfordshire

Re: DigiSpark with 6 input/output pins

Post by Mike_K »

Hi Phil

Great little project.

Just one word of caution, as you are applying 12V to the reset pin, if you use this pin as an I/O, then make sure that whatever is connected to it can withstand 12V. If it can't, then remember to disconnect it. Don't ask how I found out :oops:

Presumably, your fuse setter can (or could with minor modification) be used with ATmega as well as ATtiny chips?

For my sins, I bought an AVR Dragon a while back, mainly for the debugging functionality, but it can also do HV programming as a bonus. It is surprising how often an HV programmer is useful to rescue yourself if you are messing about with the fuses.

Cheers

Mike
User avatar
tiptipflyer
Posts: 393
Joined: 16 Feb 2018, 22:49
Location: Germany

Re: DigiSpark with 6 input/output pins

Post by tiptipflyer »

Thanks Phil,
it is always of great interest to watch this space, this is a nice gadget to have. As a fancier of Attinies it will be of good use for me.
Thanks again, I will try it out soon.

Frank
User avatar
Wayne_H
Posts: 808
Joined: 17 Feb 2018, 05:26
Location: Temora, NSW. Australia
Contact:

Re: DigiSpark with 6 input/output pins

Post by Wayne_H »

Phil_G wrote: 16 Apr 2019, 11:12 .....Video, sketch & vero photos added to opening post

Cheers
Phil
Thanks Phil. Similar to Frank, for me it's another project to try & still more to enjoy learning.

But.....The down side to being an old dog is the extra time it takes me to learn new tricks :o :lol:
Cheers,

Wayne
Once a Retrobate, always a Retrobate............ ;)
User avatar
tiptipflyer
Posts: 393
Joined: 16 Feb 2018, 22:49
Location: Germany

Re: DigiSpark with 6 input/output pins

Post by tiptipflyer »

Yes Wayne, that is another story. You are perfectly right, it gets harder to learn new tricks.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: DigiSpark with 6 input/output pins

Post by Martin »

Nice project. I shall most likely build one.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: DigiSpark with 6 input/output pins, homebrew fuse-programmer

Post by Martin »

I built mine yesterday, but I can't get it to work. I wrote a little test 'blink' style sketch to verify that the 12V is being switched - and that seems okay. I made it switch the built-in LED (13) high at the same time as switching RST (3) low and vice-versa, with 5-second pauses in each state. Sure enough when the LED is on, the voltage is 12V and when the LED is off, the voltage is close to zero.

At first I thought my display wasn't working, but it was just never updating because the fuse-reading routine hangs.

I modified the sketch slightly to display:

Phil_G's ATtiny85
Fuse programmer

on the display at start-up - that gives some confidence that the sketch and display are working.

With no ATtiny present it now hangs on that 'start-up' message display indefinitely.

With an ATtinty present, it also hangs indefinitely till I wiggle the ATtiny board - and then I get random values for the fuses appearing.

I've probably done something stupid, but at the moment, I'm stumped. Any suggestions?

Edit to add: I programmed the ATtiny with a blink sketch that blinks both the on-board LED (1) and the P5 (5) outputs. After trying the board on the fuse programmer, it still blinks the on-board LED, but not P5, and it's still programmable using a USBASP. I've NOT removed the zener diodes and other DigiSpark 'fluff' from my DigiSparks - so although I've erased the DigiSpark bootloader and they work okay for USBASP programming perhaps that's the problem?
Last edited by Martin on 18 Apr 2019, 23:36, edited 1 time in total.
User avatar
tiptipflyer
Posts: 393
Joined: 16 Feb 2018, 22:49
Location: Germany

Re: DigiSpark with 6 input/output pins, homebrew fuse-programmer

Post by tiptipflyer »

Hi guys,
I observed some weird things too. Yesterday my programmer was finished and I tried out three different digispark units, one with the big USB plug, one in blue color with a micro USB connector and a black one with a micro USB conector.
The only one, which seem to work, is the one with the big USB connector, both others do not work together with the programmer at all.
However the big USB one, which works, does some strange things too, the display will never change to 5F. After the first complete circle it changes from fuse H:FF to H:DF and stays there, but after the second complete circle the fuse has changed internaly to 5F but the display still shows DF. The blink sketch is working fine.
There will be no third complete circle, it stops after the second one.
When starting all over again, after the first circle it shows H:DF and the digispark can be programmed again, the blink sketch does not work.
When starting all over again, after the second circle it still shows H:DF but the digispark cannot be programmed anymore and the blink-sketch is working fine.

By the way, the digispark is brandnew and all diodes and other stuff are still in place.

Cheers
Frank
Post Reply