Go Down

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

MAS3

Hey Rob, welcome.

This thread has become a book by now, that's true.
But it is a book that shows the development of some different ways to build sabers.
So i'd say your best approach to this, is to read all of it.
Just read and keep reading.
Once you're done start over again and you'll recognize how (and why) things have developed in this thread over time.
This will help you deciding on what version you want to build, and perhaps improve something or make it more to your linkings.

It will be very welcome for you to show your deviations, combinations and improvements in this thread, if any, so others can benefit from it too just like you will benefit from every singe post in this thread.

Lots of success !
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Gunner89

Hello guys!

I'm doing a Basic Arduino Lightsaber, and im using
-MPU9250
-Clash Sensors Ky-002 , Ky-031
-MicroSD card module

But i got a problem with my clash section, most of the time my sensors doesn't activate the clash sound, i mean they dont seem to be reacting when i hit them but they ocassionally do react.

Here is my code, hope you can help me with this :/

Code: [Select]
#include <Adafruit_NeoPixel.h>
#include "MPU9250.h"
#include <Wire.h>
#include <TMRpcm.h>

#include <SPI.h>
#include <pcmConfig.h>
#include "SdFat.h"
SdFat sd;

#ifdef __AVR__
  #include <avr/power.h>
#endif


#define HANDLE_TAGS
#define rampMega
#define SD_ChipSelectPin 4     //define el pin para seleccionar la tarjeta SD
#define PIN            7
#define NUMPIXELS      1

Adafruit_NeoPixel pixels =
  Adafruit_NeoPixel(
    NUMPIXELS,
    PIN,
    NEO_GRB + NEO_KHZ800);

MPU9250 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

const int knockPin = 2; /////sensor de choque
int boton = 6;

int choque = 0;
int estado = 0;
int sword = 0;

int knockVal = HIGH; // This is where we record our shock measurement
boolean bAlarm = false;

unsigned long lastKnockTime; // Record the time that we measured a shock


int knockAlarmTime = 500;


int minSwing = 10000;

TMRpcm tmrpcm;   //Se crea un objeto de la librería TMRpcm


void setup() {
               Wire.begin();
    //Begin Accelerometer Code
    // initialize serial communication
               Serial.begin(38400);
               accelgyro.initialize();

               sword = 0;

               pinMode(knockPin, INPUT);
               
               pinMode(boton, INPUT_PULLUP);        //Hemos eliminado R3
               pixels.begin();
               tmrpcm.speakerPin = 9; //Se define el pin en el que está conectada la bocina
               pinMode(10,OUTPUT);
             
  Serial.begin(9600);    //Se inicia la comunicación serial


   
 
  if (!sd.begin(4, SPI_FULL_SPEED)) { return;
  }else{ Serial.println("SD OK"); }

 
}



