LED Flower

Aus Wiki CCC Göttingen
Wechseln zu: Navigation, Suche
Lf-0500-01.jpeg
Protoflower-01.jpeg

LED Flowers are a set of RGB LEDs that are controlled via USB. Everything needed for this workshop is under a free license, so feel free to copy and modify.

To get started, you first need all the parts and a PCB. You can manufacture your PCB from the board data in the git repository (see Sources). The parts are listed in the Bill of Materials section including an order number from two german component sellers. Alternatively, you can just contact Marvin and ask him to send you a complete kit. If you ask nicely, he might solder the most complicated parts for you and even pre-program the microcontroller.

Sources

Sources are available in a git repository. Just:

git clone https://cage.0x53a.de/ledflower

Or if you have SSL verification enabled:

git init
git remote add origin https://cage.0x53a.de/ledflower
git config http.sslVerify false
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git pull

Please feel free to send any patches to Marvin.

To build the firmware, you will need an AVR Toolchain and avrdude. To build the host software, you will need gtk+-2 and and libusb-1.0.

Circuit

asdf

PCB

PCB
Generated PCB preview

BOM

Necessary
Designator Value Part-No Price / EUR Count Sum / EUR
R1 3.6 kΩ, 1206 R: 0.01 1 0.01
R2 2.7 kΩ, 1206 R: 0.01 1 0.01
R3, R4 68 Ω, 1%, 1206 CSD: 10-120068 0.01 2 0.02
R5..R19, R38..R40 3.6 kΩ, 1206 R: 0.01 18 0.18
R20..R31 100 Ω, 1206 R: 0.01 12 0.12
R32..R37 150 Ω, 1206 R: 0.01 6 0.06
B1..B3 0 Ω, 1206 R: 0.01 3 0.03
T1..T18 BC807-25, SOT23 R: BC 807-25 SMD 0.04 18 0.72
C1, C2, C3 100 nF, 16 V, 0603 R: X7R-G0603 100N 0.05 3 0.15
C4, C5 22 pF, 0603 R: NPO-G0603 22P 0.05 2 0.10
C6 10 uF, 10 V, 0805 R: X5R-G0805 10/16 0.07 1 0.07
C9 100 nF, 63 V, 1206 R: X7R-G1206 100N 0.05 1 0.05
D2, D3 3.6 V Zener Diode, MiniMELF R: SMD ZF 3,6 0.05 2 0.10
X1 20 MHz R: 20,0000-HC49U-S 0.18 1 0.18
ISP, ADC, PWR 12-pin break-away connector (from a 36-pin strip) R: SL 1X36W 2,54 0.27 1 0.27
CONN_USB USB B connector R: USB BW 0.21 1 0.21
U1 ATmega88-20AU R: ATMEGA 88-20 AU 2.95 1 2.95
LED1..LED6 RGB LED  ? 0.30 6 1.80
24 Copper wires 40 cm copper wire cutoff R: CUL 500/0,63 13.90 0.058 0.81
Sum 7.84
Version 1: USB Powered
Designator Value Part-No Price / EUR Count Sum / EUR
L1 10 uH, 450 mA, 1210 CSD: 146-121R010 0.22 1 0.22
U2, C7, C8 Do not populate 0.00 0 0.00
Sum 0.22
Version 2: Externally powered
Designator Value Part-No Price / EUR Count Sum / EUR
U2 LM1117-5.0 CSD: LM1117DT-5,0V 0.95 1 0.95
C7, C8 10 uF, 10 V, 0805 R: X5R-G0805 10/16 0.07 2 0.14
D1 1N4001, MELF R: X7R-G1206 100N 0.04 1 0.04
L1 Do not populate 0.00 0 0.00
Sum 1.13
Option: Button
Designator Value Part-No Price / EUR Count Sum / EUR
R41 3.6 kΩ, 1206 R: 0.01 1 0.01
BTN Pushbutton  ? 0.10 1 0.10
Sum 0.11

Tutorial

Preface

This Tutorial consists of three parts. The first two parts do not necessarily have to be completed in the given order. Also, two people may work simultaneously, each on one part.

