![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Training Class with ROHM Sensor Board and LoRa mDot
Dependencies: MbedJSONValue libmDot mbed-rtos mbed
main.cpp@1:3ef353c7f925, 2016-02-28 (annotated)
- Committer:
- BlueShadow
- Date:
- Sun Feb 28 23:06:53 2016 +0000
- Revision:
- 1:3ef353c7f925
- Parent:
- 0:7f1c7e1755bc
Final version for Classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BlueShadow | 0:7f1c7e1755bc | 1 | /************************************************************************* |
BlueShadow | 0:7f1c7e1755bc | 2 | * Originally this was a |
BlueShadow | 0:7f1c7e1755bc | 3 | * Dragonfly Example program for 2015 AT&T Government Solutions Hackathon |
BlueShadow | 0:7f1c7e1755bc | 4 | * |
BlueShadow | 0:7f1c7e1755bc | 5 | * This is in process of being convertered to a mDot processor. mDot has a |
BlueShadow | 0:7f1c7e1755bc | 6 | * limited set of IO that are available to the ROHM board. Most of the |
BlueShadow | 0:7f1c7e1755bc | 7 | * Sensors will be used but the ones that can't have been commented out. |
BlueShadow | 0:7f1c7e1755bc | 8 | * |
BlueShadow | 0:7f1c7e1755bc | 9 | * The following hardware is required to successfully run this program: |
BlueShadow | 0:7f1c7e1755bc | 10 | * - MultiTech UDK2 (4" square white PCB with Arduino headers, antenna |
BlueShadow | 0:7f1c7e1755bc | 11 | * connector, micro USB ports, and 40-pin connector for Dragonfly) |
BlueShadow | 0:7f1c7e1755bc | 12 | * - MultiTech mDot with a LoRa radio |
BlueShadow | 0:7f1c7e1755bc | 13 | * - Seeed Studio Base Shield to elevate the ROHM board connectors away from mDOt |
BlueShadow | 0:7f1c7e1755bc | 14 | * - MEMs Inertial and Environmental Nucleo Expansion board (LSM6DS0 |
BlueShadow | 0:7f1c7e1755bc | 15 | * 3-axis accelerometer + 3-axis gyroscope, LIS3MDL 3-axis |
BlueShadow | 0:7f1c7e1755bc | 16 | * magnetometer, HTS221 humidity and temperature sensor and LPS25HB |
BlueShadow | 0:7f1c7e1755bc | 17 | * pressure sensor) |
BlueShadow | 0:7f1c7e1755bc | 18 | * |
BlueShadow | 0:7f1c7e1755bc | 19 | * What this program does: |
BlueShadow | 0:7f1c7e1755bc | 20 | * - reads data from all sensors on MEMs board and moisture sensor on a |
BlueShadow | 0:7f1c7e1755bc | 21 | * periodic basis |
BlueShadow | 0:7f1c7e1755bc | 22 | * - prints all sensor data to debug port on a periodic basis |
BlueShadow | 0:7f1c7e1755bc | 23 | * - optionally sends LoRa sensor data when the timer expires |
BlueShadow | 0:7f1c7e1755bc | 24 | * THis needs to be written yet. |
BlueShadow | 0:7f1c7e1755bc | 25 | * - optionally sends sensor data to AT&T M2X cloud platform (user must |
BlueShadow | 0:7f1c7e1755bc | 26 | * create own M2X account and configure a device) |
BlueShadow | 0:7f1c7e1755bc | 27 | * - you need to set the "m2x_api_key" field and the "m2x_device_id" |
BlueShadow | 0:7f1c7e1755bc | 28 | * field based on your M2X account for this to work |
BlueShadow | 0:7f1c7e1755bc | 29 | * - you need to set the "do_cloud_post" flag to true for this to |
BlueShadow | 0:7f1c7e1755bc | 30 | * work |
BlueShadow | 0:7f1c7e1755bc | 31 | * |
BlueShadow | 0:7f1c7e1755bc | 32 | * Setup: |
BlueShadow | 0:7f1c7e1755bc | 33 | * - Seat the mDot on the UDK2 board |
BlueShadow | 0:7f1c7e1755bc | 34 | * - Stack the Base Shield on the UDK2 Arduino headers |
BlueShadow | 0:7f1c7e1755bc | 35 | * - Make sure the reference voltage selector switch (next to the A0 |
BlueShadow | 0:7f1c7e1755bc | 36 | * socket) is switched to 3.3V so you don't blow the mDot analog converter |
BlueShadow | 0:7f1c7e1755bc | 37 | * accuracy will suffer as a result when compared to 5V. |
BlueShadow | 0:7f1c7e1755bc | 38 | * - Stack the MEMs board on top of the Base Shield |
BlueShadow | 0:7f1c7e1755bc | 39 | * - Plug in the power cable |
BlueShadow | 0:7f1c7e1755bc | 40 | * - Plug a micro USB cable away from the multiple LED String |
BlueShadow | 0:7f1c7e1755bc | 41 | * |
BlueShadow | 0:7f1c7e1755bc | 42 | * Go have fun and make something cool! |
BlueShadow | 0:7f1c7e1755bc | 43 | * |
BlueShadow | 0:7f1c7e1755bc | 44 | ************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 45 | /* |
BlueShadow | 0:7f1c7e1755bc | 46 | Sample Program Description: |
BlueShadow | 0:7f1c7e1755bc | 47 | This Program will enable to Multi-Tech mDot platform to utilize ROHM's Multi-sensor Shield Board. |
BlueShadow | 0:7f1c7e1755bc | 48 | This program will initialize most of the sensors on the shield and then read back the sensor data. |
BlueShadow | 0:7f1c7e1755bc | 49 | Data will then be output to the UART Debug Terminal every 1 second. |
BlueShadow | 0:7f1c7e1755bc | 50 | |
BlueShadow | 0:7f1c7e1755bc | 51 | Sample Program Author: |
BlueShadow | 0:7f1c7e1755bc | 52 | ROHM USDC |
BlueShadow | 0:7f1c7e1755bc | 53 | |
BlueShadow | 0:7f1c7e1755bc | 54 | Additional Resources: |
BlueShadow | 0:7f1c7e1755bc | 55 | ROHM Sensor Shield GitHub Repository: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield |
BlueShadow | 0:7f1c7e1755bc | 56 | */ |
BlueShadow | 0:7f1c7e1755bc | 57 | |
BlueShadow | 0:7f1c7e1755bc | 58 | |
BlueShadow | 0:7f1c7e1755bc | 59 | |
BlueShadow | 0:7f1c7e1755bc | 60 | #include "mbed.h" |
BlueShadow | 0:7f1c7e1755bc | 61 | #include "MbedJSONValue.h" |
BlueShadow | 0:7f1c7e1755bc | 62 | #include <string> |
BlueShadow | 0:7f1c7e1755bc | 63 | |
BlueShadow | 0:7f1c7e1755bc | 64 | // added the following help files for a mDot not required for Dragonfly. |
BlueShadow | 0:7f1c7e1755bc | 65 | #include "mDot.h" |
BlueShadow | 0:7f1c7e1755bc | 66 | #include "MTSLog.h" |
BlueShadow | 0:7f1c7e1755bc | 67 | #include <vector> |
BlueShadow | 0:7f1c7e1755bc | 68 | #include <algorithm> |
BlueShadow | 0:7f1c7e1755bc | 69 | #include "rtos.h" |
BlueShadow | 0:7f1c7e1755bc | 70 | |
BlueShadow | 0:7f1c7e1755bc | 71 | |
BlueShadow | 0:7f1c7e1755bc | 72 | // Debug serial port |
BlueShadow | 0:7f1c7e1755bc | 73 | static Serial debug(USBTX, USBRX); |
BlueShadow | 0:7f1c7e1755bc | 74 | |
BlueShadow | 0:7f1c7e1755bc | 75 | |
BlueShadow | 0:7f1c7e1755bc | 76 | // variables for sensor data |
BlueShadow | 0:7f1c7e1755bc | 77 | float temp_celsius; |
BlueShadow | 0:7f1c7e1755bc | 78 | float humidity_percent; |
BlueShadow | 0:7f1c7e1755bc | 79 | float pressure_mbar; |
BlueShadow | 0:7f1c7e1755bc | 80 | float moisture_percent; |
BlueShadow | 0:7f1c7e1755bc | 81 | int32_t mag_mgauss[3]; |
BlueShadow | 0:7f1c7e1755bc | 82 | int32_t acc_mg[3]; |
BlueShadow | 0:7f1c7e1755bc | 83 | int32_t gyro_mdps[3]; |
BlueShadow | 0:7f1c7e1755bc | 84 | |
BlueShadow | 0:7f1c7e1755bc | 85 | // misc variables |
BlueShadow | 0:7f1c7e1755bc | 86 | static char wall_of_dash[] = "--------------------------------------------------"; |
BlueShadow | 0:7f1c7e1755bc | 87 | bool radio_ok = false; |
BlueShadow | 0:7f1c7e1755bc | 88 | static int thpm_interval_ms = 5000; |
BlueShadow | 0:7f1c7e1755bc | 89 | static int motion_interval_ms = 5000; |
BlueShadow | 0:7f1c7e1755bc | 90 | static int print_interval_ms = 5000; |
BlueShadow | 0:7f1c7e1755bc | 91 | static int sms_interval_ms = 5000; |
BlueShadow | 0:7f1c7e1755bc | 92 | int debug_baud = 115200; |
BlueShadow | 0:7f1c7e1755bc | 93 | |
BlueShadow | 0:7f1c7e1755bc | 94 | |
BlueShadow | 0:7f1c7e1755bc | 95 | /**************************************************************************************************** |
BlueShadow | 0:7f1c7e1755bc | 96 | |
BlueShadow | 0:7f1c7e1755bc | 97 | ****************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 98 | |
BlueShadow | 0:7f1c7e1755bc | 99 | //Macros for checking each of the different Sensor Devices |
BlueShadow | 0:7f1c7e1755bc | 100 | #define AnalogTemp //BDE0600 |
BlueShadow | 0:7f1c7e1755bc | 101 | // #define AnalogUV //ML8511 // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 102 | #define HallSensor //BU52011 |
BlueShadow | 0:7f1c7e1755bc | 103 | #define RPR0521 //RPR0521 |
BlueShadow | 0:7f1c7e1755bc | 104 | #define KMX62 //KMX61, Accel/Mag |
BlueShadow | 0:7f1c7e1755bc | 105 | #define COLOR //BH1745 |
BlueShadow | 0:7f1c7e1755bc | 106 | #define KX022 //KX022, Accel Only |
BlueShadow | 0:7f1c7e1755bc | 107 | #define Pressure //BM1383 |
BlueShadow | 0:7f1c7e1755bc | 108 | #define SMS //allow SMS messaging now sending LORA!!!! |
BlueShadow | 0:7f1c7e1755bc | 109 | //#define Web //allow M2X communication |
BlueShadow | 0:7f1c7e1755bc | 110 | |
BlueShadow | 0:7f1c7e1755bc | 111 | |
BlueShadow | 0:7f1c7e1755bc | 112 | //Define Pins for I2C Interface |
BlueShadow | 0:7f1c7e1755bc | 113 | I2C i2c(I2C_SDA, I2C_SCL); |
BlueShadow | 0:7f1c7e1755bc | 114 | bool RepStart = true; |
BlueShadow | 0:7f1c7e1755bc | 115 | bool NoRepStart = false; |
BlueShadow | 0:7f1c7e1755bc | 116 | |
BlueShadow | 0:7f1c7e1755bc | 117 | //Define Sensor Variables |
BlueShadow | 0:7f1c7e1755bc | 118 | #ifdef AnalogTemp |
BlueShadow | 0:7f1c7e1755bc | 119 | AnalogIn BDE0600_Temp(PC_1); //Mapped to A2 pin 15 on the mDot |
BlueShadow | 0:7f1c7e1755bc | 120 | uint16_t BDE0600_Temp_value; |
BlueShadow | 0:7f1c7e1755bc | 121 | float BDE0600_output; |
BlueShadow | 0:7f1c7e1755bc | 122 | #endif |
BlueShadow | 0:7f1c7e1755bc | 123 | |
BlueShadow | 0:7f1c7e1755bc | 124 | //#ifdef AnalogUV // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 125 | //AnalogIn ML8511_UV(PA_7); //Mapped to A4 not a pin routed on the UDK to the mDot |
BlueShadow | 0:7f1c7e1755bc | 126 | //uint16_t ML8511_UV_value; |
BlueShadow | 0:7f1c7e1755bc | 127 | //float ML8511_output; |
BlueShadow | 0:7f1c7e1755bc | 128 | //#endif |
BlueShadow | 0:7f1c7e1755bc | 129 | |
BlueShadow | 0:7f1c7e1755bc | 130 | #ifdef HallSensor |
BlueShadow | 0:7f1c7e1755bc | 131 | DigitalIn Hall_GPIO0(PA_4); // assigned to D10 on Arduino, mapped to pin 17 on mDot |
BlueShadow | 0:7f1c7e1755bc | 132 | DigitalIn Hall_GPIO1(PA_7); // assigned to D11 on Arduino, mapped to pin 11 on mDot |
BlueShadow | 0:7f1c7e1755bc | 133 | int Hall_Return1; |
BlueShadow | 0:7f1c7e1755bc | 134 | int Hall_Return0; |
BlueShadow | 0:7f1c7e1755bc | 135 | int32_t Hall_Return[2]; |
BlueShadow | 0:7f1c7e1755bc | 136 | #endif |
BlueShadow | 0:7f1c7e1755bc | 137 | |
BlueShadow | 0:7f1c7e1755bc | 138 | #ifdef RPR0521 |
BlueShadow | 0:7f1c7e1755bc | 139 | int RPR0521_addr_w = 0x70; //7bit addr = 0x38, with write bit 0 |
BlueShadow | 0:7f1c7e1755bc | 140 | int RPR0521_addr_r = 0x71; //7bit addr = 0x38, with read bit 1 |
BlueShadow | 0:7f1c7e1755bc | 141 | char RPR0521_ModeControl[2] = {0x41, 0xE6}; |
BlueShadow | 0:7f1c7e1755bc | 142 | char RPR0521_ALSPSControl[2] = {0x42, 0x03}; |
BlueShadow | 0:7f1c7e1755bc | 143 | char RPR0521_Persist[2] = {0x43, 0x20}; |
BlueShadow | 0:7f1c7e1755bc | 144 | char RPR0521_Addr_ReadData = 0x44; |
BlueShadow | 0:7f1c7e1755bc | 145 | char RPR0521_Content_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 146 | int RPR0521_PS_RAWOUT = 0; //this is an output |
BlueShadow | 0:7f1c7e1755bc | 147 | float RPR0521_PS_OUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 148 | int RPR0521_ALS_D0_RAWOUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 149 | int RPR0521_ALS_D1_RAWOUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 150 | float RPR0521_ALS_DataRatio = 0; |
BlueShadow | 0:7f1c7e1755bc | 151 | float RPR0521_ALS_OUT = 0; //this is an output |
BlueShadow | 0:7f1c7e1755bc | 152 | float RPR0521_ALS[2]; // is this ok taking an int to the [0] value and float to [1]??????????? |
BlueShadow | 0:7f1c7e1755bc | 153 | #endif |
BlueShadow | 0:7f1c7e1755bc | 154 | |
BlueShadow | 0:7f1c7e1755bc | 155 | #ifdef KMX62 |
BlueShadow | 0:7f1c7e1755bc | 156 | int KMX62_addr_w = 0x1C; //7bit addr = 0x38, with write bit 0 |
BlueShadow | 0:7f1c7e1755bc | 157 | int KMX62_addr_r = 0x1D; //7bit addr = 0x38, with read bit 1 |
BlueShadow | 0:7f1c7e1755bc | 158 | char KMX62_CNTL2[2] = {0x3A, 0x5F}; |
BlueShadow | 0:7f1c7e1755bc | 159 | char KMX62_Addr_Accel_ReadData = 0x0A; |
BlueShadow | 0:7f1c7e1755bc | 160 | char KMX62_Content_Accel_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 161 | char KMX62_Addr_Mag_ReadData = 0x10; |
BlueShadow | 0:7f1c7e1755bc | 162 | char KMX62_Content_Mag_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 163 | short int MEMS_Accel_Xout = 0; |
BlueShadow | 0:7f1c7e1755bc | 164 | short int MEMS_Accel_Yout = 0; |
BlueShadow | 0:7f1c7e1755bc | 165 | short int MEMS_Accel_Zout = 0; |
BlueShadow | 0:7f1c7e1755bc | 166 | double MEMS_Accel_Conv_Xout = 0; |
BlueShadow | 0:7f1c7e1755bc | 167 | double MEMS_Accel_Conv_Yout = 0; |
BlueShadow | 0:7f1c7e1755bc | 168 | double MEMS_Accel_Conv_Zout = 0; |
BlueShadow | 0:7f1c7e1755bc | 169 | |
BlueShadow | 0:7f1c7e1755bc | 170 | short int MEMS_Mag_Xout = 0; |
BlueShadow | 0:7f1c7e1755bc | 171 | short int MEMS_Mag_Yout = 0; |
BlueShadow | 0:7f1c7e1755bc | 172 | short int MEMS_Mag_Zout = 0; |
BlueShadow | 0:7f1c7e1755bc | 173 | float MEMS_Mag_Conv_Xout = 0; |
BlueShadow | 0:7f1c7e1755bc | 174 | float MEMS_Mag_Conv_Yout = 0; |
BlueShadow | 0:7f1c7e1755bc | 175 | float MEMS_Mag_Conv_Zout = 0; |
BlueShadow | 0:7f1c7e1755bc | 176 | |
BlueShadow | 0:7f1c7e1755bc | 177 | double MEMS_Accel[3]; |
BlueShadow | 0:7f1c7e1755bc | 178 | float MEMS_Mag[3]; |
BlueShadow | 0:7f1c7e1755bc | 179 | #endif |
BlueShadow | 0:7f1c7e1755bc | 180 | |
BlueShadow | 0:7f1c7e1755bc | 181 | #ifdef COLOR |
BlueShadow | 0:7f1c7e1755bc | 182 | int BH1745_addr_w = 0x72; //write |
BlueShadow | 0:7f1c7e1755bc | 183 | int BH1745_addr_r = 0x73; //read |
BlueShadow | 0:7f1c7e1755bc | 184 | char BH1745_persistence[2] = {0x61, 0x03}; |
BlueShadow | 0:7f1c7e1755bc | 185 | char BH1745_mode1[2] = {0x41, 0x00}; |
BlueShadow | 0:7f1c7e1755bc | 186 | char BH1745_mode2[2] = {0x42, 0x92}; |
BlueShadow | 0:7f1c7e1755bc | 187 | char BH1745_mode3[2] = {0x43, 0x02}; |
BlueShadow | 0:7f1c7e1755bc | 188 | char BH1745_Content_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 189 | char BH1745_Addr_color_ReadData = 0x50; |
BlueShadow | 0:7f1c7e1755bc | 190 | int BH1745_Red; |
BlueShadow | 0:7f1c7e1755bc | 191 | int BH1745_Blue; |
BlueShadow | 0:7f1c7e1755bc | 192 | int BH1745_Green; |
BlueShadow | 0:7f1c7e1755bc | 193 | int32_t BH1745[3]; //Red, Blue Green matrix |
BlueShadow | 0:7f1c7e1755bc | 194 | #endif |
BlueShadow | 0:7f1c7e1755bc | 195 | |
BlueShadow | 0:7f1c7e1755bc | 196 | #ifdef KX022 |
BlueShadow | 0:7f1c7e1755bc | 197 | int KX022_addr_w = 0x3C; //write |
BlueShadow | 0:7f1c7e1755bc | 198 | int KX022_addr_r = 0x3D; //read |
BlueShadow | 0:7f1c7e1755bc | 199 | char KX022_Accel_CNTL1[2] = {0x18, 0x41}; |
BlueShadow | 0:7f1c7e1755bc | 200 | char KX022_Accel_ODCNTL[2] = {0x1B, 0x02}; |
BlueShadow | 0:7f1c7e1755bc | 201 | char KX022_Accel_CNTL3[2] = {0x1A, 0xD8}; |
BlueShadow | 0:7f1c7e1755bc | 202 | char KX022_Accel_TILT_TIMER[2] = {0x22, 0x01}; |
BlueShadow | 0:7f1c7e1755bc | 203 | char KX022_Accel_CNTL2[2] = {0x18, 0xC1}; |
BlueShadow | 0:7f1c7e1755bc | 204 | char KX022_Content_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 205 | char KX022_Addr_Accel_ReadData = 0x06; |
BlueShadow | 0:7f1c7e1755bc | 206 | float KX022_Accel_X; |
BlueShadow | 0:7f1c7e1755bc | 207 | float KX022_Accel_Y; |
BlueShadow | 0:7f1c7e1755bc | 208 | float KX022_Accel_Z; |
BlueShadow | 0:7f1c7e1755bc | 209 | short int KX022_Accel_X_RawOUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 210 | short int KX022_Accel_Y_RawOUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 211 | short int KX022_Accel_Z_RawOUT = 0; |
BlueShadow | 0:7f1c7e1755bc | 212 | int KX022_Accel_X_LB = 0; |
BlueShadow | 0:7f1c7e1755bc | 213 | int KX022_Accel_X_HB = 0; |
BlueShadow | 0:7f1c7e1755bc | 214 | int KX022_Accel_Y_LB = 0; |
BlueShadow | 0:7f1c7e1755bc | 215 | int KX022_Accel_Y_HB = 0; |
BlueShadow | 0:7f1c7e1755bc | 216 | int KX022_Accel_Z_LB = 0; |
BlueShadow | 0:7f1c7e1755bc | 217 | int KX022_Accel_Z_HB = 0; |
BlueShadow | 0:7f1c7e1755bc | 218 | float KX022_Accel[3]; |
BlueShadow | 0:7f1c7e1755bc | 219 | #endif |
BlueShadow | 0:7f1c7e1755bc | 220 | |
BlueShadow | 0:7f1c7e1755bc | 221 | #ifdef Pressure |
BlueShadow | 0:7f1c7e1755bc | 222 | int Press_addr_w = 0xBA; //write |
BlueShadow | 0:7f1c7e1755bc | 223 | int Press_addr_r = 0xBB; //read |
BlueShadow | 0:7f1c7e1755bc | 224 | char PWR_DOWN[2] = {0x12, 0x01}; |
BlueShadow | 0:7f1c7e1755bc | 225 | char SLEEP[2] = {0x13, 0x01}; |
BlueShadow | 0:7f1c7e1755bc | 226 | char Mode_Control[2] = {0x14, 0xC4}; |
BlueShadow | 0:7f1c7e1755bc | 227 | char Press_Content_ReadData[6]; |
BlueShadow | 0:7f1c7e1755bc | 228 | char Press_Addr_ReadData =0x1A; |
BlueShadow | 0:7f1c7e1755bc | 229 | int BM1383_Temp_highByte; |
BlueShadow | 0:7f1c7e1755bc | 230 | int BM1383_Temp_lowByte; |
BlueShadow | 0:7f1c7e1755bc | 231 | int BM1383_Pres_highByte; |
BlueShadow | 0:7f1c7e1755bc | 232 | int BM1383_Pres_lowByte; |
BlueShadow | 0:7f1c7e1755bc | 233 | int BM1383_Pres_leastByte; |
BlueShadow | 0:7f1c7e1755bc | 234 | short int BM1383_Temp_Out; |
BlueShadow | 0:7f1c7e1755bc | 235 | float BM1383_Temp_Conv_Out; |
BlueShadow | 0:7f1c7e1755bc | 236 | float BM1383_Pres_Conv_Out; |
BlueShadow | 0:7f1c7e1755bc | 237 | float_t BM1383[2]; // Temp is 0 and Pressure is 1 |
BlueShadow | 0:7f1c7e1755bc | 238 | float BM1383_Var; |
BlueShadow | 0:7f1c7e1755bc | 239 | float BM1383_Deci; |
BlueShadow | 0:7f1c7e1755bc | 240 | #endif |
BlueShadow | 0:7f1c7e1755bc | 241 | |
BlueShadow | 0:7f1c7e1755bc | 242 | /**************************************************************************************************** |
BlueShadow | 0:7f1c7e1755bc | 243 | // function prototypes |
BlueShadow | 0:7f1c7e1755bc | 244 | ****************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 245 | bool init_mtsas(); |
BlueShadow | 0:7f1c7e1755bc | 246 | void ReadAnalogTemp(); |
BlueShadow | 0:7f1c7e1755bc | 247 | // void ReadAnalogUV (); // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 248 | void ReadHallSensor (); |
BlueShadow | 0:7f1c7e1755bc | 249 | void ReadCOLOR (); |
BlueShadow | 0:7f1c7e1755bc | 250 | void ReadRPR0521_ALS (); |
BlueShadow | 0:7f1c7e1755bc | 251 | void ReadKMX62_Accel (); |
BlueShadow | 0:7f1c7e1755bc | 252 | void ReadKMX62_Mag (); |
BlueShadow | 0:7f1c7e1755bc | 253 | void ReadPressure (); |
BlueShadow | 0:7f1c7e1755bc | 254 | void ReadKX022(); |
BlueShadow | 0:7f1c7e1755bc | 255 | |
BlueShadow | 0:7f1c7e1755bc | 256 | // these options must match the settings on your Conduit |
BlueShadow | 0:7f1c7e1755bc | 257 | // uncomment the following lines and edit their values to match your configuration |
BlueShadow | 0:7f1c7e1755bc | 258 | static std::string config_network_name = "Arrow123"; |
BlueShadow | 0:7f1c7e1755bc | 259 | static std::string config_network_pass = "Arrow123"; |
BlueShadow | 0:7f1c7e1755bc | 260 | static uint8_t config_frequency_sub_band = 1; |
BlueShadow | 0:7f1c7e1755bc | 261 | |
BlueShadow | 0:7f1c7e1755bc | 262 | /**************************************************************************************************** |
BlueShadow | 0:7f1c7e1755bc | 263 | // main |
BlueShadow | 0:7f1c7e1755bc | 264 | ****************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 265 | int main() |
BlueShadow | 0:7f1c7e1755bc | 266 | { |
BlueShadow | 0:7f1c7e1755bc | 267 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); //NONE_, FATAL_, ERROR_, WARNING_, INFO_, DEBUG_, TRACE_ |
BlueShadow | 0:7f1c7e1755bc | 268 | debug.baud(debug_baud); |
BlueShadow | 0:7f1c7e1755bc | 269 | logInfo("starting..."); |
BlueShadow | 0:7f1c7e1755bc | 270 | |
BlueShadow | 0:7f1c7e1755bc | 271 | int32_t ret; |
BlueShadow | 0:7f1c7e1755bc | 272 | mDot* dot; |
BlueShadow | 0:7f1c7e1755bc | 273 | |
BlueShadow | 0:7f1c7e1755bc | 274 | /**************************************************************************************************** |
BlueShadow | 0:7f1c7e1755bc | 275 | Initialize LORA ************ |
BlueShadow | 0:7f1c7e1755bc | 276 | ****************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 277 | // get a mDot handle |
BlueShadow | 0:7f1c7e1755bc | 278 | dot = mDot::getInstance(); |
BlueShadow | 0:7f1c7e1755bc | 279 | |
BlueShadow | 0:7f1c7e1755bc | 280 | // print library version information |
BlueShadow | 0:7f1c7e1755bc | 281 | logInfo("version: %s", dot->getId().c_str()); |
BlueShadow | 0:7f1c7e1755bc | 282 | |
BlueShadow | 0:7f1c7e1755bc | 283 | // reset to default config so we know what state we're in |
BlueShadow | 0:7f1c7e1755bc | 284 | dot->resetConfig(); |
BlueShadow | 0:7f1c7e1755bc | 285 | |
BlueShadow | 0:7f1c7e1755bc | 286 | dot->setLogLevel(mts::MTSLog::TRACE_LEVEL); |
BlueShadow | 0:7f1c7e1755bc | 287 | |
BlueShadow | 0:7f1c7e1755bc | 288 | // set up the mDot with our network information: frequency sub band, network name, and network password |
BlueShadow | 0:7f1c7e1755bc | 289 | // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig() |
BlueShadow | 0:7f1c7e1755bc | 290 | |
BlueShadow | 0:7f1c7e1755bc | 291 | // frequency sub band is only applicable in the 915 (US) frequency band |
BlueShadow | 0:7f1c7e1755bc | 292 | // if using a MultiTech Conduit gateway, use the same sub band as your Conduit (1-8) - the mDot will use the 8 channels in that sub band |
BlueShadow | 0:7f1c7e1755bc | 293 | // if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels |
BlueShadow | 0:7f1c7e1755bc | 294 | logInfo("setting frequency sub band"); |
BlueShadow | 0:7f1c7e1755bc | 295 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 296 | logError("failed to set frequency sub band %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 297 | } |
BlueShadow | 0:7f1c7e1755bc | 298 | |
BlueShadow | 0:7f1c7e1755bc | 299 | logInfo("setting network name"); |
BlueShadow | 0:7f1c7e1755bc | 300 | if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 301 | logError("failed to set network name %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 302 | } |
BlueShadow | 0:7f1c7e1755bc | 303 | |
BlueShadow | 0:7f1c7e1755bc | 304 | logInfo("setting network password"); |
BlueShadow | 0:7f1c7e1755bc | 305 | if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 306 | logError("failed to set network password %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 307 | } |
BlueShadow | 0:7f1c7e1755bc | 308 | |
BlueShadow | 0:7f1c7e1755bc | 309 | // a higher spreading factor allows for longer range but lower throughput |
BlueShadow | 0:7f1c7e1755bc | 310 | // in the 915 (US) frequency band, spreading factors 7 - 10 are available |
BlueShadow | 0:7f1c7e1755bc | 311 | // in the 868 (EU) frequency band, spreading factors 7 - 12 are available |
BlueShadow | 0:7f1c7e1755bc | 312 | logInfo("setting TX spreading factor"); |
BlueShadow | 0:7f1c7e1755bc | 313 | if ((ret = dot->setTxDataRate(mDot::SF_7)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 314 | logError("failed to set TX datarate %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 315 | } |
BlueShadow | 0:7f1c7e1755bc | 316 | |
BlueShadow | 0:7f1c7e1755bc | 317 | // request receive confirmation of packets from the gateway |
BlueShadow | 0:7f1c7e1755bc | 318 | logInfo("enabling ACKs"); |
BlueShadow | 0:7f1c7e1755bc | 319 | if ((ret = dot->setAck(1)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 320 | logError("failed to enable ACKs %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 321 | } |
BlueShadow | 0:7f1c7e1755bc | 322 | |
BlueShadow | 0:7f1c7e1755bc | 323 | // save this configuration to the mDot's NVM |
BlueShadow | 0:7f1c7e1755bc | 324 | logInfo("saving config"); |
BlueShadow | 0:7f1c7e1755bc | 325 | if (! dot->saveConfig()) { |
BlueShadow | 0:7f1c7e1755bc | 326 | logError("failed to save configuration"); |
BlueShadow | 0:7f1c7e1755bc | 327 | } |
BlueShadow | 0:7f1c7e1755bc | 328 | //******************************************* |
BlueShadow | 0:7f1c7e1755bc | 329 | // end of configuration |
BlueShadow | 0:7f1c7e1755bc | 330 | //******************************************* |
BlueShadow | 0:7f1c7e1755bc | 331 | |
BlueShadow | 0:7f1c7e1755bc | 332 | // attempt to join the network |
BlueShadow | 0:7f1c7e1755bc | 333 | logInfo("joining network"); |
BlueShadow | 0:7f1c7e1755bc | 334 | while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 335 | logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 336 | // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again |
BlueShadow | 0:7f1c7e1755bc | 337 | osDelay(std::max((uint32_t)1000, (uint32_t)dot->getNextTxMs())); |
BlueShadow | 0:7f1c7e1755bc | 338 | } |
BlueShadow | 0:7f1c7e1755bc | 339 | |
BlueShadow | 0:7f1c7e1755bc | 340 | |
BlueShadow | 0:7f1c7e1755bc | 341 | /**************************************************************************************************** |
BlueShadow | 0:7f1c7e1755bc | 342 | Initialize I2C Devices ************ |
BlueShadow | 0:7f1c7e1755bc | 343 | ****************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 344 | |
BlueShadow | 0:7f1c7e1755bc | 345 | #ifdef RPR0521 |
BlueShadow | 0:7f1c7e1755bc | 346 | i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 347 | i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 348 | i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 349 | #endif |
BlueShadow | 0:7f1c7e1755bc | 350 | |
BlueShadow | 0:7f1c7e1755bc | 351 | #ifdef KMX62 |
BlueShadow | 0:7f1c7e1755bc | 352 | i2c.write(KMX62_addr_w, &KMX62_CNTL2[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 353 | #endif |
BlueShadow | 0:7f1c7e1755bc | 354 | |
BlueShadow | 0:7f1c7e1755bc | 355 | #ifdef COLOR |
BlueShadow | 0:7f1c7e1755bc | 356 | i2c.write(BH1745_addr_w, &BH1745_persistence[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 357 | i2c.write(BH1745_addr_w, &BH1745_mode1[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 358 | i2c.write(BH1745_addr_w, &BH1745_mode2[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 359 | i2c.write(BH1745_addr_w, &BH1745_mode3[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 360 | #endif |
BlueShadow | 0:7f1c7e1755bc | 361 | |
BlueShadow | 0:7f1c7e1755bc | 362 | #ifdef KX022 |
BlueShadow | 0:7f1c7e1755bc | 363 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL1[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 364 | i2c.write(KX022_addr_w, &KX022_Accel_ODCNTL[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 365 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL3[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 366 | i2c.write(KX022_addr_w, &KX022_Accel_TILT_TIMER[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 367 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL2[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 368 | #endif |
BlueShadow | 0:7f1c7e1755bc | 369 | |
BlueShadow | 0:7f1c7e1755bc | 370 | #ifdef Pressure |
BlueShadow | 0:7f1c7e1755bc | 371 | i2c.write(Press_addr_w, &PWR_DOWN[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 372 | i2c.write(Press_addr_w, &SLEEP[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 373 | i2c.write(Press_addr_w, &Mode_Control[0], 2, false); |
BlueShadow | 0:7f1c7e1755bc | 374 | #endif |
BlueShadow | 0:7f1c7e1755bc | 375 | //End I2C Initialization Section ********************************************************** |
BlueShadow | 0:7f1c7e1755bc | 376 | |
BlueShadow | 0:7f1c7e1755bc | 377 | |
BlueShadow | 0:7f1c7e1755bc | 378 | Timer thpm_timer; |
BlueShadow | 0:7f1c7e1755bc | 379 | thpm_timer.start(); // Timer data is set in the Variable seciton see misc variables Timer motion_timer; |
BlueShadow | 0:7f1c7e1755bc | 380 | Timer print_timer; |
BlueShadow | 0:7f1c7e1755bc | 381 | print_timer.start(); |
BlueShadow | 0:7f1c7e1755bc | 382 | Timer motion_timer; |
BlueShadow | 0:7f1c7e1755bc | 383 | motion_timer.start(); |
BlueShadow | 0:7f1c7e1755bc | 384 | |
BlueShadow | 0:7f1c7e1755bc | 385 | #ifdef SMS |
BlueShadow | 0:7f1c7e1755bc | 386 | Timer sms_timer; |
BlueShadow | 0:7f1c7e1755bc | 387 | sms_timer.start(); |
BlueShadow | 0:7f1c7e1755bc | 388 | #endif |
BlueShadow | 0:7f1c7e1755bc | 389 | |
BlueShadow | 0:7f1c7e1755bc | 390 | #ifdef Web |
BlueShadow | 0:7f1c7e1755bc | 391 | Timer post_timer; |
BlueShadow | 0:7f1c7e1755bc | 392 | post_timer.start(); |
BlueShadow | 0:7f1c7e1755bc | 393 | #endif |
BlueShadow | 0:7f1c7e1755bc | 394 | |
BlueShadow | 0:7f1c7e1755bc | 395 | while (true) { |
BlueShadow | 0:7f1c7e1755bc | 396 | if (thpm_timer.read_ms() > thpm_interval_ms) { |
BlueShadow | 0:7f1c7e1755bc | 397 | #ifdef AnalogTemp |
BlueShadow | 0:7f1c7e1755bc | 398 | ReadAnalogTemp (); |
BlueShadow | 0:7f1c7e1755bc | 399 | #endif |
BlueShadow | 0:7f1c7e1755bc | 400 | |
BlueShadow | 0:7f1c7e1755bc | 401 | //#ifdef AnalogUV // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 402 | // ReadAnalogUV (); |
BlueShadow | 0:7f1c7e1755bc | 403 | //#endif |
BlueShadow | 0:7f1c7e1755bc | 404 | |
BlueShadow | 0:7f1c7e1755bc | 405 | #ifdef HallSensor |
BlueShadow | 0:7f1c7e1755bc | 406 | ReadHallSensor (); |
BlueShadow | 0:7f1c7e1755bc | 407 | #endif |
BlueShadow | 0:7f1c7e1755bc | 408 | |
BlueShadow | 0:7f1c7e1755bc | 409 | #ifdef COLOR |
BlueShadow | 0:7f1c7e1755bc | 410 | ReadCOLOR (); |
BlueShadow | 0:7f1c7e1755bc | 411 | #endif |
BlueShadow | 0:7f1c7e1755bc | 412 | |
BlueShadow | 0:7f1c7e1755bc | 413 | #ifdef RPR0521 //als digital |
BlueShadow | 0:7f1c7e1755bc | 414 | ReadRPR0521_ALS (); |
BlueShadow | 0:7f1c7e1755bc | 415 | #endif |
BlueShadow | 0:7f1c7e1755bc | 416 | |
BlueShadow | 0:7f1c7e1755bc | 417 | #ifdef Pressure |
BlueShadow | 0:7f1c7e1755bc | 418 | ReadPressure(); |
BlueShadow | 0:7f1c7e1755bc | 419 | #endif |
BlueShadow | 0:7f1c7e1755bc | 420 | thpm_timer.reset(); |
BlueShadow | 0:7f1c7e1755bc | 421 | } |
BlueShadow | 0:7f1c7e1755bc | 422 | |
BlueShadow | 0:7f1c7e1755bc | 423 | if (motion_timer.read_ms() > motion_interval_ms) { |
BlueShadow | 0:7f1c7e1755bc | 424 | #ifdef KMX62 |
BlueShadow | 0:7f1c7e1755bc | 425 | ReadKMX62_Accel (); |
BlueShadow | 0:7f1c7e1755bc | 426 | ReadKMX62_Mag (); |
BlueShadow | 0:7f1c7e1755bc | 427 | #endif |
BlueShadow | 0:7f1c7e1755bc | 428 | |
BlueShadow | 0:7f1c7e1755bc | 429 | #ifdef KX022 |
BlueShadow | 0:7f1c7e1755bc | 430 | ReadKX022 (); |
BlueShadow | 0:7f1c7e1755bc | 431 | #endif |
BlueShadow | 0:7f1c7e1755bc | 432 | motion_timer.reset(); |
BlueShadow | 0:7f1c7e1755bc | 433 | } |
BlueShadow | 0:7f1c7e1755bc | 434 | |
BlueShadow | 0:7f1c7e1755bc | 435 | if (print_timer.read_ms() > print_interval_ms) { |
BlueShadow | 0:7f1c7e1755bc | 436 | logDebug("%s", wall_of_dash); |
BlueShadow | 0:7f1c7e1755bc | 437 | logDebug("SENSOR DATA"); |
BlueShadow | 0:7f1c7e1755bc | 438 | logDebug("temperature: %0.2f C", BM1383[0]); |
BlueShadow | 0:7f1c7e1755bc | 439 | // logDebug("analog uv: %.1f mW/cm2", ML8511_output); // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 440 | logDebug("ambient Light %0.3f", RPR0521_ALS[0]); |
BlueShadow | 0:7f1c7e1755bc | 441 | logDebug("proximity count %0.3f", RPR0521_ALS[1]); |
BlueShadow | 0:7f1c7e1755bc | 442 | logDebug("hall effect: South %d\t North %d", Hall_Return[0],Hall_Return[1]); |
BlueShadow | 0:7f1c7e1755bc | 443 | logDebug("pressure: %0.2f hPa", BM1383[1]); |
BlueShadow | 0:7f1c7e1755bc | 444 | logDebug("magnetometer:\r\n\tx: %0.3f\ty: %0.3f\tz: %0.3f\tuT", MEMS_Mag[0], MEMS_Mag[1], MEMS_Mag[2]); |
BlueShadow | 0:7f1c7e1755bc | 445 | logDebug("accelerometer:\r\n\tx: %0.3f\ty: %0.3f\tz: %0.3f\tg", MEMS_Accel[0], MEMS_Accel[1], MEMS_Accel[2]); |
BlueShadow | 0:7f1c7e1755bc | 446 | logDebug("color:\r\n\tred: %ld\tgrn: %ld\tblu: %ld\t", BH1745[0], BH1745[1], BH1745[2]); |
BlueShadow | 0:7f1c7e1755bc | 447 | logDebug("%s", wall_of_dash); |
BlueShadow | 0:7f1c7e1755bc | 448 | print_timer.reset(); |
BlueShadow | 0:7f1c7e1755bc | 449 | } |
BlueShadow | 0:7f1c7e1755bc | 450 | |
BlueShadow | 0:7f1c7e1755bc | 451 | |
BlueShadow | 0:7f1c7e1755bc | 452 | |
BlueShadow | 0:7f1c7e1755bc | 453 | #ifdef SMS |
BlueShadow | 0:7f1c7e1755bc | 454 | if (sms_timer.read_ms() > sms_interval_ms) { |
BlueShadow | 0:7f1c7e1755bc | 455 | sms_timer.reset(); |
BlueShadow | 0:7f1c7e1755bc | 456 | logInfo("SMS Send Routine"); |
BlueShadow | 0:7f1c7e1755bc | 457 | printf(" In sms routine \r\n"); |
BlueShadow | 0:7f1c7e1755bc | 458 | |
BlueShadow | 0:7f1c7e1755bc | 459 | char send_msg[20]; |
BlueShadow | 1:3ef353c7f925 | 460 | sprintf(send_msg, "Dilbert,%0.0f", RPR0521_ALS[0]); //***************************************probably note worthy |
BlueShadow | 0:7f1c7e1755bc | 461 | std::string send_msg_str(send_msg); |
BlueShadow | 0:7f1c7e1755bc | 462 | std::vector<uint8_t> data(send_msg_str.begin(), send_msg_str.end()); |
BlueShadow | 0:7f1c7e1755bc | 463 | |
BlueShadow | 1:3ef353c7f925 | 464 | // Added the mdot send code here vs that the sms fuction was doing. |
BlueShadow | 0:7f1c7e1755bc | 465 | // send the data to the gateway |
BlueShadow | 0:7f1c7e1755bc | 466 | if ((ret = dot->send(data)) != mDot::MDOT_OK) { |
BlueShadow | 0:7f1c7e1755bc | 467 | logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str()); |
BlueShadow | 0:7f1c7e1755bc | 468 | } else { |
BlueShadow | 0:7f1c7e1755bc | 469 | logInfo("successfully sent data to gateway"); |
BlueShadow | 0:7f1c7e1755bc | 470 | } |
BlueShadow | 0:7f1c7e1755bc | 471 | |
BlueShadow | 0:7f1c7e1755bc | 472 | } |
BlueShadow | 0:7f1c7e1755bc | 473 | #endif |
BlueShadow | 0:7f1c7e1755bc | 474 | wait_ms(10); |
BlueShadow | 0:7f1c7e1755bc | 475 | } |
BlueShadow | 0:7f1c7e1755bc | 476 | } |
BlueShadow | 0:7f1c7e1755bc | 477 | |
BlueShadow | 1:3ef353c7f925 | 478 | /************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 479 | // Sensor data acquisition functions |
BlueShadow | 0:7f1c7e1755bc | 480 | /************************************************************************************************/ |
BlueShadow | 0:7f1c7e1755bc | 481 | #ifdef AnalogTemp |
BlueShadow | 0:7f1c7e1755bc | 482 | void ReadAnalogTemp () |
BlueShadow | 0:7f1c7e1755bc | 483 | { |
BlueShadow | 0:7f1c7e1755bc | 484 | BDE0600_Temp_value = BDE0600_Temp.read_u16(); |
BlueShadow | 0:7f1c7e1755bc | 485 | |
BlueShadow | 0:7f1c7e1755bc | 486 | BDE0600_output = (float)BDE0600_Temp_value * (float)0.000050354; //(value * (3.3V/65535)) |
BlueShadow | 0:7f1c7e1755bc | 487 | BDE0600_output = (BDE0600_output-(float)1.753)/((float)-0.01068) + (float)30; |
BlueShadow | 0:7f1c7e1755bc | 488 | |
BlueShadow | 0:7f1c7e1755bc | 489 | // printf("BDE0600 Analog Temp Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 490 | // printf(" Temp = %.2f C\r\n", BDE0600_output); |
BlueShadow | 0:7f1c7e1755bc | 491 | } |
BlueShadow | 0:7f1c7e1755bc | 492 | #endif |
BlueShadow | 0:7f1c7e1755bc | 493 | |
BlueShadow | 0:7f1c7e1755bc | 494 | //#ifdef AnalogUV // analog pin A4 on Arduino connector is not connected to the mDot on the UDK. |
BlueShadow | 0:7f1c7e1755bc | 495 | //void ReadAnalogUV () |
BlueShadow | 0:7f1c7e1755bc | 496 | //{ |
BlueShadow | 0:7f1c7e1755bc | 497 | // ML8511_UV_value = ML8511_UV.read_u16(); |
BlueShadow | 0:7f1c7e1755bc | 498 | // ML8511_output = (float)ML8511_UV_value * (float)0.000050354; //(value * (3.3V/65535)) //Note to self: when playing with this, a negative value is seen... Honestly, I think this has to do with my ADC converstion... |
BlueShadow | 0:7f1c7e1755bc | 499 | // ML8511_output = (ML8511_output-(float)2.2)/((float)0.129) + 10; // Added +5 to the offset so when inside (aka, no UV, readings show 0)... this is the wrong approach... and the readings don't make sense... Fix this. |
BlueShadow | 0:7f1c7e1755bc | 500 | |
BlueShadow | 0:7f1c7e1755bc | 501 | // printf("ML8511 Analog UV Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 502 | // printf(" UV = %.1f mW/cm2\r\n", ML8511_output); |
BlueShadow | 0:7f1c7e1755bc | 503 | |
BlueShadow | 0:7f1c7e1755bc | 504 | //} |
BlueShadow | 0:7f1c7e1755bc | 505 | //#endif |
BlueShadow | 0:7f1c7e1755bc | 506 | |
BlueShadow | 0:7f1c7e1755bc | 507 | |
BlueShadow | 0:7f1c7e1755bc | 508 | #ifdef HallSensor |
BlueShadow | 0:7f1c7e1755bc | 509 | void ReadHallSensor () |
BlueShadow | 0:7f1c7e1755bc | 510 | { |
BlueShadow | 0:7f1c7e1755bc | 511 | |
BlueShadow | 0:7f1c7e1755bc | 512 | Hall_Return[0] = Hall_GPIO0; |
BlueShadow | 0:7f1c7e1755bc | 513 | Hall_Return[1] = Hall_GPIO1; |
BlueShadow | 0:7f1c7e1755bc | 514 | |
BlueShadow | 0:7f1c7e1755bc | 515 | // printf("BU52011 Hall Switch Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 516 | // printf(" South Detect = %d\r\n", Hall_Return[0]); |
BlueShadow | 0:7f1c7e1755bc | 517 | // printf(" North Detect = %d\r\n", Hall_Return[1]); |
BlueShadow | 0:7f1c7e1755bc | 518 | |
BlueShadow | 0:7f1c7e1755bc | 519 | |
BlueShadow | 0:7f1c7e1755bc | 520 | } |
BlueShadow | 0:7f1c7e1755bc | 521 | #endif |
BlueShadow | 0:7f1c7e1755bc | 522 | |
BlueShadow | 0:7f1c7e1755bc | 523 | #ifdef COLOR |
BlueShadow | 0:7f1c7e1755bc | 524 | void ReadCOLOR () |
BlueShadow | 0:7f1c7e1755bc | 525 | { |
BlueShadow | 0:7f1c7e1755bc | 526 | |
BlueShadow | 0:7f1c7e1755bc | 527 | //Read color data from the IC |
BlueShadow | 0:7f1c7e1755bc | 528 | i2c.write(BH1745_addr_w, &BH1745_Addr_color_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 529 | i2c.read(BH1745_addr_r, &BH1745_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 530 | |
BlueShadow | 0:7f1c7e1755bc | 531 | //separate all data read into colors |
BlueShadow | 0:7f1c7e1755bc | 532 | BH1745[0] = (BH1745_Content_ReadData[1]<<8) | (BH1745_Content_ReadData[0]); |
BlueShadow | 0:7f1c7e1755bc | 533 | BH1745[1] = (BH1745_Content_ReadData[3]<<8) | (BH1745_Content_ReadData[2]); |
BlueShadow | 0:7f1c7e1755bc | 534 | BH1745[2] = (BH1745_Content_ReadData[5]<<8) | (BH1745_Content_ReadData[4]); |
BlueShadow | 0:7f1c7e1755bc | 535 | |
BlueShadow | 0:7f1c7e1755bc | 536 | //Output Data into UART |
BlueShadow | 0:7f1c7e1755bc | 537 | // printf("BH1745 COLOR Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 538 | // printf(" Red = %d ADC Counts\r\n",BH1745[0]); |
BlueShadow | 0:7f1c7e1755bc | 539 | // printf(" Green = %d ADC Counts\r\n",BH1745[1]); |
BlueShadow | 0:7f1c7e1755bc | 540 | // printf(" Blue = %d ADC Counts\r\n",BH1745[2]); |
BlueShadow | 0:7f1c7e1755bc | 541 | |
BlueShadow | 0:7f1c7e1755bc | 542 | } |
BlueShadow | 0:7f1c7e1755bc | 543 | #endif |
BlueShadow | 0:7f1c7e1755bc | 544 | |
BlueShadow | 0:7f1c7e1755bc | 545 | #ifdef RPR0521 //als digital |
BlueShadow | 0:7f1c7e1755bc | 546 | void ReadRPR0521_ALS () |
BlueShadow | 0:7f1c7e1755bc | 547 | { |
BlueShadow | 0:7f1c7e1755bc | 548 | i2c.write(RPR0521_addr_w, &RPR0521_Addr_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 549 | i2c.read(RPR0521_addr_r, &RPR0521_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 550 | |
BlueShadow | 0:7f1c7e1755bc | 551 | RPR0521_ALS[1] = (RPR0521_Content_ReadData[1]<<8) | (RPR0521_Content_ReadData[0]); |
BlueShadow | 0:7f1c7e1755bc | 552 | RPR0521_ALS_D0_RAWOUT = (RPR0521_Content_ReadData[3]<<8) | (RPR0521_Content_ReadData[2]); |
BlueShadow | 0:7f1c7e1755bc | 553 | RPR0521_ALS_D1_RAWOUT = (RPR0521_Content_ReadData[5]<<8) | (RPR0521_Content_ReadData[4]); |
BlueShadow | 0:7f1c7e1755bc | 554 | RPR0521_ALS_DataRatio = (float)RPR0521_ALS_D1_RAWOUT / (float)RPR0521_ALS_D0_RAWOUT; |
BlueShadow | 0:7f1c7e1755bc | 555 | |
BlueShadow | 0:7f1c7e1755bc | 556 | if(RPR0521_ALS_DataRatio < (float)0.595) { |
BlueShadow | 0:7f1c7e1755bc | 557 | RPR0521_ALS[0] = ((float)1.682*(float)RPR0521_ALS_D0_RAWOUT - (float)1.877*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 0:7f1c7e1755bc | 558 | } else if(RPR0521_ALS_DataRatio < (float)1.015) { |
BlueShadow | 0:7f1c7e1755bc | 559 | RPR0521_ALS[0] = ((float)0.644*(float)RPR0521_ALS_D0_RAWOUT - (float)0.132*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 0:7f1c7e1755bc | 560 | } else if(RPR0521_ALS_DataRatio < (float)1.352) { |
BlueShadow | 0:7f1c7e1755bc | 561 | RPR0521_ALS[0] = ((float)0.756*(float)RPR0521_ALS_D0_RAWOUT - (float)0.243*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 0:7f1c7e1755bc | 562 | } else if(RPR0521_ALS_DataRatio < (float)3.053) { |
BlueShadow | 0:7f1c7e1755bc | 563 | RPR0521_ALS[0] = ((float)0.766*(float)RPR0521_ALS_D0_RAWOUT - (float)0.25*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 0:7f1c7e1755bc | 564 | } else { |
BlueShadow | 0:7f1c7e1755bc | 565 | RPR0521_ALS[0] = 0; |
BlueShadow | 0:7f1c7e1755bc | 566 | } |
BlueShadow | 0:7f1c7e1755bc | 567 | // printf("RPR-0521 ALS/PROX Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 568 | // printf(" ALS = %0.2f lx\r\n", RPR0521_ALS[0]); |
BlueShadow | 0:7f1c7e1755bc | 569 | // printf(" PROX= %0.2f ADC Counts\r\n", RPR0521_ALS[1]); //defined as a float but is an unsigned. |
BlueShadow | 0:7f1c7e1755bc | 570 | |
BlueShadow | 0:7f1c7e1755bc | 571 | } |
BlueShadow | 0:7f1c7e1755bc | 572 | #endif |
BlueShadow | 0:7f1c7e1755bc | 573 | |
BlueShadow | 0:7f1c7e1755bc | 574 | #ifdef KMX62 |
BlueShadow | 0:7f1c7e1755bc | 575 | void ReadKMX62_Accel () |
BlueShadow | 0:7f1c7e1755bc | 576 | { |
BlueShadow | 0:7f1c7e1755bc | 577 | //Read Accel Portion from the IC |
BlueShadow | 0:7f1c7e1755bc | 578 | i2c.write(KMX62_addr_w, &KMX62_Addr_Accel_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 579 | i2c.read(KMX62_addr_r, &KMX62_Content_Accel_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 580 | |
BlueShadow | 0:7f1c7e1755bc | 581 | //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte. |
BlueShadow | 0:7f1c7e1755bc | 582 | // However, because we need the signed value, we will adjust the value when converting to "g" |
BlueShadow | 0:7f1c7e1755bc | 583 | MEMS_Accel_Xout = (KMX62_Content_Accel_ReadData[1]<<8) | (KMX62_Content_Accel_ReadData[0]); |
BlueShadow | 0:7f1c7e1755bc | 584 | MEMS_Accel_Yout = (KMX62_Content_Accel_ReadData[3]<<8) | (KMX62_Content_Accel_ReadData[2]); |
BlueShadow | 0:7f1c7e1755bc | 585 | MEMS_Accel_Zout = (KMX62_Content_Accel_ReadData[5]<<8) | (KMX62_Content_Accel_ReadData[4]); |
BlueShadow | 0:7f1c7e1755bc | 586 | |
BlueShadow | 0:7f1c7e1755bc | 587 | //Note: Conversion to G is as follows: |
BlueShadow | 0:7f1c7e1755bc | 588 | // Axis_ValueInG = MEMS_Accel_axis / 1024 |
BlueShadow | 0:7f1c7e1755bc | 589 | // However, since we did not remove the LSB previously, we need to divide by 4 again |
BlueShadow | 0:7f1c7e1755bc | 590 | // Thus, we will divide the output by 4096 (1024*4) to convert and cancel out the LSB |
BlueShadow | 0:7f1c7e1755bc | 591 | MEMS_Accel[0] = ((float)MEMS_Accel_Xout/4096/2); |
BlueShadow | 0:7f1c7e1755bc | 592 | MEMS_Accel[1] = ((float)MEMS_Accel_Yout/4096/2); |
BlueShadow | 0:7f1c7e1755bc | 593 | MEMS_Accel[2] = ((float)MEMS_Accel_Zout/4096/2); |
BlueShadow | 0:7f1c7e1755bc | 594 | |
BlueShadow | 0:7f1c7e1755bc | 595 | // Return Data to UART |
BlueShadow | 0:7f1c7e1755bc | 596 | // printf("KMX62 Accel+Mag Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 597 | // printf(" AccX= %0.2f g\r\n", MEMS_Accel[0]); |
BlueShadow | 0:7f1c7e1755bc | 598 | // printf(" AccY= %0.2f g\r\n", MEMS_Accel[1]); |
BlueShadow | 0:7f1c7e1755bc | 599 | // printf(" AccZ= %0.2f g\r\n", MEMS_Accel[2]); |
BlueShadow | 0:7f1c7e1755bc | 600 | |
BlueShadow | 0:7f1c7e1755bc | 601 | } |
BlueShadow | 0:7f1c7e1755bc | 602 | |
BlueShadow | 0:7f1c7e1755bc | 603 | void ReadKMX62_Mag () |
BlueShadow | 0:7f1c7e1755bc | 604 | { |
BlueShadow | 0:7f1c7e1755bc | 605 | |
BlueShadow | 0:7f1c7e1755bc | 606 | //Read Mag portion from the IC |
BlueShadow | 0:7f1c7e1755bc | 607 | i2c.write(KMX62_addr_w, &KMX62_Addr_Mag_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 608 | i2c.read(KMX62_addr_r, &KMX62_Content_Mag_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 609 | |
BlueShadow | 0:7f1c7e1755bc | 610 | //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte. |
BlueShadow | 0:7f1c7e1755bc | 611 | // However, because we need the signed value, we will adjust the value when converting to "g" |
BlueShadow | 0:7f1c7e1755bc | 612 | MEMS_Mag_Xout = (KMX62_Content_Mag_ReadData[1]<<8) | (KMX62_Content_Mag_ReadData[0]); |
BlueShadow | 0:7f1c7e1755bc | 613 | MEMS_Mag_Yout = (KMX62_Content_Mag_ReadData[3]<<8) | (KMX62_Content_Mag_ReadData[2]); |
BlueShadow | 0:7f1c7e1755bc | 614 | MEMS_Mag_Zout = (KMX62_Content_Mag_ReadData[5]<<8) | (KMX62_Content_Mag_ReadData[4]); |
BlueShadow | 0:7f1c7e1755bc | 615 | |
BlueShadow | 0:7f1c7e1755bc | 616 | //Note: Conversion to G is as follows: |
BlueShadow | 0:7f1c7e1755bc | 617 | // Axis_ValueInG = MEMS_Accel_axis / 1024 |
BlueShadow | 0:7f1c7e1755bc | 618 | // However, since we did not remove the LSB previously, we need to divide by 4 again |
BlueShadow | 0:7f1c7e1755bc | 619 | // Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB |
BlueShadow | 0:7f1c7e1755bc | 620 | MEMS_Mag[0] = (float)MEMS_Mag_Xout/4096*(float)0.146; |
BlueShadow | 0:7f1c7e1755bc | 621 | MEMS_Mag[1] = (float)MEMS_Mag_Yout/4096*(float)0.146; |
BlueShadow | 0:7f1c7e1755bc | 622 | MEMS_Mag[2] = (float)MEMS_Mag_Zout/4096*(float)0.146; |
BlueShadow | 0:7f1c7e1755bc | 623 | |
BlueShadow | 0:7f1c7e1755bc | 624 | // Return Data to UART |
BlueShadow | 0:7f1c7e1755bc | 625 | // printf(" MagX= %0.2f uT\r\n", MEMS_Mag[0]); |
BlueShadow | 0:7f1c7e1755bc | 626 | // printf(" MagY= %0.2f uT\r\n", MEMS_Mag[1]); |
BlueShadow | 0:7f1c7e1755bc | 627 | // printf(" MagZ= %0.2f uT\r\n", MEMS_Mag[2]); |
BlueShadow | 0:7f1c7e1755bc | 628 | |
BlueShadow | 0:7f1c7e1755bc | 629 | } |
BlueShadow | 0:7f1c7e1755bc | 630 | #endif |
BlueShadow | 0:7f1c7e1755bc | 631 | |
BlueShadow | 0:7f1c7e1755bc | 632 | #ifdef KX022 |
BlueShadow | 0:7f1c7e1755bc | 633 | void ReadKX022 () |
BlueShadow | 0:7f1c7e1755bc | 634 | { |
BlueShadow | 0:7f1c7e1755bc | 635 | |
BlueShadow | 0:7f1c7e1755bc | 636 | //Read KX022 Portion from the IC |
BlueShadow | 0:7f1c7e1755bc | 637 | i2c.write(KX022_addr_w, &KX022_Addr_Accel_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 638 | i2c.read(KX022_addr_r, &KX022_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 639 | |
BlueShadow | 0:7f1c7e1755bc | 640 | //Format Data |
BlueShadow | 0:7f1c7e1755bc | 641 | KX022_Accel_X_RawOUT = (KX022_Content_ReadData[1]<<8) | (KX022_Content_ReadData[0]); |
BlueShadow | 0:7f1c7e1755bc | 642 | KX022_Accel_Y_RawOUT = (KX022_Content_ReadData[3]<<8) | (KX022_Content_ReadData[2]); |
BlueShadow | 0:7f1c7e1755bc | 643 | KX022_Accel_Z_RawOUT = (KX022_Content_ReadData[5]<<8) | (KX022_Content_ReadData[4]); |
BlueShadow | 0:7f1c7e1755bc | 644 | |
BlueShadow | 0:7f1c7e1755bc | 645 | //Scale Data |
BlueShadow | 0:7f1c7e1755bc | 646 | KX022_Accel[0] = (float)KX022_Accel_X_RawOUT / 16384; |
BlueShadow | 0:7f1c7e1755bc | 647 | KX022_Accel[1] = (float)KX022_Accel_Y_RawOUT / 16384; |
BlueShadow | 0:7f1c7e1755bc | 648 | KX022_Accel[2] = (float)KX022_Accel_Z_RawOUT / 16384; |
BlueShadow | 0:7f1c7e1755bc | 649 | |
BlueShadow | 0:7f1c7e1755bc | 650 | //Return Data through UART |
BlueShadow | 0:7f1c7e1755bc | 651 | // printf("KX022 Accelerometer Sensor Data: \r\n"); |
BlueShadow | 0:7f1c7e1755bc | 652 | // printf(" AccX= %0.2f g\r\n", KX022_Accel[0]); |
BlueShadow | 0:7f1c7e1755bc | 653 | // printf(" AccY= %0.2f g\r\n", KX022_Accel[1]); |
BlueShadow | 0:7f1c7e1755bc | 654 | // printf(" AccZ= %0.2f g\r\n", KX022_Accel[2]); |
BlueShadow | 0:7f1c7e1755bc | 655 | |
BlueShadow | 0:7f1c7e1755bc | 656 | } |
BlueShadow | 0:7f1c7e1755bc | 657 | #endif |
BlueShadow | 0:7f1c7e1755bc | 658 | |
BlueShadow | 0:7f1c7e1755bc | 659 | |
BlueShadow | 0:7f1c7e1755bc | 660 | #ifdef Pressure |
BlueShadow | 0:7f1c7e1755bc | 661 | void ReadPressure () |
BlueShadow | 0:7f1c7e1755bc | 662 | { |
BlueShadow | 0:7f1c7e1755bc | 663 | |
BlueShadow | 0:7f1c7e1755bc | 664 | i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart); |
BlueShadow | 0:7f1c7e1755bc | 665 | i2c.read(Press_addr_r, &Press_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 0:7f1c7e1755bc | 666 | |
BlueShadow | 0:7f1c7e1755bc | 667 | BM1383_Temp_Out = (Press_Content_ReadData[0]<<8) | (Press_Content_ReadData[1]); |
BlueShadow | 0:7f1c7e1755bc | 668 | BM1383[0] = (float)BM1383_Temp_Out/32; |
BlueShadow | 0:7f1c7e1755bc | 669 | |
BlueShadow | 0:7f1c7e1755bc | 670 | BM1383_Var = (Press_Content_ReadData[2]<<3) | (Press_Content_ReadData[3] >> 5); |
BlueShadow | 0:7f1c7e1755bc | 671 | BM1383_Deci = ((Press_Content_ReadData[3] & 0x1f) << 6 | ((Press_Content_ReadData[4] >> 2))); |
BlueShadow | 0:7f1c7e1755bc | 672 | BM1383_Deci = (float)BM1383_Deci* (float)0.00048828125; //0.00048828125 = 2^-11 |
BlueShadow | 0:7f1c7e1755bc | 673 | BM1383[1] = (BM1383_Var + BM1383_Deci); //question pending here... |
BlueShadow | 0:7f1c7e1755bc | 674 | |
BlueShadow | 0:7f1c7e1755bc | 675 | // printf("BM1383 Pressure Sensor Data:\r\n"); |
BlueShadow | 0:7f1c7e1755bc | 676 | // printf(" Temperature= %0.2f C\r\n", BM1383[0]); |
BlueShadow | 0:7f1c7e1755bc | 677 | // printf(" Pressure = %0.2f hPa\r\n", BM1383[1]); |
BlueShadow | 0:7f1c7e1755bc | 678 | |
BlueShadow | 0:7f1c7e1755bc | 679 | } |
BlueShadow | 0:7f1c7e1755bc | 680 | #endif |