help with wave shield code

Hello everyone, the project Im working on is interfacing the wave shield with a vrbot connected to a basic stamp with a serial line bridging the arduino ATMega 328 with my bs2. Im very new to the arduino and fear I bitten off more than I can chew.

My current problem is that I cant get the arduino code up and running.
The error message is "bs2data is not declared in this scope" could anyone tell me how to define this? again i apologize for my newb...ness Thank u in advance ;D

#include <avr/pgmspace.h>
#include "util.h"
#include "MediaPlayer.h"
#include <NewSoftSerial.h>

NewSoftSerial BS2 = NewSoftSerial(0, 255); // receive only

void setup() {

NewSoftSerial BS2(0, 255); // receive only
Serial.begin(9600);
BS2.begin(9600);
}

MediaPlayer mediaPlayer; // create only one object, must be global

void loop()
{

if(BS2.available() > 0) {
bs2data = BS2.read();
Serial.print("Received from BS2: ");
Serial.println(bs2data);

blinkLed();

putstring("\nThese files are on the SD card:\n");
mediaPlayer.exploreSDcard(true);

putstring("\nSD card file count = ");
Serial.print(mediaPlayer.exploreSDcard());

if(!mediaPlayer.play("Notexist")) putstring("\nFile not exist"); // result is false

putstring("\nSD card filename of file no. 3 = ");
Serial.print(mediaPlayer.fileName(3)); // now easier

putstring("\nPlay ILSE1.WAV without using stop()");
mediaPlayer.play("ILSE1.WAV");
while (mediaPlayer.isPlaying()) {
putstring(".");
delay(50);
}

if (bs2data == 'A')
{
putstring("\nPlay TWOBIT.WAV");
mediaPlayer.play("TWOBIT.WAV");
delay(2000);
Serial.println("ROBOT MOVE FOREWARD");

}

putstring("\nPlay KREZIP1.WAV");
mediaPlayer.play("KREZIP1.WAV");
delay(2000);
putstring("\nPause");
mediaPlayer.pause();
if(mediaPlayer.onPause()) putstring("\nMediaPlayer on pause");
delay(500);
putstring("\nResume");
mediaPlayer.resume();
delay(2000);
putstring("\nStop");
mediaPlayer.stop();

playComplete("ANOUK1.WAV");

putstring("\nPlay all songs");
for(int i=1; i<=mediaPlayer.exploreSDcard(); i++) playComplete(i);
printAvailableRAM();
}

no need to post the same issue twice...I already told you that you probably need to define BS2 like this:

NewSoftSerial BS2 = NewSoftSerial(0, 255);   // receive only

oops...I'm very sorry, my bad. I just saw that you did my suggested changes. I would have been easier if you would have replied in the previous topic.

sorry that i cannot help you. :frowning:

That wasnt the case, I was just a little embarrassed by how simple and stupid my questions were. Id still very much appreciate your help and im sorry if u took it the wrong way. My current problem is that I cant get the arduino code up and running.
The error message is "bs2data is not declared in this scope" could anyone tell me how to define this? again i apologize for my newb...ness Thank u in advance

#include <avr/pgmspace.h>
#include "util.h"
#include "MediaPlayer.h"
#include <NewSoftSerial.h>

NewSoftSerial BS2 = NewSoftSerial(0, 255); // receive only

void setup() {

NewSoftSerial BS2(0, 255); // receive only
Serial.begin(9600);
BS2.begin(9600);
}

MediaPlayer mediaPlayer; // create only one object, must be global

void loop()
{

if(BS2.available() > 0) {
bs2data = BS2.read();
Serial.print("Received from BS2: ");
Serial.println(bs2data);

blinkLed();

putstring("\nThese files are on the SD card:\n");
mediaPlayer.exploreSDcard(true);

putstring("\nSD card file count = ");
Serial.print(mediaPlayer.exploreSDcard());

if(!mediaPlayer.play("Notexist")) putstring("\nFile not exist"); // result is false

putstring("\nSD card filename of file no. 3 = ");
Serial.print(mediaPlayer.fileName(3)); // now easier

putstring("\nPlay ILSE1.WAV without using stop()");
mediaPlayer.play("ILSE1.WAV");
while (mediaPlayer.isPlaying()) {
putstring(".");
delay(50);
}

if (bs2data == 'A')
{
putstring("\nPlay TWOBIT.WAV");
mediaPlayer.play("TWOBIT.WAV");
delay(2000);
Serial.println("ROBOT MOVE FOREWARD");

}

putstring("\nPlay KREZIP1.WAV");
mediaPlayer.play("KREZIP1.WAV");
delay(2000);
putstring("\nPause");
mediaPlayer.pause();
if(mediaPlayer.onPause()) putstring("\nMediaPlayer on pause");
delay(500);
putstring("\nResume");
mediaPlayer.resume();
delay(2000);
putstring("\nStop");
mediaPlayer.stop();

playComplete("ANOUK1.WAV");

putstring("\nPlay all songs");
for(int i=1; i<=mediaPlayer.exploreSDcard(); i++) playComplete(i);
printAvailableRAM();
}
Back to top

you need to declare the type of your variables:

int bs2data = BS2.read();

you need to declare the type of your variables

Yeah, Tripod, but if he does it inside that if() block, he'll still be out of scope when he tries to use it later, won't he?

Actually, now that I am looking at things - the OP needs to use the code button on the comment editor, plus the OP needs to use proper code indentation. Finally (and I don't care what anybody says): don't use the "two-line" if shortcut (and if you have an opening brace, you better have a closing one at the same column position later).

I remember coding like this one time long ago; please don't repeat these mistakes...

:slight_smile:

Ahh ok thank you ;D I think I can grasp defining variables and such Im almost through compling the code all the way but yet another error message has been sent. It went to the MediaPlayerTestFunctions library and highlighted this section of the code below saying A function definition is not allowed here before '{' token. This is an upcoming school project and I have no1 to help me with it so again thank u for all your help.

void setup() // Run once, when the sketch starts

{ pinMode(onboardLed, OUTPUT); // Sets the digital pin as output
pinMode(frontLed, OUTPUT); // Sets the digital pin as output
Serial.begin(9600);
}

void blinkLed()
{ for(byte i=0; i<3; i++)
{ digitalWrite(onboardLed, HIGH); digitalWrite(frontLed, HIGH);
delay(200);
digitalWrite(onboardLed, LOW); digitalWrite(frontLed, LOW);
delay(200);
}
}

void playComplete(char* fileName)
{ putstring("\nPlay complete: ");
Serial.print(fileName);
mediaPlayer.play(fileName);
while (mediaPlayer.isPlaying())
{ putstring(".");
delay(100);
}
}

void playComplete(const int fileNumber)
{ playComplete(mediaPlayer.fileName(fileNumber));
}

void printAvailableRAM() // 590 bytes
{ int size = 1024;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL);
free(buf);
putstring("\nAvailable RAM: ");
Serial.print(size);
}

Ok is there a simple way of just changing the SerialControl example code so that it reads from the basic stamp 2's serial connection with the arduino rather than from the computer?

#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#define TWOBIT "TWOBIT.WAV"
#define ONEKHZ "1KHZ.WAV"
#define GLASS "GLASWORK.WAV"
#define PENTHOUSE "PENTHOUS.WAV"
AF_Wave card;
File f;
Wavefile wave; // only one!
#define redled 9
int wasplaying = 0;
void setup() {
** Serial.begin(9600); // set up Serial library at 9600 bps**
** Serial.println("Wave test!");**
** pinMode(2, OUTPUT);**
** pinMode(3, OUTPUT);**
** pinMode(4, OUTPUT);**
** pinMode(5, OUTPUT);**
** pinMode(redled, OUTPUT);**

** if (!card.init_card()) {**
** putstring_nl("Card init. failed!"); return;**
** }**
** if (!card.open_partition()) {**
** putstring_nl("No partition!"); return;**
** }**
** if (!card.open_filesys()) {**
** putstring_nl("Couldn't open filesys"); return;**
** }**
** if (!card.open_rootdir()) {**
** putstring_nl("Couldn't open dir"); return;**
** }**
** ls();**
// playfile(ONEKHZ);
}
void loop() {
__ char c, *toplay;__

** if (Serial.available()) {**
** c = Serial.read();**
Serial.println(c, BYTE);
** if (c == 't') {**
** toplay = TWOBIT;**
** }**
** else if (c == 'g') {**
** toplay = GLASS;**
** }**
** else if (c == 'p') {**
** toplay = PENTHOUSE;**
** }**
** else if (c == '1') {**
** toplay = ONEKHZ;**
** } else {**
** return;**
** }**

** if (wave.isplaying) {// already playing something, so stop it!**
** wave.stop(); // stop it**
** card.close_file(f);**
** }**
** playfile(toplay);**
** }**
** if (wave.isplaying && !wasplaying) {**
** digitalWrite(redled, HIGH);**
** } else if (!wave.isplaying && wasplaying) {**
** digitalWrite(redled, LOW);**
** }**
** wasplaying = wave.isplaying;**
}
void ls() {
** char name[13];**
** card.reset_dir();**
** putstring_nl("Files found:");**
** while (1) {**
** if (!card.get_next_name_in_dir(name)) {**
** card.reset_dir();**
** return;**
** }**
** Serial.println(name);**
** }**
}
void playfile(char *name) {
** f = card.open_file(name);**
** if (!f) {**
** putstring_nl("Couldn't open file"); return;**
** }**
** if (!wave.create(f)) {**
** putstring_nl("Not a valid WAV"); return;**
** }**
** // ok time to play!**
** wave.play();**
}