If you don't want so modify the project to look like something else (which of course would be perfectly okay) make sure that you execute every step exactly as described. Compare your result with the provided pictures. If you are unsure what to do contact Marvin prior to soldering. Also, the tutorial often uses designators like R4, C1 or U2. Those can be found on the PCB images at the top of this page, the Bill of Materials and the schematic.

If you encounter any problems with your device, you may also ask Marvin for support, but only if you include a correctly focused photograph of the bottom of your PCB that has an adequate resolution and an exact description of your problem.

Prerequisites

I highly recommend checking out the git repository with the current sources for the firmware and control programs. If you are building this in a workshop, you probably won't need it as your tutor may provide the initial firmware. However, the control programs are the one thing that make this project interesting. See LED Flower#Sources.

Part I: The PCB

Microcontroller

The first step in soldering this board is also the most difficult: Soldering the microcontroller. We are going to use the drag soldering technique. To do so, we first place the microcontroller on the board to get an idea of how it should be placed afterwards. Notice the pin one mark which is a small dip in one corner of the IC. This is used to orient it correctly:

Before proceeding, please read the entire section about soldering the microcontroller and make sure you understood everything. Now remove the microcontroller again, select one pad of the PCB and tin it. For this and the next two steps, you don't have to worry about any solder bridges, we will remove them afterwards.

Now grab the microcontroller with a pair of tweezers, heat up the tinned pad and place the microcontroller correctly. Do not overheat the microcontroller: If you are not able to position the microcontroller within about 10 seconds remove the soldering iron and try again after waiting a short amount of time.

To further secure it, also solder one pin on the opposite corner.

Now select one edge of the microcontroller that has not been used in the previous steps and add some Flux to pins. What comes now is not easy and probably may require multiple attempts: Solder some pins one on side of the edge at once and then just slide the soldering iron slowly and without any pressure to the other side:

If you have done everything right (right speed, correct amount of solder and flux) all pins will be soldered to the board and there will be no bridges between them:

If you have created any bridges, there are two ways to get rid of them:

  • Drag the solder away from the microcontroller.
  • Use a desoldering gun or wig.

However, repeat this process for the three other edges that are not yet soldered completely:

Decoupling Capacitors

To operate, the microcontroller needs a set of decoupling capacitors. These are two-padded components, so we will essentially replicate the first steps of the microcontroller soldering process:

  • Tin one pad,
  • add the component and
  • solder the other side.

The first one is C9, a 100 nF capacitor in a 1206 package, the biggest of the capacitors included in this kit:

Now continue with C1 using the same process. C1 is also a 100 nF capacitor, but in a 0603 package.

And now C2 and C3, both the same capacitor as C1.

Crystal Oscillator

Next step is the crystal oscillator. To prepare for that, we will first solder the capacitors C4 and C5 which are both 22 pf 0603 capacitors.

The crystal oscillator then goes directly on the other side of the pcb below those two capacitors. Just put it in and solder both pins.

Then clip off anything that is above the solder joint.

Programming and Analog Input Headers

Now we add two headers, one for programming the microcontroller, one for the analog input of the microcontroller. Again, the headers are on the back side of the PCB.

Now simply solder each pin to the PCB:

First Test

Get a lab power supply and set the maximum voltage to 5 V and the maximum current to zero. Connect the positive terminal (red) and negative terminal (black) as shown in the picture below:

Slowly increase the current. The current should not exceed 20 mA.

If you have reached 20 mA, but the voltage is still below the previously set voltage limit, something is wrong. Do not further increase the current limit as this could damage the device. Check if every component is soldered and oriented correctly, check if there are any solder bridges.

If everything is okay, connect the in-system programmer. From left to right it's: MOSI, MISO, SCK, Vcc, GND, /RESET

Programming the Microcontroller

Go into the source folder, adapt the programmer.mk to use your programmer and execute make fuses:

