Introduction: RGB-Led Clock With Bluetooth Smart
This instructable shows you how to use a Cypress-BLE-Devkit to build a RGB-LED-Clock.
You need only very few things:
- RGB-LED-Strip with 30 or 60 WS2812b-LEDs.
- a grid-style PC board
- some pin-header pins and a bit of wire.
- a 5V power-source (could be a USB-Plug!)
- The Cypress CY8CKIT-042-BLE Bluetooth® Low Energy (BLE) Pioneer Kit or if you already have a cypress programmer you only need the CY8CKIT-143 PSoC 4 BLE module
- and a stryropor-foam-ring with a flat side that suits your led-strip length
And of course a solder-iron, a PC and some tools.
Step 1: Start With the "housing"
This was actually the hardest part of the project for me.
I knew I wanted to have some kind of ring with the LED-Strip pointed to the center. There are some tutorials out there with the LED to the outside, but I didn't like that. On ebay you can also buy some ring-LED-strips with 60 LEDs, but they are pointed to you, and I didn't like the idea of looking straight into the LEDs.
Finally I found this styrofoam-ring in a local handicrafts shop. It has a 20cm diameter, the opening is 15cm and it is flat on one side and round on the other.
I used a LED-Strip with 60LEDs per meter, but only used half a meter. So this gave me a diameter of 15.9cm for the LED-Ring.
Then I only had to cut half a centimeter of the inside of the ring. And the LEDs fitted perfectly!
Because styrofoam is so light, I used double-sided tape to stick it to the conductive board with the microcontroller.
Before glueing the strip to the foam make sure you have the right direction! The strip can only be shifted in one direction. And even though it is a 50:50-chance, there is a 100% chance to do it wrong on the first try! :-)
If the clock is face down on the table, the LED-Strip has to go counter clock-wise!
Step 2: Solder the Controller-board
This step is pretty easy. I used a grid-style PC board with individual copper rings around the holes because there are not many connections to do.
To mount the BLE-module on the final clock I used some pin-headers that come in rows of 40.
Just use as many as you like! In the upper right corner there are the power-connectors and the control-pins. The other corners are just to stabilize the module. If power is applied to the module it should be done via the power pins in the middle of the module, but it is also possible to apply it to VDDA.
The PSoCs have several power-regions: VDDA for the analog part, VDDD for the digital part, VDDR for the reference. Normally they are all connected together. For details have a look into the datasheet.
Step 3: LDR and Brightness-control
In the first setup I didn't use brightness control, but I couldn't sleep in the same room because the LEDs are so bright!
The LDR and the resistor form a voltage divider. The resistance of the LDR varies with the amount of light that it receives.
This results in a variation of the voltage at the point between the resistor and the LDR. This voltage is used by the PSoC via the analog-digital converter an ADC. If the LDR is connected to the 5V, the result could straight be used to control the brightness of the strip.
bright environmennt --> high reading of ADC --> bright LED-strip
dark environment --> low reading of ADC --> dimmed LED-strip
Just debug the software and determine which values are read from your specific LDR-resistor-combination.
Step 4: Get the Software Up and Running
First of all you have to get the PSoC-Creator from here: http://www.cypress.com/go/creator/download
Then you need the support-files for the development kit: cy8ckit-042-ble-bluetooth-low-energy-ble-pioneer-kit
If you download the complete iso or the complete setup for the kit, the PSoC Creator is included. That should be everything you need to open and compile the project.
The PSoC-Creator is a rather complex IDE, because it combines some kind of schematics-editor and a typical source-code editor with several features.
Try to use some of the good examples that cypress provides. They are really good documented and most of them are running straight from the shelf.
To use this project, just unzip the file into a folder and open the cyprj-file with the psoc-creator.
I won't describe the software in detail here. The first picture in this step shows the top-design schematic with all the components that are used in this project. Most functions are commented in the code, if you have any other questions feel free to post a comment!
Step 5: Some Hints to the Project
The BLE-module can only be programmed if it is mounted on the programmer. Therefore to debug your software you first have to connect the LED-strip to the programmer board. Then you can step through your software and develop everything that you want.
If you are finished developing you take the BLE-module out of the programmer and plug it into the small bread board. You have to make sure you use the same pins during debugging as later on your own board! This is especially important for pins that are available in the BLE-module but are pre-defined on the programmer board. The RGB-Led-Pins of the programmer board are an example of this. On the blank BLE-Module you can use them for anything you like, but on the programmer board they are already used!
The PSoC-4 which is the controller on the BLE-Module works with voltages from 1.8V to 5.5V! That is perfect if you want to drive the clock with Li-Ion 3.7V batteries or from USB-ports. I set up an old powered USB-Hub to drive my raspberry pi webcam. Now this hub also drives my clock!
The debug-LED-strip is powered from the dev-board itself. Because only three LEDs are driven at a time, the USB-supply is enough. If you want to drive higher currents you should think about powering the LEDs on their own. Just connect the GND to the dev-kit to provide a common reference.
Another good hint is to try out some cypress-provided examples and tutorials. You can create them within the PSoC-Creator and they are really good. Most of them work straight out of the box. Some need a small update of individual components, but in general they are very good documented and the data-sheets or descriptions are very good.
And build the LDR-resistor voltage divider on breadboard before soldering the custom board. Because only on the programmer you can debug the software to see which values are returned from it! In the picture, which I made after the clock was finished, I substituted the LDR with a grey wire that is connected to the 3.3V-supply on the programmer. This gives some medium readings.
Step 6: Set the Time Via Smartphone
If you already know Bluetooth smart or low energy as it is called sometimes, then you might notice that this setup is not a public profile but a custom profile.
I didn't want to invest a lot of time into setting up the official time profile because I just wanted to see how this is looking. And on the other hand, a peripheral that implements the time profile client would need a central that implements a time profile server. This is not the case for the current Android-smartphones. And also the CySmart-dongle doesn't support this feature at the moment.
But hey, a lot of bla bla before we start:
Once you have programmed the BLE-board with the project, you can either use the CySmart Dongle with the PC-Software or the CySmart-App for your smart phone.
I normally use the app, because it is easy and fast. In the first screen you should find a device named "clock". This is the dev-kit!
Connect with it by clicking on the name. Do not try to pair or bond to it. It is not implemented and will fail. We also don't need any key to connect to it. That means everybody around could connect to this device and later you should take care to implement some security features!
You see one unknown service with three characteristics. These are the one I defined in the PSoC-creator. The CySmart-App doesn't know them of course, but that doesn't matter. The first Characteristic accepts date and time, the second charateristic accepts only time and the last one is the control to dim the LEDs with a custom divisor.
To set the time tap on the middle characteristic and enter 17 23 55 and tap on o.k.. The "0x" is automatically included by the app.
Once the value is sent, the clock instantly displays the new time 17:23:55. Wow!
Step 7: Next Steps
Now you know how it works and you can take the next steps:
- add some security-features to the BLE-component like pairing and bonding.
- add a BLE bootloader to update the software over the air (OTA)
- chance the implementation to the official Bluetooth SIG time profile (Time Profile)
--> for all these topics you can find examples in the PSoC-Creator!
- change the colors of the LEDs during the day
- display accumulated time: All seconds or minutes in one minute are light up until the minute or hour is full and it starts a new
- display inverse: All LEDs are on and only the current ones are off.
- send the microcontroller to sleep if there is nothing to do, this saves some power. Although the most power is used for the LEDs and the clock might not be able to run long on battery anyway.
- Make use of the alarm-feature of the RTC-component
- Add animations to the clock that appear at certain times.
- create a custom android app to control the animations
- Build it with a 120-Leds strip in half-seconds resolution
- Print your own housing
- reverse the clock on request so that it runs counter-clockwise.
the possibilites are nearly endless...
Here is an example of the clock 22:57:52: