Go Down

Topic: Arduino Lightsaber (Read 393961 times) previous topic - next topic

billpealer

#75
Oct 28, 2015, 08:32 pm Last Edit: Nov 03, 2015, 05:47 am by billpealer
lil help,. and or who wants to make a weekend's worth of drinkin money?
I have combined Sugar's code with Illuis's Code, (and made the naming consistencies jive)  and as per Jakes's recommendation : "put this SOMEWHERE in your code... " for the sending the HEX code to the WT5xxx..
Created this below.

Code: [Select]

#define WT588D_RST 7 //Module pin "REST" or pin # 1
#define WT588D_CS 6 //Module pin "P02" or pin # 11
#define WT588D_SCL 9 //Module pin "P03" or pin # 10
#define WT588D_SDA 8 //Module pin "P01" or pin # 9
#define WT588D_BUSY 10 //Module pin "LED/BUSY" or pin # 15

byte file_count = 1;

void setup() {

 pinMode(WT588D_RST, OUTPUT);  
 pinMode(WT588D_CS, OUTPUT);
 pinMode(WT588D_SCL, OUTPUT);
 pinMode(WT588D_SDA, OUTPUT);
 pinMode(WT588D_BUSY, INPUT);  

 digitalWrite(WT588D_CS, HIGH);
 digitalWrite(WT588D_RST, HIGH);
 digitalWrite(WT588D_SCL, HIGH);

}


void loop()
{

 //Turn on repeat mode
 WT588D_Send_Command(0xF2);

             //Begin playlist 0
 WT588D_Send_Command(0x00);
 
 WT588D_Send_Command(file_count);

 file_count++;

 if(file_count == 8) file_count = 0;

 delay(50); //give the module time to start playing

 while(digitalRead(WT588D_BUSY) == 0) { }

 delay(200);

}


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

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

   digitalWrite(WT588D_SCL, HIGH);
   delay(100);
}


It does,. absolutely nothing.  my arduino button press (thanks for the internal resistor code Jake)  turns on my LEDS,..  turns them off too.
plays no sound.  i still do not know how the one button will trigger DATA to go out the SCL pipe,.  nor can i deduce how this code DOES anything.  is there a .H library in play that NO ONE is talkin about?
After reading every post 7 times, spent over 25 hours,..  ergo,.. $1000.00 of man hours..
I am going offer a fire sale for anyone who'd like to buy my sound modules, and 3 arduino boards.
I have 25 hours into this project for the coding alone.  and that's real money and time for naught.

My wt588D works fine in button (key) mode,.  plays all my sounds..     i can not get the arduino to control it.

Who would like to make $100 and send me their working code for 1 line serial mode,..  not the crumbs posted here.  real operational code.  paypal at the ready.

JakeSoft

#76
Oct 29, 2015, 12:56 am Last Edit: Oct 29, 2015, 12:58 am by JakeSoft
lil help,. and or who wants to make a weekend's worth of drinkin money?

I think I see a few problems with your code, but it's pretty close.

First, if you are using 1 line mode, you don't need WT588D_CS or WT588D_SCL. Get rid of those and the pin assignments. All you need is WT588D_SDA.

You also don't need WT588D_RST. Get rid of it. Don't wire the reset pin on the WT588D to anything either, just make sure that WT588D is programmed with the "pull high resistor" set. Also, of course make sure it's programmed for one-line mode.

Code: [Select]

#define WT588D_SDA 8 //Module pin "P01" or pin # 9
#define WT588D_BUSY 10 //Module pin "LED/BUSY" or pin # 15


Now fix your WT588D_Send_Command() function to use WT588D_SDA instead of WT588D_SCL.

Next, simplify, simplify, simplify. Don't worry about looping and playing multiple files. Just get one file to play and work from there.
Code: [Select]

void loop()
{

  //Begin playlist 0
  WT588D_Send_Command(0x00);

  delay(2000);

}



If I have time I'll try to work up a simple demo and post working code in it's entirety.

JakeSoft

Here you go. I took your code and simplified it. The program will play playlist zero every 5 seconds.

Code: [Select]

