Electronics for Sonic Screwdriver prop HELP

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!

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘posting menu’ to attach the copied sketch.


Always show us a good schematic of your proposed circuit. Show us a good image of your ‘actual’ wiring.

Give links to components.

Please post the code here. I will not dig through a bunch of pages to get the code and help you. Help us to help you.

Please read the forum guidelines to see how to properly post code and some information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You may have to change the tiny85 code to work on an Uno.

Please include the entire error message. If you use the Arduino IDE, it is easy to do. there is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information. If not using the IDE, copy and paste the entire error message.

ATTiny85 != Uno

An ATtiny85 is different to the ATmega328p used in the UNO and the software isn't written to be portable.

The code uses a hardware feature of the ATtiny85 that isn't available in the ATmega328p of the UNO (a fast asynchronous timer clock operating at 64MHz).

Edited the post to include the code and the error messages, currently working the links to my components. Unfortunately I don't have a schematic for the circuit as none of the instructions I've been following include any. I did my best to recreate the setup seen in the YouTube video I linked to, here's a picture of what I did. Apologies if the image isn't the best, I just took it to remind myself of the wiring so may have missed some details

It's bad style to edit a post. Any future reader following the thread will not be able to understand what we wrote.

That setup includes the ATtiny85 so you can use the original code directly. But in this setup the UNO is used as a programmer only (the guy in the video doesn't mention that explicitly). So you first must upload the ArduinoISP code (from examples) to the UNO. Then change the board to ATtiny85 (I hope you installed the corresponding core), select Arduino as ISP for Programmer and then use "Upload Using Programmer" instead of "Upload" to get the sketch compiled and uploaded.

I tried this on the same wiring setup and still get nothing out of the speaker. Here's the error message, apologies that I have no idea what I'm doing, I've probably missed something really simple!

Sketch uses 644 bytes (31%) of program storage space. Maximum is 2048 bytes.
Global variables use 11 bytes (8%) of dynamic memory, leaving 117 bytes for local variables. Maximum is 128 bytes.
A programmer is required to upload

I'm thinking there could also be an issue with my wiring as I copied the setup from a pretty blurry video, is there an easier way to do what I'm trying to do that I haven't found yet?

You're providing just tiny bits of information.

Provide an in-depth description of what you did, what output you got and what you expected.

For example did you complete the process I described in my previous post?

Update - It works now!

Did alot of tinkering using the advice from you guys as a starting point for further research - thanks alot!

I've managed to program a chip and get sound playing from a speaker when activated by a switch - exactly as in the video I was trying to replicate. Now I just need to do some work with sampling the actual audio files as the pitch is a little off, but overall it's all gone very well!

Thanks for all the help, I know I was probably a bit annoying with providing enough info but im very grateful!

Here's the final setup, and here's a video if it in action!

The pitch is just a little lower than the video I sampled the audio from so I think I need to do a bit of tweaking in Audacity before converting it into code to get it exactly right, but I'm damned happy with it at the moment! Now I just need to figure out how to solder it all together into a compact unit that I can fit inside a Sonic Screwdriver prop.. but that's a problem for another day!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.