I'm new to this forum, and also new to µcontrollers and sketches or scripting. I've dabbled around a bit with Arduino Nanos in the past two years, and built what I wanted sucessfully by remixing existing sketches.
So now I want to dare something more complicated:
a Nano with:
- HM-10-clone BT module
- time-of-flight-sensor GY-6180 (VL6180X), capable of measuring distance 5...120mm and light in lux
- Gyro/accelerometer GY-521 MPU6050, capable of measuring acceleration and gyro, temperature and has a Digital Motion Processor
- an RGB LED
additionally, but probably not relevant for the sketch here:
- lipo-battery
- charging breakout board
- buck booster breakout board
- a self-made Android app from MIT AI2 "app"
The final device will be a lid for a certain drinking glass, that counts how much you drink, and sends the raw data to the app via BLE for processing and environmental data storage. Measuring will be done by the TOF sensor from lid to top of liquid.
The shape of the glass is known, so that the app can calculate the volume of liquid that has come in or out of the glass. A calibration routine is part of my flowchart* to have the opportunity to measure the height of the empty glass in order to even more accurate volume calculations.
I want to save energy by a couple of means:
the device will only send data via BLE when meaningful data has been measured; ie. the lid has been taken off the glass AND returned. This I'd like to determine by the MPU6050 staying in low power accel-measure mode (10μA at 1.25Hz). Once it realised it has been moved, it shall measure its angles until it lays still and horizontal upright for 1s. Only then it should measure the light beneath it to see if it lies on the table, or is back on the glass.
Then it takes the actual measurement for transmission to the app: distance, temperature, light and lipo-battery voltage, let's call this combination "dm05".
Also, it has the calibration distance (let's call it "dm00") once in the beginning (or as per user request from the app). Gyro and accel are only used within the sketch.
I want to buffer lines of measurements on the Nano in order to separate them and not have them lost when the BLE transmission is not working. Also, dm00 and dm05 should be recognizeable for the app, so it can store all dm05 and calculate the actual volume in the glass using dm00. Not exactly sure yet, how this works technically.
*please see my flowcharts in the attachment
My questions -
where am I wrong? Does this make sense - hardware (-performance), flowchart, means of data buffering and separation? The sensors and especially the Digital Motion Processor are very complex. Also, I'm not fully aware how the AI2 app will store the data, and what format is best.
Creating the flowchart and writing this post made me aware of many things I haven't thought of; also gave me a better idea how to approach this. I will be mostly copying sketches, but will certainly need help to connect them and look ar overall architecture needs.
At a later time, I might add ethanol or colour sensors to get data about the drink quality or alcohol consume, but for now this is complex to me enough already.
flowcharts.pdf (40.1 KB)
