JulianHartline.com Rotating Header Image

Tinkering Update: LED Strip Project

At the same as working on the nRF24L01+ PCB,  I’ve been progressing on another project. I picked up a 30/m addressable LED strip from Macetech. These LED strips are comprised of the WS2812 tricolor LED and controller package.

The WS2812 contains a red, green, and blue LED and a controller complete with a single line data interface and 3 PWM modules for running each of the LEDs individually at independent brightnesses. Furthermore, the controller is set up so that it can transmit signals to the next WS2812 in the strip so that these modules can be daisy chained.

When put together into an LED strip, a microcontroller can simply provide power, ground, and a single line of data to control the entire strip. To populate the LED strip, a series of  bytes is sent to the first LED. Once 3 bytes are sent (the color definition for one LED) the next byte causes the first color to be “pushed” on to the next LED. When the entire strip is populated, sending a reset signal causes each LED to display the color that it ends up with.

Sending a byte to the WS2812 requires 8 transitions on the data line each spanning 1.25 microseconds for a total of 10 microseconds per byte. Unfortunately, using a PIC18F25k80, this timing requirement allows for about 20 processor cycles for each bit transition. This is is a pretty tight requirement and I was unable to make it with my C compiler. Instead I ended up writing a method in assembly to get the timing I needed. It took awhile to get it right and it still has some minor bugs, but it was an interesting exercise.

After getting the code working on the nRF board that I previously blogged about, I designed a new PCB to better fit my requirements in a smaller package. This time I used primarily surface mount parts in significantly smaller packages. Here is the final PCB design and the populated board.



Remarkably, this board seemed to work flawlessly the first time around. Both the nRF module and the LEDs worked exactly as expected.

One additional piece of progress made with this board was our first successful use of reflow soldering to populate the board. Reflow soldering uses solder paste instead of traditional solder which is viscous at room temperature. To solder a board, solder paste is applied to all of the pads and then components are placed in the sticky paste. Once prepared, the board is simply baked to just over 180° C which causes the paste to fuse to the contacts and turn into solder, thus soldering your entire board in moments.

I’ve continued writing code for this board and have a simple proof of concept that lights the strip in some demo patterns during until it receives a packet on the wireless module. At that point, the LED strip is under remote control. Packets consist of an starting index, a length, and the payload that is copied into the LED buffer and then displayed to the LED strip.

The next step in this project is to design a new board, probably using an Atmega microcontroller that will fit into a case sold by Polycase. Getting a PCB and components to fit into a case is a new hurdle that has involved a significant amount of 3D modeling in SketchUp as well as extra spacial considerations such as switching to a flatter power jack.

Tinkering Update: nRF24L01+ Library for Microchip’s PIC microcontroller

It’s been awhile since I’ve posted anything, but I’ve been anything but boring the past few months. After hacking out the Hot Tub Remote project, I moved on to tinkering around with a PIC18F25K80. This PIC is a a very reasonable middle of the road processor. At 16Mips and 32K of program memory it has enough power for fairly ambitious projects.

Eric and I spent a decent amount of time and a few iterations to streamline the interaction between this PIC and the nRF24L01+. The nRF24L01 is a cheap and easy little wireless module that communicates in the 2.4GHZ frequency range. After breadboarding out a communicating pair of nRFs and spending a few weeks cleaning up, streamlining, and fine tuning our communication library, we started designing a PCB to make working with this module easier.

Eric did most of the work on this board and here is what the final board looked like. We shipped this board off to our Seeed Studio to be printed and received the boards and parts in the mail a few weeks later.


For this board, we carefully avoided any surface mount soldering (with the exception of the mini USB solder pads) in order to make populating the boards easier. The headers are optional and can be populated on a per-board basis depending on our needs. We ended up building out a total of 5 or so of these boards. Here is the populated board.


This board helped tremendously as far as getting the kinks worked out of our nRF code due to the increased stability afforded to us by soldered connections. A good number of the flakey behaviors from the breadboarded solution disappeared when we moved to the PCB.

