So, for the last week i've been working on an addition to the iBreathe Breathalyzer. He now has a voice and gives you commands on how to use it! it will then politely tell you how drunk you are.
Using the Text To Speech click board, i have given him a voice, and to my knowledge this is the first time the Text To Speech click board has been implemented on mBed OS!
It was over a week of porting and debugging and now the results can be seen in this video!
The code can be found at the bottom of this page (along with the original non speaking version) and can be easily adapted for any project using mBed OS. I'm sorry it's in one big main file, but i ran out of time to chop it up into smaller bytes (pun intended).
For more information on the Text To Speech Click Board click here!
IntroductionThis is a tale of boozy thoughts..
Drinking beer, wondering how much alcohol i have actually drunk, wouldn't it be nice to be able to check? and then ping the result to my smartphone? then to the cloud? and the document it as a lovely table to see alcohol intake through time?
Well here is the result!
The iBreathe Breathalyzer!
First Steps- For this project you will need:
- 1 x NXP Hexiware
- 1 x Hexiware Docking Station
- 1 x Alcohol Click Board
- 3 x 10K Resistor
- Sharp Knife
- Soldering iron and solder
- Access to a 3D printer (not necessary, but really finishes the design nicely!)
- A www.wolksense.com Login (more on this later)
- An www.mBed.com Login (also more on this later)
- Xcode (for the custom iPhone App)
Take your brand new Hexiware dev kit and have a play! it's really a one stop shop device that can do tons already, such a great development platform as a first foray in embedded design.
Plug your Hexiware onto the docking station and connect the USB cable to your computer. It will show as an attached drive called DAPLINK. This is where you will simply drag and drop your compiled *.BIN files when you have finished your program. Once dropped in the DAPLINK drive, the Hexiware will automatically load the new firmware.. how jolly easy!
ARM mBed OS 5I chose to use mBed OS5 as my platform for developing for the Hexiware for 2 main reasons:
1. Browser based SDK - I could code from any of my computers without the fear of my desktop SDK's not being configured exactly the same.
2. Really easy to get going.. seriously I was able to run my first program on my Hexiware within 5 minutes of signing up at www.mBed.com.
So without further ado, head on over to https://developer.mbed.org/account/signup/ and sign up for your free mBed account.
Once you have signed up the next step is to go to the dedicated Hexiware page. Here you will find all the information you need to get started compiling your first program
Head on over to the Hexiware Code Repository, here you will find a ton of examples that will quickly get you started programming!
To begin with I chose the Hexi_Blinky_Example , this is a nice simple LED blinking program and a great place to get started. From this page, click on "Import into Compiler" and this will fork your very own copy of the program to do with as you will... fun.
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
As you can see it's super simple with very little set up, the most important thing is to remember to include the mbed.h header file. This is essentially the mBed OS you'll be running your program on.
Hit compile! the *.BIN will download, drag and drop this onto the DAPLINK drive (the drive your Hexiware is shown as) once it has copied across, hit the reset button and boom! you have a flashing LED!
The IdeaOkey dokey, now that we're experts in mBed OS 5 it's time to start creating something.. something we can use!
I wanted to create a Breathalyzer that could tell me how much I had drunk, whether or not I was safe to drive, pinging the values to my Phone and then subsequently the cloud.
First things first, the hardware. We already have our Hexiware and Docking Station joined at the hip, so all we need to to attach our Alcohol Click Board right?
Well.. not quite. It turns our the Alcohol Click Board runs at 5V levels, and my little Hexiware's analog input is 3.3V. so it's time to do a little PCB modification to get things playing nicely with each other.
We need to add a voltage divider on the output pin of the Click Board. This where the 3 x 10K resistors come in.
You will need to cut the tracks as shown in the pictures below, and then solder the resistors in place.
Now we're ready to go! Plug in your modified click board. and load up my code from the mBed Code Repository , import it to your compiler. Hit compile, drag and drop the *.BIN to your DAPLINK drive and away you go!
Function screenshots
NOTE: I don't have access to proper calibration equipment so this is just a showcase project, I will not be held responsible for any loss of Driving Licenses, underwear, teeth or dignity.
Technical Challenges Faced in DevelopmentSo there were a few things that were not immediately obvious how to do, but after some digging, it all became clear .
1. Using Bitmap images with the Hexiware on-board OLED display. This is actually fairly straight forward. The OLED is a 96px x 96px screen, so this needs to be taken in to account when creating your images. Using Photoshop / GiMP you need to save you image as a BMP file, you will need to click advanced settings and select the BMP type as 16bppRgb565 . Make sure there are no spaces in the file name. Next step is down download the Hexiware Utility that will convert your BMP files to *.c and *.h files that can be imported into the mBed compiler.
You can process multiple images at the same time using this utility, and the cool thing is it pops them all in the same *.c and corresponding *.h files.
Make a note of where you saved them and import them into you mBed compiler as libraries. Add the *.h file into your #includes and you're ready to start pointing pointers and showing some cool pictures!
#include "mbed.h"
#include "Hexi_OLED_SSD1351.h"
#include "images.h"
/*
* Bitmaps need to be formatted as 16bppRgb565, flipped vertically
* and a 6 byte header needs to be appended at the start of the array.
* Use the following tool to create arrays for images.
* https://github.com/MikroElektronika/HEXIWEAR/tree/master/SW/ResourceCollectionTool
* It takes an image and outputs the array. It handles the flipping and the 6 byte header.
* Image needs to be converted outside the tool to fit the screen
* (Max Dimensions:96px by 96px).
*/
int main() {
/* Pointer for the image to be displayed */
const uint8_t *image1;
const uint8_t *image2;
/* Setting pointer location of the 96 by 96 pixel bitmap */
image1 = NXP_whole_bmp;
/* Setting pointer location of the 96 by 32 pixel bitmap */
image2 = NXP_banner_bmp;
/* Instantiate the SSD1351 OLED Driver */
SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
/* Turn on the backlight of the OLED Display */
oled.DimScreenON();
while (true)
{
/* Fill the screen with white to overwrite previous image */
oled.FillScreen(COLOR_WHITE);
/* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
oled.DrawImage(image1,0,0);
Thread::wait(2000);
/* Fill the screen with white to overwrite previous image */
oled.FillScreen(COLOR_WHITE);
/* Draw 96px by 32px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
oled.DrawImage(image2,0,64);
Thread::wait(2000);
}
}
Here's the mBed sample code showing how the image is referenced and send to the OLED for showing. (the full version of this code is available on the mBed Hexiware Code Repository)
Have a play around with this and all will become clear!
2. Sending my iBreathe data over Bluetooth to the Hexiware iOS App. OK this was a little bit hacky, but none the less, fun! So to cut a long story short all the UUID's for the KW40Z were preassigned to work with all the built in sensors in the Hexiware. So i pinched the Pressure sensors one and used that to transmit the data via bluetooth to the Stock Hexiware iOS app.
3. Could i create my own iBreathe iOS app to received the data? Yes! yes i could! the Hexiware App is open-source, so i was able to add my iBreathe Sensor into it with a fun logo. If you know swift, then it's not too much trauma, you just need to use a UUID for one of the unused sensors for the iBreathe Data stream. The Stock Hexiware App can be downloaded and modified from here.
My version of the app can be downloaded from the code section below. Sadly i was unable to get Wolksense to see my splendid new iBreathe logo, so for the purposes of logging, i send the data to the Pressure Sensor, and log that.
4. Text To Speech Click Board - Well, it was always my intention for this project to have a voice, but seen as there hadn't been an mBed OS implimentation on the Text To Speech Click, i'd decided to get the bulk of the project working before i attempted to get the speech working. Well... after 1 week of late nights and frustration, i managed to port the code over to work for this project. Now... currently it is NOT a library, but a pretty sizeable main.cpp file, my intention is to make a library at some point so everyone can use it trouble free. For now, copy and paste is you friend :) i learnt so much from this process, like SPI bus interfaces, how important delay timings are and how jolly satisfying when something suddenly springs to life :) I have commented code fairly well, so hopefully it makes sense. if there is anything you're unsure about, hit me up! after all this work i feel like i know it back to front :)
WolksenseAs stated i didn't get this working perfectly, but it's a nice little work around. Wolksense is a great site that takes the cloud data you pass to it and logs it.
First of all you will need to sign up here
Once you have done that you can use the Hexiware App (the stock one or my version works just as well) to register your Hexiware device. The sensors that are available will show on your screen and the data will be transmitted via your phones data connection to the Wolksense Cloud,
Using the Wolksense App (on your phone) you are able to chose which sensors you would like shown, i turned off everything other than Pressure. Named it iBreathe Breathalyzer, and hit save. I was now logging the alcohol levels by all but name.
The code for the iBreathe Breathalyzer transmits to both iBreathe and Pressure. Meaning on your phone you will see the Beer and pressure gauge showing the same value. This is a work around and should this ever go into production would of course be fixed.
One thing is for sure, Wolksense is a jolly pretty place to store all your data points!
More info on Wolksense can be found here
Autodesk Fusion360So as the final part of this project, i decided to design and 3D print an enclosure. I wanted it to be fun and practical and this is what i came up with!
It's basically a big beer! the limiting factor was the fact the Docking station is able to house 3 click boards, when i only needed 1. so the size was dictated by that.
The enclosure is 3D printed, and assembled with a combination of super glue and M3 screws. To power the iBreathe, I used a USB power bar which is housed in the beers head.
I've printed the top cover from PolyMaker Polywood PLA, the head and back cover were printed with Polymaker PLA+. I can't recommend Polymaker filament enough, it's really amazing stuff!
Printer Settings:
- Heatbed 58C
- Hot end 200C
- 20% in fill
- 70mm/s Print speed
- Use Supports
Here's how it goes together
Comments