Sunday, September 15, 2013

The new LED dimmer (Part 2 - now with brainz)

I wrote about a concept for replacing my old LED dimmer a while back (original post here), but with all the recent learnings and achievements I had to do a little brush-up on the original design (and I had a lot of fun doing so, since this brought even more improvements to the concept).

The first thing I did was to redesign the circuit. The original design was meant to be attached to a Raspberry Pi directly via I2C, which would then be receiving commands from the main controller via Ethernet. The recent discovery of the RS485 bus and the ability to integrate that directly into my circuits allowed me to completely dismiss the Raspberry Pi for this purpose, and I was even able to integrate the complete RS485 decoder circuit onto the board directly.

The finished eagle design looks like this:

New dimmer design including AVR

I then set out to build this, and I almost quit while making the PCB: It took me five attempts to get the toner for the top layer transferred to the raw copper. That, and the outlook that I had to do the same with the bottom layer almost drove me crazy. Luckily, things went way better after that: The bottom layer worked on the first attempt, and even the registration between the two layers was immediately perfect.

Here's a few pictures of the assembly:

Etched and drilled board with the first SMD components to be assembled
Microcontroller, crystal, RS485 decoder and PWM chips in place
It's alive! (Testing with the Arduino "blink" sketch)
More testing, this time with RS485 data
All amplifiers in place
Testing with actual LEDs
More testing and debugging
At that point I noticed a few communication glitches, and I ended up introducing some checksums to my self-devised serial protocol to fix them. In the picture above you can see the Arduino I used to download the firmware to the dimmer during this process.

I also ended up integrating a channel map to fix the channel sequence problems introduced by the board design right into the firmware.

Finished dimmer insides with the secondary output board on top
Finished dimmer with LED connections (Some are still available).
Here's a few things I learned from this project, too:
  • The ISP header is too close to a mounting hole. This was no big deal as long as I was working with the base board only, but with the stacked output board mounted on top the ISP header is pretty much inaccessible.
  • The overall power consumption appears to be pretty high. I only know that from the temperature the 7805 reached when multiple LEDs were on. Since the 7805 only supplies the microcontroller and the two PCAs, I suppose that it's the PCAs' outputs that run much more current than necessary to trigger the ULN2064s. The Adafruit PWM board that I previously used had 10K resistors in its output lines, and I should have included those, too. On the other hand however: Who would like to solder 32 individual 0805 SMD resistors? As a solution I replaced the 7805 with a step-down regulator that is more efficient and does not produce that much heat.
  • Drilling the front plate was a bad idea. It literally crumbled in my fingers. But since I don't own a proper milling machine, I don't have many options. (You can see the damages in the last picture if you look closely.)
Where to go from here? Well, the device itself is not complete yet: It still lacks a back plate and some proper connectors for the RS485 bus (right now, the cables go right into the housing and are plugged into the main board). I'm currently thinking about RJ10 connectors for that purpose. And I might need to replace the front plate due to damages, but that would only be cosmetics. Other than that I'm pretty contempt with the result.

Monday, September 9, 2013

Taking the bus (Part 3): The controller

You know the day is going to be good when the mailman rings at the door during breakfast time. Well, apart from the breakfast obviously. In my case, I was about to receive a box of fresh new and exciting components to build awesome stuff with:

Bunch of components
Among them was the ATMEGA328P microcontrollers I was eagerly waiting for to be able to build the controller module from my previous post. I already prepared the PCB (my first double-sided one, with lots of vias), meaning that I could start with all the SMD components right away:

Pilight controller board, partially assembled
After making sure that there were no shorts or dead solder joints on the board I was ready to add the headers and program the microcontroller:

Finished controller board

Port illustration
Size comparison: Full-size Arduino, Pilight controller, Arduino Mini
Programming with ArduinoISP
The programming step was a little troublesome, because I wired the cable to connect the controller to the Arduino incorrectly, meaning that my controller was missing ground and in constant reset state. Of course the cable was the last part I checked... However, after fixing it programming went fine.

After that, I hooked the board to the WS2801 LED pixel strand only to find out that i switched data & clock on the SPI port. Oh well. Luckily, I could make it work with a corresponding cable:

Controller in place
I previously named this the "Pilight universal controller" because I designed it to be able to drive all the various pilight devices - and so I needed to try the I2C port, too:

Pilight controller driving a PCA9685 PWM board
I'm very glad it all worked out so nicely. This first controller prototype will now resume its work on the pixel strand, and I am back to the drawing board to integrate the same microcontroller circuit into the LED dimmer board.