The library that we ended up developing is available on Github: nRF_PIC18F25k80

In my next post, I’ll continue filling in the missing pieces from the last few months including a few more circuit boards that Eric and I designed and had printed.

Remote control hot tub

If you’ve ever owned a hot tub, you’ve surely been driving home from a long day or night wishing that the hot tub would be ready for you when you got home. I decided to do something about this.

Because we’re renting, I decided that instead of trying to pull apart the wall unit for controlling the hot tub, I’d go with the more mundane approach of wiring up a servo to push the hot tub button on command. I chose the Electric Imp as my platform primarily because I’ve been experimenting with it recently for another project that I’m working on. Having worked only with PIC microprocessors before, I found the Electric Imp to be surprisingly intuitive and easy to set up and  use. Instead of spending hours tinkering with a breadboard full of wires and a resistor or two, the Electric Imp fits easily into a development board, can be powered by a mini-USB cable, and configures itself to your home WiFi network without too much difficulty through a mobile app.

The Electric Imp, once connected to your wireless network, is accessible via the Electric Imp web application that allows you to track all of your devices and upload code to each one of them as well as configure the way that they interact with each other.

Once getting past some of the initial setup woes inherent in every tinkering project, the programming and wiring was very simple.

2013-06-19 23.15.49


Experiment’s End

I’ve decided to stop my experiment for now. The main reason for this is that I felt like I was adjusting quite a bit the first weekend but only to about half of where I wanted to be. I expected to adjust at least a little more the second weekend, but this did not go as expected. If anything the second weekend felt like I wasn’t further adjusting at all, I continued to be overcome by drowsiness when I was supposed to be awake. If anything, I’d say it was more difficult to stay awake a week down the line.

I am not, by any means, saying that this means that this sort of sleep schedule is impossible. I think that with a little more discipline, this could work. In fact, although I’ve stopped this experiment. I am already thinking about trying it again, probably this time with some slight modifications based on my experience for this past experiment.
Reaction Time:
9/14/10 9:52 am 273.2 ms

Day 8-9

After oversleeping, the day went pretty well, through the night I was able to stay awake fairly easily, probably due to the extra sleep although during the day there were a few times where I nodded off for a few seconds. One thing that I find particularly interesting about the entire thing is that my drowsiness level fluctuates drastically during the day but doesn’t seem to depend on anything in particular. Sometimes I’ll be drowsy right before a nap other times I’ll be drowsy right after a nap. Most commonly, however, I’m drowsy in the early morning. In some cases this drowsiness is extreme and threatens to induce an unscheduled nap, the rest of the time its just a general feeling.

Some other blogger mentioned that he took some extra naps during especially tired times and I’m tempted to try it. The main problem with being drowsy is that if I do fall asleep, I do so without having an alarm set. If I instead decided to take an extra nap, I might be able to avoid this.
Reaction Time:
9/11/10 12:31 pm 253.8 ms

Day 7

Overslept last night for 5 hours when I accidentally fell asleep after waking from my 2:30 am nap as my 5:30 am nap approached. I think it could have been avoided if I had gotten up and gone for a walk or did something engaging instead of sitting around staring at my computer screen. The main thing is that on certain nights at around this time my body gets so tired that resisting the drag to bed is really quite difficult.

The first sign is just a feeling of lazyness that precludes things to keep myself awake such as walks or demanding activities. This feeling sets in more and more until I can barely keep my eyes open.

I did some additional research today on polyphasic sleep, I found one set of articles that were extremely skeptical of the entire thing claiming that it gathers its strength from the attention it gets on the Internet and that it has not been proven in any labs.

The best research in the area seems to be done by Dr. Claudio Stampi, a sleep researcher specializing in this area. There is a good video about a study of his featuring the Uberman sleep schedule. The video seems to be quite guarded in its analysis. Although the conclusion seems to be that the body can learn to function under a polyphasic sleep schedule, it is not without duress. The research mentioned that mental performance was inhibited during the maintenance of this schedule although the subject’s self-report seemed fairly positive for most of the experiment.

