052117_1850_TinkeringTu1.jpg

Tinkering Tuesday – HUEify – JN5169 Xiaomi Smart Button – Part 1 – Making a connection

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
Starting vTouchInitHardware
Stoping vTouchInitHardware

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.

To be continued sooner or later.

UPDATE

I flashed the JN5169 binary provided by Peter on the Xiaomi SmartHome button but it didn’t join. Unfortunately the debug output on that build doesn’t provide much information.
I build a new one from the demo application with all debugs enabled and the keys in place as I did with the JN5168 but I am getting the same output I had when not correctly putting the keys in place the first time with the JN5168 (see my post http://www.boriswerner.eu/tinkering-tuesday-hueify-making-the-custom-binary-and-the-demo-app-work-on-the-jn5168/):

Try To join 6a075d40c86781e on Ch 11
Try join status 00
Join failed ad

I already researched the error code „ad“ before:

ZPS_APL_APS_E_SECURITY_FAIL: An APSDE-DATA.request requesting security has resulted in an error during the corresponding security processing.

Which definitely hints to a key problem. So the general function is there and it even tries to connect to the bridge but get’s a bad response. That can’t be everything here 😉

 

Links

http://faire-ca-soi-meme.fr/domotique/2017/05/09/test-xiaomi-power-socket/

http://faire-ca-soi-meme.fr/hack/2017/04/24/hack-xiaomi-mi-smarthome-decouverte-de-clef/

http://faire-ca-soi-meme.fr/domotique/2017/04/15/test-xiaomi-mijia-6-in-1-smart-home/

http://faire-ca-soi-meme.fr/domotique/2017/04/04/detournement-capteur-de-mouvement-xiaomi/

http://faire-ca-soi-meme.fr/domotique/2017/03/13/hack-xiaomi-mi-smarthome-zigbee-sniffer/

http://faire-ca-soi-meme.fr/domotique/2017/02/27/hack-xiaomi-mi-smart-temperature-and-humidity-sensor/

JN5169 discussion on https://peeveeone.com/?p=187&

050317_1802_TinkeringTu1.jpg

Tinkering Tuesday – HUEify – PWM to RGB LED strip driver Board

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

You can download the fritzing file here: 16PWMIn_4RGBOut

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.

I put together a small sketch that activates the colors one after the other on all 4 strips. You can download it here: Arduino_Mega_4_RGB_Strip_Color_Test

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.

042117_1148_TinkeringTu2.jpg

Tinkering Tuesday – HUEify – JN5168 to Arduino Mega PWM extension

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):

Connecting the JN5168 to the Arduino Mega via logic level converter
Connecting the JN5168 to the Arduino Mega via logic level converter

Software serial connection from JN5168 to the Arduino (JN5168 program)

I used the default UART port of the JN5168 because of two reasons:

  1. It is activated by default and the demos are already making use of the output
  2. 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 :

DBG_vUartInit(DBG_E_UART_0, DBG_E_UART_BAUD_RATE_115200);

and change it to:

DBG_vUartInit(DBG_E_UART_0, DBG_E_UART_BAUD_RATE_9600);

Do the same in the function vInitialiseApp() in the same file.

I tried two different approaches to send output to the arduino:

  1. Use the debug output of the TRACE_LIGHT_TASK / DEBUG_LIGHT_TASK
  2. 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

DBG_vPrintf(TRACE_LIGHT_TASK

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",
u8Endpoint,
u8Red,
u8Green,
u8Blue,
sLight.sLevelControlServerCluster.u8CurrentLevel,
sLight.sColourControlServerCluster.u8CurrentHue,
sLight.sColourControlServerCluster.u8CurrentSaturation);

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:

#ifdef DEBUG_PWM
#define TRACE_PWM TRUE
#else
#define TRACE_PWM FALSE
#endif

Then, in the function DriverBulb_vOutput() I added the following after the calls to vAHI_TimerStartRepeat at the end:

#if TRACE_PWM
DBG_vPrintf(TRACE_PWM, "\n# EP %d On %d R %d G %d B %d L %d",
(uint8)10,
bIsOn,
u8Red,
u8Green,
u8Blue,
u8CurrLevel
);
#endif

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:

/* Scale colour for brightness level */
u8Red = (uint8)(((uint32)u8CurrRed * (uint32)u8CurrLevel) / (uint32)255);
u8Green = (uint8)(((uint32)u8CurrGreen * (uint32)u8CurrLevel) / (uint32)255);
u8Blue = (uint8)(((uint32)u8CurrBlue * (uint32)u8CurrLevel) / (uint32)255);

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:

SerialReadPWMFromJN5168

Conclusion

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.

