Arduino Lightsaber

For those who have no WT588D programmer I finally got to upload audio to the board using only the Arduino and processing. This is based on AdaFruit's audio transfer code for the Trinket. Link to the code can be found on this thread:

http://forum.arduino.cc/index.php?topic=227435.msg2466463#msg2466463

USE AT YOUR OWN RISK

For JakeSoft here's a youtube vid for you :slight_smile:

With lightsaber sounds loaded. Still needs to work on my button/sensor codes.

Question: Do we need to issue a stop command (0xFE) before we play another audio group?

purgedsoul:
Question: Do we need to issue a stop command (0xFE) before we play another audio group?

No. Just make sure the WT is set to edge retrigger. i suggest a delay(100); after every WT_send_command(0x..)

Update:
I disconnected the Busy pin from the arduino to the WT and everything still works.
Frees up an arduino pin too.

and

Jake, I'll give that a try.

I over came the swing repeat with the standard debounce code.

int SW_sensor = 9  //sensor button pin
long time = 0  //time of nothing
long debounce = 200 //200ms is the margin of error to determine a press, hold, or rapid press
bool swing_sound

setup
digitalWtite(SW_sensor,HIGH);
swing_sound = false;

void loop()
{

  // if the swing sensor was toggled and not just held at a state for less than 200ms
 
 if (digitalRead(SW_sensor) == HIGH && digitalRead(SW_sensor) == LOW && millis() - time > debounce) {
    
if (swing_sound)

  // do nothing.  get coffee but be back in 100 ms
     delay(100);
   
 else
      WT_send_command(1); // swing sound
      delay(100);

    time = millis();    
  }
}

billpealer:
No. Just make sure the WT is set to edge retrigger. i suggest a delay(100); after every WT_send_command(0x..)

Update:
I disconnected the Busy pin from the arduino to the WT and everything still works.
Frees up an arduino pin too.

and

Jake, I'll give that a try.

I over came the swing repeat with the standard debounce code.

int SW_sensor = 9  //sensor button pin

long time = 0  //time of nothing
long debounce = 200 //200ms is the margin of error to determine a press, hold, or rapid press
bool swing_sound

setup
digitalWtite(SW_sensor,HIGH);
swing_sound = false;

void loop()
{

// if the swing sensor was toggled and not just held at a state for less than 200ms

if (digitalRead(SW_sensor) == HIGH && digitalRead(SW_sensor) == LOW && millis() - time > debounce) {
   
if (swing_sound)

// do nothing.  get coffee but be back in 100 ms
    delay(100);
 
else
      WT_send_command(1); // swing sound
      delay(100);

time = millis();   
  }
}

Look at you, Bill: Answering questions complete with sample code!

"Indeed, you are powerful" --Darth Vader

Good for you!
"Pass on what you have learned" --Yoda

...I should stop now, huh? :slight_smile:

did anybody acomplished a more "stable" or "simple" solution?

IF so

any hope for a collection of information for the NOOBs (aka ME, i dont code nor have eletronics knowledge?)

i ask cause this is the closest Open source solution for the sound card component of lightsabers.

i REALLY do not have the money for proprietary cards, but i do have the passion to work the kinks of assembling the eletronic components of an open source solution.

im new to the scene (you could tell huh?)

Ok, so I was originally just going to make a stunt saber from pvc. Who needs all that fancy audio? Then I saw that the new hasbro toy sabers have a similar board to the 2010 models. Ok, maybe for $15 that might be worth a play. But now, seeing what you have done with the arduino, I really wanna a make that. I am pretty overwhelmed by what is involved though. My only experience with arduino is buying pre-built boards to run multiwii for multi rotors, which I first decided on because of the open source/community behind it. I've uploaded sketches and messed with parameters, but nothing like what you've done here. I plan to get a pro mini and sound board and mess with it, but what you have in your Mk II seems perfect to me. I can figure out the led fade easily enough and probably triggering the audio, but how you scroll through options and change colors is beyond me at the moment. For the moment, I am better at dremelling pvc to make a hilt than writing arduino code.

I'm in the same boat. I'm fascinated by what the Arduino is capable of, but can't code. However, I'm pretty handy with a recipe, so once somebody posts a step by step guide... I'm all in.

