Arduino Lightsaber

Hi everyone!
First of all, thanks for the inspiring amount of information contained in this thread, you guys have been doing an amazing job!

I'm joining the ranks of those building their own lightsaber, and I have the circuit mostly done, quite similarly to how many of you guys have done it (Arduino Pro Mini 3.3v, adxl335, wt588d-u controlled with a 1-wire configuration, RGB LED controlled via 3 MOSFETs, one 18650 battery with TP-4056 protection/charging circuit). The software is mostly based on Jakesoft's USaber library.

Everything works nicely as long as I test the components one by one (in a configuration Arduino + component). And it still works when I put everything together, as long as I power the wt588-u via USB from my PC.
But as soon as I power the wt588-u with the same battery as the rest of the circuit, a lot of noise starts to appear on the readings of the adxl335, continuously triggering false swings and clashes, even if the sensor is perfectly still.

Note that when I say I power the wt588-u with a battery, I mean I tried every possible way of powering it I could think of:

  • 3.3v on VCC and VDD from the arduino
  • 3.3v on VCC and VDD from a dc-dc converter
  • 5v on VDD via a step-up converter
  • 5v on VDD-USB via a step-up converter
  • USB cable, from the battery via a step-up converter with USB out.

Notice that I have tried two differernt adxl355 and two different wt588-u, so it is not an issue of a single component.

Also, simply adjusting the thresholds does not work, because the false readings I get when I turn on the sound are higher than what is detected as a the strongest swing when the sound is off: I would have to hit the sensor very hard to get any reading at all, at those levels.

At this point I am seriously considering switching to a different sensor, or a different audio player, but I'd rather avoid it if at all possible, given that it would likely take a couple months for them to be delivered.

Has any of you experienced anything similar and do you guys have any suggestion on how to get stable readings from the sensor?

mikyt:
But as soon as I power the wt588-u with the same battery as the rest of the circuit, a lot of noise starts to appear on the readings of the adxl335, continuously triggering false swings and clashes, even if the sensor is perfectly still.

Has any of you experienced anything similar and do you guys have any suggestion on how to get stable readings from the sensor?

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?

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.

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

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

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.

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.

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 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

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

Arduino Lightsaber - Exhibition / Gallery - Arduino Forum

All your questions are answered if you are willing to research this site: GitHub - Protonerd/FX-SaberOS: System code for Arduino based Lightsaber replicas for DIYino family boards

Hi Jake,
first of all, thanks for your reply. Sorry for "ignoring" it: I somehow completely missed it.

JakeSoft:
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

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.

Protonerd:
All your questions are answered if you are willing to research this site: GitHub - Protonerd/FX-SaberOS: System code for Arduino based Lightsaber replicas for DIYino family boards

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

JakeSoft:
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

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: Hum sound in last foundfont slot not playing · Issue #85 · Protonerd/FX-SaberOS · GitHub

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

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!

jenga67:
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.

jbkuma:
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.

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 (Adafruit Feather nRF52 Bluefruit LE [nRF52832] : ID 3406 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits), 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.

The latest on S.T.R.E.A.M.

Like this video for a free upgrade:

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: GitHub - JakeS0ft/STREAM: STREAM GUI and documentation

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:

One of the tutorials I was using for the Adafruit soundboard was here:

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

Hi,

I see this excellent program and update it's great work !

but i have two problem with json error -> arduinojson 5 to arduinojson6 have you update code ?

and see for two variator potentiometer rv1 500k and rv2 100k how setting this please ? no oscillator

difference between 3002/6002 and 9032 ? more pcb stable ?

now i build this pcb (3002/6002) and it run (without json part program and no testing call for now)

Thanks !

Newest development from Jake and myself is the XStream running on a DIYino Infinity, here is the first shot at dynamic swing sound:
OmiSwing demo1

It is based on Jake's sound library made for the nRF52 BLE core, which is at the heart of the Infinity.

More saber and IoT awesomeness soon!

Hi Protonerd, it looks super cool!

Are you planning to start selling infinity boards any time soon?