The completed serial connection from JN5168 to Arduino Mega and custom PWM to RGB LED adapter board
The completed serial connection from JN5168 to Arduino Mega and custom PWM to RGB LED adapter board

This is the current progress with connections ready for two RGB strips.

Custom PWM to RGB LED strip adapter board (work in progress)
Custom PWM to RGB LED strip adapter board (work in progress)

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 😉

Working_Prototype

Tinkering Tuesday – HUEify – Making the custom binary and the demo app work on the JN5168

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:

if (sStackEvent.eType == ZPS_EVENT_NWK_FAILED_TO_JOIN) {
DBG_vPrintf(TRACE_CLASSIC, "Join failed %02x\n", sStackEvent.uEvent.sNwkJoinFailedEvent.u8Status );
vTryNwkJoin();
}

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:

Next steps

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.

031317_2050_TinkeringTu9.jpg

Tinkering Tuesday – HUEify RGB Strips mit dem NXP JN5168

Wie schon angekündigt soll unsere Nachtkonsolenbeleuchtung mittels eines ZigBee Light Link kompatiblen Chips, dem NXP JN5168, an das Philips Hue System angeschlossen werden. Peter Visser, alias PeeVeeOne (www.peeveeone.com) hat da eine super Vorarbeit geleistet.

Die benötigten Teile sind mittlerweile da. Das ist zum einen der Chip selbst (Amazon: RF MOD, IEEE802.15.4, STD PWR, INT ANT JN5168-001-M00Z By NXP) und dann ein relativ beliebiger FTDI zu USB Serial Converter.

JN5168 anlöten und neue Firmware aufspielen

Da sich meine Lötkünste schon im normalen Bereich, also einem Rastermaß von 2,54mm eher so in Grenzen halten, war ich mit dem Breakout der Pins vom JN5168 maßlos überfordert. Coolerweise war auch mein Lehrmeister in Sachen Elektronik (www.doktor-andy.de) begeistert von dem Projekt, sodass er sofort bereit war mir das anzulöten. Mit einem Schluck Bier und daraus folgender ruhiger Hand am Montagabend wurden dann mit dünnem Kupferdraht die benötigten PINs herausgeführt:

Andy mein Lötmeister! Er sei gepriesen!
Die erste Kupferleitung ist angelötet

Wirklich notwendig für das Projekt sind:

  1. Pin 3 (SPIMISO): der muss auf GND gelegt werden um den Chip programmieren zu können
  2. PIN 17 (VDD): 3,3V (wichtig, am FTDI nicht vergessen von 5V auf 3,3V umzustellen)
  3. PIN 18 (GND): Ground
  4. Pins 19, 20, 21 (DIO 11-13): dies sind die PWM Pins, die für die Ansteuerung des RGB-Strips benötigt werden

Wir haben zusätzlich noch Pin 22, den Reset-Pin, herausgeführt, aber letztlich garnicht benutzt. Kurz stromlos stellen geht auch.

20170306_190156
Kleine Spinnenbeine aus Kupfer

 

Mit blieben dann nur kleine Zuarbeiten, wie etwa das Auftrennen der Streifenrasterplatine in der Mitte:

20170306_190222
HiWi Boris bei der Arbeit

Auf dem Breadboard mit dem FTDI verbunden (Rx an Tx und umgekehrt…):

Die Programmierung ging nach Anleitung von www.peeveeone.com beim ersten Versuch gleich durch. Erst den EEEPROM löschen:

Dann die neue Firmware aufspielen:

Freudig erregt bin ich nach Hause gefahren und hab die Philips Hue App angeschmissen und die Bridge auf die Suche nach dem neuen Lichtlein geschickt. Wichtig ist erst die Suche zu starten, dann den Strom am JN5168 anschließen. Und wer hätte es gedacht: Sofort erkannt!

Angezeigt wird sie als „Color Light 1“

Also auf zum nächsten Schritt, den RGB-Strip ansteuern.

RGB-Strip an Arduino betreiben

Damit ich mir den JN5168 nicht gleich verbrate, weil ich irgendwas nicht korrekt angeschlossen hab, wird erstmal mit dem Arduino die Verkabelung getestet. Dazu nutze ich im Grunde das Anschlussdiagramm von Adafruit aus dem RGB-Strip-Tutorial. Ich habe mich für die Nutzung von MOSFETs entschieden und habe bei Conrad den BUZ11 besorgt. Davon 3 angeschlossen und den Beispiel-Code von Adafruit aufgespielt bringt das gewünschte Ergebnis:

