Pages: [1] 2   Go Down
Author Topic: Laser-harp sketch error...need help, please.  (Read 1132 times)
0 Members and 1 Guest are viewing this topic.
FL, US
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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


* Laser_Harp_Online_Instructions-5.pdf (1333.07 KB - downloaded 35 times.)
* RS_DIY_LaserHarpJr.ino (1.22 KB - downloaded 12 times.)
* Tone.cpp (11.5 KB - downloaded 13 times.)
* Tone.h (3.23 KB - downloaded 13 times.)
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you know which version of the Arduono IDE you're using?
« Last Edit: January 29, 2013, 02:17:17 pm by lloyddean » Logged

FL, US
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

FL, US
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* Screen Shot 2013-01-29 at 3.35.21 PM.png (93.22 KB, 1124x319 - viewed 33 times.)

* Screen Shot 2013-01-29 at 3.29.21 PM.png (56.87 KB, 596x385 - viewed 26 times.)
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

FL, US
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* Screen Shot 2013-01-29 at 6.06.47 PM.png (147.82 KB, 1124x632 - viewed 28 times.)

* Screen Shot 2013-01-29 at 6.08.10 PM.png (553.72 KB, 1331x643 - viewed 33 times.)
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should have the following hierarchy -

Code:
    RS_DIY_LaserHarpJr/
    └── RS_DIY_LaserHarpJr.ino

instead of a folder named "LaserHarpJr.ino/"
Logged

FL, US
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.





* Screen Shot 2013-01-30 at 6.09.11 PM.png (623.98 KB, 1448x951 - viewed 28 times.)

* Screen Shot 2013-01-30 at 6.15.20 PM.png (507.85 KB, 1368x953 - viewed 20 times.)
« Last Edit: January 31, 2013, 10:53:32 am by fselso » Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 30, 2013, 08:58:50 pm by lloyddean » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

#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.
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need the latest version of the IDE.

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: