Go Down

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

JakeSoft

If this video gets enough likes, I'll unlock multi-font support in the free version of STREAM. Watch until the end for details!

S.T.R.E.A.M. is Free Video


Protonerd

This is definitely a stellar Episode of the Arduino Saber Story!!! I already did my homework, at home 4 sabers are now running the S.T.R.E.A.M. show and every time I ignite it, it is another time to be amazed. I definitely contribute to those sound profile extensions

MrDoggss

#1442
Mar 23, 2019, 07:32 am Last Edit: Mar 23, 2019, 07:37 am by MrDoggss
I've been following this thread for a long time, and am happy to see people still posting.  Figured I would post my latest, since it's based on Jakesoft's OP.

LED string blade is coming along, and I'm starting work on the hilt.  The biggest progress I have made is the electronics. After doing some testing, and ordering parts (still need more parts...)  here is what I did.

I designed a board, and had it made.  1st try at this, and it shows.  It works, and now I just need to solder IC sockets and connect wires. Nothing special, but not bad for a prototype.







JakeSoft

I've been following this thread for a long time, and am happy to see people still posting.  Figured I would post my latest, since it's based on Jakesoft's OP.

LED string blade is coming along, and I'm starting work on the hilt.  The biggest progress I have made is the electronics. After doing some testing, and ordering parts (still need more parts...)  here is what I did.

I designed a board, and had it made.  1st try at this, and it shows.  It works, and now I just need to solder IC sockets and connect wires. Nothing special, but not bad for a prototype.

Hey, that's pretty cool. It's a brew-board for my original design! There was a guy "Canobi" who did something similar quite some time ago. (I'm not sure what happened to him or his inventions; we haven't heard from him in a long time.)

Does your board assume 3-wire or 1-wire serial for the WT588D? What are you using for the software? It's exciting to see some new stuff.

Chevyrwicked

I have been seeking full Arduino code for lightsaber. all I see all your file is random code and I couldn't understand how to put it together at all. this pic below is what connected right now without mos regulator. but I have step down dc to dc inverter.  I have 5 file loaded to wt588d-u for 00h file for one line mode (001 lightsaberpulse.wav, 002 ltsaberswing05.wav, 003 ltsaberhit01.wav, 004 ltsaberon01.wav, 005 ltsaberoff01.wav). is there any way how I code Arduino for this design I have now?

thanks
rob

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

Protonerd

I have been seeking full Arduino code for lightsaber. all I see all your file is random code and I couldn't understand how to put it together at all. this pic below is what connected right now without mos regulator. but I have step down dc to dc inverter.  I have 5 file loaded to wt588d-u for 00h file for one line mode (001 lightsaberpulse.wav, 002 ltsaberswing05.wav, 003 ltsaberhit01.wav, 004 ltsaberon01.wav, 005 ltsaberoff01.wav). is there any way how I code Arduino for this design I have now?

thanks
rob

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

All your questions are answered if you are willing to research this site: https://github.com/Protonerd/FX-SaberOS

mikyt

#1446
Apr 02, 2019, 10:15 pm Last Edit: Apr 02, 2019, 10:20 pm by mikyt
Hi Jake,
first of all, thanks for your reply. Sorry for "ignoring" it: I somehow completely missed it.

Welcome!

Your setup sounds very similar to what I used for my Mk. III saber. The only difference is that I used the 16-pin version of the WT588D. I did not experience the same issue you describe, however I seem to recall others saying they have. Maybe I just got lucky. What kind of battery are you using?
I'm using a 3.7v 18650 LiPo battery, and a step-up converter to bring it to 5v.
I have tried powering the WT588D chip in any possible configuration I could think of, with 5v or 3.3v, coming from either the Arduino or a variety of set-up/-down converters drawing power directly from the battery. All to no avail