Das einzige was auffällt ist, dass der RGB-Strip nicht korrekt beschriftet ist. Die Pins sind wie folgt gekennzeichnet: + – R – G – B allerdings ist die eigentliche Belegung + – R – B – G. Naja, zum Glück ist wenigstens der + Pin richtig…

Nun gut, dann geht es ans Eingemachte. Die PWM-Pins wurden an den JN5168 angeschlossen, GND entsprechend mit an GND vom Arduino angeschlossen und auch der 3,3V Anschluss vom Arduino an den VDD vom JN5168 angeschlossen. Hier ein Video vom ersten anschalten:

Mehr gab es beim ersten Mal leider nicht zu bewundern, da der Empfang in meinem Arbeitszimmer so schlecht war, dass die meiste Zeit nichts passiert ist. Am nächsten Abend habe ich die Schaltung ins Wohnzimmer rübergebracht. Dabei hatte ich einige Kabel abgemacht um es separat zu tragen. Danach habe ich erstmal 1,5h damit verbracht das Ganze wieder zusammenzusetzen und herauszufinden warum „genau der gleiche Aufbau“ einfach nicht funktioniert. Weder am Arduino noch am JN5168 hat der Strip geleuchtet. Bis ich dann am Abend gemerkt habe, dass ich ein GND-Kabel auf der anderen Seite des Breadboard Siderails angeschlossen habe und nicht bedacht habe, dass die in der Mitte nochmal getrennt sind (im Bild mit rot gekennzeichnet und dann auch mit einem Jumper-Kabel überbrückt)…

Am Wochenende wurde dann alles nochmal richtig getestet und verkabelt und siehe da, es wird Licht und die Farben ändern sich. Allerdings leider nicht ganz so wie erhofft. Grün geht, blau geht, rot irgendwie nicht so richtig und das wichtigste: der Strip lässt sich nicht ausschalten sondern wird dann einfach komplett hell. Spricht eigentlich ja dafür, dass da was mit Common Anode / Common Cathode LED verkehrt läuft, aber eigentlich sollte das alles korrekt sein. Hier mal als Video:

Als erstes habe ich dann den Strip nochmal an den Arduino angeschlossen und geschaut, ob ich bei direkter Ansteuerung jeweils einer Farbe die entsprechenden LEDs zum Leuchten bringen kann. Das funktioniert.

Das erste was ich nun tun werde ist mir nun die Verkabelung am JN5168 nochmal zu Gemüte führen (also mal nur jeweils einen Kanal des Strips anschließen und schauen wie sich die jeweilige LED verhält). Dazu wird dann die Entwicklungsumgebung von NXP installiert und dort etwas geforscht. Das ist da wo der eigentliche Spaß beginnt! Der Doku kann man entnehmen, dass man mehrere Endpoints (also mehrere Lampen) auf einem Chip konfigurieren kann. Außerdem kann man den Chip auch als Aktor (also als Lichtschalter / Dimmer Switch) konfigurieren. Nicht ganz eindeutig ist, ob man auch einen Mischbetrieb fahren kann. Wenn ich richtig lese, dann nicht. Aber das werde ich trotzdem ausprobieren. Aber dafür muss erstmal wieder Zeit her.

022517_1401_TinkeringTu5.jpg

Tinkering Tuesday – DIY Lichter / Dinge mit Philips Hue verbinden – einfache und komplizierte Möglichkeiten

Wie schon angekündigt möchte ich die LED Strips für die Beleuchtung unserer Nachtkonsolen mit Philips Hue verbinden. Die Original-Strips sind leider zu breit. Nun möchte ich mal die Varianten beschreiben, die so möglich sind um Dinge ins Hue-Ökosystem zu bringen. Erst geht es um Dinge zur Steuerung, dann Dinge, die gesteuert werden sollen (das viel interessantere).

Aktoren

Hier geht es erstmal darum einen Knopf, Sensor oder irgendwas in der Art zu benutzen um das Licht zu schalten. Dazu findet man so einiges im Netz, daher hier nur mal ein paar Anregungen:

  1. Natürlich alles Aktoren, die Philips selbst anbietet (Dimming Switch, Tap, Bewegungsmelder)
  2. Diverse Third-Party Lösungen (Amazon Echo, Logitech Harmony, Nest,…)
  3. Diverse Smartphone Apps, z.B. all4hue, meine App der Wahl
  4. Über die Hue API (also generell über alles, was einen Netzwerkzugang zur Bridge hat): https://developers.meethue.com/
  5. Im Speziellen von einem Arduino aus (per Ethernet Shield): http://commentfr.xyz/diy/3477-wie-steuern-philips-hue-lichter-von-einem-arduino.html
  6. Via Amazon Dash Button Hack: (hierzu gab es beim letzten Programming Pursday einen Post von mir)
  7. Kodi Media Center mit Hue als Ambilight: http://stadt-bremerhaven.de/philips-hue-und-kodi-zur-ambilight-zentrale-verknuepfen/
  8. Raspberry Pi, ohne Bridge, via Raspbee Shield: https://raspberry.tips/hausautomatisierung/raspberry-pi-lichsteuerung/

