Hi all!
Having a bit of trouble with this one so figured I'd ask some experts..
Basically I'm trying to recreate the Sonic Screwdriver electronics shown in this video Sonic Screwdriver Sounds by Arduino and ATTiny85 - YouTube
I've set up my Arduino Uno as shown in the video but when I try to upload the code this guy links to in the comments (seen below step 14 of this Instructables tutorial https://www.instructables.com/Working-Sonic-Screwdriver-Version-30/ )
I keep getting errors, one example is 'Compilation error: 'TIMSK' was not declared in this scope'
I'm very new to Arduino and have basically no idea how coding works, so if anyone could have a look at the code I'm trying to use that would be really helpful! If I need to give any additional info then please let me know.
Update
Apologies for not attaching the code earlier, my bad for not reading the posting guidelines!
//MODIFIED Version of Adafruit Trinket code to give attiny85 PCM capability
//The Attiny will take a very short sound sample that will sound good if looped
//I used the sound of a sonic screwdriver to example this capability
//Crete PCM using a program such as http://thieumsweb.free.fr/english/gbacss.html, copy the code right after PROGMEM = { and make sure that it ends with the };
//I use 8000 as my sample rate as allows the longest soundbyte to be uploaded to the chip
/*
if you change the sample rate, alter the sample_rate value
Otherwise the program will create a looped sound on pin 4 of the attiny85
*/
// Audio playback sketch for Adafruit Trinket. Requires 3.3V
// Trinket board and Winbond W25Q80BV serial flash loaded with
// audio data. PWM output on pin 4; add ~25 KHz low-pass filter
// prior to amplification. Uses ATtiny-specific registers;
// WILL NOT RUN ON OTHER ARDUINOS.
int sample_rate = 8000;
const unsigned char sample[] PROGMEM = { 1, 104, 149, 116, 129, 1195, 33, 201 };
int fish = 0;
int sizesample = sizeof(sample);
void setup() {
delayMicroseconds(100); // Stabilize
// Set up Timer/Counter1 for PWM output
TIMSK = 0; // Timer interrupts OFF
TCCR1 = _BV(CS10); // 1:1 prescale
GTCCR = _BV(PWM1B) | _BV(COM1B1); // PWM B, clear on match
OCR1C = 255; // Full 8-bit PWM cycle
OCR1B = 127; // 50% duty at start
pinMode(4, OUTPUT); // Enable PWM output pin
// Set up Timer/Counter0 for sample-playing interrupt.
// TIMER0_OVF_vect is already in use by the Arduino runtime,
// so TIMER0_COMPA_vect is used. This code alters the timer
// interval, making delay(), micros(), etc. useless (the
// overflow interrupt is therefore disabled).
// Timer resolution is limited to either 0.125 or 1.0 uS,
// so it's rare that the playback rate will precisely match
// the data, but the difference is usually imperceptible.
TCCR0A = _BV(WGM01) | _BV(WGM00); // Mode 7 (fast PWM)
if (sample_rate >= 31250) {
TCCR0B = _BV(WGM02) | _BV(CS00); // 1:1 prescale
OCR0A = ((F_CPU + (sample_rate / 2)) / sample_rate) - 1;
} else { // Good down to about 3900 Hz
TCCR0B = _BV(WGM02) | _BV(CS01); // 1:8 prescale
OCR0A = (((F_CPU / 8L) + (sample_rate / 2)) / sample_rate) - 1;
}
TIMSK = _BV(OCIE0A); // Enable compare match, disable overflow
}
void loop() {
delay(1000);
}
ISR(TIMER0_COMPA_vect) {
OCR1B = pgm_read_byte(&sample[fish]); // Read flash, write PWM reg.
fish++;
if (fish >= sizesample) { fish = 0; }
/*
if(++index >= samples) { // End of audio data?
index = 0; // We must repeat!
flash.endRead();
flash.beginRead(6); // Skip 6 byte header
}
*/
}
Here's the error messages mentioned `C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino: In function 'void setup()':
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:29:3: error: 'TIMSK' was not declared in this scope
TIMSK = 0; // Timer interrupts OFF
^~~~~
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:29:3: note: suggested alternative: 'TIMSK0'
TIMSK = 0; // Timer interrupts OFF
^~~~~
TIMSK0
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:30:3: error: 'TCCR1' was not declared in this scope
TCCR1 = _BV(CS10); // 1:1 prescale
^~~~~
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:30:3: note: suggested alternative: 'TCCR1A'
TCCR1 = _BV(CS10); // 1:1 prescale
^~~~~
TCCR1A
In file included from c:\users\topca\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:99:0,
from c:\users\topca\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,
from C:\Users\topca\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:28,
from C:\Users\topca\AppData\Local\Temp\arduino\sketches\C20ABD3199A960782FB5DAEDD290B355\sketch\sonicscrewdriverattiny85final.ino.cpp:1:
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:31:15: error: 'PWM1B' was not declared in this scope
GTCCR = _BV(PWM1B) | _BV(COM1B1); // PWM B, clear on match
^
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:32:3: error: 'OCR1C' was not declared in this scope
OCR1C = 255; // Full 8-bit PWM cycle
^~~~~
C:\Users\topca\OneDrive\Documents\FD3E9QEHR3EOA6E\sonicscrewdriverattiny85final\sonicscrewdriverattiny85final.ino:32:3: note: suggested alternative: 'OCR1A'
OCR1C = 255; // Full 8-bit PWM cycle
^~~~~
OCR1A
exit status 1
Compilation error: 'TIMSK' was not declared in this scope`
I'll get a list of components together and a picture of my wiring in a seperate comment
Pretty sure I've added the code correctly on here but let me know if I've done anything wrong!
Thanks!