Quote
One  possibility is that you have an EMI problem with the power to your ADXL335 where having the sound active is introducing noise and causing your readings to go crazy.  To test this, try adjusting the volume of the sound to a really low number while monitoring your sensor and see if the readings level out. (use the SetVolume() function on the WT588DSoundPlayer). If the readings become stable at low volume, you may need to introduce a decoupling capacitor somewhere in your circuit to smooth out power delivery. 
I had independently come to the same hypothesis about the noise. I haven't tried lowering the volume, but I had started experimenting with various capacitors in various positions.
In the end I figured that the noise travels along the data connection (I'm unsing the 1-wire protocol) between the arduino and the sound chip. If I unplug that cable while a sound is already playing the noise disappears, the readings from the sensor become reasonable, and the noise in the sound disappears as well... and of course I cannot trigger new sounds, at that point, which is of course unacceptable.

The way I managed to make everything bearable was:
1) switching to a GY-521 as the sensor: it seems to be much more robust to noise
2) powering the WT588D chip with 5v from a step-up converter, and adding a 10uF, 50v capacitor in parallel the 5v, right next to the WT588D. This doesn't help with the noise on the data line, but at least reduces the noise I hear from the loudspeaker.


All in all, this works. Still, I'm a bit unhappy with it. I have just received a DFPlayer mini, and I'm experimenting with it to see if it behaves any better, before finalizing my build.

I'll try and send an update here when I know more.

Chevyrwicked

All your questions are answered if you are willing to research this site: https://github.com/Protonerd/FX-SaberOS

thanks for info tho and it took me a week to figure that link you provide to do the research. but I coded it for myself using wt588d-u and Arduino nano usb by those research and this is what I come up with below with the code and I tried my best when I push button. nothing work. but wt588d-u I have reprogrammed to key mode.

const int buttonPin = 10;     // the number of the pushbutton pin
const int ledPin =  1;      // the number of the LED pin
const int humPin = 2;
const int clashPin = 3;
const int swingPin = 4;
const int clash_sensorPin = 6;
const int swing_sensorPin = 7;
const int threshold = 100;

int buttonState = 0;         // variable for reading the pushbutton status
int sensorReading = 0;

void setup() {
 pinMode(buttonPin, INPUT); // button
 pinMode(ledPin, OUTPUT); // led
 pinMode(humPin, OUTPUT); // hum sound
 pinMode(clashPin, OUTPUT); // clash sound
 pinMode(swingPin, OUTPUT); // swing sound
 pinMode(clash_sensorPin, INPUT); // clash sensor
 pinMode(swing_sensorPin, INPUT); // swing sensor
 Serial.begin(9600);       // use the serial port
}

void loop() {

 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH) {
   // turn LED on:
   digitalWrite(ledPin, HIGH);
   digitalWrite(humPin, HIGH);
 } else {
   // turn LED off:
   digitalWrite(ledPin, LOW);
   digitalWrite(humPin, LOW);
 }
 sensorReading = digitalRead(clash_sensorPin);

 if (sensorReading >= threshold) {
   digitalWrite(clashPin, HIGH);
   Serial.println("clash!");
 }
 sensorReading = digitalRead(swing_sensorPin);

 if (sensorReading >= threshold) {
   digitalWrite(swingPin, HIGH);
   Serial.println("swing!");

 }
 delay(100);
}

MrDoggss

#1448
Apr 18, 2019, 11:22 pm Last Edit: Apr 18, 2019, 11:23 pm by MrDoggss
Hey, that's pretty cool. It's a brew-board for my original design! There was a guy "Canobi" who did something similar quite some time ago. (I'm not sure what happened to him or his inventions; we haven't heard from him in a long time.)

Does your board assume 3-wire or 1-wire serial for the WT588D? What are you using for the software? It's exciting to see some new stuff.

I used the 3 wire config for the WT588D.  Software wise, I will be honest, I have few versions saved and I'm not sure who created them. They are definitely from references somewhere in this thread though. Once I figure it out I will post credit for it. 

I'll have to modify whatever I use since I am running a Pro Mini with 2 main LED's. I am not a coder, so that could be interesting! lol

F4LL3N

#1449
Apr 20, 2019, 06:28 pm Last Edit: Apr 20, 2019, 08:52 pm by F4LL3N
Hi All, I'm working on my very first homemade Lightsaber, and I've decided to do it with FX-SaberOS.

For my build I'm using a home-brew (Arduino Nano) + MPU6050 + DFPlayer Mini. The DFPlayer is not a XY original one, but it does has a blue led and the white marks around the soldered parts, so I think it should work. For the power supply I'm using an old charger connected to the breadboard and connected to the VIN connector (the charger provides 6~7v).

The sketch version is latest from master, and I've configured to use the DIYino PRIME board, and STRINGLED (at least for testing, I haven't really decided which blade to use yet), and the sound founts used are the ones from the git repository, but I've only copied the "SF01_VanillaLyte", which is the soundfont I'm using.