Update: Here's another short video of the controller in action. Enjoy :)


Friday, September 6, 2013

Taking the bus (Part 2)

Over the last few days I've been working on a lot of small things, and I've had a lot of new interesting findings. This is a combined blogpost of all the new stuff I'm working on.

For one, I took apart my central pilight controller Raspberry (after a staggering uptime of 224 days!) and had it equipped with an upgraded version of the RS485 shield from my previous post. I didn't take pictures this time, but the RS485 part is basically still the same. What I've done is I've added both I2C and SPI outputs to the board for a directly attached LPD8806 strip and a 20*4 LCD display respectively.

From there, I ran a long network cable (about 10m) across my room for  RS485 testing. I would have preferred a phone line, but unfortunately I don't have one yet, and the network cable was the only cable at hand that met the electrical requirements and was long enough.

Pilight central command with attached RS485 line

On the other end of this line now sits an Arduino, which has already replaced the Raspberry Pi that was once used to drive the WS2801 LED pixel strand there.

I've been working on the serial protocol that is run over the RS485 line and the corresponding Arduino sketch to fix a few glitches. It's now operating properly, and will also allow me to address multiple target devices attached to a single line.

Also, a friend of mine that also happens to be the local Raspberry & Arduino dealer was so kind to provide me with a few more Arduino boards for experimenting, among them an Arduino Mini. I immediately had to try this one out, and after a little bit of fiddling with the cables (the Mini comes without USB, nor does it have a standard-compliant ISP port for programming) and modifying the sketches I was able to integrate it into my system successfully.

Arduino Mini with MAX485 on breadboard, RS485 line on the right

I also did a little measuring and was pleasantly surprised that the complete circuit on the breadboard consumes a mere 20mA. That (apart from other improvements like the drastically reduced latency) really is a huge advantage over the Raspberry Pi based solution.

Since all those little experiments have worked out so well, I've also had plenty of time to read up on where to go from here. I'm currently working on a first board that will in turn replace the Arduino again. I've taken the same microcontroller that sits on most Arduinos (the ATMEGA328P), added only the necessary components to make it work, a MAX485 bus driver and headers for ICSP, I2C and SPI. Here's what the design looks like:

Pilight universal controller board (size: 23*37mm)
It is slightly larger than the Arduino Mini (the TQFP package of the processor is bigger, and the Arduino does not have RS485) but it's still pretty tiny. I'm curious what case options will be available for such a small board.

I've also thought about a way to get some configuration (like device ids) onto the controllers (that's what the CONFIG jumper is for) but I haven't had the time to test it out yet, so this will be part of a later post.

I've also postponed the production of the new LED dimmer for now, since the current version is designed to be driven by an external controller (in my original plan that would have been a Raspberry Pi). With all those new findings however I'd really like to integrate the controller right into the dimmer itself, which would allow me to directly connect it to the RS485 bus without any additional hardware.

Next steps will be to compile a list of parts for the new controller, since this will most probably be the next device for me to build. I'll post another update on this soon.

Tuesday, September 3, 2013

The new traffic light (Part 2)

UPS was so kind to deliver a batch of 20 PCA9685 chips to my door today. I was very pleased, since that allowed me to continue some of my projects. Today, I'm writing about the traffic light again, since that is the project i selected for testing.

I don't have much experience soldering SMD components, and so I immediately messed up the first board I had prepared in my previous post. Always check that your components are properly aligned with their solder pads! Moving them is pretty much impossible once a few of the pins have been soldered to the board. On a second note, I might need to get that hot air station.

I had more luck with the second attempt. Take a look at the finished board:

Top side with the two ULN2803 amplifiers

Bottom side with the PCA9685
I must admit, this is not my prettiest job. But the solder joints are all clean, and no shorts are on the board.

I had to prepare a few more cables, but once I hooked up the board to one of my Raspberry Pis it was immediately found by i2c-detect. For testing purposes I have attached a new cable to the one side of the light that I had already reworked before. I still need to get out the drill and the hot glue gun for the other three sides.

I tried it out with the Adafruit demo code that is destined for their PWM board, and since this is the exact same chip it worked right out of the box. I added a few lines and the result is a complete traffic light sequence in about 20 seconds:


But wait, there's more. I chose the PCA9685 because it is capable of outputting PWM. This is what it looks like when run with pilight code. Enjoy!