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!


Saturday, August 31, 2013

Taking the bus

So you remember the bunch of boards I wired together for my previous post? Well, when I returned home today I was very happy to find a parcel full of electronic parts in the mail. It included the MAX3485 / MAX485 chips I ordered for this project, and with them I altered the circuit a little:


As you can see, most of the parts are still in place: bargraph display, PWM board, Arduino, Raspberry Pi. What you might be missing is the USB cable between the Pi and the Arduino: it's no longer necessary. Instead, the devices are now connected through a RS485 bus (the small, 3-wire cable that's visible between the Pi and the breadboard).

The amazing part is: In theory, when done right, that little cable can be extended to lengths of many meters, under certain conditions even kilometers. I don't think I will be going to such lengths, but that sure is enough to wire up a complete appartment or even house.

Another advantage of this concept is that I can daisy-chain multiple receivers to this bus, so that a single cable should be enough to wire up a whole lighting system.

This is very close to a DMX system already, however I think I will stick with the way it works now since I'm not sure wether the Raspberry Pi is capable of producing the necessary signal timing.

Some details.

Since the MAX3485 (a 3.3V compatible bus chip) was only available in an SMD package, I had to come up with a little testing shield in eagle:


This board is a mere transmitter due to the fact that the MAX3485 is designed for half-duplex mode. Switching between sending and receiving however would require an electronic signal that the Pi is (at least to my knowledge) unable to produce. I thought about wiring up a GPIO port, but this is purportedly too slow. Writing back to the Pi however is not really a requirement for my purpose, so I simply pulled the DE pin high, which means that this shield is only capable of transmitting data.

For the Arduino side, i wired everything onto a breadboard for now:


This is basically the same circuit, except that I used a MAX485 (the 5V equivalent) and pulled DE and RE low to put it into permanent receiving mode.

Next steps: I'm currently trying to figure out a protocol that will allow me to address multiple receivers on a single bus, without introducing too much of a delay. I'll post my results as soon as I worked something out.

Wednesday, August 28, 2013

Getting started with Arduino

Today I came up with another nice little contraption:


Now you're probably wondering what that is. That question is pretty easy to answer: From bottom to top, that's a Raspberry Pi driving an Arduino driving a PWM board driving a 10-LED-bargraph board.

Not satisfied with this answer? I can understand that. There's more questions behind that. Let's start with the less obvious things. Why the bargraph? It's a simple component that was readily assembled and was designed to be connected to the PWM board. It's a nice visual indicator of what's going on.

Why the PWM board? Again, the answer is: because I had one at hand. I could have used something else, but in combination with the bargraph again it gives a nice visual representation of what I was trying to accomplish.

So then the real deal is in the Arduino? From my previous projects I already know that I can directly interface the PWM board from the Pi. So basically there's not a real point in passing signals through an Arduino, or is there?

Yes there is. This is the first time I'm trying to build something Arduino-related at all, and this might actually turn out to be a nice advantage to future builds.

It's the connection between the Arduino and the Raspberry Pi that I will actually try to improve upon in the next days. So all this basically is going to be my testbed with a known-working state.

Right now I'm researching ways of replacing the connection with some kind of bus (RS485 seems very promising, and from there DMX is not far away) or even make it wireless (but most solutions appear to be rather expensive). If my idea works out, this could mean that I will no longer need a dedicated Pi for each of my devices, but instead a cheaper and smaller (think of the Mini!) Arduino would be sufficient. I might event manage to integrate the microcontroller directly onto my own boards!

And now this is an answer that hopefully gives you an insight on what really lies behind a few simple lights.

Oh, almost forgot, there's also a small video. Enjoy!


The new traffic light

Well, so the 'ole traffic light I wrote about earlier has become a little obsolete recently, and so I wanted to give it a little overhaul. In my original post I already mentioned the four sides that it has, but since I was kind of lazy with the original build, only one side was actually connected. Also, since I kind of like the idea of integrating this into the PiLight system, I wanted to make the lights on it dimmable.

Since another project I'm currently working on will incorporate the PCA9685 chip, this is a good chance to try out a small part of the circuit before going large, and also makes the traffic light worthy of its own posts on this blog.

Here's a picture of the board I designed for this little project. It consists of a PCA9685, two ULN2803 amplifiers, a set of pre-resistors for the LEDs, and some more SMD passives for the configuration of the PCA.