void loop() {
                estado = digitalRead(boton); //// la variable estado tendrá el mismo valor que tenga la entrada en, la cual es el pulsador que enciende /apaga el sable
               

               
if (estado == HIGH) {
  if (sword == 0) {  /// sección encendido espada
   delay (10);
    tmrpcm.setVolume(6);
    tmrpcm.play("pON2.wav");

   sword = 1;
   delay(150);
   pixels.setPixelColor(0, pixels.Color(0, 50, 0));
   pixels.show();
   delay(700);
goto tab;
}
else{ /// sección apagar espada
   delay(10);
   tmrpcm.setVolume(6);
   tmrpcm.play("pOFF2.wav");
   tmrpcm.loop(0);

   sword = 0;

   pixels.setPixelColor(0, pixels.Color(0, 0, 0));
   pixels.show();
   delay(2000);
}
}
else{ ////espada encendida-------------------------------------------------------------------------------------
  if (sword == 1) {
    tab:
    delay (150);
    tmrpcm.setVolume(6);
    tmrpcm.quality(0);
    tmrpcm.play("humXLL.wav",10);
    tmrpcm.loop(1);
   
    while(estado == LOW){
   delay(50);

        ///////////////sección choque

 delay (5);
 choque =  digitalRead(knockPin);///////caso de choque
if (choque == HIGH) {
      tmrpcm.setVolume(6);
      tmrpcm.play("clash2.wav");
      delay(460);
      goto tab;
goto tab;
}


 
//////Sección detección movimiento

    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    if((ax > 20000 && ax <= 25000) || (ay > 20000 && ay <= 25000))
   
         {
          delay(100);
          tmrpcm.setVolume(6);
          tmrpcm.quality(0);
          tmrpcm.play("swing4.wav");
          delay(460);
          goto tab;
         }
    if((ax < -20000 && ax >= -25000) || (ay < -20000 && ay >= -25000))   
         {
          delay(100);
          tmrpcm.setVolume(6);
          tmrpcm.quality(0);
          tmrpcm.play("swing6.wav");
          delay(460);
          goto tab;
         }
    if(( (abs(gx) > 29000 && abs(gx) < 35000) && (abs(gy) > 29000 && abs(gy) < 35000) ) ||
       ( (abs(gy) > 29000 && abs(gy) < 35000) && (abs(gz) > 29000 && abs(gz) < 35000) ) ||
       ( (abs(gx) > 29000 && abs(gx) < 35000) && (abs(gz) > 29000 && abs(gz) < 35000) ) )
         {
          delay(100);
          tmrpcm.setVolume(6);
          tmrpcm.quality(0);
          tmrpcm.play("swing8.wav");
          delay(460);
          goto tab;
         }
         


    delay (15);
    estado = digitalRead(boton);
}
  }
else {
   
delay(300);
}
}
delay(100);
}


Srry about my english :p

Protonerd

Do you use an interrupt capable pin to read your clash sensor? Is it a mechanical one?

fedetanga

Hi, which type of batteries do you use to power up a basic saber with arduino nano and wt588D?

JakeSoft

Hi, which type of batteries do you use to power up a basic saber with arduino nano and wt588D?
If you are using a Nano, I'd recommend 7.4V Lithium Ion Battery. If you power the Nano via the RAW pin, you'll be able to get a regulated 5 volts and 3.3 volts from the Nano and use those to power your WT588D. Disclaimer: Your sound might still be weak unless you power your WT588D's VDD pin with a stronger 5 volt supply. However, I've seen some users (mainly Bill Pealer) using that method with some success. Try it on a breadboard first until you find something that works.

jenga67

#1355
Feb 06, 2018, 03:45 pm Last Edit: Feb 06, 2018, 03:55 pm by jenga67
Hi guys!

A quick question, do you think this power setup would be ok to run homebrew on Nano through USB,
DFPlayer and LED through an additionaly added connectors from before the dc-dc (3.7v)?

Power bank 5V 1A

Would be nice to read your opinion.

maximiliam

Helo jedis
I have this error msg when compiling


Arduino 1.8.5



"file included from /home/max/Arduino/libraries/USaber/motion/ADXL335MotionManager.h:28:0,
                from /home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:24:
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'LinkedList<T>::LinkedList() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:30:102:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:101:6: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 root=false;
     ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:102:6: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 last=false;
     ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'LinkedList<T>::~LinkedList() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:30:102:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:121:7: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 last = false;
      ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'bool LinkedList<T>::add(T) [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:102:36:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:192:12: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 tmp->next = false;
           ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'T LinkedList<T>::pop() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:279:14:   required from 'T LinkedList<T>::shift() [with T = AxisData]'
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:108:24:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:248:13: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  tmp->next = false;
            ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:256:8: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  root = false;
       ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:257:8: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  last = false;
       ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'ListNode<T>* LinkedList<T>::getNode(int) [with T = AxisData]':
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:312:34:   required from 'T LinkedList<T>::get(int) [with T = AxisData]'
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:143:44:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:158:9: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 return false;
        ^
