This one will be a rather short post to describe the LED rings that I used for the background effect.
They are very cheap WS2812B based LED rings from ebay. I bought 3 different ones, 7 LEDs (1,10 EUR), 16 LEDs (2,29 EUR) and 24 LEDs (3,69 EUR). The wiring is very easy, the WS2812B is addressable and requires only 5V, GND and one control pin from the Arduino. They are even chainable so I connected the control pins of all three rings to only require one singel Arduino pin.
In the following picture you can see the wiring. Yellow is the control pin chained from the biggest to the smallest ring. The black ground wire is also chained. I decided to provide the 5V to every ring on its own to avoid a loss of brightness (but I guess with only 47 LEDs that was not really necessary). I even made a professional looking schematic, see the small orange paper in the pic?!
In the next picture you see the solder pads in a closeup.. Here is the smallest ring only connecting the input side (black=GND, red=5V, yellow=control pin). As you saw above I secured everything with hot glue.
Here it is already glued to the back of the stage:
As a beginning I searched for an easy to use library and found FastLED. They are also compatible with Adafruits NeoPixel. So go have a look there. They have great guides.
This is using readymade color palettes and combines that with a random noise generator. You can influence the parameters (e.g. with the sound input) and so make this you own. I didn’t have so much time so I just fed in some parameters from my sound input and adapted it to the number of LEDs. The result will later be described in my Software wrapup.
I used acrylic glass that I sanded so it is not clear but milky to make the effect more outstanding. That will be seen later in the woodworking part. In my demonstration video you can see the rings in action (here directly starting at 0:11):
This on its own worked great. But I had to learn that this is working just as the first code and is blocking the Arduino / slowing it down so much that everything else is not working as I was expecting it to be (especially the Audio analysis). Also together with the LED rings it was not really working out. It also produces interferences in the power lines. I used one single power source (5V 3A). But this led to so much interferences in using the stepper motor in the Audio output that I had to come up with another solution. More on that in a later part 😉
In the video there is the disco ball in action (starting at 0:48):
I bought some stage lights from Playmobil (see also my post on the Playmobil parts):
They have a diameter of 1cm inside. So I thought „why not buy big LEDs that fit in there?“. I measured and looked through the online shop of http://www.conrad.de. I figured out that the 10mm LEDs will not fit because they have a slightly wider ring on the bottom. The 8mm LEDs also have this ring but this one is about 10mm so fit perfectly.
I bought 9 of these in the colors red, yellow and green (after the guy at the parts counter wanted to also sell me white ones. Right before going to the checkout I saw that they cost 4.95 EUR each. He nearly got me. Now I know I always have to ask for the price of all parts, even if they seem nearly the same…).
Back home I calculated the resistors needed and came up with the following results using http://ledcalc.com/:
What I didn’t think of was how bright they would be. When I connected everything I was a bit disappointed but having a look at the data sheets I understood why and blamed myself. They only have 3 mcd of light. That’s really next to nothing. A candle has about 1000 mcd. So I will go back to using 5mm LEDs that are cheaper and easier to find in various colors and with a much higher mcd value. Lesson learned!
I then just ordered a cheap LED set from ebay with higher mcd values and 5 colors each in sizes 5mm and 3mm. Those are quite acceptable in brightness. Only the green LED is very dark (although it has the highest mcd ratings… can anyone explain that? I experimented with resistors from 82 ohm to 100 ohm but it is not very bright). I won’t do the full resistor math here, just use an online LED calculator
The light distribution is very wide but I also had some LEDs from a cheap starter set which are more like a spot light. I will combine both and will place the spots. I also have red, blue and green LEDs from those but the green ones have the same brightness problem so I will just use red and blue. I combine the red and blue spots together with the yellow ones from the set in the Playmobil spots and have two white spots at fixed points at the side of the stage for the disco mirror ball (5cm diameter) I bought from Conrad:
The spotlights are mounted on a 4mm aluminum rod:
That is a tight fit but is just the right tension to not move easily and be able to move the spots.
Schematics LED controller board
From my HUEify project I had good experiences with using a MOSFET to drive LEDs so I bought some BUZ11 again (I know, not the best ones to use but at least here a very cheap way to go). So the plan is to drive the LEDs in color groups, each driven by a BUZ11. In the groups the LEDs will be connected in parallel with a resistor each.
This is the basic cabling for one LED. There are two pin headers for power (top=GND, botton=5V) and one pin header for the control pin of the Arduino. Three of the LEDs are connected to one MOSFET with common 5V. The build process is documented in the following pictures:
Resistors first, then the cables to LED’s anode (red cabling).
Then solder the MOSFETs, the pin headers for the control pins and the pin headers for GND in place (I took 2 here which was a good decision in the end. I will explain that later). If you have a closer look at the picture above: do you see what’s wrong? Post it in the comments… Always double-check before soldering!
On the right side is another pin header (also 2 pins here) for the 5V power. Above are the black cablings from the LED’s cathodes. The lower part is for the white LEDs for the mirror ball. I messed up with one resistor so I had to solder a third one… Here the cabling is a bit different because I wired them directly to pins 9 and 10 of the Arduino. I also messed up with the black cable: it goes to the LED’s anode, not cathode so I used yellow cabling to the anode to be reminded of the mistake. It helped! And finally some hot glue to hold everything in place (that is a whole lot of cables…)
Here is a picture to give you an idea of the mess of cables (LED rings are also included there):
I used tape to hold the cable pairs together and marked them to see which is connected to which MOSFET. Also a good idea!
To put them into the spots I had to drill a hole in the spot itself. I think it was a 4mm drill that was perfectly fitting. After that I put some heat shrink tubing in place:
Putting the cables through and adding another small heat shrink tubing to the black wire:
Then I soldered the LED in place:
Always test after sodlering and before shrinking the heat shrink tubes:
Then put the LED into the spot and use hot glue to hold in place:
Last but not least put them on the rod (more on that in a future post):
In the following picture you can see one of the spot LEDs for the disco ball. They are just hot glued into the side walls:
And it’s always a good idea to prepare for mass production:
The control of the lights will be described in the software wrapup. Next week will be about the disco ball, including the control of the stepper motor.
I found several music related sets and also wedding related ones that I will just list here. The picture is linked to Amazon using my partner ID. If you choose to buy something I would be glad if you’d use the link.
Link and Picture
Set name (german)
Pop Stars Stage Bühne
Pop Stars Tour Bus
Pop Stars Keyboarder
Pop Stars Band
Disco mit Liveshow
Sängerin am Keyboard
Link and Picture
Set name (german)
Brautpaar mit Hochzeitstorte
Hochzeitsgäste im Partyzelt
Brautmodengeschäft mit Salon
Hochzeitspavillon mit Brautpaar
Fotograf mit Blumenkindern
From those sets I researched all the parts that I could use and got the prices and availabilty from the Playmobil spare parts service. Unfortunately I found the really helpful site http://playmodb.org/ after I researched everything via the manuals from Playmobil. But as a hint: use it if you search for something:
To research the part numbers from sets just enter the set number:
This would have saved me some work. If you are not sure about the part, just match the part number from the inventory with the picture. For prices just go to the Playmobil service site and enter the part number:
Most of the parts I searched for had no picture and sometimes the names are also not the best ones. PlaymoDB is much better!
Another hint: Don’t forget to order the stickers for the parts that require some, e.g.:
Sometimes there are even several options:
At the service you have two options. The first one is to directly order in the shop. But there were nearly no parts available that I wanted to order. There is a hint that you have to make an individual order:
There is a separate form for that: https://www.playmobil.de/ersatzteilbestellung But there you can only enter 10 parts. I read some forum posts on http://www.klickywelt.de/ and they just call (also not cool if you want many parts) or send an email (in Germany it’s firstname.lastname@example.org). Please save them some work and prepare your list with part numbers and names and how many you want. I even included the prices. You will get an offer with the total costs which you have to confirm and then receive a package a few days later J
I didn’t know about the service before I purchased my first set, the rockstar (4784) via https://www.ebay-kleinanzeigen.de/. That was cheap and included a guitar, a microhpne and stand and the amp, so it was okay. I also (still) don’t know whether you are able to order the figures from the spare part service or how much they cost because you don’t find them in the spare part search, so I searched and ordered them separately. The wedding couple (5163) was matching the real couple okay (the couple from 9229 would have matched better but that was only announced when I researched and the whole set would anyway been to expensive) and I got that with a coupon also really cheap. I had to search for a boy (they have a kid and a band needs a drummer) a little longer but found a very cheap offer of the set 9230 with a boy as a flower kid also on https://www.ebay-kleinanzeigen.de/. I haven’t yet sold the leftover parts, so if someone is in need of a photographer set without a boy or of a rockstar without equipment…
Here is a list of parts that I researched. For most of the things you need several parts, e.g. for the guitar you need 3 parts (the neck, the body and the strap), for the drum even more. I listed them seperately as complete sets though they include equal parts. For the final order I consolidated that of course:
Subject / required quantity (if more than 1)
Bass Drum Front
Bass Drum Back
Cymbal Stand Rod
Sticker (for the whole stage set)
Drum Seat (blau)
Drum Seat Stand
Guitar Stand Rod
Guitar Stand Bottom
Guitar Strat blue
Strat Body blue
Guitar Strat white
Strat Body white
Strat Body white (alternative)
Guitar Strat red
Strat Body red
Guitar Strat yellow
Strat Body yellow
Guitar Neck (brown)
Micro Stand (short)
Micro Stand rod
Micro Stand Bottom
Micro Stand (boom)
Micro Stand rod
Micro Stand Bottom
Counter base, solid
Guitar Amp 3T
Guitar Amp 3T (Aufkleber)
Drumsticks and -jazz broomsticks
Micophone black round
PAR yellow glass
PAR red glass
PAR orange glass
Light 2 (Set 6983)
PAR light-yellow glass
PAR light pink glass
PA-Box Sticker 4x PA-Box
PA-Box Sticker alternative: whole stage set
My final order was the following (german, not including parts that I didn’t use in the final product and which I already had from the sets):
Adapter-Clip 3 6
Stange 46×3 6mm
Etikett 5610 „Carrying Case Band“
Etikett 4784 „Rockstar“
Here again a picture of the first (with the rockstar as drummer and some additional parts I ordered) and the final setup:
Next week I will most probably continue with the assembly of the LED spots.
As a wedding gift for a befriended couple, both are musicians, I build a stage for Playmobil figures. The result can be seen in the following pictures (a video is at the end of the article):
In a series of blog posts within the nest weeks I will describe in detail how I build it, what the difficulties were and everything I had in mind that would be also possible (but as a matter of time I wasn’t able to implement in the final product). Today will be about the basic idea and the implemented functions.
The inspiration came from a gift we got to our own wedding. In a small wooden frame there was a horse (my wife is a horse rider), bride and groom with a guitar on it. Unfortunately I don’t have a picture of the gift as a whole but I still have the figures:
I thought that I could reuse the guitar and build a small stage with a couple on it. But then there questions came up: I would need new figures, a second guitar (or a bass guitar). And a stage with no light or music at all?
My first thoughts were about figures. I came up with Playmobil. I saw guitars there and after some internet research I found a big community about customizing Playmobil. And even stumbled upon several pictures on Pinterest about rebuilding Rock Bands (I Love Clicks, e.g. Bon Jovi in the following image):
But that’s also not what I wanted and was too expensive.
But there were some cool things: The whole music equipment like the drums, guitars and microphones. The light spots. After another short research I came up with the spare part service from Playmobil (this is the german link but they also provide that in different countries): https://www.playmobil.de/content/spareparts_info/SPAREPARTS_INFO.html
Great! But you need the part numbers. I googled all the sets with music equipment and searched for the part numbers. You can use the manuals available with the set numbers on the Playmobil site and/or http://playmodb.org/. I will provide the details in the next blog post.
The basic functions I came up with were:
Light reacting to sound
And then it went all out of control… J But more on all the ideas in a future post.
As I already said the stage should be like a festival stage. That includes a certain size. The first draft was to use DIN A4 and/or DIN A3 sized sheet wood. But two of those were not quite the size. And I had to plan for some space for all of the electronics:
So it had to be bigger! The detailed measures and the plans for the wood will follow in a separate post.
I did some more research and because of my electronic knowledge is mainly based on the Arduino as a controller and I had some cheap ones lying around, I wanted to do everything on this basis. I found a library to play music from an (micro) SD card and I already played around with lighting in my HUEify project. Build some LEDs into the spot is not the most difficult thing.
The other features have evolved by internet surfing and eBay. The following is included into the final stage:
Play music from a microSD card
Buttons for Play/Next/Stop
Sound Sensor to analyze the ambient sound
Sensitivity-potentiometer for the Sound Sensor
Switch for swithing between internal and external audio
LED-spots (3 blue, 3 red and 3 yellow spots, each color can be controlled seperately, more or less, more on that later …)
LED-rings behind a milky acrylic glass as the background, LEDs controllable seperately
Turning disco ball (by a stepper motor) with seperate white spots
That’s it. Here is the backpanel:
From top to bottom:
Button: Audio Playback (short push=Play/Next, long pugh=Stop)
Switch: Input Switch (left=internal audio playback, right=external sound)
Potentiometer: Sensitivity for external sound (controls the threshold volume for activating the light)
Cable: Using a rubber from a beer bottle to hide the cable hole. Two cables, small black=audio player, grey=light control.
And now I will finish this post with a video (Music: Monkey Fly – Whatever – www.monkeyfly.de):
In the next weeks I will continue with the detailed posts. I have already written some of the really technical posts, but I will try to have the general posts before the nitty gritty details.
Als Hochzeitsgeschenk für ein befreundetes Paar, beide Musiker, habe ich eine Bühne für Playmobilfiguren gebaut. Das Ergebnis ist in den folgenden Bildern zu sehen (ein Video gibt es unten):
In einer Serie von Beiträgen werde ich detaillierter beschreiben, wie das Ding aufgebaut ist, was sich mir für Schwierigkeiten in den Weg gestellt haben und was mir noch alles im Kopf herumgeschwirrt ist, aus Mangel an Zeit dann aber nicht mehr umgesetzt werden konnte. Heute geht es erst mal um die grundlegende Idee und die Funktionen.
Inspiriert hat mich ein Geschenk, das wir zu unserer eigenen Hochzeit bekommen haben. Es war ein Rahmen, darauf ein Pferd, ein Hochzeitspaar, er mit einer kleinen Gitarre in der Hand. Ich habe leider kein vollständiges Bild mehr, aber die Figuren:
Da dachte ich mir, das lässt sich doch auch für die beiden anpassen. Aber als kleine Bühne. Die Gitarre kann ich nutzen, ggf. Die beiden Figuren auch. Aber dann kamen erst die Probleme: woher einen kleinen Bass oder eine zweite Gitarre bekommen? Vielleicht andere Figuren? Und dann muss es ja auch nach einer Bühne aussehen.
Also mal überlegt. Und auf Playmobil gekommen. Da hab ich doch auch schon mal Gitarren gesehen. Eine kurze Recherche im Internet bringt eine Community zu Tage, die sich mit Playmobil beschäftigt und verschiedenste Szenarien nachbaut. Auf Pinterest gibt es da auch so einiges, wie etwa die „I Love Clicks“ Bilder, hier z.B. Bon Jovi:
Auch einige Bühnen sind dort zu finden, aber nicht so wie ich mir das vorgestellt habe:
Direkt von Playmobil gibt es auch eine Popstars Bühne:
Aber das ist ja auch garnicht so wie ich mir das vorgestellt hatte und auch zu teuer.
Großartig! Dafür braucht man aber die Teilenummern. Also erstmal nach Sets gegoogelt, die Musikteile beinhalten. Dann die Einzelteile herausgesucht (dabei helfen http://playmodb.org/ und die Anleitungssuche auf der Playmobil Homepage sehr weiter). Alles weitere dazu kommt in einem seperaten Teil.
Als Grundfunktionen habe ich mir dann folgendes überlegt:
Licht passend zur Musik
Und dann ist es irgendwann aus dem Ruder gelaufen J
Zu allen weiteren Ideen später nochmal mehr.
Insgesamt sollte die Bühne wie eine Festival-Bühne daherkommen. Zuerst habe ich mit A4-großen Spanplatten geplant. Dann aber schnell gemerkt, dass das nichts werden kann. A3 war auch noch sehr gedrängt (hier schon mit dem Bühnensetup und den Hochzeitsfiguren):
Also musste es noch größer werden. Die genaue Holzplanung und die Abmessungen gibt es ebenfalls in einem späteren Teil.
Dann etwas weiter recherchiert und da sich meine Elektronikkenntnisse hauptsächlich auf den Arduino konzentrieren und ich davon noch einige billige rumliegen habe, wurde auf der Basis versucht die Hauptfunktionen umzusetzen. Audio kann man mit dem Arduino mittels einer Library von einer (micro) SD Karte abspielen. Check.
Licht ist sowieso kein Problem. Die Spots, die auch bei der oben abgebildeten Bühne zum Einsatz kommen kann man einfach mit LEDs bestücken und die Steuerung kenne ich ja schon von meiner HUEify-Serie.
Alle weiteren Funktionen haben sich dann durch Stöbern bei eBay ergeben. Hier der volle Funktionsumfang, der letztlich in der fertigen Bühne steckt:
Musik von microSD-Karte abspielen
Button für Play/Next/Stop
Sound Sensor, der die Umgebungsgeräusche erkennt
Sensitivity-Regler für den Sound Sensor
Umschalter zwischen internem/externem Audio
LED-Spots (jeweils 3 blaue, 3 rote und 3 gelbe, pro Farbe steuerbar, naja, fast…)
LED-Ringe als Bühnenhintergrund (hinter milchig geschliffenem Acrylglas), LEDs einzeln ansteuerbar
Drehbare Diskokugel mit seperaten weißen Spots
Das ist es grob. Hier einmal das Backpanel:
Von oben nach unten:
Taster: Audio Playback (kurzes Drücken=Play/Next, langes Drücken=Stop)
Kippschalter: Input Switch (links=interne Audio-Wiedergabe, rechts=externer Sound)
Potentiometer: Sensitivity für externen Sound (regelt, ab welcher Lautstärke auf Sound reagiert wird)
Kabeldurchführung: ein Flaschengummi von einer Flensflasche (bzw. einem Alster, da es ein blaues Gummi hatte)
Als Abschluss für heute gibt es noch ein Video (Music: Monkey Fly – Whatever – www.monkeyfly.de):
In der nächsten Woche geht es dann mit Detailberichten weiter. Ich habe einige Teile bereits vorgeschrieben, allerdings geht es da eher um den eher trockenen Software-Part. Ich versuche möglichst erst die spannenden Dinge zu dokumentieren und eine einigermaßen sinnvolle Reihenfolge hinzubekommen. Außerdem wird es diese Einführung spätestens am Wochenende noch auf Englisch geben, da alle anderen Teile ebenfalls in englischer Sprache erscheinen werden.
This is a side project to the original HUEify series on connecting a custom light to the HUE ecosystem. On the site http://faire-ca-soi-meme.fr/ there are some articles about what’s inside the Smart Home Gadgets of Xiaomi (at the end of this I provide all the links currently available). Every single piece is taken apart and detailed pictures were taken describing all the identifiable parts. With my little bit french from school even I can read through it. But maybe Google Translator may help others.
I decided to order two pieces because they were very cheap at Gearbest at that time and they would make a perfect match to the nightpanel lights I am currently building and replace the currently used Amazon Dash button. And because they just arrived and I am waiting for PeeVeeOne to publish his solution for the Multiple Endpoint RGB lights on the JN5168, I will now try my luck with the Xiaomi button to see whether I can get it to communicate with Hue.
On faire-ca-soi-meme there are several detailed images of the button and also the pinout from the test pins. Unfortunately these are pogo pins and my tries to solder a wire to them were not very successful. I was successful though with using jumper wires to connect 3.3V and GND to the battery connector, hot-glueing two jumper wires together in the right spacing and forcing it to the pogo pin connectors for RX and TX with a soldering hand. The fifth pin that is required is only temporary and is the SPIMISO pin next to RX/TX. Just shortly connect a ground wire to it when connecting the power (even with my shaky hand that works).
If that is done right you can open the Device Info in NXP Beyond Studio (use 1000000 Baud and the correct COM Port):
I then compiled the Controller_OnOffSensor Demo app from NXP although in the documentation it is only described to work with the JN5168 demo hardware. I used the compile flag for the JN5169 and it compiled successfully. There is an error when flashing the firmware with the flash utility from BeyondStudio but this is only the validation after flashing. The reason is that the chip was read-protected from Xiaomi in order to make reengineering their firmware impossible (or not-so-easy). So the flashing was successful which can be seen from the serial monitor after rebooting:
APP: Switch Power Up...........................(several dots more)
Heap size at step 1 is 11412 bytes (start=04003fe4 end=04006c78)
APP: Watchdog timer has reset device!
Heap size at step 2a is 11412 bytes (start=04003fe4 end=04006c78)
Heap size at step 3 is 11412 bytes (start=04003fe4 end=04006c78)
Heap size at step 4 is 11412 bytes (start=04003fe4 end=04006c78)
Heap size at step 5 is 8216 bytes (start=04004c60 end=04006c78)
Heap size at step 6 is 8216 bytes (start=04004c60 end=04006c78)
Starting Touch Interface...
This ouput is repeated from the timer resetting the device. There seems to be something wrong. The last output message can be found and after that the drivers eTouchInit method is called. I added some debug output and commented out the first for loop (is this a delay or what is that for?):
This results in the following output (the BWE was added because I wanted to be sure I have the correct call):
APP: Switch Power Up...........................(several dots more)
Heap size at step 1 is 11428 bytes (start=04003fd4 end=04006c78)
APP: Watchdog timer has reset device!
Heap size at step 2a is 11428 bytes (start=04003fd4 end=04006c78)
Heap size at step 3 is 11428 bytes (start=04003fd4 end=04006c78)
Heap size at step 4 is 11428 bytes (start=04003fd4 end=04006c78)
Heap size at step 5 is 8232 bytes (start=04004c50 end=04006c78)
Heap size at step 6 is 8232 bytes (start=04004c50 end=04006c78)
Starting Touch Interface...BWE
So there seems to be something wrong with the for-loop. Maybe it tries to read from a wrong pin (because it was made for the JN5168). I will have to take a closer look at the driver and see what I can do. I think I have to understand how it is working first (it is build for a remote control with several buttons so I guess a more simple solution has to be found). I also have to see which DIO pin the buttons are connected to…
In parallel there are also some comments from lucac81 on peeveeone.com about using the JN5169 and Peter also wrote that he ordered some, so maybe the master is faster than me 😀 lucac81 had trouble even installing the light firmware compiled for the JN5169 so maybe I will even try flashing that on the chip to see what happens with the button (just to see if it works, of course I will not use a button to make a light…). I also remember a comment asking about using the chip as a switch for HUE. So maybe someone else is also making progress on this end. I am open for any discussion/help/input.
Today I want to show you the board that I created in order to drive 4 RGB LED strips from 16 PWM outputs of the Arduino Mega. It is not the best design as this is my first board and I began without really knowing how to connect the strips in the end 😉 This board connected to the Arduino Mega controlled by the output of the JN5168 will then be the final solution to integrate light in to our nightstands.
I built the design in fritzing so let’s have a look at it:
J3, J5, J7, J9 are the connectors (male pin headers) for the PWM pins from the Arduino Mega
J2, J4, J6, J8 are also male pin headers to connect the RGB strips
J1 ist the input for the external power source (5V in my case) also as male pin headers
J22 are additional ground pins to connect the ground from the Arduino (I connected three because you never know…)
Q1 – Q12 are MOSFETs, in my case BUZ11
On the board I put all ground connections to the second PCB side (orange) so the connections are clear.
When I had already started soldering the board I thought about how I wanted to connect the RGB strips in the final setup and I decided to go with commonly available 4 wire RGB strip cable (can be found on ebay) and connect it via screw terminals. I was not able to change the design I already started so I just added another board (in the end I had enough space on the same board) which had four 4-pin headers again directly connected to four 4-output (okay, it’s eight 2-output) screw terminals:
I did not put much effort in making the fritzing pretty so the schematic view is a real mess and in the breadboard view I just used perfboard without any wire connections. So essentially just use the PCB view. It should be obvious. Anyway I would modify the board to make direct connections to the screw terminals if you want to use it. But it is working now and it is my first completely self designed and soldered board J
This is the progress with the first working module (I already showed a work in progress version in the previous post):
This is the final board including all terminals and pin headers. I even have space to include the logic level converter (LLC) that I need for the JN5168. This way I can directly connect the grounds all on this board. This is not yet soldered because I ran out of solder wire.
This is the board connected to the Arduino and currently directly from the pin headers to the RGB strips.
This is a video of the Arduino Mega controlling all 4 strips via PWM signals from 16 pins:
Next task is to solder the LLC and reconnect the JN5168. Then I have to prepare the wires to connect from the screw terminals to the RGB strip (needs a little soldering and heat shrink tubing). This will then suffice to control all 4 strips with the same setting (one endpoint) but the final piece will then be to create 4 endpoints on the JN5168 to control the 4 strips independently.
The JN5168 chip itself has only 5 PWM outputs and thus is not able to control more than one RGB LED strip. To overcome this I want to connect an Arduino Mega to the JN5168. The Mega has 15 PWM outputs so up to 5 RGB strips can be connected. To connect the two devices I chose to use the standard UART serial interface that is activated by default in the NXP demos. In this post I will describe how to connect the two devices and what to do to make the Arduino understand commands from the JN5168.
Hardware serial connection from JN5168 to the Arduino
As the Arduino is using 5V level on the serial connection and the JN5168 is using 3.3V a logic level converter (LLC) has to be used. This little device connects the two serial interfaces shifting from 5V to 3.3V. The connection can be seen in the following image (to drive the JN5168 from the Arduino connect an additional wire from the 3V3 pin of the Arduino to PIN 17 of the JN5168):
Software serial connection from JN5168 to the Arduino (JN5168 program)
I used the default UART port of the JN5168 because of two reasons:
It is activated by default and the demos are already making use of the output
I didn’t connect any additional wires than the ones that need to be connected to flash the chip and use the PWM output and the default UART is also used to flash the firmware
To have a more stable connection to the Arduino I reduced the baud rate from 115600, which is the default rate, to 9600 which the Arduino can handle better. To do this in the file app_start_light.c go to the function vAppMain() and search for the line :
Do the same in the function vInitialiseApp() in the same file.
I tried two different approaches to send output to the arduino:
Use the debug output of the TRACE_LIGHT_TASK / DEBUG_LIGHT_TASK
Define a custom debug flag to directly output the PWM signal.
As I didn’t have success yet creating multiple RGB endpoints and am waiting for PeeVeeOne to publish his work on multiple endpoints, I first went with option 2 which is currently not able to hand over an identifier for the endpoint which the option 1 is able to. The second option has the advantage that it handles smooth transitions, which the other one doesn’t. Once I am able to create more endpoints I may create another output. I will describe both solutions anyway:
Option 1: TRACE_LIGHT_TASK
First, activate the debug flag in the Makefile:
CFLAGS += -DDEBUG_LIGHT_TASK
Then go to the file app_zcl_light_task.c and search for
I modified the first appearance (in APP_ZCL_cbEndpointCallback) of the function, where it outputs a new line and the RGBL (Red, Green, Blue, Level) values to include an identifiying symbol (§) and the endpoint:
DBG_vPrintf(TRACE_LIGHT_TASK, "\n§ EP %d R %d G %d B %d L %d ",
psEvent->u8EndPoint, u8Red, u8Green, u8Blue, sLight.sLevelControlServerCluster.u8CurrentLevel);
There is a second appearance in the same file and the same function (APP_ZCL_cbEndpointCallback ) where I did the same thing again.
In the file App_Light_ColorLight.c there are two other usages of the function which handle the identification effect. In the function APP_vHandleIdentify() there is currently no handle for the endpoint available so I didn’t modify this one. In the vIdEffectTick() there is an endpoint reference available so I added this similar to the function call above.
DBG_vPrintf(TRACE_LIGHT_TASK, "§ EP %d R %d G %d B %d L %d Hue %d Sat %d\n",
In the end the Arduino will receive a message will look like this:
§ EP 10 R 255 G 227 B 139 L 147 Hue 0 Sat 0 X 24939 Y 24701 M 1 On 1 OnTime 0 OffTime 0
This one call will result in 10 PWM changes in the JN5168 to have a nice transition. This is why I currently go with the second option:
Option 2: TRACE_PWM
First, I defined and enabled a new debug flag in the Makefile:
CFLAGS += -DDEBUG_PWM
Then in the file DriverBulb_JN516X_RGB.c I added the following to the definition section at the beginning:
Then, in the function DriverBulb_vOutput() I added the following after the calls to vAHI_TimerStartRepeat at the end:
DBG_vPrintf(TRACE_PWM, "\n# EP %d On %d R %d G %d B %d L %d",
Together with the first option this will result in the following output (as I said it produces a smooth transition):
§ EP 10 R 255 G 227 B 139 L 147 Hue 0 Sat 0 X 24939 Y 24701 M 1 On 1 OnTime 0 OffTime 0
# EP 10 On 1 R 170 G 151 B 92 L 170
# EP 10 On 1 R 167 G 148 B 91 L 167
# EP 10 On 1 R 165 G 146 B 89 L 165
# EP 10 On 1 R 162 G 144 B 88 L 162
# EP 10 On 1 R 160 G 142 B 87 L 160
# EP 10 On 1 R 157 G 139 B 85 L 157
# EP 10 On 1 R 154 G 137 B 83 L 154
# EP 10 On 1 R 152 G 135 B 82 L 152
# EP 10 On 1 R 149 G 132 B 81 L 149
# EP 10 On 1 R 147 G 130 B 80 L 147
You can also see that the RGB values changed. This is according to the level value. The calculation is:
The level is not really necessary in the output because the RGB values are already adjusted. I kept them anyway.
Software serial connection from JN5168 to the Arduino (Arduino program)
For the Arduino part I first setup the serial connection (I connected it to Serial2) and read the input. Based on the first character (§ or # are the relevant ones for the two options) the program decides whether the whole line is relevant.
Then it parses the input line using the function strtok(). Then I set the PWM using analogWrite(pin, value).
The serial input is lagging sometimes (though I think this is only the case when using the serial output to the other serial port) so garbage is getting read as a line. In case of not set values I checked whether the value is correctly set. Otherwise the old value is used. This may lead to wrong values but better than nothing.
My currently used Arduino sketch (using only one PWM output) can be downloaded here:
This may not be the best way of communication (SPI may be better) but it is the easiest to setup. To command 4 separate endpoints I may have to use option 1 and go without transitions or implement them myself on the arduino. The bottle neck seems to be the serial connection as the arduino seems to be too slow to process the serial input fast enough. This is another argument for option 1 as it sends fewer lines. Although it is sending more than one line for a simple light change, too. Maybe the app itself also sends several commands to have a nice transition. I may check this later on. In any case I recommend disabling all other debug outputs to make better use of the serial communication and loose fewer lines.
Currently I am also building a board to connect everything together. It will not be very professional (as I will be using many jumper wires instead of connecting everything directly but I want to be flexible) but should work for me. It will be hidden away anyway. The board connected to the Arduino and the serial connection to the JN5168 can be seen in the upper left with one temporarily connected RGB strip. In the final version they will be connected with screw terminals. The LLC will also go from the breadboard to the custom board.
This is the current progress with connections ready for two RGB strips.
There will be 4 RGB connections in the final version to be connected with screw terminals, the LLC and a connection for an external power source. This is all still work in progress so I will publih the final schematics when I am ready and know that everything is working as expected. And of course I hope that the weather will be getting better here so I can disassemble our night desks and get them to my workbench (actually my balcony which is why I am hoping for good weather 😉
Today I will describe my progress on the development of my own Hue connected lights. Because other people developing with the JN5168 are not necessarily german speakers I will continue my project (which I call HUEify) in english. There is some discussion going on at the latest post from PeeVeeOne.
As I had some trouble with the build provided by PeeVeeOne (lights not turning off, dimming and red not working properly) I had to go through the proecss of building my own binary. This was planned anyways because I have some other plans on top. This post is all about my troubles getting the demo app and a custom build project to work. This should be seen as an additional detailed description to the information that can be found at PeeVeeOne’s website and github repository. So far it is all his work that I am just setting to work on my device. The general setup of the developing environment BeyondStudio and the demo application is described in this post by PeeVeeOne.
Building the binaries
First of all I had some trouble building the binaries from both the NXP demo and the github project PeeVeeOne supplied. Both were not joining the Hue bridge and were not giving any debug information, though the binary directly downloaded from PeeVeeOne was doing both without any issues.
The build of the NXP Demo Application (JN-AN-1171) is defaulted to create a binary for the JN5169. To change this I changed the default in the Makefile (Common_Light/Build) to 5168:
But that is not enough as the builder is getting the command additionally (mind the configuration in the dropdown at the top of the window) In the project properties you have to change the Build command:
Now the correct binary will be build.
Sometimes I had the binary not correctly rebuild after changes as it didn’t recognize any changes (nothing new to build). Then it helped not to use the normal „Build“ but the „Build selected“ and choosing the options „Clean selected configurations“ and „Build selected configurations“:
Debugging the Demo Application and making it work
To trace the startup and the connection you can leave the USB serial converter (FT232) wired to the chip after flashing the binary. It will send debug information which you can read at your PC. I use the serial monitor from the Arduino IDE (you have to close the monitor before flashing the binary because it will lock the serial connection and you get an access error).
In the default of the demo application and the PeeVeeOne github rep the debugs are not enabled. To do this, just uncomment the options in the Makefile (you don’t need all of them, actually I use only some from the first block, check the source code for the relevant ones):
It will show something like this:
This is the debug output when starting the device with no search for new devices from the Hue bridge. It goes through all channels serching for something to connect to.
With a search from the bridge started instead of
LIGHT NODE RESET
Disc st 0 c 1 sel 255
Pan 6a075d40c856781e Ch 11 RCap 3 PJoin 0 Sfpl 2 ZBVer 2
No more nwks to try
I got the following output from the demo application:
LIGHT NODE RESET
Disc st 0 c 1 sel 0
Pan 6a075d40c856781e Ch 11 RCap 1 PJoin 1 Sfpl 2 ZBVer 2
Try To join 6a075d40c86781e on Ch 11
Try join status 00
Join failed ad
No more nwks to try
So it seems like 6a075d40c856781e is the ID of my bridge. When not searching for devices it recognizes it but is not trying to join. When searching for devices it is trying but it is not successful.
This was all from my office room which is located at the other end of our appartment. Moving closer to the bridge the original binary from PeeVeeOne successfully joined and I get the following output:
Discover on ch 11
disc status 00
Disc st 0 c 1 sel 0
Pan 6a075d40c856781e Ch 11 RCap 2 PJoin 2 Sfpl 2 ZBVer 2
Try To join 6a075d40c856781e on Ch 11
Try join status 00
Joined as Router
I was searching the error message and found the lines in the code that output it:
Having a closer look at the error message in the output it gave the two letters „ad“ after the „Join failed“. This was actually an error code. In the User Guide of the ZigBee PRO Stack (JN-UG-3101) I was able to find the code (9.2.2 APS Codes):
ZPS_APL_APS_E_SECURITY_FAIL: An APSDE-DATA.request requesting security has resulted in an error during the corresponding security processing.
This made me think of a post at PeeVeeOne’s about Keys. And voila, using the keys in the right places (zpr_light_node.c and app_light_commission_task.c) it successfully joined. Sometimes it’s just careful reading.
Custom Build from PeeVeeOne
I also applied the debugging to the repository from PeeVeeOne’s github and was moving closer to the bridge so it finally joined my hue bridge. The problems I described in my last post (dimming and the color red not properly working and turning of the light not working) was caused by the inverting of the PWM signal PeeVeeOne was applying. I already had that in mind when turning of the light in the App caused the lights to turn bright. So switching the signal did the trick. In the file DriverBulb_JN516X_RGB.c go to line 57 and modify the value from TRUE to FALSE:
The final outcome can be seen in this youtube video:
Until now it was all about the initial setup. But this is where the fun begins. Now I can program the device to my likes and I already have something in mind. I hope to find the time to try it soon. There are some more blog posts about the development, based on PeeVeeOne’s findings, e.g. SevenWatt hacking a SmartPlug from Innr. I am looking forward to see the other projects.
My goal is to use the JN5168 with multiple endpoints configured to act as not only one light to the hue bridge but as several (e.g. to separately control all 4 parts of our nightstands). PeeVeeOne is also working in this direction with controlling 4 dimmable lights with one module. I have some other ideas I first have to check for feasibility and then there will be updates here.