I've come to a new hurdle in my saber smithing adventure. While researching components, I realized that to upload the audio files to the wt588 you need pc software while I am on a mac. Yes, I could use some virtualization, but I was hoping for a more native or cross platform solution and I don't want to buy software for a one time use. Are there any mac compatible sound modules out there that would work like the wt588?

Maybe this will help?

JakeSoft:
Look at you, Bill: Answering questions complete with sample code!

"Indeed, you are powerful" --Darth Vader

Good for you!
"Pass on what you have learned" --Yoda

...I should stop now, huh? :slight_smile:

thanks.
i have a code mechanics question...
Why do i need the saber_is_on (or any bool statement) to be set to false in the setup,.. when i am declaring it false after the if statement?

example:
bool saber_on
void setup
saber_on = false;
void loop
{
if(digitalRead(button) == LOW) //button is pressed
{
if(saber_on) //Saber is on, so turn it off
{
//ADD CODE HERE TO TURN OFF THE LED AND PLAY OFF SOUND
saber_is_on = false;
}
else //Saber is off, so turn it on
{
//ADD CODE HERE TO TURN ON LED AND PLAY ON SOUND
saber_is_on = true;
}
}
}

so,.. it has been declared false in the set up AND after the if statement? Double false? isn't that a true? why cant i just have this and ditch the bool altogether?

void loop
{
if(digitalRead(button) == LOW) {//button is pressed

send_command(0); // off sound
delay(100);
}
else //Saber is off, so turn it on
{
send_command(1); //on sound
delay(100);
}
}
//end
i am pretty sure i started with that type of code, and when the button was toggled, it repeated like crazy.... "ma-ma-ma-ma-ma-ma" mamasita que es pasando!"

i am going to re-test,.. and i like your != simple debounce variant. simple. i'll try it.

nom_smile:
Maybe this will help?

https://www.arduino.cc/en/Main/Software

@nom_smile, I think you were talking to me. That only refers to the arduino itself. I have that working already as I've used it to upload sketches for my multiwii multi rotors. What I am referring to is the wt855 sound module which is not an arduino piece of hardware.
This is from the post that jakesoft referenced about the arduino code to work with the module:
"There is a shared Google drive with the control software to upload wav files to the devices, the user manuals, and schematics , they are well written for this type product: WT588D.rar - Google Drive"
The software is only pc compatible.

iamearlgrey:
@nom_smile, I think you were talking to me. That only refers to the arduino itself. I have that working already as I've used it to upload sketches for my multiwii multi rotors. What I am referring to is the wt855 sound module which is not an arduino piece of hardware.
This is from the post that jakesoft referenced about the arduino code to work with the module:
"There is a shared Google drive with the control software to upload wav files to the devices, the user manuals, and schematics , they are well written for this type product: WT588D.rar - Google Drive"
The software is only pc compatible.

This question comes up once in a while. As far as I know there is no way to make it work on a Mac without a virtual machine.

I know, I'm just as shocked as you; I thought everything "just worked" on a Mac. (I couldn't resist).

billpealer:
thanks.
i have a code mechanics question...
Why do i need the saber_is_on (or any bool statement) to be set to false in the setup,.. when i am declaring it false after the if statement?

example:
bool saber_on
void setup
saber_on = false;
void loop
{
if(digitalRead(button) == LOW) //button is pressed
{
if(saber_on) //Saber is on, so turn it off
{
//ADD CODE HERE TO TURN OFF THE LED AND PLAY OFF SOUND
saber_is_on = false;
}
else //Saber is off, so turn it on
{
//ADD CODE HERE TO TURN ON LED AND PLAY ON SOUND
saber_is_on = true;
}
}
}

so,.. it has been declared false in the set up AND after the if statement? Double false? isn't that a true? why cant i just have this and ditch the bool altogether?

void loop
{
if(digitalRead(button) == LOW) {//button is pressed

send_command(0); // off sound
delay(100);
}
else //Saber is off, so turn it on
{
send_command(1); //on sound
delay(100);
}
}
//end
i am pretty sure i started with that type of code, and when the button was toggled, it repeated like crazy.... "ma-ma-ma-ma-ma-ma" mamasita que es pasando!"

i am going to re-test,.. and i like your != simple debounce variant. simple. i'll try it.

Well, the code I posted was just supposed to give you an idea. Actually, it won't work unless you also wait for them to let off the button, otherwise it'll rapidly toggle between off and on as long as the button is pressed.

