-
1Wiring it up
The Fritzing image (original Fritzing file also attached) shows the wiring. With the Circuit Playground, the wiring is pretty simple. All the sensors and LEDs are already connected.
The battery charger is not the same as what I used, which was an inexpensive USB battery bank using a Li-Ion battery and connecting through the USB instead of the battery connector. If you buy a charger board the wiring should be pretty clear. The battery bank I used required me to solder a couple wires to the back of the USB port (actually using a USB cable was too bulky).
The hookup is pretty straightforward:
- Bluefruit TX connects to Arduino RX
- Bluefruit RX connects to Arduino TX
- Bluefruit CTS connects to ground
- Charger board + connects to Bluefruit VIN and to VBAT on Arduino
- Charger board - connects to the middle of the switch
- Bluefruit ground (gnd) and Arduino ground connect to the side of the switch
- Finally, the battery + and - connect appropriately to the charger board
-
2Breadboard
I used a tiny breadboard for the Bluefruit module, and the switch. The Circuit Playground is attached on the end with a little double sided tape. The breadboard also comes with double sided foam tape, which we will use to attach it to the inside of the box. This provides support for the Circuit Playground (the battery will support the other side as its just the right height).
The bread board has enough room on it to support a couple sensors for future enhancements, or any other changes we might want to make.
The switch is a breadboard friendly switch with a 3 pin right angle header soldered to it, so it can mount sideways on the breadboard. This allows it to extend through a hole on the side.
-
3Box it up
Amac Box
Who doesn't love Amac boxes? You know the ones. They come in lots of sizes and colors and they have flush lids and they're completely 'square' (no slopes or ridges or anything) and they can stack nicely. I love them. My grandmother always had these in her home full of interesting things and I would explore them for materials I could use. My kids spotted this cool box I made and their curiosity exploded. What is that? Its glowing! And the cycle repeats...
So it was a natural thing to put this project into an Amac box. Since we are generating light in any color, I had to go with a clear box, even though the colored ones are just so.. beautiful! In retrospect, I could have gotten one clear box and one colored box and used the clear lid with the colored bottom.
The 2 5/16" x 3 1/16" size "flush lid" box was the perfect size. The height allowed for the battery to stand up and double as support for the Circuit Playground, and the width x depth of the box was just comfortably big enough for the diameter of the Playground board. The lid also is short, about a quarter inch, so the board can be right up on top.
Make some holes
I drilled two small holes with a 5/8" drill to create a slot for the charger USB to go through, then used an x-acto knife to cut the bridge between them out and to smooth the holes. I did the same thing for the power switch and again for the USB on the Circuit Playground at the top so I could be reprogrammed without removing it. I did NOT cut a hole in the lid though, so the lid covers this hole when in operation.
-
4Test
Before you try to place it all into the box make sure its working. When you turn it on, you should see a little green LED on the Circuit Playground, and a blinking red LED on the Bluefruit. Using the Bluefruit LE Connect app, you should be able to connect to your PID and send it some commands:
Flashlight mode at brightness 60 (it goes from 0 to 255):
M1 60
I've had it sitting on my desk at work for 2 days now on a single charge, in organ/visualizer mode mostly, and it hasn't drained the battery yet. In candle mode I've had it running all night while sleeping.
-
5Mobile app
It is far beyond the scope to detail how to build a mobile app to control this device. There are many ways to do it. I have built a simple app using Ionic framework (and prototyped using Ionic Creator) which you can use. Provided is the apk to install on your Android phone, but you can download and build the app yourself for Apple or Android. The app is available on Google Play. The whole source code is available on GitHub if you want to study it or compile your own version (and maybe contribute to the code yourself.. I would love any submissions!).
The app is very simple, it works by sending simple text data through the Bluetooth connection as a "virtual" serial port. The PID receives this data and acts on it. There's nothing fancy here (beyond what Bluetooth does for us, behind the scenes), so we have to invent a "language" or "protocol" so the app can communicate to the PID.
The app uses the Ionic Native BLE library to scan for available devices, and then connect to the first one it finds with the name "Personal Illumination Device". In theory, it could connect and control multiple devices but I did not flesh out the code to do so (and I've only built one device).
The control protocol is 'M' for mode, followed by a number, and then depending on the mode, additional data. So for example, flashlight mode is:
M1 50
The '50' is the brightness, from 0 to 255.
Other modes are as follows:
Reading mode:
M2 50
Detect / Sense mode:
M3
Sleep and Wake:
M4S
Turns on the nightlight color
M4O
Turns off the light
M4W
Turns on the waking light color
Organ / Visualizer mode:
M6
Candle mode:
M7
-
6Controller code
To actually compile and run the code on an Arduino, you can't beat create.arduino.cc! You have to install a plugin first, but this is much easier than installing the full Arduino editor. Plus your programs are stored online and can be accessed anywhere. The code for this instructable is thus available here. Once you have the plugin installed, you can program the Circuit Playground by simply connecting it to the computer with a standard USB cable.
Setting up the code takes a few steps (this could be simplified..). The first time you load the code, you need to uncomment a block of code at line 112:
<p>/**<br> * Uncomment the code below the first time you load, so that it can set the name of the bluetooth device * while (! ble.isConnected()) { delay(500); }</p><p> //** change the name of our bluetooth device. We dont have to do this everytime because its stored, but this is easy ble.sendCommandCheckOK("AT+GAPDEVNAME=Personal Illumination Device"); */</p>
Change it to this:
<p>/**<br> * Uncomment the code below the first time you load, so that it can set the name of the bluetooth device * / while (! ble.isConnected()) { delay(500); }</p><p> //** change the name of our bluetooth device. We dont have to do this everytime because its stored, but this is easy ble.sendCommandCheckOK("AT+GAPDEVNAME=Personal Illumination Device"); </p>
Then compile and load the code onto your Arduino. Turn the PID off and then on again, then, use the Bluefruit LE app to locate your device and connect to it using the UART mode. This will then cause the Arduino to rename itself. At this point you can send commands to your PID to see how it works.
Once this is done, you can comment out the code again and then reload it. Your PID is now ready to use.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.