Using Tiny85 reset pin with WS2182 led

I couldn't get WS2182 led to work with attiny85, it was stuck solid white

To get WS2182 led to work with attiny85 i had to change tools/clock to 8MHZ then burn bootloader, then upload my sketch, then it worked

But i want to use attiny85 pin 1, the reset pin (pb5)

So i do the above, then use the HV programmer sketch to enable pin 1 as a gpio

But now my led is stuck solid white again, like it was until i did the burn bootloader fix

Has the HV programmer sketch below undone my 8MHZ burn bootloader?

// AVR High-voltage Serial Fuse Reprogrammer
// Adapted from code and design by Paul Willoughby 03/20/2010
// http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/
// Fuse Calc:
// http://www.engbedded.com/fusecalc/

      // To use pin 1 of Attiny as gpio
      // 1. Upload your program to Attiny
      // 2. Change below to writeFuse(HFUSE, 0xFE);
      // 3. Upload this sketch to uno board, connect HV programmer and Attiny
      // 4. Open serial monitor, enter any key, Reset pin will now be a gpio

      // To return pin 1 to a reset pin
      // 1. Change below to writeFuse(HFUSE, 0xFF);
      // 3. Upload this sketch to uno board, connect HV programmer and Attiny
      // 4. Open serial monitor, enter any key, Reset pin will now be a reset pin

#define RST 13 // Output to level shifter for !RESET from transistor
#define SCI 12 // Target Clock Input
#define SDO 11 // Target Data Output
#define SII 10 // Target Instruction Input
#define SDI 9 // Target Data Input
#define VCC 8 // Target VCC

#define HFUSE 0x747C // not here!!
#define LFUSE 0x646C
#define EFUSE 0x666E

// Define ATTiny series signatures
#define ATTINY13 0x9007 // L: 0x6A, H: 0xFF 8 pin
#define ATTINY24 0x910B // L: 0x62, H: 0xDF, E: 0xFF 14 pin
#define ATTINY25 0x9108 // L: 0x62, H: 0xDF, E: 0xFF 8 pin
#define ATTINY44 0x9207 // L: 0x62, H: 0xDF, E: 0xFFF 14 pin
#define ATTINY45 0x9206 // L: 0x62, H: 0xDF, E: 0xFF 8 pin
#define ATTINY84 0x930C // L: 0x62, H: 0xDF, E: 0xFFF 14 pin
#define ATTINY85 0x930B // L: 0x62, H: 0xDF, E: 0xFF 8 pin

void setup() {
  pinMode(VCC, OUTPUT);
  pinMode(RST, OUTPUT);
  pinMode(SDI, OUTPUT);
  pinMode(SII, OUTPUT);
  pinMode(SCI, OUTPUT);
  pinMode(SDO, OUTPUT); // Configured as input when in programming mode
  digitalWrite(RST, HIGH); // Level shifter is inverting, this shuts off 12V

  Serial.begin(19200);
  Serial.println("Code is modified by Rik. Visit riktronics.wordpress.com and electronics-lab.com for more projects");
  Serial.println("-------------------------------------------------------------------------------------------------");
  Serial.println("Enter any character to start process..");
}


