Wednesday, April 9, 2014

Lights In a Jar

I've liked blue lights since I was a kid. I noticed the blue lights when we drove past the airport. I like blue glass also. It's a pleasing color. I was drinking some wine recently and was struck by the blue bottle.


I thought it might look nice if illuminated from inside. Being a little creative, I thought about fun ways to light the bottle from the inside. My first thought was using white LEDs. I though, why not put some strings of LEDs inside at different angles. The next day, I remembered I had an Adafruit Trinket laying around and wondered if it would fit in the mouth of the bottle. It does, with room to spare! How many PWM outputs? 3? nice! Each can drive 20mA, so hmm, ok, with a transistor, could drive some more LEDs off each output. I settled on 3 strings of 4 LEDs hung at different heights in the bottle. I thought I could drive them to fade out at regular intervals to add some interest and make it a little more dynamic.

I wrote some code and soon found that the 3rd PWM output wasn't enabled by default using the Arduino IDE. There is a workaround on the Adafruit forums. Their whole site was down for maintenance when I was working on the code, so I didn't get that fix in until later that evening. I made a video of the problem prior to that, so you can see the earlier code in action. I've posted the code on github.

Let me take a little time to talk about the code for those not so familiar with software design (since that is my profession). If you follow the github link and look at LightsInAJar.ino, you'll find the normal setup and loop functions, but also more. The PWM4_init and analogWrite4 functions come from that forum post and handle the pint 4 PWM problem I mentioned. Setup is pretty straight forward in that it sets the 3 output pin modes, then configures the troublesome PWM output. After that, we get into some logic for a state machine. For those unfamiliar, state machines have been around for a long time. They are sometimes helpful in software since they consist of discrete states and transitions between states. In this case, I've defined 4 states for each of the outputs;
// states for 3 led strands
// 0 = off
// 1 = turning on
// 2 = on
// 3 = turning off

