Go Down

Topic: newby on wave shield v2.0 by elechouse.. play sound by a piezo trigger.help.. (Read 5003 times) previous topic - next topic

arbee

i am a newbie on programming. please help.

i just bought a wave shield v2.0 on ebay. but the seller send me the new version which is the wave shield v3.0. it was smaller than the earlier version. but the seller told me that the v3.0 is also like the v2.0...

then i put my wave shield v3.0 on my arduino uno to try and play it. and then i uploaded the example code given by the seller.. he said that the codes of v2 can also be used in v3.. it played the audios i put in the sd card..

the problem is, i can't understand most of the codes. i want to make a project using piezo as sensors to play a certain audio file on the shield. say piezo sensor 1 will play the first audio and then stop. piezo sensor 2 will play the second audio and then stop. etc..

i have codes for detecting piezo sensors, but i just can't connect the codes of it to the codes of  the wave shield to make it the trigger for playing the sound.. and also i was trying that if the piezo sensor sense a little bit of force, the volume sound will also be low, and when the piezo sense hard force, the volume of the sound will be high while playing that sound..

please help. what should i do?

Caltoa

This is the shield version 2: http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=168_170&products_id=2161
Is version 3 the same ? Can you give a link to version 3 ? just copy the url in the text.
Could you upload your sketch. Use the '#'-button for the code tags.

You are doing two things at once.
Start with the piezo buttons first. Disconnect the wave shield and send messages to the serial monitor. Do you use 1M resistors parallel to the piezo elements ?
http://arduino.cc/en/Tutorial/Knock

Once the piezo buttons are doing what you want, test the Wave shield and try to understand the code and how the volume is controlled. After that combine both.

arbee

thank you for the reply.  :)

yes, that is the version 2. the version 3 is like version 2 cut in half.. the seller told me that the manual for version 3 is on process, so that's why i don't know the details of it.. and i dont have the manual for version 3,, the seller just said that its like the version two. the picture of v3 is attached.

i just followed the sketch in version two. here it is

Code: [Select]
/*
This code is show how Arduino Wave Module works with Arduino.
Code is not optimized. Any improving work on it is encouraged.
*/
int RST = 3;
int CLK = 9;
int DAT = 8;
   
   
void setup() {   
   
   
    pinMode(RST, OUTPUT);
    pinMode(CLK, OUTPUT);
    pinMode(DAT, OUTPUT);
   
   
    digitalWrite(RST, HIGH);
    digitalWrite(CLK, HIGH);
    digitalWrite(DAT, HIGH);
   
    digitalWrite(RST, LOW);
    delay(5);
    digitalWrite(RST, HIGH);
    delay(300);
}

void loop() {

  send(0x0000);//play file 0000
  delay(10000);//delay 10 seconds
 
  send(0x0001);//play file 0001
  delay(10000);//delay 10 seconds
 
  send(0x0002);//play file 0002
  delay(10000);//delay 10 seconds
 
  send(0xfff0);//set voice volumn to 0 (turn off)
  delay(3000);
 
  send(0xfff4);//set voice volumn to 4
  delay(3000);
 
  send(0xfff7);//set voice volumn to 7
  delay(3000);
 
  send(0xfffe);// pause
  delay(5000);
  send(0xfffe);//play
 
 
 
  while(1);
}
void send(int data)
{
  digitalWrite(CLK, LOW);
  delay(2);
  for (int i=15; i>=0; i--)
  {
    delayMicroseconds(50);
    if((data>>i)&0x0001 >0)
      {
        digitalWrite(DAT, HIGH);
        //Serial.print(1);
      }
    else
       {
         digitalWrite(DAT, LOW);
        // Serial.print(0);
       }
    delayMicroseconds(50);
    digitalWrite(CLK, HIGH);
    delayMicroseconds(50);
   
    if(i>0)
    digitalWrite(DAT, LOW);
    else
    digitalWrite(DAT, HIGH);
    delayMicroseconds(50);
   
    if(i>0)
    digitalWrite(CLK, LOW);
    else
    digitalWrite(CLK, HIGH);
  }
 
  delay(20);
}


that code plays the wave shield right. it can play, pause, previous and next the sounds.

