Software apps and online services
In this project, I am going to show you how to use a photoresistor with LightBlue Bean using an analog voltage reading method. The connection diagram of photosensor connecton to microcontroller is actually simple, and it is shown below:
A LightBlue Bean, of course! This is the bit that reads the light intensity value, and later, you can send those values to your phone. You will also need a photoresistor and a pulldown resistor with 10K resistance.
I've been using PlatformIO for a while, and all I can say is that is simple, wonderful, open source ecosystem for IoT development built on top of GitHub's Atom text editor.
The people behind the LightBlue Bean and Bean+ boards released their new Bean Loader, the application that allows you to build and upload new sketches to your beans. You can use Bean Loader with latest version of Arduino IDE, but I used PlatformIO IDE. The great news about this is that the Bean Loader is cross-platform, and also supports Linux.
It's simple to install Bean Loader CLI. First, you need to make sure you have installed Node.js and npm (by typing in the command line
node -- version
npm --version). Now type:
npm install -g bean-sdk.
To check if the bean SDK is installed type
bean -v. You can find more info at: https://punchthrough.com/bean/docs/guides/getting-started/cli-loader/.
Since LightBlue Bean is based on Atmel AVR chip (Atmel 328P - the same chip which uses Arduino Uno), you need to make sure that PlatformIO has installer Armel AVR platform. In command line now type:
platformio platform install atmelavr
Now you just need to run these two commands to setup and compile a sketch for the Bean:
platformio init -b lightblue-bean platformio run -e lightblue-bean
The Bean Loader CLI provides a command to upload sketches. If you use the Arduino IDE, the upload button actually just builds and copies the sketch binary to “~/.beansketches/bean/”. This is the folder the list_compiled_sketches command of the CLI reads to output available firmware. So, if you have a firmware file there called “led.hex” you can upload it to your Bean with:
bean program_sketch led -n bean01
Ok, but actually you need only to parse a path to HEX file to bean command, which actually uploads hex file to the LightBlue-Bean. So, PlatformIO generates also a hex file, which you can find in .pioenvs/lightblue-bean/firmware.hex project folder. So, to upload HEX file generated from PlatformIO you need to type the command:
bean program_sketch .pioenvs/lightblue-bean/firmware.hex -n bean01
The code with generated ready-to-upload hex file is located on my GitHub repository (link below). It is really simple now to send data from photosensor to your Android-based phone.
In order to send messages from LightBlue-Bean, you need to enable Virtual Serial, since LightBlue-Bean doesn't use USB communication, but rather Bluetooth 4.0 (Bluetooth Low Energy). You can find here how to enable Virtual Serial.
Lastly, there is output from putty (you need to configure putty to use serial communication with the speed 9600 baud):