I am trying to get my ATTiny85 to send serial messages through my Arduino Mega to my pc, but it isn't working. I don't get anything but if I send a command I get 'ÿ' returned. I am trying to follow this tutorial. I am guessing it's something to do with the fuses which are set (to save energy when not bleeping), but I don't know how to unset them - I have tried re-burning the bootloader and commenting out the fuse set lines and the problem was not resolved.
Here is my code:
#include <SoftwareSerial.h>
#include <avr/sleep.h>
#include <avr/power.h>
int PIEZO = 0;
int LED = 1;
#define WDTCR_REG WDTCR
volatile long watchdog_counter = 0;
void setup(void)
{
Serial.begin( 9600 );
Serial.println("starting...");
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
ADCSRA &= ~(1<<ADEN); //Disable ADC
ACSR = (1<<ACD); //Disable the analog comparator
DIDR0 = 0x3F; //Disable digital input buffers on all ADC0-ADC5 pins
setup_watchdog(7);
pinMode(PIEZO, OUTPUT);
pinMode(LED, OUTPUT);
annoy();
}
void loop()
{
sleep_enable();
sleep_mode();
if (watchdog_counter >= 10) {
watchdog_counter = random(3);
annoy();
}
}
void annoy() {
Serial.println("annoying");
digitalWrite(LED, HIGH);
tone(PIEZO, random(5000, 12000));
delay(500);
noTone(PIEZO);
digitalWrite(LED, LOW);
}
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR_REG |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR_REG = bb;
WDTCR_REG |= _BV(WDIE);
}
ISR(WDT_vect) {
watchdog_counter++;
}
Can anyone help?