Auf dieser Seite ist Philips also sehr offen was die Hackability des Systems angeht. Auf der anderen Seite sieht es schon schlechter aus:

Reaktoren

Hier gibt es natürlich die Standard-Wege.

  1. Alles was eine Lampenfassung hat kann natürlich mit den kompatiblen Lampen (Philips Hue, Osram Lightify, Innr, GE Link) ausgestattet werden. Dann natürlich die Standalone Lampen und LED Strips (z.B. Hue Bloom, Hue Iris, Hue Go, Hue Lightstrip+, Osram Lightify LEDs)
  2. Für alles was einen Stecker hat und nur ein an/aus Signal braucht kann man den Osram Lightify Plug nutzen

Wenn es darüber hinaus geht wird es schon spannender:

  1. Mit allem was einen Netzwerkanschluss zur Bridge hat kann man die Hue Bridge über die API abfragen (Polling), z.B. https://github.com/jbonachera/hue-dimmers-poller oder https://www.npmjs.com/package/homebridge-hue (hat den Nachteil, dass in regelmäßigen Abständen abgefragt werden muss, was zu Zeitverzögerungen und verpassten Events führen kann)
  2. Man kann auch die Steuerung z.B. eines LED-Lightstrips+ abfangen und einen eigenen LED Strip anschließen (Spezifikationen beachten, 24V, 24 Watt Netzteil im Standard, hier kann man mit entsprechenden Bastellösungen bestimmt auch noch weiter gehen indem man z.B: eine größere oder weitere Stromversorgung einhängt)
  3. Es gibt mittlerweile eine Serie von Geräten einer deutschen Firma (Dresden Elektronik), die unter anderem Vorschaltgeräte für LED Strips beinhaltet, die mit Hue kompatibel sind: https://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control/ Hier z.B. auf Amazon: Vorschaltgerät für RGB/RGBW.
  4. Dann gibt es noch die ultimative Bastellösung von Peter aus den Niederlanden (alias PeeVeeOne), der eine Innr Leuchte geöffnet und einen Dump der Firmware des darin enthaltenen Chips NXP JN5168 gemacht hat und so einen Weg gefunden hat einen MeshBee bzw. einen „nackten“ JN5168 zu einem von Hue erkennbaren Device zu machen. Das Ganze hat er auch auf GitHub verfügbar gemacht.

Die letzte ist für mich die interessanteste, da flexibelste Lösung. Allerdings auch die mit den größten Herausforderungen. Zum ersten: Woher einen MeshBee bekommen? In Deutschland schonmal nicht so einfach. Auch beim Hersteller SeeedStudio selbst ist er nicht mehr verfügbar. Einen Shop habe ich gefunden, der nach Deutschland liefert robotshop.com, allerdings kommen da zu den knapp 22 Euro pro Modul nochmal 18 Euro Versand drauf. Das ist happig. Zusätzlich wird überall empfohlen den UartSBee V5 zur Programmierung zu benutzen, der nochmal mit 20 Euro zu Buche schlägt.

PeeVeeOne hat mit einem „nackten“ JN5168 und einem entsprechenden Breakoutboard weiter gearbeitet. Leider ist auch dieses Breakoutboard in Deutschland nicht zu bekommen. Also mal einen guten Bekannten gefragt, was man da machen kann und eigentlich müsste man den JN5168 doch auch ohne Breakoutboard bzw. mit einem selbstgebauten PCB betreiben können. So kompliziert ist das Ding nicht. Also mal einen über amazon bestellt: RF MOD, IEEE802.15.4, STD PWR, INT ANT JN5168-001-M00Z By NXP.

Zur Programmierung sollte auch ein normaler FTDI USB zu Seriell Adapter funktionieren, daher habe ich mal den hier bestellt: FT232RL 3/5V FTDI USB zu auf TTL Serial Adapter Modul Arduino Mini Port DETE203.

Der Plan ist, dass ich damit dann direkt meinen LED Strip in den Nachtkonsolen ansteuern kann und ggf. sogar noch mehr möglich ist (nicht nur die Ansteuerung von LED Strips per PWM, sondern auch anderer toller Dinge (die ich noch nicht weiß, aber die Möglichkeit ist geil!).

In der nächsten Woche gibt es dann das Hands-On mit dem JN5168. Das wird fein.