So far, and after several retries, I've mange to get it working, well, most of it. I'm having a small issue with sounds. The sounds seems to be OK (though sometime it appears to me they get all mixed up, in those cases I just restart the board, and it starts OK), the problem is the blade ignition sound doesn't seems to finish, it gets stoped before, and there is no HUM nor swing sounds. In other words, you ignite the blade, then silence, press the main button and the blaster sounds, then silence... you shut the blade off, and then silence (actually that last one is OK hehe).

Can anyone give me a hand to find what could be happening? From what I've read some possible options are: the SD card format/copy problem, the fake DFPlayer, but I'd like to know if is there any other thing I could be missing here.

Thanks in advance!

Find attached a pic of my "first attempt" circuit.


EDIT: On a second thought, my problem might be related to this issue: https://github.com/Protonerd/FX-SaberOS/issues/85

Since I'm only using a single soundfont, my first soundfont is also my last one.

jenga67

Hi guys! I hope you all are well and doing some bits on lightsaber development here and there.

I recently saw a video about a smooth swing - a new thing for custom lightsabers.
Have any of you guys thought about how can smooth swing be implemented with Arduino?

Cheers!

jbkuma

Have any of you guys thought about how can smooth swing be implemented with Arduino?
A number of us have looked at various ways to do this with both hardware and software, but I don't think anyone has done it with an atmega328p based setup.  It would also take some wizardry to do with the external sound chips we typically use.  The best options revolve around using more advanced chips.  There is some development being done currently on nRF52 based and ESP32 based saber boards.  Nothing is currently publicly available for those yet though.

JakeSoft

#1452
Oct 13, 2019, 05:38 pm Last Edit: Oct 13, 2019, 05:53 pm by JakeSoft
A number of us have looked at various ways to do this with both hardware and software, but I don't think anyone has done it with an atmega328p based setup.  It would also take some wizardry to do with the external sound chips we typically use.  The best options revolve around using more advanced chips.  There is some development being done currently on nRF52 based and ESP32 based saber boards.  Nothing is currently publicly available for those yet though.
I did publish an audio library for nRF52 a few weeks ago.

https://github.com/JakeS0ft/nRF52Audio

It's not 100% ready for prime time, but anyone interested can take a look. The library assumes you are using the Arduino core for the Adafruit Feather nRF52 Bluefruit LE - nRF52832 (https://www.adafruit.com/product/3406), but could likely be ported to work with other cores. It features an ability to play back sounds a different rates (higher/lower pitch) as well as do ployphonic playback (multiple sounds playing at the same time). We are planning to use this to add dynamic swing to the DIYino Infinity boards. We still have a lot of work to do before we have a full saber sketch, though. 

JakeSoft

#1453
Dec 14, 2019, 09:54 pm Last Edit: Dec 20, 2019, 03:24 am by JakeSoft
The latest on S.T.R.E.A.M.

Like this video for a free upgrade:
https://youtu.be/B90S8di6p9g

For those who don't know, S.T.R.E.A.M. is the easy-button for a full featured DIY saber sound board. Just download the package from GitHub and everything can be done from a simple-to-use GUI. Its targeted hardware is Protonerd's DIYino system (Arduino Nano + MPU6050 + DFPlayer Mini).

Download it for free here: https://github.com/JakeS0ft/STREAM


mlbCubFan

#1454
Dec 23, 2019, 04:02 pm Last Edit: Dec 23, 2019, 04:09 pm by mlbCubFan
Hi there, it looks like you've received 97 pages or so of these types of messages, but I'm new to arduino and have been working on a lightsaber for about a month.  I'm trying to use the blade from the new Disney Galaxy's Edge lightsabers in my own custom made hilt.

I've been able to make the blade ramp up on, steady on, and ramp down off.

I've connected an MPU 6050 and been able to make it flash another color when moved or clashed.

But when I moved to sound it keeps playing the power on sound over and over again on loop.

I'd like to think there is a simple bug in my code that I'm missing because I'm a noob.  Otherwise maybe it is a short in my soldering.

I am using:

* Arduino Nano
* MPU 6050 gyro sensor
* Adafruit Audio FX SoundboardI w
* PAM 8302 amplifier
* Homemade PCB board with two resistors and pogo pins to interface with the Disney blade

