Welcome to Open Saber
The goal of open saber is provide source code, circuit diagrams, and documentation for making an Arduino (and compatible) based lightsaber. The focus is on the internals of the saber, not how to build the case.
Why? For the joy of the problem, working together, and learning / playing with Arduinos. There are certainly commercial solutions to saber electronics, but if you want to build and contribute to the code and internals, this site is for you!
The information and documentation assume a basic knowledge of Arduinos, electronics, soldering, etc.
In 2017, the design switch from through hole components, which have wires and can be fairly easily hand soldered, to SMD components, which need to be flow soldered in an oven. The current code uses only the SMD approach. If you are interested in the through hole approach, check out the source at FIXME
The Open Saber site / repo is 3 things:
An Open Saber electronics in action here: https://youtu.be/9_-Rfe4UBJM.
There are over 5 working sabers on the OpenSaber design with cases by SaberZ, UltraSabers, TCSS v1, and SaberForge ASP.
The version number - as much as it is consistent - references the PCB board. The PCB board is called a "shield" because it sits on top of a Teensy Microcontroller.
I use the largest possible SMD components to make it as straightforward as possible for a human to solder. They are still small.
Generally speaking the shields sit on a Teensy 3.5. You can also use a Teensy 3.2, but you need to connect an SD card on the SPI interface. (The 3.2 does not have an integrated SD card.)
Note that many commits to the github repo are parts for a 3D printer. While you are welcome to use them, the focus of this site is the electronics, which can be re-used from saber to saber. The physical parts are unique to each saber (unless you use a standard case, of course.)
I am not affiliated with any of these, but have found them all useful.
An overview of the parts of a saber, with specific examples of the Gecko.
Technically speaking, to organize you electrical thoughts, a saber is a very fancy flashlight.
In roughly front to back order, an saber is:
FIXME new wiring diagram
LEDs are used in a bunch of places. Specific concerns are discussed below, but for all the LEDs it's good to have a handly calculator. The Vf comes from the LED data sheet. The Vsource depends on which circuit it is connected to.
A LED calculator: http://led.linear1.org/1led.wiz
This calculator will select the next higher standard resistor, which is almost always what you want. However, if you want to calculate the exact resistance:
R (ohms) = (Vs - Vf) / amps_through_led
Specific LED usage:
The high power LED that lights the blade. Powered by the battery
at 4.2 to 3.5 volts. Typcially about 1 Watt
(or higher) per channel, and the resistors are typically 1 Watt.
Typically a Vf of about 3.0 and expects 350mA of power. But
get correct values from the datasheet! Generally has a resistor
of 1-4 ohms. Note that once you select an LED, and add the
resistor and specs into the pins.h
file, the microcontroller
will use PWM to keep the power at the specified level (or less.)
This means you can sometimes round down on the resistor values:
for example, if the perfect
resistor is 1.6 ohms, and the
calculator recommends 1.8 ohms, you might use a 1.5ohm to give
the microcontroller a little more "range" to work with.
LED indicator lights, usually on the buttons. Powered at Vcc, 3.3 volts, stable from the microcontroller. In theory these often take 20mA, about a 47 ohm resistors. But that is BRIGHT. I often use 470 or 1000 ohm resistors.
DotStar smart LEDs. Used for user indicators. (Power meter, volume, etc.) Driven by the prop shield, requires no resistors. (The provided wiring diagram does not include this.)
The saber uses a common ground. There are 4 positive power voltages. Please be aware of the power supply. Shorts between the supplies can cause big issues. It's very important to not "cross" the power supplies or use the wrong one.
Convention, and the current design, uses a 2.1mm recharge jack. Wiring of the jack is such that:
This is useful, and convention for almost all saber designs, but a little weird. For it to work (safely) for case #1, the grounded sleeve of the recharge port should be isolated from "true ground" and the case of the saber. You need to be careful with a metal port, or use an insulated plastic one.
Sabers run off 4 AAA, 3.7 Li-Ion, or 7.4 Li-Ion. OpenSaber is designed around a 3.7 Li-Ion.
Why?
3.7v
Note that the actual battery voltage varies significantly, and the control circuit accounts for that.
The electronics are the heart of the OpenSaber project. The files are ExpressPCB files. I regret the proprietary solution, but I've been happy thusfar with the service.
The shield - which is the PCB that sits on top of the Teensy - collects together 1) an audio amplifier, 2) a DotStar LED controller, 3) an accelerometer, and 4) and emitter LED power onto one board. It also provides an SPI inteface connection for an external SD card, display, or similar.
A microcontroller, the Teensy 3.2 or 3.5, is the micro-computer that runs the software. It controls the blade state, the color of the LEDs, the color of the blade, and does audio processing.
It is soldered to a shield PCB. The microcontroller can be programmed directly via USB. The 3.5 includes an integrated SD card (handy!), but an SD breakout board can be connected via the SPI interface.
LED amplifier The LED uses a 3 channel, 350ma (average) controller. The microcrontroller uses an amplifier bridge made of 3 MOSFETS to drive the LEDs. Voltage monitoring is used to keep the LED current constant. You may change the LED current in the software.
LED a 1 WATT Cree or Luxeon LED in a star configuration is typical. The LED uses a common anode, as well as 3 control lines: Red, Green, and Blue. They 4 wires are connected from the LED to the front side of the emitter electronics.
The code assumes 1 or 2 switches.
In a 2 switch configuration, you may also (when the blade is on) hold auxillary and then tap the main switch to cycle through the blade color / sound palettes.
In a 1 switch configuration, a tap mode switches between "blade", "palette", and "volume". Long press either turns the blade on/off, or selects the palette or volume.
Audio playback is integrated into the main micro controller. It takes 44.1kHz in; you will need to convert files to 44.1k. They are typically not 44.1kHz when provided, so you will need to convert.
You can have up to 10 sound "fonts" or sound banks. Each font needs to be in its own sub-directory, which will be the name of the font.
All the names can be postfixed with a number for random variation: SWING
or
SWING01
for example. Note that the card / code is limited to 8.3 filenames.
You can't mix names in a group; using both BLDON and POWERON in the same
sound font will confuse the sound output.
The code is really the heart of this project. The code is set up to compile in the Arduino IDE, using the Teensyduino extension.
First you will need to set up libraries. Then you need to configure you particular saber in "pins.h".
I feel guilty about every forked library; but it's hard to work around API issues. Theser are minor forks, at least.
The current design uses the (really great) LIS3DH. https://github.com/leethomason/Adafruit_LIS3DH
The OLED display is required to compile, although it isn't supported as part of OpenSaber yet. (I use it in a personal saber.)
https://github.com/leethomason/OLED_SSD1306
'pins.h' contains the wiring pinout, documentation, and features switches. The tricky #define is the SERIAL_DEBUG macro. If on, you can connect the USB header and debug the saber. However, without a USB connection, the saber won't work if SERIAL_DEBUG = 1. The serial port won't be found, the timeouts kick in, and the saber essentially "locks up". It's a great to be able to debug, but remember to SERIAL_DEBUG=0 and upload that sketch when you are done.
Pins contains a bunch of other macros, which you can disable when you build the saber, and turn on one by one.
'pins.h' also contains the description of the LED: forward voltage, resistor values, etc. You need to set this for your particular build.
Note that there is an equation for UVOLT_MULT which controls the volt meter. There's some variability; once the saber is assembled, I suggest adjusting this value by checking computed vs. measured values. (Type 'vbat' on the command line to get the current computed value.)
The OpenSaber code will maintain an average of 350mA current (or whatever you specify) across the LED. This block of code in pins.h is important for tuning:
static const int32_t UVOLT_MULT = 6680;
#define ID_STR "Gecko (Sentris Body) RGB Luxeon"
static const int32_t RED_VF = 2900; // milli-volts
static const int32_t RED_I = 350; // milli-amps
static const int32_t RED_R = 2400; // milli-ohms
VF: forward voltage, from the LED spec. I: milli-amps of power R: the resistor value you used
And finally the UVOLT_MULT. It's a little tedious to calculate,
and doesn't turn out to be useful to do so. Once your saber
is up and running, wait until it hits the 3.7 volt range.
Measure the power with a voltmeter. Run vbat
on the saber
command line to get the measured value. Adjust UVOLT_MULT,
and recompile.
UVOLT_MULT' = UVOLT_MULT * V_measured / vbat
And then re-check the vbat
just to be sure. It should
be close, but doesn't need to be exact.
If you connect via USB, you can open the COM port to the saber and issue commands. Do this by opening the Serial Monitor and entering comminds in the terminal that appears. This works irrespective of SERIAL_DEBUG.
The saber has 8 palettes. The palette is a combination of:
blade color
impact color
sound font
bc
will return the current blade color for current palette. bc #rrggbb
will set the blade color for the current palette. It will also show the
current draw of the color. I generally keep it at 1000mA or less, although
you could theoretically draw about 1/2 the batter capacity. Do keep in mind
how well your LED is able to sink heat.
ic
gets / sets the impact color or "blade flash".
pal
returns the current palette. pal <0-7>
sets the current palette.
font
gets/sets the sound font in use.
fonts
lists the available sound fonts.
vol
and vol <0-204>
gets and sets the current volume.
`vbat' is the current battery level, in milli-volts. 4200 is fresh, 3700 is nominal, 3500 is low. This is read from the Vmeter of the emitter circuit.
util
is the current utilization of each channel. It is computed from Vbat.
90 90 76
means that the saber will use 90% red, 90% green, and 76% of
the blue channel. This keeps the average current through the LED constant.
When Vbat drops to 3.7V, these will all be 100%.
pwm
is the current Pulse Width Modulation of the red, green, and blue LEDs.
mot
and mot <1.1+>
gets and sets the threshold, in g-force, that
the saber will detect as motion, and play the motion sound effects.
imp
and imp <1.1+>
gets and sets the threshold, in g-force, that
the saber will dectect as impact, and play the impact sound effects.
stat
will display all of the current saber settings.
reset
will reset the palettes to their default values.
accel
prints the current accelerometer output. Useful for checking
calibration and that your axis are set up correctly.
test
runs the saber test suite.
'play' plays a sound on the SD card. You need the full name: 'play demichel.wav' or 'play bespin2/hum.wav'
In practice I've found that there are two drivers to the design: