I'm just trying out a Trinket 5v from Adafruit, and trying the "Trinket React Counter" project on their site found here:
I was previously able to get the blinking light test code to work, but when I try to compile the code for this project (included below) I get an error, saying:
"Error compiling for board Adafruit Trinket (AtTiny 85 @ 16MHz)."
Here is the code:
// Adafruit Trinket React Counter Sketch - 7-segment display
//
// Use a 7-segment LED backpack to display the number of times a
// button has been pressed. Great for building a physical 'like'
// or react button. The value will be stored in EEPROM so it
// will persist between power down/up.
//
// NOTE: As-is this sketch needs to run on a Trinket because it
// assumes the switch on pin #1 has a pull-down resistor to ground.
// If using another board without this pull-down you can explicitly
// add a ~10kohm resistor from digital #1 to ground.
//
// Author: Tony DiCola
// License: MIT (https://opensource.org/licenses/MIT)
#include <EEPROM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
// Uncomment the line below to reset the counter value in EEPROM to zero.
// After uncommenting reload the sketch and during the setup the counter
// will be reset. Then comment the line again and reload to start again
// (if you don't comment it out then every time the board powers on it
// will reset back to zero!).
#define RESET_COUNT
// OR just hold the button for longer than the RESET_HOLD_SECOND below
// to reset the count!
// Configuration:
#define LED_BACKPACK_ADDRESS 0x70 // I2C address of the backpack display.
// Keep the default 0x70 unless you
// change the backpack's address bridges.
#define COUNT_BUTTON_PIN 1 // Digital input connected to the button that
// will increase the count. This line should
// have a pull-down resistor to ground. The
// opposite side of the button should be
// connected to a high level like 5V or 3.3V.
#define COUNT_ADDRESS 0 // Address in EEPROM to store the counter.
// This will take 2 bytes (16-bit value).
// You don't need to change this unless you
// want to play with different EEPROM locations.
#define RESET_HOLD_SECONDS 5 // Number of seconds to hold the button down to
// force a reset of the count to zero. Set to 0
// to disable this functionality.
// 7-segment display
Adafruit_7segment backpack = Adafruit_7segment();
uint32_t holdStart = 0;
void update_display() {
// Get the count value from EEPROM and print it to the display.
uint16_t count;
EEPROM.get(COUNT_ADDRESS, count);
backpack.print(count, DEC);
backpack.writeDisplay();
}
void setup() {
// Setup button inputs.
pinMode(COUNT_BUTTON_PIN, INPUT);
// Initialize the LED backpack display.
backpack.begin(LED_BACKPACK_ADDRESS);
// Clear the count in EEPROM if desired.
#ifdef RESET_COUNT
uint16_t count = 0;
EEPROM.put(COUNT_ADDRESS, count);
#endif
// Update the display with the current count value.
update_display();
// Reset the last known time the button wasn't being held.
holdStart = millis();
}
void loop() {
// Take a couple button readings with a small delay in between to detect when
// the signal changes from high to low, i.e. the button was released.
int firstCount = digitalRead(COUNT_BUTTON_PIN);
delay(20);
int secondCount = digitalRead(COUNT_BUTTON_PIN);
// Check for count button release.
if (firstCount == HIGH && secondCount == LOW) {
// Button was released!
// Increment the count value stored in EEPROM.
uint16_t count;
EEPROM.get(COUNT_ADDRESS, count);
count += 1;
EEPROM.put(COUNT_ADDRESS, count);
// Update the display with the latest count value.
update_display();
}
// Reset the hold start if the button wasn't pressed (i.e. first and last were not both high levels).
if ((firstCount != HIGH) || (secondCount != HIGH)) {
holdStart = millis();
}
// Check if the button has been held for the amount of reset time.
if ((RESET_HOLD_SECONDS > 0) && ((millis() - holdStart) >= (RESET_HOLD_SECONDS*1000))) {
// Reset to zero and update the display!
uint16_t count = 0;
EEPROM.put(COUNT_ADDRESS, count);
update_display();
// Reset the hold time to start over again.
holdStart = millis();
// Flash the display a few times to give time to remove finger.
for (int i=0; i<5; ++i) {
delay(200);
backpack.clear();
backpack.writeDisplay();
delay(200);
update_display();
}
}
}
The verbose whatnot finishes like this, suggesting an issue with the SPI library:
Using library EEPROM at version 2.0 in folder: C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\EEPROM
Using library Wire at version 1.0 in folder: C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\Wire
Using library Adafruit_LED_Backpack at version 1.1.6 in folder: C:\Users\Adam\Documents\Arduino\libraries\Adafruit_LED_Backpack
Using library Adafruit-GFX-Library at version 1.2.2 in folder: C:\Users\Adam\Documents\Arduino\libraries\Adafruit-GFX-Library
Using library SPI at version 1.0 in folder: C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI
exit status 1
Error compiling for board Adafruit Trinket (ATtiny85 @ 16MHz).
But Googling and searching this forum hasn't found any solutions.
Error message is incomplete; usually you don't need to set it to "verbose" as the important bits will be shown. The problem is in the part you didn't post.
Well the entire error without verbose checked exceeded the maximum length of a post, so here's half...
Arduino: 1.8.5 (Windows 10), Board: "Adafruit Trinket (ATtiny85 @ 16MHz)"
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In member function 'void SPISettings::init_AlwaysInline(uint32_t, uint8_t, uint8_t)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:146:16: error: 'SPE' was not declared in this scope
spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:146:27: error: 'MSTR' was not declared in this scope
spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:146:65: error: 'DORD' was not declared in this scope
spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::beginTransaction(SPISettings)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:203:5: error: 'SPCR' was not declared in this scope
SPCR = settings.spcr;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:204:5: error: 'SPSR' was not declared in this scope
SPSR = settings.spsr;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In static member function 'static uint8_t SPIClass::transfer(uint8_t)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:209:5: error: 'SPDR' was not declared in this scope
SPDR = data;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:217:14: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ; // wait
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:217:25: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ; // wait
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In static member function 'static uint16_t SPIClass::transfer16(uint16_t)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:223:11: error: 'SPCR' was not declared in this scope
if (!(SPCR & _BV(DORD))) {
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:223:22: error: 'DORD' was not declared in this scope
if (!(SPCR & _BV(DORD))) {
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:224:7: error: 'SPDR' was not declared in this scope
SPDR = in.msb;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:226:16: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:226:27: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:230:16: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:230:27: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:233:7: error: 'SPDR' was not declared in this scope
SPDR = in.lsb;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:235:16: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:235:27: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:239:16: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:239:27: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::transfer(void*, size_t)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:247:5: error: 'SPDR' was not declared in this scope
SPDR = *p;
^
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:250:16: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:250:27: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:255:14: error: 'SPSR' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:255:25: error: 'SPIF' was not declared in this scope
while (!(SPSR & _BV(SPIF))) ;
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::setBitOrder(uint8_t)':
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:292:31: error: 'SPCR' was not declared in this scope
if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
^
In file included from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,
from c:\users\adam\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\pgmspace.h:90,
from C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:28,
from sketch\sketch_may05a.ino.cpp:1:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:292:43: error: 'DORD' was not declared in this scope
if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
^
In file included from C:\Users\Adam\Documents\Arduino\sketch_may05a\sketch_may05a.ino:37:0:
C:\Users\Adam\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SPI\src/SPI.h:293:10: error: 'SPCR' was not declared in this scope
else SPCR &= ~(_BV(DORD));
^
Those errors point to you not having selected the correct board in the IDE. This looks like processor registers, which vary a bit between processors.
Thank you so much for your help, I will try that.