This the the improved and updated project and program for the earlier automatic pill dispenser project. Includes and rfid, stepper, servo, led-ldr and a load sensor integrate. time stamp is sent to the cloud and saved..

Dependencies:   EthernetInterface FXAS21002 FXOS8700 M2XStreamClient MFRC522 Servo jsonlite mbed-rtos mbed

Fork of Accel_Mag_Gyro_SensorStream_K64F_AGM01_M2X by AT&T Developer Summit Hackathon 2016

Committer:
AswinSivakumar
Date:
Tue Dec 22 00:23:52 2015 +0000
Revision:
0:4fd1b0bd1594
Child:
1:5e587e213940
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AswinSivakumar 0:4fd1b0bd1594 1 /* Copyright (c) 2015 NXP Semiconductors. MIT License
AswinSivakumar 0:4fd1b0bd1594 2 *
AswinSivakumar 0:4fd1b0bd1594 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
AswinSivakumar 0:4fd1b0bd1594 4 * and associated documentation files (the "Software"), to deal in the Software without
AswinSivakumar 0:4fd1b0bd1594 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
AswinSivakumar 0:4fd1b0bd1594 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
AswinSivakumar 0:4fd1b0bd1594 7 * Software is furnished to do so, subject to the following conditions:
AswinSivakumar 0:4fd1b0bd1594 8 *
AswinSivakumar 0:4fd1b0bd1594 9 * The above copyright notice and this permission notice shall be included in all copies or
AswinSivakumar 0:4fd1b0bd1594 10 * substantial portions of the Software.
AswinSivakumar 0:4fd1b0bd1594 11 *
AswinSivakumar 0:4fd1b0bd1594 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
AswinSivakumar 0:4fd1b0bd1594 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
AswinSivakumar 0:4fd1b0bd1594 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
AswinSivakumar 0:4fd1b0bd1594 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AswinSivakumar 0:4fd1b0bd1594 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AswinSivakumar 0:4fd1b0bd1594 17 */
AswinSivakumar 0:4fd1b0bd1594 18 #include "FXAS21002.h"
AswinSivakumar 0:4fd1b0bd1594 19 #include "FXOS8700.h"
AswinSivakumar 0:4fd1b0bd1594 20 #include "mbed.h"
AswinSivakumar 0:4fd1b0bd1594 21 #include "M2XStreamClient.h"
AswinSivakumar 0:4fd1b0bd1594 22 #include "EthernetInterface.h"
AswinSivakumar 0:4fd1b0bd1594 23
AswinSivakumar 0:4fd1b0bd1594 24 // Initialize Serial port
AswinSivakumar 0:4fd1b0bd1594 25 Serial pc(USBTX, USBRX);
AswinSivakumar 0:4fd1b0bd1594 26
AswinSivakumar 0:4fd1b0bd1594 27 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
AswinSivakumar 0:4fd1b0bd1594 28 FXOS8700 accel(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 29 FXOS8700 mag(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 30 FXAS21002 gyro(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 31
AswinSivakumar 0:4fd1b0bd1594 32 // Set Sensor Stream details
AswinSivakumar 0:4fd1b0bd1594 33 char deviceId[] = "8b34bc421abf15b7ec6471fa19513a98"; // Device you want to push to
AswinSivakumar 0:4fd1b0bd1594 34 char streamAcc[] = "acc_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 35 char streamMag[] = "mag_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 36 char streamGyr[] = "gyr_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 37 char m2xKey[] = "737018ea33de7760ab346c85ae2d9d27"; // Your M2X API Key or Master API Key
AswinSivakumar 0:4fd1b0bd1594 38
AswinSivakumar 0:4fd1b0bd1594 39 int main()
AswinSivakumar 0:4fd1b0bd1594 40 {
AswinSivakumar 0:4fd1b0bd1594 41 // Intialize Ethernet connection
AswinSivakumar 0:4fd1b0bd1594 42 EthernetInterface eth;
AswinSivakumar 0:4fd1b0bd1594 43 eth.init();
AswinSivakumar 0:4fd1b0bd1594 44 eth.connect();
AswinSivakumar 0:4fd1b0bd1594 45 printf("Success. Connected!. Device IP Address is %s\r\n", eth.getIPAddress());
AswinSivakumar 0:4fd1b0bd1594 46
AswinSivakumar 0:4fd1b0bd1594 47 // Initialize the M2X client
AswinSivakumar 0:4fd1b0bd1594 48 Client client;
AswinSivakumar 0:4fd1b0bd1594 49 M2XStreamClient m2xClient(&client, m2xKey);
AswinSivakumar 0:4fd1b0bd1594 50 int ret;
AswinSivakumar 0:4fd1b0bd1594 51
AswinSivakumar 0:4fd1b0bd1594 52
AswinSivakumar 0:4fd1b0bd1594 53 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
AswinSivakumar 0:4fd1b0bd1594 54 accel.accel_config();
AswinSivakumar 0:4fd1b0bd1594 55 mag.mag_config();
AswinSivakumar 0:4fd1b0bd1594 56 gyro.gyro_config();
AswinSivakumar 0:4fd1b0bd1594 57
AswinSivakumar 0:4fd1b0bd1594 58 float accel_data[3]; float accel_rms=0.0;
AswinSivakumar 0:4fd1b0bd1594 59 float mag_data[3]; float mag_rms=0.0;
AswinSivakumar 0:4fd1b0bd1594 60 float gyro_data[3]; float gyro_rms=0.0;
AswinSivakumar 0:4fd1b0bd1594 61
AswinSivakumar 0:4fd1b0bd1594 62 printf("Begin Data Acquisition from FXOS8700 and FXAS21002....\r\n\r\n");
AswinSivakumar 0:4fd1b0bd1594 63 wait(0.5);
AswinSivakumar 0:4fd1b0bd1594 64
AswinSivakumar 0:4fd1b0bd1594 65 while(1)
AswinSivakumar 0:4fd1b0bd1594 66 {
AswinSivakumar 0:4fd1b0bd1594 67 accel.acquire_accel_data_g(accel_data);
AswinSivakumar 0:4fd1b0bd1594 68 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
AswinSivakumar 0:4fd1b0bd1594 69 printf("%4.2f,\t%4.2f,\t%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]);
AswinSivakumar 0:4fd1b0bd1594 70 wait(0.01);
AswinSivakumar 0:4fd1b0bd1594 71
AswinSivakumar 0:4fd1b0bd1594 72 mag.acquire_mag_data_uT(mag_data);
AswinSivakumar 0:4fd1b0bd1594 73 printf("%4.2f,\t%4.2f,\t%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]);
AswinSivakumar 0:4fd1b0bd1594 74 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
AswinSivakumar 0:4fd1b0bd1594 75 wait(0.01);
AswinSivakumar 0:4fd1b0bd1594 76
AswinSivakumar 0:4fd1b0bd1594 77 gyro.acquire_gyro_data_dps(gyro_data);
AswinSivakumar 0:4fd1b0bd1594 78 printf("%4.2f,\t%4.2f,\t%4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
AswinSivakumar 0:4fd1b0bd1594 79 gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
AswinSivakumar 0:4fd1b0bd1594 80 wait(0.01);
AswinSivakumar 0:4fd1b0bd1594 81
AswinSivakumar 0:4fd1b0bd1594 82 ret = m2xClient.updateStreamValue(deviceId, streamAcc, accel_rms);
AswinSivakumar 0:4fd1b0bd1594 83 printf("send() returned %d\r\n", ret);
AswinSivakumar 0:4fd1b0bd1594 84 ret = m2xClient.updateStreamValue(deviceId, streamMag, mag_rms);
AswinSivakumar 0:4fd1b0bd1594 85 printf("send() returned %d\r\n", ret);
AswinSivakumar 0:4fd1b0bd1594 86 ret = m2xClient.updateStreamValue(deviceId, streamGyr, gyro_rms);
AswinSivakumar 0:4fd1b0bd1594 87 printf("send() returned %d\r\n", ret);
AswinSivakumar 0:4fd1b0bd1594 88 wait(1);
AswinSivakumar 0:4fd1b0bd1594 89 }
AswinSivakumar 0:4fd1b0bd1594 90
AswinSivakumar 0:4fd1b0bd1594 91 }