Your code won't work either and will have a similar problem.

void loop
{ 
 if(digitalRead(button) == LOW) {//button is pressed 
    
        send_command(0);  // off sound
        delay(100);
     }
     else //Saber is off, so turn it on
     {
        send_command(1);  //on sound
        delay(100); 
     }
}

Here is what will happen (go ahead, try it):
Action: Press the button and hold it
Result: The off sound is played over and over and over every 100 ms until the button is released.

Action: Button is pressed and released
Result: The off sound is played for 100 ms and then the on sound is played every 100 ms.

Your solution provides no way to turn off the saber.

My solution was flawed as well; not intended to be complete. For it to work, you have to wait for the user to let off the button before you look for it again.

loop()
{
   if(digitalRead(button) == LOW) //button is pressed
   {
      if(saber_is_on) //Saber is on, so turn it off
      {
         //ADD CODE HERE TO TURN OFF THE LED AND PLAY OFF SOUND
         saber_is_on = false;
      }
      else //Saber is off, so turn it on
      {
         //ADD CODE HERE TO TURN ON LED AND PLAY ON SOUND
         saber_is_on = true;
      }

      delay(20); //de-bounce it a little
      while(digitalRead(button) == LOW) {} //Wait for them to let off the button   
   }
}

Something like that will set up the logic to allow for toggling states and prevent rapid-fire activation event triggering.

Thanks, I figured that was the case. I'm not all that shocked. Anything development wise is usually left out of the mac realm unless you really know what you're doing and I do not. And it's just to add the audio files. I re-read the post about the working code for the wt588d and saw the discussion about programming with the external usb programmer and purged soul's success on programming without a programmer. It all looks to be done in arduino and processing which should be achievable on a mac. I also noticed that the instructable that the concept came from, the user was using a mac as well. Hmmm. Still a little over my head. Feasible but not simple. I did, however, find a free legal way to put windows on a virtual machine.

though taking the "easy" way out may be pushing me over to the dark side.
thanks again jakesoft for inspiring this whole adventure and anyone else who puts up helpful hints.

Ok. time to move it to the hilt.

anyone have a novel way to make a button trigger 2 sounds?

meaning

if button pressed and released
play_sound(1);
delay(100);

if pressed and released again less than 700mm since the last press and release
play_sound (2);
delay(100);

if pressed and held down
// do not play sound 1 over and over again every 100ms

i have the first and last parts figured out,.. it's the middle i have yet to figure out.

give me a week before you guys go nuts with examples... maybe i can figure it out.

billpealer:
Arduino Lightsaber Project testing complete. - YouTube

Ok. time to move it to the hilt.

Hey, nice job. It looks like you've got a viable solution there.

I misinterpreted the flicker schematic so here is how it should be wired for uC control:

It only half worked the way I had it configured, 1w LEDcame on but the flicker LED didn't.

Configured as it's supposed to be, it's a bit harder to bypass for a constant LED channel on my PCB as there's not much room left for routing.

hey just joined read most of the post on this topic even generated a list of parts from it. so once i get the boards i need the cable as well right. and the coding of the sound and such fairly simple yes? one thing not known to me is batterie holder can i use a 4aaa or what? dont want to over power or under power the system. yes i am a true noob to arduino just herd about it as of late. so any tips and so forth would helpful. and if anyone need a saber design i can do it. even to scale if need be though it may take some time.

one more thing need wire gage as well just in case.

JakeSoft:
This question comes up once in a while. As far as I know there is no way to make it work on a Mac without a virtual machine.

I know, I'm just as shocked as you; I thought everything "just worked" on a Mac. (I couldn't resist).

iamearlgrey:
@nom_smile, I think you were talking to me. That only refers to the arduino itself. I have that working already as I've used it to upload sketches for my multiwii multi rotors. What I am referring to is the wt855 sound module which is not an arduino piece of hardware.
This is from the post that jakesoft referenced about the arduino code to work with the module:
"There is a shared Google drive with the control software to upload wav files to the devices, the user manuals, and schematics , they are well written for this type product: WT588D.rar - Google Drive"
The software is only pc compatible.

JakeSoft.. So the software needs a virtual audio interface? for it to work in a mac setting? (sorry been a bit busy)