The tutorials for how to interface with a Disney blade were found here:
https://www.youtube.com/watch?v=GTTxhPCvGb4
https://www.youtube.com/watch?v=YQRXhHM4Ixs

One of the tutorials I was using for the Adafruit soundboard was here:
https://github.com/sidlebj/ECE387Final/wiki

The Wiring was
Arduino 5V to Adafruit VIN and MPU VIN and Amp VIN and Blade VIN
Arduino Ground to Adafruit Ground and MPU Ground and  Amp Ground and Blade Ground
Arduino D2 to blade data
Arduino D3 to Adafruit trigger 0
Arduino D4 to Adafruit trigger 1
Arduino D5 to Adafruit trigger 2
Arduino D6 to Adafruit trigger 3
Arduino D7 to Adafruit trigger 4
Arduino D8 to a switch and then switch to ground
Arduino A4 to MPU SDA
Arduino A5 to MPU SCL
Adafruit Left channel to Amp A+
Adafruit audio ground to Amp A-




The code is below, thanks in advance for any help.

//For controlling a Savi's/Legacy Blade with Arduino

//Digital out needs to be 2.5V,
//So use voltage splitting on the 5V
//Digital out line of an Arduino

int resetCycle = 174500;
int restPeriod = 653;
int duty_cycle_length = 3600;
int digitalPin = 2;


// Setup toggle switch
boolean switchOn = 0;
int switchPin = 8;

// Setup sound ports
int soundon = 3;
int soundhum = 4;
int soundoff = 5;
int soundswing = 6;
int soundclash = 7;
 

#include <Wire.h>

long accelX, accelY, accelZ;
float gForceX, gForceY, gForceZ;

long gyroX, gyroY, gyroZ;
float rotX, rotY, rotZ;

long accelXp, accelYp, accelZp;
float gForceXp, gForceYp, gForceZp;

long gyroXp, gyroYp, gyroZp;
float rotXp, rotYp, rotZp;

long accelXd, accelYd, accelZd;
float gForceXd, gForceYd, gForceZd;

long gyroXd, gyroYd, gyroZd;
float rotXd, rotYd, rotZd;

float gForceT;

float rotXa, rotYa, rotZa;

float rotT;

void setup() {
 
  pinMode(switchPin, INPUT); //lightsaber switch code
  pinMode(digitalPin, OUTPUT); //blade data pin
  digitalWrite(digitalPin, HIGH);

  pinMode (soundon, OUTPUT);
  pinMode(soundhum, OUTPUT);
  pinMode(soundoff, OUTPUT);
  pinMode(soundswing, OUTPUT);
  pinMode(soundclash, OUTPUT);
 

boolean switchOn = false;

 
  Serial.begin(9600);
  Wire.begin();
  setupMPU();

  gyroXp = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX
  gyroYp = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY
  gyroZp = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ

  accelXp = Wire.read()<<8|Wire.read(); //Initializes accelerometer
  accelYp = Wire.read()<<8|Wire.read(); //
  accelZp = Wire.read()<<8|Wire.read(); //
}


void loop()
{
  recordAccelRegisters();
  recordGyroRegisters();
  processAccelData();
  processGyroData();
  printData();
  delay(125);

if (digitalRead(switchPin) == LOW && switchOn == false)
    {
        digitalWrite (digitalPin, LOW);
        switchOn = !switchOn;
        digitalWrite (soundon, LOW);
        delay (125);
        digitalWrite (soundon, HIGH);
        perform_animation(0x26);
        delay (125);
        digitalWrite (soundhum, LOW);
    }

if (abs(accelX) > 30000 || abs(accelY) > 30000 || abs (accelZ) > 30000)
    {
        digitalWrite (soundhum, HIGH);
        digitalWrite (soundclash, LOW);
        delay (125);
        digitalWrite (soundclash, HIGH);
    }

if ((abs(accelX) > 25000 && abs(accelX) <30000) || (abs(accelY) > 25000 && abs(accelY) < 30000) || (abs(accelZ) > 25000) && (abs(accelZ) < 30000))
  { 
  digitalWrite (soundhum, HIGH);
  digitalWrite (soundswing, LOW);
  delay (125);
  digitalWrite (soundswing, HIGH);
  }

 if (digitalRead (switchPin)==HIGH && switchOn ==true)
   {
     switchOn = !switchOn;
     digitalWrite (soundhum, HIGH);
     digitalWrite (soundoff, LOW);
     delay (125);
     digitalWrite (soundoff, HIGH);
   } 
   else {
     digitalWrite (digitalPin, HIGH);
     digitalWrite (soundhum, HIGH);
     }
}


