Arduino Lightsaber

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

No, the WT588D uploader/programmer software (This is the software that compiles the bin file to be uploaded to the WT588D module) works only on Windows.

hey i am guessing that when you used the accelerometer that it eliminated the use of the motion sensor. is this correct?

Dear Friends just a couple of questions.

Im trying to do the same build as Jakesoft using an accelerometer and the clash sensor. First of all, is there a way to include the "play command" to reproduce the boot up just once sound by including it in the void setup?

Is it possible to play the hum sound in the background and interrupt it as a swing is detected by the accelerometer? Then resume it and continue playing it in a loop.

Im trying to accomplish this without using any delay functions in the main loop to avoid lag.

Currently using the wt588d, an arduino nano and a mm8452 accelerometer. So far i have accomplished to run the functions "power on and power off" (including led and corresponding sound) with an attach interrupt function, a hardware debounce with an inverse Schmitt trigger and the 1 line serial mode.

hey billpealer, do you have the completed code that you can share with us? I've been working hard on mine and it works but could always use tweaking. I have a suggestion for the changing of the swing and clash sounds, use the CASE SELECT option in Arduino. Here's the working part of my code that does this. Note, i'm still using 3-line serial mode and am hoping to look at your completed code to modify mine for 1-line.

int clashValue;
int swooshValue;
int clashSound;
int swooshSound

(under loop)

switch (clashValue) {
    case 1:
      clashSound = 0x03;
      break;
    case 2:
      clashSound = 0x04;
      break;
    case 3:
      clashSound = 0x05;
    case 4:
      clashSound = 0x06;
      break;
  }
 switch (swooshValue) {
    case 1:
      swooshSound = 0x08;
      break;
    case 2:
      swooshSound = 0x09;
      break;
    case 3:
      swooshSound = 0x0a;
    case 4:
      swooshSound = 0x0b;
      break;
  }
clashValue = random(4);
  swooshValue = random(4);

(outside loop)

void swoosh() {               //am using a ADXL335 accelerometer and had to create values so the
  calibrated = false;         //vibration from the clash didn't trigger the swing sound
  if (canSwing = true) {
  if (isclashing == false) {
      sendcommand(swooshSound);
      delay(5);
    }
  }
  canSwing = false;
  delay (5);
}

void clash() {
  if (isOn) {
    digitalWrite(clashLed, HIGH);
    isclashing = true;
    sendcommand(clashSound);
    delayMicroseconds(2000);
    digitalWrite(clashLed, LOW);

    isclashing = false;

  }
}

Hello, to program the wt588d-16p i need use this arduino scheme? or the scheme is only to play the sounds with arduino sensing the messagens? i didnt understand this...

Thanks

darkside: hey i am guessing that when you used the accelerometer that it eliminated the use of the motion sensor. is this correct?

Yeah, the tilt sensor would have been kind of redundant, so I removed it in my Mk. III system when I added the accelerometer. I'm still not totally satisfied with how that's working, I've got to come up with a better swing detect algorithm.

thanks JakeSoft for the info i am still waiting on the rest of the parts. so as of now i am just getting the feel for how it should come together. any tips on the programming would be useful. and i also checked out your videos to better understand the setup. i say job well done. PS. the programming is rather new to me, i understand how to get into it its just the code writing that i am leery about. one line three line is new to me. first time trying this in any case.

kingale: Im trying to do the same build as Jakesoft using an accelerometer and the clash sensor. First of all, is there a way to include the "play command" to reproduce the boot up just once sound by including it in the void setup?

Yes, that would work.

kingale: Is it possible to play the hum sound in the background and interrupt it as a swing is detected by the accelerometer? Then resume it and continue playing it in a loop.

Im trying to accomplish this without using any delay functions in the main loop to avoid lag.

Yes, if you read the rest of this thread you'll see several ways to do exactly that. One caveat is that your hum sounds need to play from the start each time, you can't interrupt them and then start playing again from where you left off.