then for the piezo sensor, yes, i used 1M resistor parallel to it and also i tried to sense it and have tried some of the codes i saw on the net. here it is..

Code: [Select]
int ledPin = 13;

int knockSensor = 0;               

byte val = 0;

int statePin = LOW;

int THRESHOLD = 10;



void setup() {

pinMode(ledPin, OUTPUT);
       
Serial.begin(9600);

}



void loop() {

  val = analogRead(knockSensor);     

  if (val >= THRESHOLD) {

    statePin = !statePin;

    digitalWrite(ledPin, statePin);

    Serial.println("Knock!");



  }

  delay(100);  // we have to make a delay to avoid overloading the serial port

}



then this one is my latest code for piezo sensor that i want to put into the codes of the wave shield for triggering it to play the sound when it reach a certain threshold..

Code: [Select]
int sensePin = 0;

int ledPin = 13;

void setup()
{
  // put your setup code here, to run once:
  analogReference(DEFAULT);
 
  pinMode(ledPin, OUTPUT);
 
 
}

void loop()
{
 
  int val = analogRead(sensePin);
 
   if(val >30) digitalWrite(ledPin, HIGH);
  else digitalWrite(ledPin, LOW);
  // put your main code here, to run repeatedly:
 
}


my problem is, i don't know where to put the codes of piezo to the codes of wave shield for it to be the trigger for playing the sound,, i tried inserting this one to the void loop of wave shield but it doesn't make any changes.

Code: [Select]
  int val = analogRead(sensePin);

  if(val <30) { send(0x0000);
   delay(10000);
   send(0xfff2);
   delay(3000);
   send(0xfffe);
   delay(5000); }


of course i have done int sensePin=1 in the first part of the sketch..
please help?

Caltoa

Thanks for the photo.

I don't understand how to use the Elechouse Wave shield. It's just as confusing for me as it is for you. I don't have the time to look into the Elechouse library yet.
Perhaps the best way is make it less confusing by seperating the different code functionality.
You might end up with a number of test sketches, but that is normal.

Can you start with the Wave sketch example, and make a function that plays file 0000 ?
Keep the send() function, remove the "while(1);" in the loop(), because that "while(1);" is to stop the sketch.
If you think your function is working, remove everything from the loop() and only use a call to that function and add a delay.
That function should be called over and over again.

Make another function that checks the knock sensor, and it should return a value or boolean.
Use that function in loop() to test if a knock sensor is activated, and if it is, call the function for file 0000.

After that, extend it for other waves and other knock sensors.

If you manage to do this step by step, you are becomming a programmer  :P . Splitting up the real world into seperate functions or code blocks is how to think as a programmer.

arbee

a really big thanks for all of the advice! :D
i just made experiments on the sketch and then after several trials it worked :D thanks! i just put the sketch of the piezo into the loop of the wave shield and then as you said i didn't include while(1) thanks a lot! :D

bonnyr

Hi there,

Not to hijack the thread, but I've got the same shield the OP has received. I cannot make it work using a
SainSmart UNO board - no sound is coming out of the headset jack or the PWM holes.

Here's what I tried:

1. Put a single .wav file, named 0000.wav on the root directory of the SD card. Arduino code is from the bundled instructions,
    except I removed playing any other file than the first. The wav file is a  16-bit PCM 11KHz mono file. No dice.

2. Repeated with a different file, the provided 0000.ad4. No dice.

3. Tried to use the UNO as a power supply (so program just resets the state of the DATA/CLK pins) and use the buttons
     on the board. No dice

I am wondering if my issues are:
a. Faulty shield;
b. Wrong format of file names on SD card;
c. Incorrect documentation - the pins used to program the shield have changed between V2 and V3 and the new board
    is not even connected (as it's smaller) to DP0-DP7 and any of the Analog pins. The documentation is pretty sparse.
    One of the main differences, other than the pins, is that the RESET pin is no longer documented in the wave diagram,
    but is mentioned in description of each pin...

Any info would be appreciated on what to do to get this to work..
Anyone who has been able to get this board to work - what files were you using? How are they formatted?


Cheers,

Bonny

Go Up