void perform_animation(byte cmd){
  digitalWrite (digitalPin, LOW);
  delayMicroseconds(resetCycle);
  digitalWrite(digitalPin, HIGH);
  delayMicroseconds(resetCycle);
  digitalWrite(digitalPin, LOW);
  delayMicroseconds(resetCycle);

  for(int i= 7; i>= 0; i--){
    if(bitRead(cmd, i)){
      duty_cycle(.65);
    }else{
      duty_cycle(.33);
    }
  }

  digitalWrite(digitalPin, HIGH);
  delay(restPeriod);
}

void duty_cycle(float percentage){
  digitalWrite(digitalPin, HIGH);
  delayMicroseconds(duty_cycle_length * percentage );
  digitalWrite(digitalPin, LOW);
  delayMicroseconds(duty_cycle_length - (duty_cycle_length * percentage));
}




void setupMPU(){
  Wire.beginTransmission(0b1101000); //This is the I2C address of the MPU (b1101000/b1101001 for AC0 low/high datasheet sec. 9.2)
  Wire.write(0x6B); //Accessing the register 6B - Power Management (Sec. 4.28)
  Wire.write(0b00000000); //Setting SLEEP register to 0. (Required; see Note on p. 9)
  Wire.endTransmission(); 
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4)
  Wire.write(0x00000000); //Setting the gyro to full scale +/- 250deg./s
  Wire.endTransmission();
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5)
  Wire.write(0b00000000); //Setting the accel to +/- 2g
  Wire.endTransmission();
}

void recordAccelRegisters() {
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x3B); //Starting register for Accel Readings
  Wire.endTransmission();
  Wire.requestFrom(0b1101000,6); //Request Accel Registers (3B - 40)
  while(Wire.available() < 6);
  accelX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX
  accelY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY
  accelZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ
  processAccelData();
}

void processAccelData(){
  gForceX = accelX / 16384.0;
  gForceY = accelY / 16384.0;
  gForceZ = accelZ / 16384.0;

  gForceXp = accelXp /16384.0;
  gForceYp = accelYp / 16384.0;
  gForceZp = accelZp / 16384.0;

  gForceXd = gForceX - gForceXp;
  gForceYd = gForceY - gForceYp;
  gForceZd = gForceZ - gForceZp;

  gForceT = gForceXd + gForceYd + gForceZd;

  gForceXp = gForceX;
  gForceYp = gForceY;
  gForceZp = gForceZ;

}

void recordGyroRegisters() {
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x43); //Starting register for Gyro Readings
  Wire.endTransmission();
  Wire.requestFrom(0b1101000,6); //Request Gyro Registers (43 - 48)
  while(Wire.available() < 6);
  gyroX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX
  gyroY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY
  gyroZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ
  processGyroData();
}

void processGyroData() {
  rotX = gyroX / 131.0;
  rotY = gyroY / 131.0;
  rotZ = gyroZ / 131.0;

  rotXp = gyroXp / 131.0;
  rotYp = gyroYp / 131.0;
  rotZp = gyroZp / 131.0;

  rotXd = rotX - rotXp;
  rotYd = rotY - rotYp;
  rotZd = rotZ - rotZp;

  rotXa = fabs (rotXd);
  rotYa = fabs (rotYd);
  rotZa = fabs (rotZd);

  rotT = rotXa + rotYa + rotZa;

  rotXp = rotX;
  rotYp = rotY;
  rotZp = rotZ;

}

void printData() {
  Serial.print("Gyro (deg)");
  Serial.print(" X=");
  Serial.print(rotX);
  Serial.print(" Y=");
  Serial.print(rotY);
  Serial.print(" Z=");
  Serial.print(rotZ);
  Serial.print(" Accel (g)");
  Serial.print(" X=");
  Serial.print(gForceX);
  Serial.print(" Y=");
  Serial.print(gForceY);
  Serial.print(" Z=");
  Serial.println(gForceZ);
  Serial.println("Total G's=");
  Serial.println(gForceT);
  Serial.println("Total degrees=");
  Serial.println(rotT);
}

Go Up