source$ make fuses
avrdude -c avrispmkII -P usb -B  100 -p m88  -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e930a
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xdf"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xdf:
avrdude: load data hfuse data from input file 0xdf:
avrdude: input file 0xdf contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xf9"
avrdude: writing efuse (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.05s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xf9:
avrdude: load data efuse data from input file 0xf9:
avrdude: input file 0xf9 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xf9 != 0x01
avrdude: verification error; content mismatch

avrdude: safemode: efuse changed! Was f9, and is now 1
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

make: *** [fuses] Error 1

If you are asked if you want to change back the efuse as it has not been written correctly, just say 'n'. In fact the fuse has probably been written correctly, the upper bits are just not writable and always remain 1.

To program the microcontroller and check if the oscillator is working, just execute make:

source$ make
Building objects  build/base.o  build/usb.o  build/leds.o  build/usbdrv/usbdrv.o  build/usbdrv/oddebug.o  build/usbdrv/usbdrvasm.o -> build/out.elf -> build/out.hex
make build/out.hex
make[1]: Entering directory `source'
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/base.c -o build/base.o 
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/usb.c -o build/usb.o 
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/leds.c -o build/leds.o 
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/usbdrv/usbdrv.c -o build/usbdrv/usbdrv.o 
src/usbdrv/usbdrv.c:115: warning: overflow in implicit constant conversion
src/usbdrv/usbdrv.c:154: warning: overflow in implicit constant conversion
src/usbdrv/usbdrv.c:156: warning: overflow in implicit constant conversion
src/usbdrv/usbdrv.c: In function ‘usbHandleResetHook’:
src/usbdrv/usbdrv.c:550: warning: unused parameter ‘notResetState’
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/usbdrv/oddebug.c -o build/usbdrv/oddebug.o 
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax   -c src/usbdrv/usbdrvasm.S -o build/usbdrv/usbdrvasm.o
avr-gcc -std=gnu99  -W -Wall -pedantic -DF_CPU=20000000UL -mmcu=atmega88 -O2 -ffreestanding -Wl,--relax    build/base.o  build/usb.o  build/leds.o  build/usbdrv/usbdrv.o  build/usbdrv/oddebug.o  build/usbdrv/usbdrvasm.o -o build/out.elf 
avr-size build/out.elf 
   text	   data	    bss	    dec	    hex	filename
   1862	      2	     65	   1929	    789	build/out.elf
avr-objcopy -R .eeprom -O ihex -v build/out.elf build/out.hex 
copy from `build/out.elf' [elf32-avr] to `build/out.hex' [ihex]
make[1]: Leaving directory `source'
make flash
make[1]: Entering directory `source'
avrdude -c avrispmkII -P usb -B  1 -p m88  -U flash:w:build/out.hex:i 

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s 

avrdude: Device signature = 0x1e930a
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "build/out.hex"
avrdude: writing flash (1864 bytes):

Writing | ################################################## | 100% 0.20s

avrdude: 1864 bytes of flash written
avrdude: verifying flash memory against build/out.hex:
avrdude: load data flash data from input file build/out.hex:
avrdude: input file build/out.hex contains 1864 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.10s

avrdude: verifying ...
avrdude: 1864 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

make[1]: Leaving directory `source'

USB Port

Solder R2, R3 (both 68 Ω), R4 (2.7 kΩ), D2, D3 (both 3.6 V Zener Diodes) and the USB connector as shown below.

Testing the USB Port

Let's test the USB port. However, note that this port does not follow the USB specifications and could damage your computer. There are at least two ways to prevent this:

  • First connect the device to a hub that is not connected to the Host and see what happens. Then connect your Host to the Hub.
  • Even better would be to add a USB isolator as the one used below.

After connecting the Device to your Host, you should get a notification about a new USB device:

trottel kernel: [76212.960126] usb 1-4.3.2: new low speed USB device using ehci_hcd and address 59

When you see this line, the tricky part of this Workshop is done.

Finishing the PCB's Core

Just to improve some electromagnetic emissions, add bridges (or 0 Ohm Resistors) B1, B2 and B3.

Base & Reset Resistors

Now we are going to add the /Reset pull-up resistor R1 and base resistors R8 to R19 and R38 to R40 with 3.6 kΩ resistors

Transistors

Now we are adding the transistors T1 to T18 (BC807).

LED Resistors

Next are the resistors that limit the current flow through the LEDs. If you are using the parts supplied at the 27C3 Peace Mission in Göttingen, you can just use the values given here. If you are using other LEDs, please calculate your own Values. First are the 150 Ω resistors R32 to R37 for the red LEDs. Then the 100 Ω resistors R26 to R31 for the green and R20 to R25 for the blue LEDs are following:

Optional: Voltage Regulator for external Supply

Instead of using the USB power supply, you can also add an external supply, for example a 9V battery. Do not use USB power supply and the external voltage regulator simultaneously!

To use this supply, add a two pin connector as shown below:

Then add a 1N400x diode to D1, an LM1117 (AMS1117, &c.) to U2 and 10 uF, 10V capacitors to C7 and C8:

Test the voltage regulator by setting your lab power supply to 7.5 V and 0 A. Connect the supply to the two pins you just added and slowly increase the current limit. You should see a current of about 20 to 30 mA when the voltage limit is reached. If this is not the case, you probably did something wrong.

Optional: Button

Part II: The LEDs

For this part you will need 6 RGB LEDs, about 20 centimeters of heat shrink and enameled copper wire with a diameter of 0.6 to 1.0 mm (more may work too, less may not be stable enough).

Cut 4 pieces of wire off the spool, each about 30 to 40 cm in length.

Use enamel removal tweezers to get 5 mm of clean copper on one end of each wire.

Get one LED and bend the leads outwards to about 20 to 30 degrees. This does not have to be exact as we will bend them back once we are finished.

Mount the LED in one finger of a third hand and pre-tin its leads.

Now, also tin all four wires at the end where you removed the enamel.

You can now solder the copper wires to the LED lead without adding new solder. Try to solder the wires as near to the LED case as possible. Beware: The copper wire may heat up faster than you think.

After soldering all four wires, you can turn the LED around and clip off any extra lead.

To prevent any short circuits, cut the heat shrink into sizes that are long enough to cover the remaining LED lead and put those pieces on the leads.

There are many ways to shrink a heat shrink. The probably most simplistic one is to use a lighter. However, do not put the heat shrink into the flame, about 5 to 10 centimeters above the flame are enough.

Now switch to the other end of the copper wires. Place them in a drill chuck. Make sure that the length of all wires from the chuck opening to the LED is equal.

Firmly grab the other side of the wires and slowly start the drill. You should get something like in the images below.

Release the drill chuck and cut all wires to equal size. Then remove about 5 mm of enamel. Though this is not necessary it may be a good idea to tin the end of the wires.

It's time to test our construction. Get a lab power supply, set the voltage limit to about 3.2 V and the current limit to 10 to 20 mA. Then probe different combinations on the of the wires to find out what lead is connected to ground, positive red, positive green or positive blue:

To adapt the wires to the PCB, they should be bent so they are in the following order: ground, positive red, positive green and positive blue.

Part III: Putting them together

Now we put the result of part I and part II together.

To do so, we first make sure that the legs are still in the correct order: Ground, Red +, Green +, Blue +. Do this as described in part II:

Somehow mark the ground pin, for example by bending it outwards:

Put the LED into the PCB. The Ground pin is the one that is clockwise the last (from the component side of the PCB, the side with the microcontroller) or the first (from the top side of the PCB, the side with the USB and programming connector).

Just solder it. Make sure that the solder joints are good as those will have to withstand any force applied to the LED.

Now just test the LED and repeat these steps for the next five LEDs.

What now?

Well, everything necessary is done! Now:

  • Decorate, paint and glue until this really looks like a flower or whatever you want to have.
  • Check out control programs from the official git sources to this project (see LED Flower#Sources).
  • Feel free to contribute any new ideas and send a photo of your flower to fl@deaggi.net [1] or simply add it yourself to LED Flowers.

Known Issues

As many other things, this project ist far from perfect:

  • We do not yet implement correct LED fading. For correct human perception of the different brightness levels we would have to implement a logarithmic scale. There are some trials to do so using a 16-bit PWM instead of 8 bits in the git history, however, they all brought up different more severe issues.
  • Sometimes some PWM actions are deferred due to the time-critical in-software USB operation. This leads to perceivable flickering of the LEDs when tey are are at a brightness level. This also complicates the issue above as this makes it a bit harder to implement a correction on the host side.

However, both issues can be ignored, as long as you do not need calibrated colors and on every RGB LED there is one LED that is at brightness level 15 or higher.