/***********************************
WT588D One Line Serial Demo

Plays playlist 0 every 5 seconds.

JakeSoft 2015
***********************************/

#define WT588D_SDA 4 //Connect to WT588D Pin #10
#define WT588D_BUSY 7 //Connect to WT588D Pin #15

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);
}

void setup() {
  pinMode(WT588D_SDA, OUTPUT);
  pinMode(WT588D_BUSY, INPUT);

  digitalWrite(WT588D_SDA, HIGH);
}

void loop()
{

  //Begin playlist 0
  WT588D_Send_Command(0);
 
  delay(5000);
}


I  used arduino pins 4 and 7, but you can use whatever you want.

One other thing to check for is to make sure that you have the right processor selected in your Arduino IDE. I'm using the 8 Mhz version but it defaults to the 16Mhz version of you just select "Pro or ProMini" from the board menu. If you have the wrong processor selected then your timings will all be off and it won't work.


JakeSoft

#78
Oct 30, 2015, 02:37 am Last Edit: Oct 30, 2015, 02:39 am by JakeSoft
Firstly, in 3 line mode, I do not get the same as the timing diagram in the documentation.

My sound plays fine (and have tested the right ones are being selected using about 140 test sounds).

The documentation ( http://e-radionica.com/productdata/WT588D%20CHIP&MODULE%20DETAILED%20INFORMATION.pdf ) shows the sound (and busy signal) starting after 2 ms and states it happens 2 ms after successful data transmission.  The 2 ms in the diagram is referenced to the data becoming stable and not the rising edge of the last clock.  I would expect it to be referenced the last clock rising edge so this diagram at least seems inaccurate in one respect.

What I get is that sound and busy do not start until 24mS after the rising edge of chip select.  This is reliable and if I delay the CS further it still always happens 24ms after the rising CS!

The documentation may be wrong or this may indicate I am not doing things correctly.

Does anybody else have experience with this or has timed the time until the busy signal?
Yeah, the documentation is overly optomistic about the response times on the busy signal. I see this also; you are probably not doing anything wrong. Sometimes I'll see delays of up to 50 ms before the busy signal registers! 2ms? I have never observed it being that fast. The sound might actually start playing within that time, but the busy pin won't rise or fall that fast.


Secondly with reference to the repeat function.  An example is given where the repeat command is sent before the sound command is started.

The documentation states on page 18 that the repeat command repeats the sound that is currently playing so this example would not be expected to work if the documentation is right.

If I do it as teh documentation suggests then it seems to work; however if I follow the example then it does not work ever.  The only way I could see the example working is if the code was in a loop so that the repeat command was sent again before the sound ended.


Does anyone have any definitive experience of making the repeat command work reliably?

Your experiences/ comments on the above would be appreciated.
The documentation is right in this case. The code I posted before would only work for the reason you stated; if it's in a loop. To get repeat to work, you do have to send the repeat command immediately after you send the command to start playing a sound. I'm sorry I messed this up earlier, but I played with it tonight and it seems to work pretty well if you code it like this:

Code: [Select]

WT588D_Send_Command(0); //Play sound 0
WT588D_Send_Command(0xF2); //Repeat sound


However, the next time you send a command to play a sound, it'll play normally one time through unless you again send the 0xF2 command to make it loop. I mistakenly thought this was a toggle type function to turn looping on and off, but it's not apparently. It only applies to whatever is playing at the time you sent the loop command. I hope that helps.

Canobi

Thanks for all the tips and help your giving us @JakeSoft :)


One thing I need some clarification on is pin output voltages.