The code in the update function handles what to do in each state. If you check the main loop, it calls update for each LED, then delays 20 milliseconds and repeats, forever. So, for each LED, update is called every 20 milliseconds. Each state increments a counter since I want the LED to remain in each state for a period of time. It also checks a limit to see when it is time to move to the next state. For states 0 and 2, it simply waits and moves to the next state. For states 1 and 3, the PWM value for that pin is also changed. In those states, we are either turning the LED on or off, so we pass the counter value to analogWrite4 when turning the light on, and we pass 128-counter when turning the light off (instead of decrementing the counter. All of the state machine logic is the same for each LED. I set up the state variables differently for each LED to make each output start at a different state, and counter value. I also used "pass by reference" to allow me to pass variable into the update function and use those external variable directly within the function.

Enough about the code! I have single LEDs turning on and off, but I still needed to design the transistor driver circuit and since I'm a little rusty on that, I looked for an on-line circuit simulator. I found CircuitLab which worked pretty well, but for serious use, they need a paid acct. If anybody can give me a pointer to some decent open source visual circuit simulation, I'd be very happy!
I set up a simple driver circuit, designed to handle 4 LEDs at 20mA each. Here's a picture I took of the simulation.

I wired this up and it worked very nicely! I will point out that I am using blue LEDs for breadboarding. I ordered some compact white LEDs from eBay and hope to get those within a week. They were $2.30 for 100, which is way more than I need, but 1/10th the price of RadioShack (which is where I picked up the transistors and resistors).


To power this, I plan on using an old wall adapter for a bluetooth headset. Those put out 300mA and will be enough for this since 12 LEDs at 20mA each + 12mA for the trinket adds up to 252mA. I plan on including a proper power switch as well since I want to power the whole thing off. Otherwise, I may have simply connected a pushbutton to the trinket and made a software switch. I'll follow up with the rest of the project soon!

Tuesday, February 4, 2014

Eclipse Clock - making the case

I've had the circuit running on the breadboard and the software is in a workable state, so what's next? Well, I could work on the circuit board or the case. I chose the case. My idea was to use MDF (medium density fiberboard) for the back since it is very easy to work with and stable. I also knew I needed a way to cut perfect circles. I have a Bosch Colt hand router that came with a fence bracket. I was able to use part of that along with a 1/2" nylon bushing, screw and wing-nut to make a circle cutting jig. Pictures of that later. First, I had ideas about how the case would look and how it should be put together. As I got to the point of actually making the case, I jotted down a cross-section diagram with dimensions in my notebook.


The dimensions in there are pretty accurate. Let's call the parts "back", "spacer" and "front". The back and spacer are made from 1/2" MDF and the front was made from some curly maple that I got at a local specialty wood store. I chose curly maple since it was interesting to look at and quite hard. I bought a 7" x 15/16" board that I cut into 2 16" sections and jointed and glued together to form a 14"x"16" piece. I made the one dimension 16" so that it was easier to feed through a drum sander. I ran the glued board through the sander until each side was perfectly flat and no glue seam remained.


Now, I had all of my materials and I needed to start cutting circles! I got a 1/4" straight bit for the router and made some test pieces for the back. The problem was that the Adafruit 1M LED strip needed to form a perfect circle with the ends meeting perfectly so the LED spacing would be consistent, even at the joint. 1M circumference results in a 12.53" diameter circle. I adjusted my circle cutting jig to 6.25" (radius). It turns out I needed to try a couple of times. The first back piece was too small (the ends of the LED strip overlapped by about 1/2 LED length.). The second one was too large (too much gap in the ends of the strip). The third one.. the third one was just right! I had very minimal overlap and didn't feel like I needed a 4th!

\

This picture shows the MDF after I've made about 3 passes. You really shouldn't take more than 1/8 of material at a time. The bit would overheat. You can clearly see the jig I made in this picture. The hard part was measuring between the bit and the center of the nylon spacer. I had to use a screw driver to tighten the screw and double check the measurement each time. Notice the 1/2" guide hole in the MDF. That's what guides the entire cutting operation.

I should point out what might be obvious, but not to somebody who is new to this type of thing. You must make the larger diameter cuts first. Cut the outer diameter groove, then I actually went further out and cut all the way through to make the disk. This was how I left that little shelf for the LED strip to rest on. Once the outer diameter is cut, move in and cut the inner radius. Once you cut the inner radius, you can't go back and do the outer radius because that guide hole is no longer part of the piece!

The next thing I made was the spacer. It was a circle of MDF about 3/4" wide. After that, I could start on the maple case front. I chose one side that would be visible on the outside based on the grain pattern I liked. I then cut the opposite side. I drilled a guide hole and started routing the groove on the outer diameter. This maple is definitely harder than MDF! Go slow and make small depth adjustments as you go. It will take a while!


Once the circle is cut out, I had to start on the recessed area. This is visible in the cross section and will be where the electronics live. I made 2 grooves that formed the boundary for the recess. These were 3/8" deep.


Next, I had to remove the rest of the material between those grooves. Doing this with that 1/4" bit would have been time consuming. Luckily, I had a 1/2" bit from another project so I was able to use that to clear the material in 3 passes (many more if you consider advancing the depth bit-by-bit).

Finally, I was done clearing out the recess. I should mention that I had to run the shop vac between each pass due to the amount of sawdust created. Here's proof!


Final step is to remove the center disk and complete the front case shape. I worked on making the groove deeper and deeper, then a final check of my spacer to be sure it fit. This would be the last chance to get in there and adjust the recess area!


Once that was done, some light sanding and checking how it all fit together. I decided to mount the LED strip next to get a better idea of how it all worked when put together. I used about 7 dabs of hot-melt glue to attach the strip. Prior to doing this, I created some space behind the joint in strip. I needed room to attach wires and route them to the interior of the case.


I also used a saber saw to cut a flat on the spacer ring. I figured this would leave plenty of room for the electronics and was part of my original plan when calculating dimensions.


See? Plenty of room for the Arduino Micro and my own small board (which I still need to build!) With everything held together, here's how it looks. I have some rough sanding to do on the outer and inner radius of the front part of the case. I also used a chamfer bit to ease the front edge of the case. I think it looks pretty slick.



Next time, I'll show more about the electronics and the finished look of the case.

Saturday, January 18, 2014

Eclipse Clock

I was initially impressed by a clock I saw called the "Equinox Clock" posted here. The author went into some detail on the construction, but it wasn't a full how-to. I thought about doing my own, but all of the work he did with the separate driver chips and LEDs kept me from getting started. Mostly because of the time investment required. When I saw that Adafruit Industries started selling 1M strips of their "NeoPixels", I thought that would be a great alternative and most of the work spent on the clock would go into other things besides custom circuit boards and interconnects.

I plan on posting all of my plans and code on-line with instructions to help you build your own. I'm calling it "Eclipse Clock" because I think it looks more like a solar eclipse (and I didn't want to steal the name). Here's the part list I'm using;

  • 1M Neo-Pixel strip
  • Arduino Micro
  • DS1307 RTC chip
  • 32.786 KHz crystal
  • CR2032 lithium battery (and holder)
  • push-button switch (N.O.)
  • small Cds cell
  • 4 10K Ohm resistors
  • 1 1000 uF capacitor
  • 5v power supply (4 amps ideally, more on that later)