void loop() {
  if (Serial.available() > 0) {
    Serial.read();
    pinMode(SDO, OUTPUT); // Set SDO to output
    digitalWrite(SDI, LOW);
    digitalWrite(SII, LOW);
    digitalWrite(SDO, LOW);
    digitalWrite(RST, HIGH); // 12v Off
    digitalWrite(VCC, HIGH); // Vcc On
    delayMicroseconds(20);
    digitalWrite(RST, LOW); // 12v On
    delayMicroseconds(10);
    pinMode(SDO, INPUT); // Set SDO to input
    delayMicroseconds(300);
    unsigned int sig = readSignature();
    Serial.println("Reading signature from connected ATtiny......");
    Serial.println("Reading complete..");
    Serial.print("Signature is: ");
    Serial.println(sig, HEX);
    readFuses();
    if (sig == ATTINY13) {

      Serial.println("The ATtiny is detected as ATtiny13/ATtiny13A..");
      Serial.print("LFUSE: ");
      writeFuse(LFUSE, 0x6A);
      Serial.print("HFUSE: ");

      
      writeFuse(HFUSE, 0xFF); // Disable Reset Pin = 0xFE, Enable Reset Pin = 0xFF


      Serial.println("");
    } else if (sig == ATTINY24 || sig == ATTINY44 || sig == ATTINY84 ||
               sig == ATTINY25 || sig == ATTINY45 || sig == ATTINY85) {

      Serial.println("The ATtiny is detected as ");
      if (sig == ATTINY24) Serial.println("ATTINY24..");
      else if (sig == ATTINY44) Serial.println("ATTINY44..");
      else if (sig == ATTINY84) Serial.println("ATTINY84..");
      else if (sig == ATTINY25) Serial.println("ATTINY25..");
      else if (sig == ATTINY45) Serial.println("ATTINY45..");
      else if (sig == ATTINY85) Serial.println("ATTINY85..");

      writeFuse(LFUSE, 0x62);
      writeFuse(HFUSE, 0xDF); // ResetDisable = 5F, Enable = DF **change here for tiny85**
      writeFuse(EFUSE, 0xFF);


    }

    Serial.println("Fuses will be read again to check if it's changed successfully..");
    readFuses();
    digitalWrite(SCI, LOW);
    digitalWrite(VCC, LOW); // Vcc Off
    digitalWrite(RST, HIGH); // 12v Off

    Serial.println("");
    Serial.println("");
    Serial.println("");
    Serial.println("");
  }
}

byte shiftOut (byte val1, byte val2) {
  int inBits = 0;
  //Wait until SDO goes high
  while (!digitalRead(SDO))
    ;
  unsigned int dout = (unsigned int) val1 << 2;
  unsigned int iout = (unsigned int) val2 << 2;
  for (int ii = 10; ii >= 0; ii--) {
    digitalWrite(SDI, !!(dout & (1 << ii)));
    digitalWrite(SII, !!(iout & (1 << ii)));
    inBits <<= 1; inBits |= digitalRead(SDO);
    digitalWrite(SCI, HIGH);
    digitalWrite(SCI, LOW);
  }
  return inBits >> 2;
}

void writeFuse (unsigned int fuse, byte val) {

  Serial.println("Writing correct fuse settings to ATtiny.......");

  shiftOut(0x40, 0x4C);
  shiftOut( val, 0x2C);
  shiftOut(0x00, (byte) (fuse >> 8));
  shiftOut(0x00, (byte) fuse);

  Serial.println("Writing complete..");
}

void readFuses () {

  Serial.println("Reading fuse settings from connected ATtiny.......");

  byte val;
  shiftOut(0x04, 0x4C); // LFuse
  shiftOut(0x00, 0x68);
  val = shiftOut(0x00, 0x6C);
  Serial.print("LFuse: ");
  Serial.print(val, HEX);
  shiftOut(0x04, 0x4C); // HFuse
  shiftOut(0x00, 0x7A);
  val = shiftOut(0x00, 0x7E);
  Serial.print(", HFuse: ");
  Serial.print(val, HEX);
  shiftOut(0x04, 0x4C); // EFuse
  shiftOut(0x00, 0x6A);
  val = shiftOut(0x00, 0x6E);
  Serial.print(", EFuse: ");
  Serial.println(val, HEX);
  Serial.println("Reading complete..");
}

unsigned int readSignature () {
  unsigned int sig = 0;
  byte val;
  for (int ii = 1; ii < 3; ii++) {
    shiftOut(0x08, 0x4C);
    shiftOut( ii, 0x0C);
    shiftOut(0x00, 0x68);
    val = shiftOut(0x00, 0x6C);
    sig = (sig << 8) + val;
  }
  return sig;
}