The tradeoff seems to be, as with most things quantity versus quality. A full nights sleep will keep you at full capacity but a polyphasic cycle will grant you a large amount of extra time at a lower mental capacity.

In the sidebar there were another set of videos by a girl who vlogs about her polyphasic sleeping and claims to enjoy her schedule very much. Her user page can be found here: http://www.youtube.com/user/aeia

I do rather enjoy staying up all night, even if I’m not fully alert the entire time. I have high hopes for the day that I become fully adjusted to this schedule.

Reaction Time
9/6/10 4:17 am 275.6 ms

Day 6

Today has been relatively unremarkable, although I was a little tired especially during the middle of the afternoon, I made all my naps on time and slept for their full duration. I suspect the feeling of tiredness has to do with the fact that I overslept the previous night. The effect that this oversleeping had on my naps resulted in me being a lot less rested.

I most certainly look forward to the point that I can feel fully rested after every nap and less drowsy during my waking hours, but for the time being I’m glad that I can function fairly well during my waking hours which are much more plentiful now.

Reaction Time:
9/9/10 2:30 am 271.8 ms

Day 5

Unfortunately I overslept again, still working on engineering a louder alarm clock. The reason this time is basically that the alarms that I’m using are timers set to 20 minutes. Unfortunately the guy who wrote the first alarm clock didn’t think that timer alarms needed any form of persistence (eg snooze). Because of this, my alarms will go off for a few minutes and then eventually assume that I’ve woken up even if I haven’t so much as touched them.

Anyway whatever the case, at work today I was wide awake due to this drastic oversleeping, although I’m fairly convinced that I would have been fine anyway.

At the suggestion of my scientist dad, I’ve decided to record my reaction time over the next few weeks. Unfortunately, I missed my chance to get a baseline for this but I’ll be interesting to see if there are any patterns emerging.

The tool I used is here: http://getyourwebsitehere.com/jswb/rttest01.html

My first recording..
9/7/10 11:30pm 275ms

This is low compared to the median and average, I’m a little surprised but I’ll blame it on being sleepy right now as it is right before my nap time.

Day 4

Today went very well, I was awake, alert and my naps were all at the correct time for the right duration. The evening went well too until about 2:30 this morning. I got extremely sleepy and eventually took a 1-2 hour nap. I think the primary reason for this is that I was sitting in a dark room watching movies.

Staying awake during the day has been a lot easier than staying awake at night. I’ve been constantly snacking to try to keep myself awake. I think that watching movies was probably a bad idea, I should have picked something a little bit more active. I think that with a decent snack food, a bright room, and an mentally engaging activity, night time adjustment might be quite a bit easier.

Except for these minor setbacks, I’m feeling pretty good most of the time. Mostly awake and functional although I wouldn’t say that I’ve gotten full alertness back yet.

Day 3

Oops, not only did I oversleep once, I overslept TWICE today. This morning, I overslept my 2:30 am nap until 7:30, very unfortunate. I didn’t feel tired today, probably as a direct result of actually sleeping.. It messed up my nap schedule a bit and I ended up oversleeping another nap in the afternoon for two hours. This morning, I managed to oversleep because my phone’s battery died. I guess it was foolish of me to assume that 20% battery life would last for 20 minutes.. This afternoon I overslept because I only set one alarm and it didn’t wake me. In the future I plan on being extra diligent in setting multiple alarms.

Despite having overslept a few times, I’m not as worried about my adjustment as I was originally. After I overslept this morning I had a nap that I woke up in the middle of remembering a dream. It wasn’t particularly vivid and by now I’m second guessing whether I actually had it. At any rate, I think that my naps will be getting better from here on out.

Its a bit past midnight now, I’m apprehensive about my next two naps which I’ll have to be sure to wake from without any help from my girlfriend. Today I’ve been rather off on my schedule for naps, but today I plan on trying to adhere very closely to my set nap times.