The clock will consist of an strip of LEDs shining sideways out of a round case. They radiate outwards and end up reflecting off the wall. There is a single pushbutton for setting the clock and changing color scheme between some presets. A real-time clock chip keeps accurate time. Hours are represented by 3 lit pixels, minutes by 1 lit pixel and seconds by another lit pixel. Themes can change color values of these as well as use a separate background color (which could let you have a fully lit ring with dark values for hours/minutes/seconds).

Source code will be on github.

More in a future post, but that's where I'm starting!

Monday, February 28, 2011

Twinkling Lights - a 555 timer contest entry

When Jeri and Chris first came up with the 555contest.com idea, I was intrigued. I'd used the chip back in the early 80's when in highschool. I still had a bunch of them in a drawer. It was just a matter of what to do with them. When I worked on my masters project (in Computer Science), I used something called spectral synthesis which simply means combining simple waveforms to form a more complicated one. The idea there was that I was trying to render what looked like realistic landscapes including mountains and valleys. If you get enough waves sine waves mashed together, you end up with something that looks somewhat random.
I decided to apply that to square waves and use logic gates to combine those waves. I figured if I could have the right set of timer frequencies set up, and combine them as inputs to 4-input NAND gates, I could drive LEDs that would twinkle in a pseudo-random way. That is what this project is about.
First, some math. I had to figure out just how many timers I'd need to generate a reasonable number of combined outputs. It turns out using Combinations from set theory works here. Given 4 inputs, there is exactly 1 way to combine those in a group of 4. If I used 5 timers, I can have 5 unique combinations of 4. With 6 timers, 15 combinations, 7 timers, 35 combinations. I figured 15 LEDs was enough for the scope of this effort.
I used totally non-scientific means to create the base frequencies. I used a handy 555 timer calculator and found that using a 10 uF cap, 10K and 100K resistors let me get about .68 Hz output at near 50% duty cycle. So, I went fishing in my parts drawers and found some capacitors I had laying around (1uF -33uF). I varied the resistor values a little till I got some blink rates that looked reasonable.

Next, I had to wire up the NAND gates. Having the combinations printed helped a lot! I was also starting to run out of jumper wires.

So, there you have it. Ideally, I'd play around with the timer frequencies a bit. For a more artistic presentation, I'd like to see the LEDs either embedded into a poster of a space scene, or scattered across one of the kids room ceilings.
Oh, I ordered some parts for this from Digikey (one of the contest sponsors). Good Karma, no?

Tuesday, August 25, 2009

Electrical Panel for a Catalina 27