DJWing79: hey billpealer, do you have the completed code that you can share with us? I've been working hard on mine and it works but could always use tweaking. I have a suggestion for the changing of the swing and clash sounds, use the CASE SELECT option in Arduino. Here's the working part of my code that does this. Note, i'm still using 3-line serial mode and am hoping to look at your completed code to modify mine for 1-line.

i am not using a accelerometer so i can't say what will work for your set up. can you tell me what ISNT working, and maybe we can sort it out.

this is the working code for 1 line serial. i think others have said they have reduced the below delay times.

void WT588D_Send_Command(byte addr) { digitalWrite(WT588D_SDA, LOW); delay(5);

for(int i = 0; i < 8; i++) { digitalWrite(WT588D_SDA, HIGH); if(bitRead(addr, i)) { delayMicroseconds(600); digitalWrite(WT588D_SDA, LOW); delayMicroseconds(200); } else { delayMicroseconds(200); digitalWrite(WT588D_SDA, LOW); delayMicroseconds(600); } }

digitalWrite(WT588D_SDA, HIGH); delay(100); } //end WT588D_Send_Command

What happens is when I tell it to play the hum sound it gets distorted and then starts clicking even when i put a long enough delay in for the sound to play.

ok i am guessing that the +5V in #6 indicates the 5V regulator which connects to both boards in the diagram. and the led mossfet gates i think i have figured out.

hey just checking things out on amazon for next build when i have mastered this one and found a WTV020-SD-16P sound board there. have anyone hear good things about it or what. it can either be a 5V or 3.3V.

darkside: hey just checking things out on amazon for next build when i have mastered this one and found a WTV020-SD-16P sound board there. have anyone hear good things about it or what. it can either be a 5V or 3.3V.

Check out this thread on that particular module:

http://forum.arduino.cc/index.php?topic=117009.0

  • older modules are 3.3V check if you have newer one that can accept 5V.
  • you need to look for a compatible micro SD card 1GB (newer higher capacity cards will not be accepted)
  • you need to convert your audio file so that it can be recognized by the module.
  • SD card needs to be formatted so that memory spaces are contiguous.
  • noticeable delay during playback between sound files (so no gapless playback).

purgedsoul: Check out this thread on that particular module:

http://forum.arduino.cc/index.php?topic=117009.0

  • older modules are 3.3V check if you have newer one that can accept 5V.
  • you need to look for a compatible micro SD card 1GB (newer higher capacity cards will not be accepted)
  • you need to convert your audio file so that it can be recognized by the module.
  • SD card needs to be formatted so that memory spaces are contiguous.
  • noticeable delay during playback between sound files (so no gapless playback).

This is consistent with everything I have read about them. I looked into it as a candidate but rejected it for some of the above reasons. Obi1 even said that he tried it for his saber sound board project and it flunked out pretty much for the failure to do gap-less playback. I'm sure it's fine for some things, but for this application it's not up to the task.

DJ, i can’t even begin to understand till you post a sample of the code that interacts with the accelerometer. if i had to guess, id say you have some noise in the PWM of the speakers,… distorted how? can you make a video?

also the clicking? ,… hmm. sounds like the accelerometer is tweaking the arduino to send junk to the WT. why dont you just drop $3.50 and do analog sensors like Jakes MKII. i did. they are good. more than good. fine and dandy. as long as you position them correctly and understand how they work,… you can move in contrived ways that really make the thing sing. also,… if you want perfect sounds during a good rough duel,… seriously,. nothing on the market will do it. i have seen very expensive light saber duels, and they sound like poorly dubbed videos, and the smacking of polycarbonate will be louder than it all.

darkside:
ok i am guessing that the +5V in #6 indicates the 5V regulator which connects to both boards in the diagram. and the led mossfet gates i think i have figured out.

do not use a regulator. waste of space. the arduino does it for you if you go to the RAW in pin. 5v-12v unregulated power… AKA a battery.

also,. no offense to Jake,… his diagram does not go into proper mosfet wiring nor how he delivers the correct voltage/current to the LEDs. the attached photo will walk you thru how to do it with out a regulator, and WITH an led DRIVER, and how to wire the mosfet. the mosfet is tied to the WT588 and the LED in my setup. turning off both LED and WT when there is no audio to play is not a bad thing.

