Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: libmDot mbed-rtos mbed
Fork of Adafruit_I2C_9dof_mDot_TTN by
Diff: main.cpp
- Revision:
- 11:a2a6b1214ae4
- Parent:
- 10:798cac7d3dcb
--- a/main.cpp Mon Sep 12 00:23:43 2016 +0000
+++ b/main.cpp Mon Sep 12 15:45:13 2016 +0000
@@ -30,6 +30,10 @@
#include <vector>
#include <algorithm>
+ AnalogIn ain(PB_1);
+ DigitalOut dout(PA_0);
+
+
// TTN Keys, setup your application and get your own keys at https://www.thethingsnetwork.org/wiki/Backend/Overview
static const uint8_t netowork_session_key_array[] = { 0x22, 0xDF, 0x20, 0x0C, 0x71, 0x5A, 0xCC, 0x35, 0xB8, 0x20, 0x5F, 0xAE, 0xC7, 0x00, 0x5A, 0x63 };//
@@ -56,21 +60,22 @@
int main() {
+ dout = 0;
+
+ // Declare and initialize variables
+ int16_t system_voltage = 3300;
+ float conversion_ratio = 0.2;
+ float zero_dust_voltage = 0.4;
+ float voltage = 0;
+ float concentration = 0;
- // Declare and initialize variables
int32_t ret;
mDot* dot;
- char cmd[2]; // I2C command address byte 8-bit
- char my_data[6]; // I2C return address bytes 16-bit
- uint16_t mag_x; // Intermediate variable
- uint16_t mag_y; // Intermediate variable
- uint16_t mag_z; // Intermediate variable
std::vector<uint8_t> data; // mDot data->send variable
char data_str[64]; // Intermediate conversion variable
- uint32_t update_interval = 15000; // TTN transmission interval (loop interval)
- int16_t analog_input;
+ uint32_t update_interval = 4000; // TTN transmission interval (loop interval)
+ float analog_input;
//initialize pins for analog input
- AnalogIn ain(A0);
// get a mDot handle
dot = mDot::getInstance();
@@ -121,16 +126,32 @@
}
while (true) {
-
- analog_input = ain;
- logInfo("analog input = %d", analog_input);
+ dout = 1;
+ wait_us(280);
+ analog_input = ain;
+ dout = 0;
+ wait_us(720);
+
+ //convert to voltage in mv
+ voltage = (system_voltage / 1024.0 ) * analog_input;
+ logInfo("voltage = %f", voltage);
+
+
+ //voltage to concentration
+ concentration = voltage * conversion_ratio;
+
+
+
+
+
+ logInfo("concentration [ug/m^3] = %f", concentration);
// Empty data vector
data.clear();
// Push temperature value into data array
- sprintf(data_str, "%d", analog_input);
+ sprintf(data_str, "%f", analog_input);
for (int i = 0; i<strlen(data_str); i++)
{
data.push_back(((char*)data_str)[i]);