The robot project has been on hold for many months. The main reason is because we bought a sail boat! I should point out it is a 1976 Catalina 27 (hull # 2833). I've done a lot of work on the boat, from refinishing/fairing the bottom, to refinishing the teak and now, replacing the electrical panel. The toggle switches are all crusty and sometimes intermittent. The fuses are out dated and I'd like to add more circuits.
There is a perfectly good panel available from Catalina Direct. For over $170 after shipping is factored in, I decided I'd try to do one myself. In my youth, I made all kinds of projects, and sometime even the boxes that contained them.



To start with, I measured the old switch panel and screw locations. I got that put into Adobe Illustrator. I searched on the Surplus Center web site and found these switches and circuit breakers which look remarkably like the Catalina Direct ones (and I've seen one those in person, because a fellow Catalina 27 owner I know bought one). I used the dimensions from these parts to layout the panel. I actually chose to lay it out like the Catalina Direct panel. It is a sensible layout, and adds 3 more circuits. I also was free to label it exactly the way I like. In final construction, I ended up swapping out the circuit breakers I had ordered with some nicer ones from a local electronics supplier. They were slightly smaller and had nice hardware with the. Switch order: $30 New breakers: $13



I did a search with google maps and found Recognition Experts who were able to laser engrave the panel based on my drawing. Panel: $35

The new panel material was a little on the thin side. I decided that I need to add some thing on back to stiffen it. So, I used some aluminum angle to make a piece that is bolted in with the circuit breakers. Also, once soldering the bus wires to the switches (one for grounding for the indicator lamps, and the other for the breaker protected power feed), the section with the switches was stabilized.



Total project cost was just over $80.


Sunday, January 25, 2009

Finally, some wheels I like, and I think they have great potential. They are described here. Basically, 6 inches in diameter, pneumatic with steel hubs and 2 bearings. They'll absorb some of the shock so the robot won't be shaken to bits. Ryan thinks they look kinda like moon rover wheels! I researched sprockets and chains. It looks like #25 chains (the smallest ANSI standard) could work, but they are a bit small and might not take the loads well. They are rated at 140 lb working load. If I went up to a #35 chain, the working load goes up to 480 lbs. The reason for my concern is this robot could easily top around 100 lbs (rough estimate). If there are sudden loads when starting up or changing directions, that could really shock the chain. The #25 has a top end rating of 781 lbs, so maybe that will work. The other nice thing about the smaller chain is that sprocket selection is simplified. With smaller pitch comes more teeth in a given diameter sprocket. For these wheels, I wanted to have a sprocket that will mount to spacers on those bolts you see in the hub of the wheel. I also want the teeth of the sprocket to be well within the outer radius. The reasons for this are mostly so that the chain won't run too close to the ground. I also anticipate some flexing in the tires, so we can't assume the wheels are always going to be the same diameter during robot movements. I found a nice 42 tooth sprocket that fits well on the wheel. Using a 13 tooth sprocket on the motor, I get a 3.2:1 ratio. Using the spreadsheet I mentioned in an earlier post, that gives an estimated top speed of 25 MPH. I also figure I'll have 2 idler pulleys, one on each side of the motor sprocket, so that the chain contacts as much of the motor sprocket as possible. That will also give me a nice way to tension the chain.
Another thing I'm thinking about is a way to mount the batteries. I want something that will be very sturdy and maybe even provide some cushioning. I was thinking of aluminum angles at the corners of the batteries, but I think something that supports more of the battery surface would be better. Maybe an aluminum plate with a thin closed cell foam pad, with some fairly large holes cut out to let things "breathe". OK, that's it for now.

Sunday, November 30, 2008

Radio Gear

A stop at a local hobby shop brought me to this radio. The Spektrum DX5e has just enough features to allow me to control this thing remotely to test the chassis. It's a digital 2.4 GHz radio, but without any of the fancy features that would have driven the cost way up. The Sabertooth motor controller I mentioned several posts back will connect nicely to the included receiver. In addition, the Sabertooth has a BEC which will power the receiver off my main batteries. One more thing checked off my shopping list!