also,… to bypass default or interrupt hum,… just program the WT so that every activation sound, except for blade off, is followed by 20-30 seconds of hum looped. it wont take up any more space on the device and plays seamlessly with less or no gaps.

so in the WT programer:

0x00 off sound,… no hum.
0x01 on sound, followed by 30 seconds of hum
0x02 swing sound, 20 seconds of hum,
0x03 clash sound, 20 seconds of hum

etc
etc

you need 6 arduino commands,.

//button toggle code of choice
turn on led (or truly, send a pin HIGH state to the MOSFET)
turn off led (send a LOW state to the MOSFET

//button toggle code of choice
play on sound (0x01) ( this should play 10ms after the turn on LED high state. the WT needs 5-10ms to… “boot up”)
play off sound (0x00)
play clash (0x03)
play swing (0x02)

[img http://forum.arduino.cc/index.php?action=dlattach;topic=261980.0;attach=152407[/img]

if you are using an accelerometer,. all of the above info may be moot. i actually like the analog swing sensors. and the alternating debounce button codes with 100ms delays seems to really kill it!! good swings, nice clashes,.and also a reversed debounce function to throw in alternating swing and clash sounds, if they happen close together,. meaning… a single swing with go HUM. a full 360 or 2 swing triggers in less than 1000ms but more than 200ms will go zHum, VRhurm. one hit will go CLAShh! 2 hits in less than 1000ms, but more than 200ms will go Clashh, Cleeerchzzs!

capice?

sometimes the above doesn’t work perfect or the same everytime, and gets rather random with you are moving around for a few minutes and holding the saber in wierd positions before you swing or clash it,… but random is fine with me too! the real key is the right sound type plays when it should.

i don’t even have a hum command or interrupt for arduino. heck i don’t even have one on the WT,. the sound is of course loaded to the WT, bu no Hex address has it to play. it is just the tail of all the other sounds

in my off LED command, i also give it (1200) delay so,… the LED turns off, JUST as the off sound resolves,… the LOW state also cuts power to the WT sound module. this is so there are no false positives from the swing and clash sensors. and again, less arduino code to mull over. nothing says OFF like cutting the power. no code needed.

This code uses the 3-line serial mode and ADXL335 accelerometer, WT588D, Arduino Pro Mini 3.3v and the OneButton library. I got it working pretty well. But I am trying to move over to the 1-line serial mode and it isn’t playing nice. that’s what I mean. I hope this helps. I am also trying to develop a RGB color changing scheme via the buttons that I saw from another forum.

Lightsaber_2b.zip (2.93 KB)

oh and I apologize for the code not being more streamlined and neat.

why use a 5V regulator for WT588D? The arduino nano have a 5V output. regards

billpealer: do not use a regulator. waste of space. the arduino does it for you if you go to the RAW in pin. 5v-12v unregulated power... AKA a battery.

This is good advice if you are using both a 5V Arduino board and a WT588D-u (the one with the built in USB). The WT588D-u board lets you get away with just powering the VDD pin which can operate at 5V. You used a Nano which has a 5V regulator built in, so you are all set.

The 16-pin WT588D works differently. It won't operate unless you power both the VDD and VCC pins. (The manual may not say that, but that's how it really seems to work.) The VCC pin needs to be 3.3V.

So, let's say you are working with a 3.3V Pro Mini like I used and a 16-pin WT588D. The VDD pin on the WT588D may also be 3.3V just like the VCC (meaning you won't need an external regulator) but won't be as loud as if you give it 5V. So, if you are running with a 3.3V Arduino board or a 16-pin WT588D, then you need an external regulator for maximum loudness because you need both a 3.3V and a 5V source. However, it will work if you jumper both the VCC and VDD pins to 3.3V, it just won't be as loud. I'm not sure what happens if you give 5V to both VCC and VDD. I assume bad things like fried flash on the WT588D, but who knows?

A lot of experimenting to figure all that out.

billpealer: |500x281