/home/max/Arduino/libraries/USaber/DIYinoSoundSerial.cpp:367:6: warning: always_inline function might not be inlinable [-Wattributes]
void DIYinoSoundSerial::setRxIntMsk(bool enable) {
     ^
/home/max/Arduino/libraries/USaber/StringBlade.cpp: In member function 'StringBlade::PowerUp(int)':
/home/max/Arduino/libraries/USaber/StringBlade.cpp:98:32: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
  analogWrite(mChannelPins[lPin], 255);
                               ^
/home/max/Arduino/libraries/USaber/StringBlade.cpp:96:2: note: containing loop
 for(int lPin = 0; lPin <= 6; lPin++)
 ^
O sketch usa 5440 bytes (17%) de espaço de armazenamento para programas. O máximo são 30720 bytes.
Variáveis globais usam 564 bytes (27%) de memória dinâmica, deixando 1484 bytes para variáveis locais. O máximo são 2048 bytes.
Biblioteca inválida encontrada em /home/max/Arduino/libraries/DFplayer: /home/max/Arduino/libraries/DFplayer"

JakeSoft

#1357
Feb 11, 2018, 03:29 am Last Edit: Feb 11, 2018, 03:33 am by JakeSoft
Helo jedis
I have this error msg when compiling


Arduino 1.8.5


Code: [Select]

"file included from /home/max/Arduino/libraries/USaber/motion/ADXL335MotionManager.h:28:0,
                from /home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:24:
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'LinkedList<T>::LinkedList() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:30:102:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:101:6: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 root=false;
     ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:102:6: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 last=false;
     ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'LinkedList<T>::~LinkedList() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:30:102:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:121:7: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 last = false;
      ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'bool LinkedList<T>::add(T) [with T = AxisData]':
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:102:36:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:192:12: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 tmp->next = false;
           ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'T LinkedList<T>::pop() [with T = AxisData]':
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:279:14:   required from 'T LinkedList<T>::shift() [with T = AxisData]'
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:108:24:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:248:13: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  tmp->next = false;
            ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:256:8: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  root = false;
       ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:257:8: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
  last = false;
       ^
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h: In instantiation of 'ListNode<T>* LinkedList<T>::getNode(int) [with T = AxisData]':
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:312:34:   required from 'T LinkedList<T>::get(int) [with T = AxisData]'
/home/max/Arduino/libraries/USaber/ADXL335MotonManager.cpp:143:44:   required from here
/home/max/Arduino/libraries/USaber/motion/../support/LinkedList.h:158:9: warning: converting 'false' to pointer type 'ListNode<AxisData>*' [-Wconversion-null]
 return false;
        ^
/home/max/Arduino/libraries/USaber/DIYinoSoundSerial.cpp:367:6: warning: always_inline function might not be inlinable [-Wattributes]
void DIYinoSoundSerial::setRxIntMsk(bool enable) {
     ^
/home/max/Arduino/libraries/USaber/StringBlade.cpp: In member function 'StringBlade::PowerUp(int)':
/home/max/Arduino/libraries/USaber/StringBlade.cpp:98:32: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
  analogWrite(mChannelPins[lPin], 255);
                               ^
/home/max/Arduino/libraries/USaber/StringBlade.cpp:96:2: note: containing loop
 for(int lPin = 0; lPin <= 6; lPin++)
 ^
O sketch usa 5440 bytes (17%) de espaço de armazenamento para programas. O máximo são 30720 bytes.
Variáveis globais usam 564 bytes (27%) de memória dinâmica, deixando 1484 bytes para variáveis locais. O máximo são 2048 bytes.
Biblioteca inválida encontrada em /home/max/Arduino/libraries/DFplayer: /home/max/Arduino/libraries/DFplayer"

I just installed 1.8.5 IDE and pulled the latest USaber from GitHub. I was able to build the ADXL335 motion example sketch and the DIYino example saber sketch. Can you tell us what sketch you are trying to build when this happens?

Also, USaber is only officially supported on Windows. If you are using Mac or Linux you are in uncharted territory. I'll do my best to help, but I have no way to test on other platforms at present.

Gunner89

Do you use an interrupt capable pin to read your clash sensor? Is it a mechanical one?
I use the pin 2 on my Arduino One for my clash sensor SW-18020P

JakeSoft

#1359
Feb 12, 2018, 04:09 am Last Edit: Feb 12, 2018, 04:17 pm by JakeSoft
I use the pin 2 on my Arduino One for my clash sensor SW-18020P
Code: [Select]

loop ()
{
...
choque =  digitalRead(knockPin); //DON'T DO THIS HERE!
if (choque == HIGH) {
      tmrpcm.setVolume(6);
      tmrpcm.play("clash2.wav");
      delay(460);
...
}


The above code is your problem. You are using an interrupt-capable pin, but you never set up an ISR (interrupt service routine). So, your code is only polling for the status of that pin periodically. The reason it works only sometimes is that the pulse from the clash switch is very fast. Sometimes you'll catch it, sometimes you won't. If you set up an interrupt, you'll never miss it.

You should research how to use the attachInterrupt() function.

MissNewtype

#1360
Feb 21, 2018, 11:00 am Last Edit: Feb 21, 2018, 11:16 am by MissNewtype
Heya, I'm using an Arduino Nano, an MPU6050, and a DFPlayer Mini. I'm using LightsaberOS. I've got my MPU6050 calibrated via the script.

I've got all three wired up and programmed, but I'm kinda stumped at where to go from here. Which pins do I wire my two momentary switches to?

Second question/issue, I plan on using Luxeon Star LED's, and a couple RGB Stars, but I haven't got a clue how to wire them into the circuit. Do I need a mosfet of some sort to control the LED, or is it wire in with a resistor situation?

I plan on using one or two 2600 maH 18650's and a charging module that outputs 5v to power the entire thing.

Thanks!!


Edit: Upon examining the schematic on their GitHub, I've discovered the switches go to D12 for the main switch, and D4 for the secondary switch.

I've still got no clue when it comes to using Star/Luxeon LED's, or RGB Stars.

jbkuma

LightsaberOS has evolved into FX-SaberOS which is available here:
https://github.com/Protonerd/FX-SaberOS

I have posted a number of wiring diagrams in the wiki that should help.  You don't need to switch to use the diagrams since we directly evolved FX from LSOS, but there are a lot of new features and refinements you might enjoy.

jenga67

#1362
Feb 23, 2018, 02:52 pm Last Edit: Feb 23, 2018, 02:59 pm by jenga67
Hello everyone!

I have a question, what do you guys think about an 3d printed ABS (plastic) Modular hilt system?

I am in a process of 3d-modeling and printing such a system for my own use, but I also think it could be used in the wider range going forward.

Would you consider using a plastic modular system? Maybe you know someone who is already doing this?

Will get my first test prints next Thursday, I can share how it turned out if you are interested.

jbkuma

Hello everyone!

I have a question, what do you guys think about an 3d printed ABS (plastic) Modular hilt system?

I am in a process of 3d-modeling and printing such a system for my own use, but I also think it could be used in the wider range going forward.

Would you consider using a plastic modular system?
I've seen such things on Thingiverse before. I've been printing shells that I put over an aluminum core

Protonerd

I was (am?) contemplating a modular chassis system, I just need to figure out how to put threads to cylindrical objects... I have a basic module already on Thingiverse fitting to my Stardust boards, and I want to add different extensions, like USB breakout (w/mini and micro + charge indication LED hole), speaker holder, one to hold a crystal etc.

On top of that I also will make a 3D printed clamp box (-like thing) to house the buttons for one of my old MHS hilts. So plenty of ideas to realize with a 3D printer :)

Go Up