Attiny84 e Attiny85

Estou a fazer umas coisas e queria usar um destes Attiny´s, o Attiny85 estive a testar o sleep mode, usando este código:

#include <avr/sleep.h>
#include <avr/interrupt.h>

const int switchPin                     = 3;
const int statusLED                     = 2;

void setup() {

    pinMode(switchPin, INPUT);
    digitalWrite(switchPin, HIGH);
    pinMode(statusLED, OUTPUT);

    // Flash quick sequence so we know setup has started
    for (int k = 0; k < 10; k = k + 1) {
        if (k % 2 == 0) {
            digitalWrite(statusLED, HIGH);
            }
        else {
            digitalWrite(statusLED, LOW);
            }
        delay(250);
        } // for
    } // setup

void sleep() {

    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT3);                   // Use PB3 as interrupt pin
    ADCSRA &= ~_BV(ADEN);                   // ADC off
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                                  // Enable interrupts
    sleep_cpu();                            // sleep

    cli();                                  // Disable interrupts
    PCMSK &= ~_BV(PCINT3);                  // Turn off PB3 as interrupt pin
    sleep_disable();                        // Clear SE bit
    ADCSRA |= _BV(ADEN);                    // ADC on

    sei();                                  // Enable interrupts
    } // sleep

ISR(PCINT0_vect) {
    // This is called when the interrupt occurs, but I don't need to do anything in it
    }

void loop() {
    sleep();
    digitalWrite(statusLED, HIGH);
    delay(1000);
    digitalWrite(statusLED, LOW);
    }

Está tudo Ok, no entanto, para o projecto que queria fazer preciso de mais uns 2 pinos, e se calhar estou a pensar num Attiny84 que tenho tb aqui.

  • Posso usar o mesmo código no Attiny84, do modo sleep que usei acima?

Sim, mas poderás ter de trocar os pinos.

Tenho as ligações iguais a estas.

Estava a testar o simples Blink test (que no Attiny85 funciona bem) no Attiny84 não estou a conseguir.

  • Fiz Upload do sketch "ArduinoISP" para o Arduino Uno
  • No menu 'Board' defini "Attiny84 @ 20MHz"
  • No menu 'Programmer' defini 'Arduino as ISP'

No código do BlinkTest meti o LED no pino "2", e liguei o LED ao 5º do chip Attiny84 (D2) mas não funciona.. alguma ideia?

Como não consigo editar o post acima, e para se perceber melhor o que fiz:

Código usado:

int led = 2;

void setup() {                
  pinMode(led, OUTPUT);     
}

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

O LED liguei-o no PB2 (pino 5) do Attiny84 (com uma resistência de 1k no GND).

Meteste um cristal de 20MHz no attiny84? Ele só tem um cristal interno de 8MHz e um divisor de 8...

Como tal, é impossível de o correr sem cristal.

Ups..não coloquei nenhum. Como não tenho agora aqui um de 20MHz vai ter esperar por amanhã para testar então.

Como o Attiny85 funcionou bem sem crystal nem me lembrei..

Obrigado pela dica