also,. no offense to Jake,.. his diagram does not go into proper mosfet wiring nor how he delivers the correct voltage/current to the LEDs. the attached photo will walk you thru how to do it with out a regulator, and WITH an led DRIVER, and how to wire the mosfet. the mosfet is tied to the WT588 and the LED in my setup. turning off both LED and WT when there is no audio to play is not a bad thing.

No offense taken. Thanks for filling in the gap! It was clever how you exploited the VF of your chosen LED the way to did. One question, though: How do you achieve maximum LED brightness if you are using something like a Cree XPE2 that has a forward voltage of ~3.5 v @ 1000ma? Or what if you are using a Lux Rebel red with a forward voltage of 2.4V @ 700ma? Is the LM2596 adjustable?

billpealer: also,.. to bypass default or interrupt hum,.. just program the WT so that every activation sound, except for blade off, is followed by 20-30 seconds of hum looped. it wont take up any more space on the device and plays seamlessly with less or no gaps.

Hey! You stole my trick! :-) Yeah, this is by far the easiest way to get gapless transition to hum after a clash or swing.

billpealer: if you are using an accelerometer,. all of the above info may be moot. i actually like the analog swing sensors. and the alternating debounce button codes with 100ms delays seems to really kill it!! good swings, nice clashes,.and also a reversed debounce function to throw in alternating swing and clash sounds, if they happen close together,. meaning.. a single swing with go HUM. a full 360 or 2 swing triggers in less than 1000ms but more than 200ms will go zHum, VRhurm. one hit will go CLAShh! 2 hits in less than 1000ms, but more than 200ms will go Clashh, Cleeerchzzs!

I totally agree. Although adding an accelerometer allows you to do some cool things, people seriously underestimate what a PITA is to get it working properly while simultaneously underestimating what you can do with a tilt sensor. If you want to detect swings along another axis with simple tilt sensor, you can add a second sensor and orient it perpendicular to the first one. This is how the MR/Hasbro Force FX lightsaber sound boards work and people are putting them in custom sabers all the time. Reading what Bill posts here makes me want to revisit my Mk. II code and play with what can be done.

I've said it before, but there are many many MANY ways to wire/code this so it'll work. Thanks Bill for presenting one more by sharing your design.

yup yup yup.

all that he said /\ ||

the 5v regulator is needed because the 3.3v pro mini VCC will only send 3.3 v to the WT. i forgot you are using a pro mini 3.3v. jake man, have you found a decent amp?

i just did something really interesting,.. i got the Nano to STACK onto the WT588d-U INSIDE my hilt. i just shaved 1.24 inches of space. I am soldering tonight. both USB ports face the same way, so you can reprogram both units,. with out even taking it out of the hilt. i may do 2 tilt sensors with the new space. or an amp. i found one on ebay that should work.

and no,. i have never achieved maximum output fomr my LEDS,.. but i am getting a good consistant 70% output, and no resistors burning up my batts, and YES, the step down buck converter IS adjustable... but it adjusts kinds cruddy. .3v increments. the potentiometer is shite. the luxeon 3w blue rebel is rated for 3.4v and 450ma for it's optimal operation. yeah, it maxes out with some other numbers, but for mcd, i am right in the zone.

the buck step down settings i got are: 2.82v, 3.18v, 3.37v, 3.45, 3.51,.. for what ever reason. i think as it gets higher, it becomes more acute. I use the 3.37 for my green Luxeon rebels at 600ma with no issue, and the 3.45v for my blue at 650ma with no issues yet. the leds get warm. i have had them running for 10 minutes with no issue. The LM2596 buck is rated for 3A out. that must be at the higher spectrum of Vin. at 8v in.. i have never been able to push more than 650ma at 3.45v. i did crank the blue up to 3.6, and got 690ma,. but i tuned it down pretty quick. the current must be auto regulated. just the voltage is adjustable.

i seriously think 500-600 ma is plenty for these 3W leds,.. pretty bright.

also,. by adding the reversed debounce code to the tilt, it will trigger a swing when the ball rolls from one side,. OR if the ball is left to rest in the closed circuit position for more than 200ms, it will play an alternating swing sound when the circuit closes (low state). so it acts like 2 sensors. and vice versa.