Go Down

Topic: simply smartwav example (Read 2242 times) previous topic - next topic

djdeeno

Hi,

I have buy a Smartwav for the Arduino to try to play some wav files from it. You can see it here:
http://playground.arduino.cc/SmartWAV/SmartWAV

A nice good working standalone wav player, but i want to use it to play some tracks while i pushing a button on the Ardiuno Uno. That is for a little funfair ride model, when i push a button on the Arduino, the motor is gonna be running and a sound (on the smartwav) is playing.

My question, and i can't find the answer in the documents, dont on Arduino smartwave example page, not on the forum here, but its must be easy i think.

A example INO file with in
Push a button and play "test.wav" on the smartwave. thats all.
can someone help me with this?

i hope so, als on Arduino and Smartwave site says, there wil be examples soon..... wel that 3 years ago :-(

http://www.vizictechnologies.com/#!smartwav/c118s

Thanks allot

kind regards

MD

CrossRoads

I use these MP3 players in projects. Send a simple serial command  to play a file.
http://www.mdfly.com/search.php?search_query=mp3
I play back thru a pair old desktop computer speakers (self powered).
Can find plenty of battery powered speakers at amazon.com.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

djdeeno

Thanks but i have a smartwav.

this is what i have build but he doens't work, i see nothing happend , communicate with rx and tx is maybe problem?

this is the code:
Code: [Select]
#include <SMARTWAV.h>     //include the SMARTWAV library!

SMARTWAV sWav;            //create our object called sWAV (smartWAV)

const int button = A0;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

void setup() { //initial setup
  //This function must always be called for SMARTWAV support
  sWav.init();  //configure the serial and pinout of arduino board for SMARTWAV support
  sWav.reset(); //perform an initial reset

  pinMode(1,OUTPUT);
  pinMode(0,INPUT); 
  Serial.begin(9600);
   }


void loop() { //main loop
 
  delay(1000);

  if (buttonState == HIGH) {                       //write the code that checks if the button is pressed
    sWav.playTrackName("test");        //call the song by it's name, don't add the ".wav" extension
   }
}

siutoejai

Code: [Select]




#include <SMARTWAV.h>     //include the SMARTWAV library!

SMARTWAV sWav;            //create our object called sWAV (smartWAV)

const int buttonPin = 2;       // TRY PIN 2 OR OTHER PINS ON THE RIGHT SIDE OF YOUR UNO for eg
int buttonState = 0;         // SET IT TO 0

void setup() { //initial setup
  //This function must always be called for SMARTWAV support
  sWav.init();  //configure the serial and pinout of arduino board for SMARTWAV support
  sWav.reset(); //perform an initial reset

 
  pinMode(2,INPUT);  // CONNECT A 10K RESISTOR FROM PIN 2 TO GROUND AS IN THE DIAGRAM

   }


void loop() { //main loop
 
  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH)  // WHEN YOU PRESS THE BUTTON  THE BUTTONSTATE GOES FROM LOW TO HIGH


 {     
   
 

    sWav.playTrackName("test");        //call the song by it's name, don't add the ".wav" extension
   }
}










http://arduino.cc/en/Tutorial/Button

siutoejai

#4
Feb 25, 2015, 06:03 am Last Edit: Feb 25, 2015, 06:56 am by siutoejai
Code: [Select]
const int button = A0;     // THIS IS ONE OF THE ANALOG PINS A0-A5 ON UNO


PINS O AND I ARE  TRANSMIT AND RECEIVE



if you do not have any 10k resistors

http://arduino.cc/en/Tutorial/DigitalPins
http://arduino.cc/en/Tutorial/AnalogInputPins

Read the two websites above too

btw

Quote
Notes for example code below: See the SMARTWAV.h file for the Arduino three Arduino pins to use.
make sure u connected the right pins

or change the pins as follows:

Code: [Select]

/********************************************************
 USER DEFINITIONS
********************************************************/
#define TXPIN 3     //software UART Transmit pin - Connect this pin to SmartWAV RX pin
#define RXPIN 2     //software UART Receive pin - Connect this pin to SmartWAV TX pin
#define RESET 4     //reset - Connect this pin to SmartWAV reset pin

djdeeno

#5
Feb 25, 2015, 11:55 pm Last Edit: Feb 26, 2015, 12:03 am by djdeeno
Wow thanks alot!!!!

I have build this and we are a little further right now  :)
have tx and rx on the 2 and 3 pins and a resset on pin 4, when i push the resset button on the arduino, and (strange) tip with my finger on the arduino, he plays de test.wav.

when i pressed the button on A0 there nothings gonne play anymore, it seems that it working 1 and not when mpressed the button but when comes with my finger to the arduino, seems like something about inteferentie.
this is the code i used and test it:

Code: [Select]
#include <SMARTWAV.h>     //include the SMARTWAV library!

SMARTWAV sWav;            //create our object called sWAV (smartWAV)

