Go Down

Topic: Laser-harp sketch error...need help, please. (Read 1 time) previous topic - next topic

fselso

Hi, I am attempting to build a laser harp but I am getting an error message when I try to upload the code.

I first saw this diy project in the Nov 2012 Popular Science magazine. It's a RadioShack sponsored Hackerspace challenge; here is the link:https://www.radioshackdiy.com/project-gallery/hackerspace-winner-announcement

It uses the Arduino Uno and a sketch for the sounds. I followed the instructions... http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/Laser_Harp_Online_Instructions.pdf ...downloaded and unzipped the .ino file http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/RS_DIY_LaserHarpJr.ino.zip

I assembled the hardware exactly as described in the instructions and am using an iMac with OS X Lion 10.7.5
I have no experience with code. I thought this was a straight forward project and did not require any programming knowledge. If anyone can help, I would very much appreciate it.

Here is the code...

Code: [Select]

#include <Tone.h>

const boolean DEBUG = false;

const int CALIBRATION_PIN = A5;
const int SPEAKER_PIN = 8;
const int SENSOR_COUNT = 3;

typedef struct
{
  int pin;
  int note;
} sensor_type;

sensor_type sensor[SENSOR_COUNT];

Tone notePlayer;

void setup(void)
{
  if (DEBUG) {
    Serial.begin(9600);
  }
  sensor[0].pin = A0; // analog input 0, etc...
  sensor[0].note = NOTE_G3;
  sensor[1].pin = A1;
  sensor[1].note = NOTE_D4;
  sensor[2].pin = A2;
  sensor[2].note = NOTE_A4;
 
  notePlayer.begin(SPEAKER_PIN);
}

void loop(void)
{
  int calibration = analogRead(CALIBRATION_PIN);
  if (DEBUG) {
    Serial.print("cal: ");
    Serial.print(calibration);
  }
  int activeSensor = -1;
  for (int p = 0 ; p < SENSOR_COUNT ; p++) {
    int sensor_value = analogRead(sensor[p].pin);
    if (DEBUG) {
      Serial.print("\tsensor ");
      Serial.print(p);
      Serial.print(": ");
      Serial.print(sensor_value);
    }
    if ( sensor_value < calibration ) {
      activeSensor = p;
      if (DEBUG) Serial.print("!"); // "!" indicates note being played
    }
  }
  if (DEBUG) Serial.println();
  if (activeSensor == -1) {
    notePlayer.stop();
  } else {
    notePlayer.play(sensor[activeSensor].note);
  }
  if (DEBUG) delay(1000);
}



And this is the error message(s) I get:

RS_DIY_LaserHarpJr:17: error: 'Tone' does not name a type
RS_DIY_LaserHarpJr.ino: In function 'void setup()':
RS_DIY_LaserHarpJr:25: error: 'NOTE_G3' was not declared in this scope
RS_DIY_LaserHarpJr:27: error: 'NOTE_D4' was not declared in this scope
RS_DIY_LaserHarpJr:29: error: 'NOTE_A4' was not declared in this scope
RS_DIY_LaserHarpJr:31: error: 'notePlayer' was not declared in this scope
RS_DIY_LaserHarpJr.ino: In function 'void loop()':
RS_DIY_LaserHarpJr:57: error: 'notePlayer' was not declared in this scope
RS_DIY_LaserHarpJr:59: error: 'notePlayer' was not declared in this scope


lloyddean

#1
Jan 29, 2013, 07:58 pm Last Edit: Jan 29, 2013, 08:17 pm by lloyddean Reason: 1
Do you know which version of the Arduono IDE you're using?

fselso

Sorry, I forgot to include that. Yes, it's R3. I guess that's version 3?

lloyddean

First guess is that you haven't place the folder the files 'Tone.h' and 'Tone.cpp' came in into the correct place required for Libraries.

If you'll bring up the preferences you'll see a field named "Sketchbook Location".  Going to that location and you'll find a folder labeled 'libraries'.  Place the folder with the files 'Tone.h' and 'Tone.cpp' into that "libraries" folder.

Try building again.

fselso

I've tried several times. I've attached a couple of screen shots.

lloyddean

Again, place the folder "Tone" in the folder "libraries", not next to it but in it.

fselso

Ok, I downloaded it again and put it in the libraries folder. When I do, it is displayed in the column to the right, but it is in the libraries folder.

Next I followed the instructions and it says, "Open the "LaserHarpJr.ino" file with your Arduino software and click the right-arrow button (next to the
check button). Some LEDs should blink on the Arduino board, and after a few moments, you should
see "Done Uploading" in the console area of the Arduino software. Your sketch should now be running!"

But when I do that, I get an "Error Compiling" message instead of "Done Uploading":

core.a(main.cpp.o): In function `main':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:11: undefined reference to `setup'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:14: undefined reference to `loop'