If an arduino is running at 5v, does it output 5v to its pins (assuming they're set to output).

I'd like to run the flicker LED from pin 5 so will need to add a resistor for it if it does.

RTPfan

Hi Jakesoft,

Thanks for the reply about the delay.  I suspected the timing diagram was wrong.  Interestingly I only get 24mS and haven't seen longer delays but I will look out for that.

Thanks for clarifying about the repeat function.

Have you found it to be reliable?  The reason I ask is that I have two parts of my code that repeat the idle hum sound.  One when it goes from powerup to idle.  The second when it goes to clash and then drops back to idle.

The first one works fine.  The second one does not repeat yet the code is identical!  I started to wonder if it was a toggle (so first turned it on and second was turning off) hence the reason for my question. But you confirming that I need to issue the repeat command during playback of the sound I want repeated means no toggle.

Now I am wondering if I have a longer delay sometimes so the repeat is issued before the sound has started playing so the repeat command is not enabled.



Hi Canobi,

With respect to your flickering circuit.  Looking at it you may have trouble with the MOSFET.  The VGSon may not be satisfied and it may not turn on properly or at all.  That may be helped by having the resistor and the LED both on the drain side. You still could have a voltage drop across the flicker LED that might make still cause grief.

In any case, while the flickering LED is an ingenious idea, I would suggest it is better to do it in the software.  It gives you more flexibility as having it done in hardware locks you in to it always flickering the way the chip wants.

Related to that, has anyone tried these to drive the LEDs? ( http://www.ebay.com/itm/161807194247 )
You can parallel them (two for 700mA) and they are more efficient than a resistor MOSFET combination.  They are specifically designed for driving LEDs from an 18650 working efficiently to hold brightness as the voltage drops from a fully charged 4.2V.  Nice and small space saving solution.  I understand that you just need to PWM the power pin directly from a port pin.  Mine have just arrived and I am yet to try them.






JakeSoft

#81
Oct 31, 2015, 01:26 am Last Edit: Oct 31, 2015, 01:27 am by JakeSoft
Thanks for all the tips and help your giving us @JakeSoft :)


One thing I need some clarification on is pin output voltages.

If an arduino is running at 5v, does it output 5v to its pins (assuming they're set to output).

I'd like to run the flicker LED from pin 5 so will need to add a resistor for it if it does.

No problem. I just hope I get to see some YouTube videos of all of your creations. I'll consider that a fine reward. :-)

I'm not sure how you're planning to run it, but if you're doing the standard Luxeon/Cree high-powered LED route, you won't power that directly from an Arduino pin anyway. Not enough current will be available to drive the LED. You'll need a MOSFET or a PEX from TCSS.

Canobi

#82
Oct 31, 2015, 01:43 am Last Edit: Oct 31, 2015, 01:47 am by Canobi
Ah well, PWM it is then. Thanks for the info RTPfan.


@JakeSoft

Was inquiring about voltages for the flicker LED, the blade LED is powered directly from the battery.

billpealer

#83
Oct 31, 2015, 04:52 am Last Edit: Nov 03, 2015, 05:43 am by billpealer
finally. i had like 2 a ha moment.  one is,. that i HATE coding,..  i thought Flash Action script and MEL was bad,..  I get an F- i C++
But, alas,..  my parents said i can do anything,. and my 5 year old pat me on the back last night and siad,. "But Dad, you told me Pealer's never give up."
i cracked it.

i dont know how i did it,.  but i turned the sound module 180 degrees when moving it from one bread board to another.  looked good on the board,.  100%  broken. Do'h!

Illuis's code used a different SCL naming convention, that i did not catch,..  arduino did tho.

this works,..    anyone can use it,..  make sure you configure the sound uploading module to  edge trigger.

videos to come...  if you don't know how to make buttons trigger functions,..   billpealer at yahoo dont com.  either way i will upload the final,.the updated button code,.. the line diagram, and full video in 2-3 weeks.     i also want to add, that a $15 sound module in a star wars walmart light saber is dang near the same thing as this...  just add the mosfet/2w LED and better 2w speaker to that and the Custom Saber Shop Sabers are good to go.

Code: [Select]
#define WT588D_SCL 9 //Module pin "P03" or pin # 10
#define WT588D_BUSY 10 //Module pin "LED/BUSY" or pin # 15

byte file_count = 1;

void setup() {

 
 pinMode(WT588D_SCL, OUTPUT);  
 pinMode(WT588D_BUSY, INPUT);  
 

}


void loop()
{
 WT588D_Send_Command(0x02);  //blade on with looped hum for 80 seconds. if you dont swing for 80 seconds, why is it on?
 delay(1500); //delay for testing  waiting for buttons from china.

 WT588D_Send_Command(0x01); //swing sound with 80 seconds of hum
 delay(1000);
 WT588D_Send_Command(0x01); //one more swing sound 'cause it sounds cool
 delay(1000);
 WT588D_Send_Command(0x00); //powerdown sound, no hum loop. der.. its off.
 delay(4500);

 delay(200);

}


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

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

   digitalWrite(WT588D_SCL, HIGH);
   delay(100);
} //END

billpealer

#84
Oct 31, 2015, 05:11 am Last Edit: Nov 03, 2015, 05:44 am by billpealer
I still don't know how Sugarbombs and Illuis got what they got,.. when the documentation of the Wt588Du has this to say about one/three line serial C code.

Code: [Select]
Send_oneline(unsigned char addr)
{      unsigned char i;      SDA=0;      
delay1ms(5);         /* delay 5ms */      
for(i=0;i<8;i++)          {SDA=1;          
if(addr & 1)             {delay100us(6);      
/* 600us */              SDA=0;            
delay100us(2);       /* 200us */        }              
else {              delay100us(2);     /* 200us */            
SDA=0;              delay100us(6);       /* 600us */  }    
addr>>=1;

}           SDA=1; }



they took the above and translated it into,..

void WT588D_Send1(byte addr) {
   digitalWrite(wt_scl, LOW);
   delay(5);

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

   digitalWrite(wt_scl, HIGH);
   delay(100);
}


WHAT THE @#$%^

is the an online gibberish translator you guys are holding out on here?

RTPfan

@Canobi

An arduino output should be able to drive a flicker LED.  I would imagine it would be < 20ma but you should look on the LED data sheet.

A problem may be that the MOSFET gate is a voltage driven element and there may be insufficient current to operate.  You make be relying on leakage currents.

I would guess you would might need a (1K??) resistor between the gate and the source (ie to Vbat) of the (P channel??) MOSFET.  Then reverse the flicker LED and drive it active low.

Whether this might work depends upon a couple of things like the voltage drop of the flicker LED, value of VBat and VGSon for the MOSFET.  You haven't given that information so it is hard to say .......

Still if it works well as you have it drawn then the answer is that, subject to the flicker LED data sheet that the current is <20ma an arduino pin should be fine.



Canobi

Ah yes, sorry about the lack of info, it's a slight failing of mine so I'll shed some light on things.

The mosfet is an FDN327N which is rated for 2A. The gate threshold is .4v ~ 1.5v (max saturation is 8v) and according to the datasheet it only draws 250uA. This last bit might be a misunderstanding on my part, but that was all I could find regarding how much current the gate sources.

The flicker LEDs I went for are the red ones which have a Vf of 2.2v @25mA. I chose them as they had the closest working Vf to the gate threshold.

My thoery is that since the arduino is 5v and the pins sink 20mA it should work as I'd only need to drop a few Vs for the LED and it would pass enough current through to the gate for it to operate.

I have a bunch of those fets so I can use one as a guinea pig to test the theory out when the flicker LEDs arrive.

I can also use the experiment to help nail the pad design for the LED as I need to turn it into an SMT component. It'll sit right under the arduino so it can't go through hole like it was meant to and necessity is the mother of invention as they say.....

Canobi

It has occured to me that the flickering will effect the fade in/out function, which just wouldn't look right.

My first thought on how to get round this problem is to use a second pin that bypasses the flicker LED:



All well and good, but how does one name a second led pin when declaring its function?

For the flicker LED I have:

int ledPin = 5;     // flicker led to mosfet gate


Is it as simple as naming another pin as a led pin (eg.  int ledPin = 6; )and then just call that number when it's wanted?

billpealer

#88
Nov 02, 2015, 09:36 pm Last Edit: Nov 03, 2015, 05:46 am by billpealer
I just read the comments.  And did my best to digest them.  Thanks JakeSoft. I don't think in code. as it probably is clear.
I am having replay stutter.  I think it is because the button playback is in void loop and it is cycling like mad.

I do have 2.2 questions?

I do not have this in my code "digitalWrite(WT588D_SCL, HIGH);"

1a. does it matter what pin number i use on the arduino for the SDA / SCL pin? and the comment that the "WT588D_SCL" need be changed to "...SDA" in my code?  I don't have SCL set to HIGH in the setup. As is your SDA. and Illuis's code uses SCL as a name, you use SDA,..  would a rose by any other name, not smell as sweet?  So it is not a critical change, just for standard naming right? i like to use the word button, i see a lot of "switchPin" in code or outPin, where as i use "LED".

If i need pinMode(WT588D_SCL, HIGH); in set up,..
1b. Why?

Code: [Select]


//my code
#define LED 13
#define LED2 12
#define WT588D_SCL 9 //Module pin "P03" or pin # 10
#define WT588D_BUSY 10 //Module pin "LED/BUSY" or pin # 15
#define button 7             //the on-off button
byte file_count = 1;

void setup() {

 
pinMode(WT588D_SCL, OUTPUT);  
pinMode(WT588D_BUSY, INPUT);
pinMode (button, INPUT_PULLUP);


}
// end my code


when i run a void loop with the WT588d's function

example: all the above plus this below.

void loop()
{
WT588D_Send_Command(0x02);
delay (1234);
}

it plays, and delays. and repeats.



also,
when i use a standard button command.
void loop()
{
if(button == HIGH)
{WT588D_Send_Command(0x02);  //blade on

}  //end


It works when i press the button, but just plays rapidly. it is akin to me rapid tapping the button if it was in key mode.   But i only hit the toggle button once. I know it is cycling thru the void loop.  If i use the switch Boolean code,. it wouldn't let me treat the send_command as it does an LED state.
Code: [Select]
// Boolean
void loop()
{
reading = digitalRead(button);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
  if (state == HIGH)
    state = LOW;
  else
    state = HIGH;

  time = millis();    
}

digitalWrite(LED, state); // turns off LED2, and on LED pin 13 and signal to mosfet

digitalWrite(LED2, !state);  // turns off LED and on LED pin 12 just to show the toggle works

previous = reading;

if (state)
WT588D_Send_Command(0x02); // on sound
else (!state)
WT588D_Send_Command(0x00); // off sound
}
}  //end