Traffic light board design
I took some photos during the etching process for documentation. I'm working with the direct toner transfer method mainly because it's much more convenient (once you have access to a laser printer), but also because it requires less chemicals.

The first step is to cut out a piece of board that fits your dimensions.

Printed circuit on copper side (for illustration)

Marking the board dimensions on the board itself

Nice and shiny board after cutting
The next step is to transfer your design onto the actual board. This process involves a sheet of glossy paper (I just tore out a page of an old Reichelt catalogue, but from what I read most glossy magazines should do), some acetone, an iron, a bowl of soapy water and a brush.

Final board design printed onto glossy paper (had to glue it to a page of regular paper because it was too small)

Everything prepared: Iron, board, and the printout

Cleaning the board with acetone to remove any fingerprints or other kinds of dirt on the surface

Ironing the printout onto the board

This is what it looks like after ironing

Dumping the whole thing into a bowl of warm, soapy water

The paper will soak up completely in the water after a few minutes, and can then easily be brushed off.

This is what the board will look like after cleaning & drying.
I noticed at that point that the ground plane on the right side wasn't correctly transferred on. I would have been able to fix this by starting over, but since the plane in question was non-functional I didn't bother.

The board is now ready to be etched. (DISCLAIMER) Please note that the chemicals used in the following steps are dangerous and can seriously harm your health, clothes, workbench and the environment if used incorrectly. I will not take responsibility for any harm caused by you after reading this. (END OF DISCLAIMER)

The only thing that needs to be done now is to put the board into the etching solution of your choice. I'm using ferric chloride (Fe3Cl) basically because it was the only ethant available at our local electronics store. It works perfectly at room temperature, and will etch a board in typically twenty minutes.

Board submerged in etching solution
After about twenty minutes the board is usually ready to be washed off, the exact point of time however is best determined by repeated visual inspection of the etching process. Once all the non-printed areas are clear of copper, the board is finished.

This is what the board looks like after etching and cleaning:


To get the toner back off the board, simply use acetone:


After doing some quick measurements I noticed that some of the traces obviously were too close together, resulting in shorts between some of the leads. I had to cut them up using a utility knife:


Next step is to drill the holes for the through-hole components (I used a 0.8mm drill and a dremel for that):

Always put an old piece of wood under your board while drilling!

Finished!
That's all for now. I'm currently waiting for the components for the board to arrive (I finally found a source for the PCA9685, too) and will follow up with another post once they arrive.

The ole' traffic light

One of the first things I wanted to do with the Raspberry Pi was to turn one into an "extreme feedback device"1 because due to its size, the fact that it runs a fully-fledged Linux and the versatility of its connections it would be easy to interface both the server and some lights.

Because I wanted to start on the software early, I built a little mock-up device at first that did nothing more than connect three different color LEDs to GPIO pins on the Raspberry Pi:


I went with the "traffic light" color scheme because it matches the three different states used by Jenkins.

After wrapping up the code, I found the right hardware for this on Amazon:


I bought this since a life-size or real traffic light (yes, they are available on ebay every once in a while) would have been a little over the top price- and sizewise. It comes with two "car" sides (showing red, yellow and green) and two "pedestrian" sides (with only red and green). It has a switch with three positions on the bottom, and a pushbutton on the top. It originally runs off three AA batteries.

After opening it up I didn't really bother much with the original functionality and pretty much instantly ripped out the original board. What was unexpected though was the small tungsten light bulbs I found on the inside since I was really expecting LEDs. The good news at this point was that the removal of the original board freed enough space for a bare Raspberry Pi + WiFi to be fit inside.

After drilling up the holes and installing 5mm ultra-bright LEDs I hooked up another ULN2064 to amplify the GPIO outputs since the 30mA current necessary to drive the LEDs appeared a little bit too much for Raspberry Pi to me. I also drilled holes into the bottom and ran a power supply cable through the foot.

Here's a few pictures of it in action:

First experiments with regular LEDs that turned out to be too dark

Ultra-bright indicating broken build

Ultra-bright indicating good build

The code for this little hack is still available on Github.


1 An extreme feedback device is a tool often used in agile programming. Its purpose is to show the integrity of a software project. The idea is to detect software errors as soon as possible and to make them visible and obvious to everyone involved. It usually involves a continuous integration server like Jenkins.