const int buttonPin = A0;       // TRY PIN 2 OR OTHER PINS ON THE RIGHT SIDE OF YOUR UNO for eg
int buttonState = 0;         // SET IT TO 0

void setup() { //initial setup
  //This function must always be called for SMARTWAV support
  sWav.init();  //configure the serial and pinout of arduino board for SMARTWAV support
  sWav.reset(); //perform an initial reset


   }

void loop() { //main loop
  
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH)  // WHEN YOU PRESS THE BUTTON  THE BUTTONSTATE GOES FROM LOW TO HIGH
    
 {
 
    sWav.playTrackName("test");        //call the song by it's name, don't add the ".wav" extension
   }
}



when i dont used the resset cable, the sketch wil be playing directly after the arduino resset.

so what can this be? i have 2 smartwav and both have the same effect.
Also same when i use pin 7 for the button, or A0 it does't matter.


thanks again all!!

kind regards Marcel Netherlands

a photo:



djdeeno

Thanks everybody, its working now  ;)
I have change the button and the way to tricker it.

But i have other question also, maybe its a little thing.
when i push the button, the led wil be on and wav wil be play, what i want is when i push the button again, he must play a other wav file, lets say test2.wav.
when thats oke, than he must play de the first again.

 i mean this:

Code: [Select]
#include <SMARTWAV.h>     //include the SMARTWAV library!

SMARTWAV sWav;            //create our object called sWAV (smartWAV)

int led = 12;

void setup() { //initial setup
  //This function must always be called for SMARTWAV support
  sWav.init();  //configure the serial and pinout of arduino board for SMARTWAV support
  sWav.reset(); //perform an initial reset
 
  pinMode(7, INPUT); 
  pinMode(led, OUTPUT);   
  digitalWrite(7, HIGH);

   }

void loop() { //first time
 


  if (digitalRead(7) == LOW)  // WHEN PRESS IT FOR THE FIRST TIME
 
     
 {
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);               // wait for a second

    sWav.playTrackName("test");        //call the song by it's name, don't add the ".wav" extension
     delay(10000);               // wait for a second         
         digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   


   }
}

void loop() { //second time
 


  if (digitalRead(7) == LOW)  // WHEN PRESS IT FOR THE SECOND TIME
 
     
 {
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);               // wait for a second

    sWav.playTrackName("test2");        //call the song by it's name, don't add the ".wav" extension
     delay(10000);               // wait for a second         
         digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   


   }
}






djdeeno

Thanks everybody,

I have found a sketch to combine it, so i can work further with my project.
When the mini fairfair is ready i show what he Arduino do for this project.

Kind regards

Marcel

siutoejai

u r using two loops hm... i do not think it is a good way


you may try button count or  something like the following

Code: [Select]
const int buttonPin = 2;               
unsigned long startTime;                 
unsigned long duration;                 
const int led = 8;
const int led1 = 9;
void setup() {
  pinMode(buttonPin, INPUT);             
                   
 pinMode(led,OUTPUT);
  pinMode(led1,OUTPUT);
 
}

void loop() {
 
  if (digitalRead(buttonPin) == HIGH)
  {
    startTime = millis();                   
    while (digitalRead(buttonPin) == HIGH)   
      ;  // do nothing
   
    duration = millis() - startTime;         
   
  }
   ledon();
    led1on();
}
 void ledon()
 
 {  if (duration >=100 && duration <=4000 )
   { digitalWrite(led, HIGH);}
    else
    {digitalWrite(led, LOW);}
  }
 
  void led1on()
  {  if (duration >=4001)
   { digitalWrite(led1, HIGH);}
    else
    {digitalWrite(led1, LOW);}
  }
 



press the button very fast between 100 and 4000 miliseconds

u do something within the loop

hold the button longer   u do something within the loop



void led     and void led1   are two functions


it is just an example to control two leds

u may change it to control your sound board

also  look for button count examples


u can choose which song to play by reading the button counts

siutoejai

#9
Feb 28, 2015, 10:08 am Last Edit: Feb 28, 2015, 10:11 am by siutoejai
using button count

press the button once  to play a song

press the same button the second time to play the next song
and then so on

when it reaches the end of your song list

it goes back to the first one

if you do not need to debug it with your serial monitor , just remove the code for that


Code: [Select]
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 8;       // the pin that the LED is attached to
const int ledPin2 = 9;    
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
 pinMode(ledPin2, OUTPUT); // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;

  
  
  counting1();
  counting2();

 resett();
}


void resett() {

if (buttonPushCounter==3)
{ buttonPushCounter = 1;
  delay(20);}

}

void counting1() {
 if (buttonPushCounter==1) {
   delay(20);
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }
  
}

void counting2() {
  
  if (buttonPushCounter==2) {
    delay(20);
    digitalWrite(ledPin2, HIGH);
  } else {
   digitalWrite(ledPin2, LOW);
  }
}



this is my rookie way of doing it according to the button count example


u can change it to suit your needs

Go Up