i can make buttons trigger LED pins using the Boolean and debounce, but i can't seem to ge tit to jive with making a button trigger the statement or function of what ever the thing is that "WT588D_Send_Command(0x02);" is.   i was under the impression that it was a function, but after hours of reading and now dreaming in gibberish arduino code,  i am now leaning toward that it is a statement.

googling "buttons run functions or statements arduino"

has born no fruit.  gets me to the same 3 tutes  that do not apply to this.

JakeSoft

I do not have this in my code "digitalWrite(WT588D_SCL, HIGH);"

1a. does it matter what pin number i use on the arduino for the SDA / SCL pin? and the comment that the "WT588D_SCL" need be changed to "...SDA" in my code?  I don't have SCL set to HIGH in the setup. As is your SDA. and Illuis's code uses SCL as a name, you use SDA,..  would a rose by any other name, not smell as sweet?  So it is not a critical change, just for standard naming right? i like to use the word button, i see a lot of "switchPin" in code or outPin, where as i use "LED".
The name change is not critical, it's just that it's generally a good idea to name variables something meaningful that reflects what the really are. As your projects start to grow in complexity this becomes important otherwise it's hard to understand what is going on when you read your code and especially difficult for anyone else to understand. That makes it hard for anyone to help you. For example, if I had a motor wired to open a door on pin 5, what makes more sense "DoorMotorPin" or "WindowArmPit"?

SCL means "serial clock" in 3-line serial mode however it has no meaning in one-line serial mode for the WT588D. The SDA is "serial data", which is what the pin is really doing.

It doesn't matter what Arduino pin you use for SDA so long as the other end is plugged into the right pin on the WT588D module.

If i need pinMode(WT588D_SCL, HIGH); in set up,..
1b. Why?
This guarantees that the pin is an a known state when the loop starts. 

Go Up