So, you reset the fuses, burned a new bootloader and then ran a HV programmer to blow your fuses away (that's what a HV programmer does, including resetting the RESET when you blew it away).

1 Like

To avoid this problem, use an ISP programmer like the outstanding Pololu AVR programmer v 2.1. Then your program can occupy all of program memory and you can set the fuses to anything you like.

Keeping it simple:

  1. Set at85 to 8mhz in tools/clock then burn bootloader
  2. Upload my sketch
  3. Use HV programmer sketch to enable reset pin as gpio

I need to know how to stop HV programmer sketch (attached) from undoing step 1

Why do you want to use PB5 (Pin-1(RESET/)) when there are other DIO pins -- PB0, PB1, PB2, PB3, and PB4?

I have a usbasp programmer, how do I set the tiny85 to 8mhz if I upload using the no bootloader option?
Then how do I stop the HV programmer sketch from changing it back to 1mhz after I’ve set the reset pin as a gpio

All nonsense about programmers aside. You don't actually need a HV programmer to set the fuse for using Reset as a normal GPIO pin, but only to undo that setting. Still it's good you have the HV-programmer working up front.

Anyway look at AtTiny Fuse calculator and compare this to the HV-programmer sketch that you have been using

      writeFuse(LFUSE, 0x62);
      writeFuse(HFUSE, 0xDF); // ResetDisable = 5F, Enable = DF **change here for tiny85**
      writeFuse(EFUSE, 0xFF);

You can either consider not writing to LFUSE at all or write the clock settings to use 8MHz by setting bit 7 'unprogrammed' which results in LFUSE being 0xE2.

1 Like

Procedures:
1. Read the following Tables (Figure-1) to understand the functions of the Fuse Bits of ATtiny85 MCU.




Figure-1:

2. From the Tables of Fig-1, choose the following values for the fise bits and set them using AVR Programmer.

EF = 0xFF
HF = 0xDF (Pin-1 is RESET/-pin to allow ISP Programming.
LF = 0xE2  (no division by 8, opearing clock is 8 MHz internal).

3. Place the ATtiny85 onto AVR Programmer and Upload your sketch which is using Pin-1 as DIO line to drive the Pixel-LED.

4. Now, use AVR Programmer to set the following fuse bits:

EF = 0xFF
HF = 0x5F (Pin-1 is DIO pin,; ISP Programming is inhibited).
LF = 0xE2  (no division by 8, opearing clock is 8 MHz internal).

5. Take out ATtiny85 from the AVR Programmer. Place it on Breadboard and connect 5V, GND, and Pixel-LED with ATtiny85. The circuit should work.

Simplest solution is actually to set the fuses to whatever you want them to be using the HV-programmer after uploading the sketch. As stated before it is a good idea to have the HV-programmer working before disabling the RESET pin. (mind you, you can never be fully sure until trying that out i guess, but the HV part is not the tricky part as such.)

A HV Programmer is a Faster Parallel Programmer and much more expensive than the LV slower Serial AVR Programmer. Most of the Arduno Users own AVR Programmer.

A parallel programmer is not required for AtTiny85 (i would only think to use it on an AtMega328P)
The HV programmer is actually just a simple circuit which provides 12v+ (or more up to 15v, but 12v is the spec) where the Arduino runs the sketch that the OP has posted (or variants of that) and toggles the RESET to 12v+
A simple NPN transistor and a couple of resistors. is all that is needed as well as a 12v source.
If for some reason the AtTiny is set to a clockrate that differs from the internal clock or RESET or SPI has been disabled, a HV-programmer is required to undo this. (whereas on an Atmega328p a parallel programmer is required, but those take quite a bit of effort to built.)

Since the OP is doing exactly the disabling of RESET, chances are a HV-programmer will be required if the sketch is to be updated or the AtTiny re-used. Anyway the OP already has a HV-programmer and was using it.

I actually just built a simple SPI programmer using ArduinoISP sketch which does the trick for the chips i use.

Thanks for the help guys

I made my own HV & normal tiny85 programmer, it just plugs into uno and uses 12v center positive,
For anyone who needs them:
https://www.dropbox.com/scl/fo/0rn07ogtroa75prk0znlh/AGzf9EF4LvDrfMQmH1S0Jc4?rlkey=zlo49a6hp1w459rd30o5a7krt&st=b3ma7y9a&dl=0

https://www.dropbox.com/scl/fo/s7um12ce7an47poyylxuh/ALpecOSw6uemjfpx6rzJJJU?rlkey=nbeg32cqcpxfry4yd3gpbofpw&st=r0pxrsom&dl=0

Oh wow you took it a step further than i did. Though i did use a simple MT3608 circuit to provide the 12v from the UNO's 5v source. I kept it on experimentation board, i need only one.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.