BlinkBox – A test tool for addressable LED development

This project got featured on the official arduino blog as well as hackaday! Thanks to everyone that shared!

I work with addressable LEDs a lot. For all that they’re great for, they’re kind of hard to debug when you have a lot of them connected up at once. This is especially apparent when you have many small single modules in hard to reach spaces.

Here’s my solution:

This lets me set the color and number of LEDs in a strip, and then displays a color pattern. This way I can tell if an LED has become disconnected in a strip, or if a channel  inside a particular has died.

Features

  • Select LED type with the type switch, 4 positions
  • Can test up to 400 LEDs at a time, if you can find a worthy power supply
  • 3 Test modes
    • RGB – 1 second red, 1 second green, 1 second blue
    • HUE – Lock strip at HSV (x, 255, 255) and x loops from 0-255
    • WHTE – Set the strip to RGB(255, 255, 255)
  • Count and Mode are saved into eeprom, so you don’t have to keep resetting the strip if it powers off
  • Wall mount fittings

Design Explanation

All of the raw code solidworks, and KiCAD have been posted on my github. You can look at the 3D models on thingiverse as well.

Mechanical

Here are a couple of quick renders of the assembly design:

The screw mount behind the pushbuttons is extended to be able to support the pressure without flexing:
I added a ridge so you can grab onto something as you interact with the switches / buttons.

Electronics

Here’s the circuit:

There really isn’t a lot going on here, the parts are probably the coolest part of the project. The 5V jack is a 6mm DC barrel jack, the pushbuttons are illuminated 16mm pushbuttons from adafruit,  the on/off switch is a locking toggle switch, and the 4 position rotary switch can be found here.

I wired up the circuit on a spare piece of perfboard.

Software

My code is available on my github.

The LED driving part of the code is based on FastLED, a beautiful library for driving these types of addressable LEDs.

The rest of the code is mostly just a hardware UI problem, and isn’t all that interesting. LED count “ramps” as you hold the button down. The longer you hold the button, the faster the

Wrap up

That’s pretty much it! I’ve already gotten some use out of this tool and have found great satisfaction in taking the time to make it look nice as it will be a permanent addition to my lab.

I’ll post any updates I make to this project as edits to the top of this post.

Thanks for reading, and here are a few more photos:

Wall-Mounted Drybox for 3D Printing with Nylon

It’s well known that nylon based 3D printer filaments need to be dried out before they’re used. What happens though when you have a 30+ hour print? The spool can take on a lot of moisture in that amount of time and compromise the print.

Many people have solved this problem by making filament dryboxes, somewhat airtight containers that contain a desiccant to dry out the air inside of the chamber.

I have to print several large parts from nylon for client, and I was having trouble in the last hours of the print due to the spool taking on water from the air. I decided to build one of these chambers but with a twist:

 

Mine is wall mounted! Space in my lab is a premium and the walls are free real estate.

The parts for this build is are available on my Thingiverse page. Oh and if you’re curious, I’m using a wall-outlet-rechargeable desiccant pack from Amazon which I got for $15.

The bolts are M3x10mm, and the nuts are M3 nuts, both from McMaster Carr.

Thanks for reading!

Why you should use Processes instead of Threads to isolate loads in Python

Key Learning

Python uses a Global Interpreter Lock to make sure that  memory shared between threads isn’t corrupted. This is a design choice of the language that has it’s pros and cons. One of these cons is that in multi-threaded applications where at least one  thread applies a large load to the CPU, all other threads will slow down as well.

For multi-threaded Python applications that are at least somewhat time-sensitive, you should use Processes over Threads.

Experiment

I wrote a simple python script to show this phenomenon. Let’s take a look.

The core is this increment function. It takes in a Value and then sets it over and over, increment each loop, until the running_flag is set to false. The value of count_value is what is graphed later on, and is the measure of how fast things are going.

The other important bit is the load function:

Like incrementload is the target of a thread or process. The z variable quickly becomes large and computing the loop becomes difficult quickly.

The rest of the code is just a way to have different combinations of increment and load running at the same time for varying amounts of time.

Result

The graph really tells the story. Without the load thread running, the process and thread versions of increment run at essentially the same rate. When the load thread is running, increment  in a thread grinds to a halt compared to the process which is unaffected.

That’s all! I’ve pasted the full source below so you can try the experiment yourself.

Multiple Frequency Counter for Arduino

Ever wanted to measure the frequency of a square wave using an Arduino? There are a couple of good solutions out of there to do this, but not all of them had the capacity to do multiple inputs. I couldn’t find this quickly so here is my solution.

Here’s the link to the code if you want to skip ahead. The code uses interrupts and doesn’t use any kind of delaying so it’s good for giant state-machine applications. My application for this is measuring signals from 10Hz-100Hz in which this can measure within 1% error. The absolute limits of the code are 1Hz-50KHz.

This project is on GitHub if you want to send a pull request to make improvements.

Setup

For testing, I wrote a simple function generator and uploaded it to a separate arduino. It outputs a pulse train with periods of 10ms (100Hz) and 5ms (200Hz) on pins 2 and 3. I attached LEDs and their resistors for debugging.

Pins 2 and 3 on the function generator to pins 2 and 3 on the frequency counter.

setup

The code for this simple function generator is here:

Frequency Counter

This code will work fine in a stateless application, because there are no delay statements (which some other frequency counters I’ve seen online use). It’s a little bit complicated, send me a pull request if you can refactor it to be cleaner.

Here’s the sketch:

I’ve written most of the important notes as comments in the source, but a couple more details:

  • The important data is stored in period_averages_ms and frequency_averages_hz. You address them using the indices defined at the top of the file. Make sure you call compute_counts()  before using this data. Keep it somewhere in main().
  • You could easily add more frequencies, you just have to NUMSIGS, make a specific ISR, and another attachInterrupt line in setup()
  • It uses interrupts which might not be right for your proejct, but normally shouldn’t get in the way of too much stuff.
  • If the ISR hasn’t seen a new edge in 1000000us, both period_averages_ms[p_index] and frequency_averages_hz[p_index] will be set to zero! This means that slowest frequency that this code can detect is 1Hz!

If you have any questions on how to add more signals, leave a comment!

Results

Here’s the output in the serial monitor attached to my function generator from earlier:

result

That’s like less than 1% error! Pretty good!

I also tested the code with a real function generator. Things worked really well until around 50KHz, so I would say that this code can’t be trusted past 50KHz.

10 Hz

50 KHz

Thanks for reading!