SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the E-Textiles category should be posted in this forum.
#204962
I followed these instructions to reprogram the Lily tiny:
https://learn.sparkfun.com/tutorials/re ... winkle/all
The test function worked great but I tried to upload new code to slightly modify the blink on/off function on the lily tiny and it failed to upload. Now I cannot load any code onto the AVR+Lily tiny. The light on Pin 0 on the AVR works and the lily tiny still works on it's own so this tells me the individual pieces are still functional. What other tests can I run to determine what the problem is?

Code with modifications that I tried to upload:
Code: Select all
/******************************************************************************
  LilyTiny (ATtiny85, internal 8 MHz clock)
  Emily Lovell
 
  Controls the behavior of up to four LEDs, depending on pin:
    Pin 0: fades in and out
    Pin 1: heartbeat
    Pin 2: blinks on and off
    Pin 3: twinkles randomly
******************************************************************************/

// Constant definitions
#define maxBrightness 255.0

#define maxTimeOn 9999 
#define blinkTime 2000 

// Variables and constants for fading pin. Needs to be a pin with PWM hardware
//  available; on the Tiny85 that's pin 0 and pin 1 only.
#define fadePin 	0  			// Redefine the pin name to something
								//  application specific.
int fadeDirection 	= 1; 		// 1 is brighter, -1 is dimmer
int fadeStep 		= 1; 
int fadeBrightness 	= 1; 

// Variables and constants for fading pin. Needs to be a hardware PWM pin; on
//  Tiny85 that's pin 0 and pin 1 only.
#define HEARTPIN	1 			// Redefine the pin name to something
								//  application specific.
int heartStage = 0;
float heartBrightness = 0;
float heartCounter = 0;

// variables for blink pin (pin 2)
int blinkPin = 2; 
int blinkDelay = blinkTime;
int blinkState = false;

// variables for twinkle pin (pin 3)
int twinklePin = 3; 
int timeOn = 0;
float currentBrightness = 0;
int targetBrightness = 0;
float timeToBright = 0;
float stepToBright = 0;


void setup()
{
  pinMode(twinklePin, OUTPUT);
  startOver();
  pinMode(blinkPin, OUTPUT);
}

void loop()
{
  // calculate brightness for twinkle pin (determined 
  // by how much time the LED is on vs. off) 
  timeOn = calcTimeOn(currentBrightness);
  digitalWrite(twinklePin, HIGH);
  delayMicroseconds(timeOn + 1);
  digitalWrite(twinklePin, LOW);
  delayMicroseconds(maxTimeOn - timeOn);

  // recalculate brightness for twinkle pin
  currentBrightness += stepToBright;
  timeToBright--;
  if(timeToBright == 0)
    startOver();
 
  // calculate brightness for heartbeat pin (by cycling 
  // through phases of pulse pattern)
  heartCounter++;
  if (heartCounter > 144) {
    heartStage = (heartStage + 1) % 4;
    heartCounter = 0;
  }
  else {
    switch(heartStage) {
      case 0:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/12.0;
        heartBrightness += 255/12.0;
        if (heartBrightness > 255)
          heartBrightness = 255;
        break;
      case 1:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/24.0;
        heartBrightness -= 255/24.0;
        if (heartBrightness < 0)
          heartBrightness = 0;
        break;
      case 2:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/12.0;
        heartBrightness += 255/12.0;
        if (heartBrightness > 255)
          heartBrightness = 255;
        break;
      case 3:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/72.0;
        heartBrightness -= 255/72.0;
        if (heartBrightness < 0)
          heartBrightness = 0;
        break;
    }
  }
    
 
  // drive blink pin high or low, depending on how much time has passed
  blinkDelay--;
  if (blinkDelay == 0) {
    blinkDelay = blinkTime;
    blinkState = !blinkState;
    digitalWrite(blinkPin, blinkState);
  }  
  
  // increase/decrease brightness of fade pin in steady incremental steps
  analogWrite(fadePin, fadeBrightness);
  fadeBrightness += fadeStep * fadeDirection;
  if (fadeBrightness >= 255) {
    fadeBrightness = 255;
    fadeDirection = -1;
  }
  if (fadeBrightness <= 0) {
    fadeBrightness = 0;
    fadeDirection = 1; 
  }
}

// calculate ratio of time LED is on/off to acheive particular brightness
int calcTimeOn(int desiredBrightness) {
  return desiredBrightness / maxBrightness * maxTimeOn;
}


// restart a new twinkle 
void startOver(){
  if (random(0, 1) == 1)
    targetBrightness = currentBrightness + random(100, 200);
  else
    targetBrightness = currentBrightness - random(100, 200);
  if (targetBrightness < 0)
    targetBrightness = maxBrightness + targetBrightness;
  targetBrightness %= (int)maxBrightness;
  timeToBright = random(10, 30); 
  stepToBright = (targetBrightness - currentBrightness) / timeToBright;
}
#205034
Hi olivia_c,

What error(s) do you get when you attempt to upload to the LilyTiny? Is it the same as the error when the issue first showed up? If so, can you either copy-paste it or take a screenshot of it and attach it to your reply? If it was different, do you by chance remember what the error was? That will help us identify what the problem is and how it might be fixed.

Also, when you are uploading, are you making sure to select ATTiny85 and the correct clock speed (8MHz) as well as selecting the USBtinyISP as your programmer? The troubleshooting steps in the TinyAVR Programmer Hookup Guide may also help you fix the issue.
#205081
Interesting. It looks like the AVR Programmer is not responding/"acking" properly to Arduino or you have a loose connection somewhere. If you are using Windows, does the Tiny AVR Programmer still show up properly in your Device Manager like this section of our Hookup Guide shows? If it is not showing up properly, try uninstalling the device and re-installing the drivers and see if that helps.

Also, how are you connecting to the ATTiny on the LilyTiny? If you are using the IC Test Clip that we recommend in the Re-Programming the LilyTiny/LilyTwinkle guide, double check the orientation of that IC Clip as well as all of the wires going to it to make sure all your connections are secure and correct.