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: FXOS8700Q M2XStreamClient SocketModem jsonlite mbed
Fork of M2X_MTS_Accel by
Revision 3:e425cec88d5f, committed 2014-09-05
- Comitter:
- jb8414
- Date:
- Fri Sep 05 02:05:55 2014 +0000
- Parent:
- 2:bf9a98c3f73e
- Child:
- 4:913fe6d89ea4
- Commit message:
- Convert for K64F board
Changed in this revision
| FXOS8700Q.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FXOS8700Q.lib Fri Sep 05 02:05:55 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
--- a/main.cpp Wed Sep 03 20:19:00 2014 +0000
+++ b/main.cpp Fri Sep 05 02:05:55 2014 +0000
@@ -1,21 +1,9 @@
#include "mbed.h"
-#include "MMA8451Q.h"
+#include "FXOS8700Q.h"
#include "M2XStreamClient.h"
#include "include_me.h"
#include "math.h"
-#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
- PinName const SDA = PTE25;
- PinName const SCL = PTE24;
-#elif defined (TARGET_KL05Z)
- PinName const SDA = PTB4;
- PinName const SCL = PTB3;
-#else
- #error TARGET NOT DEFINED
-#endif
-
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
-
using namespace mts;
const char key[] = "<key>"; // Replace with your M2X user account master key
@@ -25,6 +13,7 @@
// set to 1 for cellular shield board
// set to 0 for wifi shield board
#define CELL_SHIELD 0
+#define SUCCESS 1
// ssid and phrase for wifi
std::string ssid = "<ssid>"; // Replace with your Wifi ID (SSID)
@@ -33,16 +22,17 @@
int main()
{
+ printf("starting\n\r");
#if CELL_SHIELD
- MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+ MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTC17, PTC16, PTA1, PTC2);
serial->baud(115200);
Transport::setTransport(Transport::CELLULAR);
Cellular* cell = Cellular::getInstance();
- cell->init(serial, PTA4, PTC9); //DCD and DTR pins for KL46Z
+ cell->init(serial, PTA2, PTE25); //DCD and DTR pins for K64F
int max_tries = 5;
int i;
- std::string apn = "wap.cingular"; // set to the appropriate APN (i.e. "m2m.com.attz" for M2X SIMs)
+ std::string apn = "wap.cingular"; // set to the appropriate APN (i.e. "m2m.com.attz" for M2X SIMs, "wap.cingular" for others)
i = 0;
while (i++ < max_tries) {
@@ -89,7 +79,7 @@
wait(2);
printf("Waiting %d seconds...\n\r", i);
}
- MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
+ MTSSerial* serial = new MTSSerial(PTC17, PTC16, 256, 256);
serial->baud(9600);
Transport::setTransport(Transport::WIFI);
Wifi* wifi = Wifi::getInstance();
@@ -106,13 +96,38 @@
Client client;
M2XStreamClient m2xClient(&client, key);
int ret;
-
+
+ // Add code below to read accelerometer data and post to M2X stream
+ // ...
+
// Create an accelerometer instance
- MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
-
- printf("MMA8451 ID: %d\n", acc.getWhoAmI());
+ FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
+ acc.enable();
+ printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
+
+ while (true) {
+
+ float x, y, z;
+ acc.getX(&x);
+ acc.getY(&y);
+ acc.getZ(&z);
+
+ printf("Accel X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z);
- // Add code here to read accelerometer data and post to M2X stream
- // ...
-
+ // Calculate pitch and roll. Find the maximum tilt angle.
+ float pitch = atan(x / sqrt(y * y + z * z));
+ float roll = atan(y / sqrt(x * x + z * z));
+ float maxTilt =
+ max(abs(roll), abs(pitch)) * 180.0 / 3.14159;
+ printf("pitch: %5.1f roll: %5.1f maxTilt: %5.1f\n\r",
+ pitch, roll, maxTilt);
+
+ // If the maximum title is over 20 degrees, then send
+ // data to stream
+ if (maxTilt > 20) {
+ ret = m2xClient.post(feed, stream, maxTilt);
+ printf("send() returned %d\r\n", ret);
+ wait(0.5);
+ }
+ }
}
\ No newline at end of file