Screen shots attached...

Thanks again for your help.

lloyddean

You should have the following hierarchy -

Code: [Select]

    RS_DIY_LaserHarpJr/
    ??? RS_DIY_LaserHarpJr.ino


instead of a folder named "LaserHarpJr.ino/"

fselso

#8
Jan 31, 2013, 12:19 am Last Edit: Jan 31, 2013, 04:53 pm by fselso Reason: 1
Screen Shot 2013-01-30 at 6.09.11 PMAs recommended, I put the RS_DIY_LaserHarpJr.ino into the RS_DIY_LaserHarpJr folder. I tried to name it RS_DIY_LaserHarpJr/ but the system didn't like the /.
I still got the "Error compiling" message.
I attached 2 screen-shots to be able to include all of the code and the error message.




lloyddean

#9
Jan 31, 2013, 01:13 am Last Edit: Jan 31, 2013, 02:58 am by lloyddean Reason: 1
Create a folder named "RS_DIY_LaserHarpJr" into which you place the file "RS_DIY_LaserHarpJr.ino"

Double-click the file "RS_DIY_LaserHarpJr.ino" tp launch the Adruino IDE, build and run.

The '/' means directory otherwise known as a folder.

jdblair

Hello- Sorry to open up this old thread, but I am having a similar problem to the one described above.

First off, thank you for your assistance. 

I am attempting to build a laser harp in accordance to this site's instructions: http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/Laser_Harp_Online_Instructions.pdf

I have all the equipment, but when I attempt to upload or verify the sketch, I get multiple errors.

Here is the sketch:

Code: [Select]


#include <Tone.h>

const boolean DEBUG = false;

const int CALIBRATION_PIN = A5;
const int SPEAKER_PIN = 8;
const int SENSOR_COUNT = 3;

typedef struct
{
  int pin;
  int note;
} sensor_type;

sensor_type sensor[SENSOR_COUNT];

Tone notePlayer;

void setup(void)
{
  if (DEBUG) {
    Serial.begin(9600);
  }
  sensor[0].pin = A0; // analog input 0, etc...
  sensor[0].note = NOTE_G3;
  sensor[1].pin = A1;
  sensor[1].note = NOTE_D4;
  sensor[2].pin = A2;
  sensor[2].note = NOTE_A4;
 
  notePlayer.begin(SPEAKER_PIN);
}

void loop(void)
{
  int calibration = analogRead(CALIBRATION_PIN);
  if (DEBUG) {
    Serial.print("cal: ");
    Serial.print(calibration);
  }
  int activeSensor = -1;
  for (int p = 0 ; p < SENSOR_COUNT ; p++) {
    int sensor_value = analogRead(sensor[p].pin);
    if (DEBUG) {
      Serial.print("\tsensor ");
      Serial.print(p);
      Serial.print(": ");
      Serial.print(sensor_value);
    }
    if ( sensor_value < calibration ) {
      activeSensor = p;
      if (DEBUG) Serial.print("!"); // "!" indicates note being played
    }
  }
  if (DEBUG) Serial.println();
  if (activeSensor == -1) {
    notePlayer.stop();
  } else {
    notePlayer.play(sensor[activeSensor].note);
  }
  if (DEBUG) delay(1000);
}



The errors I receive are as follows:

C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope

How should I go about fixing these errors?

Any help would be greatly appreciated! Thank you very much.

holmes4

You need the latest version of the IDE.

Mark

jdblair

I downloaded the 1.5.4 version, and am still receiving these errors:

Arduino: 1.5.4 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"

C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope

And here is the verbose version of the errors:

Arduino: 1.5.4 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega -IC:\Users\jdblair\Documents\Arduino\libraries\Tone C:\Users\jdblair\AppData\Local\Temp\build6849503120442158854.tmp\RS_DIY_LaserHarpJr.cpp -o C:\Users\jdblair\AppData\Local\Temp\build6849503120442158854.tmp\RS_DIY_LaserHarpJr.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega -IC:\Users\jdblair\Documents\Arduino\libraries\Tone -IC:\Users\jdblair\Documents\Arduino\libraries\Tone\utility C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp -o C:\Users\jdblair\AppData\Local\Temp\build6849503120442158854.tmp\Tone\Tone.cpp.o

C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope


Thank you very much

holmes4

In user lib, (the tone that you downloaded and put in your libs in your sketch's folder) edit Tone.cpp

Code:
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <wiring.h>
#include <Arduino.h>
#include <pins_arduino.h>
#include "Tone.h"

In other words add the #include <Arduino.h> to the list of defines and it will build (or it did for me).

Mark

jdblair

Would you mind copying your entire working code? I apologize- I've very new to coding and Arduino software.

Also, do you have any other tabs in the sketch?

Thank you,

Justin

Go Up