Software for Sensor box, read analogue values and send using nRF
Dependencies: MMA8451Q mbed nRF24L01P
Fork of Acclerometer_node by
Revision 3:5c7f4e5a7605, committed 2015-05-30
- Comitter:
- trisjph
- Date:
- Sat May 30 14:25:00 2015 +0000
- Parent:
- 2:fb6e66ce1d84
- Child:
- 4:7d3a1dfe5454
- Commit message:
- lklkklklkl;
Changed in this revision
| MMA8451Q.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/MMA8451Q.lib Sat May 30 14:25:00 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- a/main.cpp Sat May 30 12:56:14 2015 +0000
+++ b/main.cpp Sat May 30 14:25:00 2015 +0000
@@ -1,19 +1,31 @@
#include "mbed.h"
#include "nRF24L01P.h"
+#include "MMA8451Q.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
Serial pc(USBTX, USBRX); // tx, rx
+PinName const SDA = PTE25;
+PinName const SCL = PTE24;
+
nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTE0, PTE1, PTD0); // mosi, miso, sck, csn, ce, irq
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
-int main() {
+int main()
+{
+
+ MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
+ //PwmOut rled(LED1);
+ //PwmOut gled(LED2);
+ //PwmOut bled(LED3);
// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
// "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
// only handles 4 byte transfers in the ATMega code.
-#define TRANSFER_SIZE 4
+#define TRANSFER_SIZE 24
char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
int txDataCnt = 0;
@@ -35,41 +47,37 @@
my_nrf24l01p.setReceiveMode();
my_nrf24l01p.enable();
+
+
+ printf("MMA8451 ID: %d\n", acc.getWhoAmI());
+
while (1) {
+ float x, y, z;
+ x = abs(acc.getAccX());
+ y = abs(acc.getAccY());
+ z = abs(acc.getAccZ());
+ //rled = 1.0f - x;
+ //gled = 1.0f - y;
+ //bled = 1.0f - z;
+ wait(1);
+ txDataCnt = sprintf(txData, "X:%1.3f,Y:%1.3f,Z:%1.3f\n", x,y,z);
+
+ printf("X:%f,Y:%f,Z:%f size %i %s\n", x, y, z,txDataCnt, txData);
+
// If we've received anything over the host serial link...
- if ( pc.readable() ) {
-
- // ...add it to the transmit buffer
- txData[txDataCnt++] = pc.getc();
- // If the transmit buffer is full
- if ( txDataCnt >= sizeof( txData ) ) {
+ // ...add it to the transmit buffer
+ //txData[txDataCnt++] = pc.getc();
- // Send the transmitbuffer via the nRF24L01+
- my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-
- txDataCnt = 0;
- }
+ // If the transmit buffer is full
- // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
- myled1 = !myled1;
- }
-
- // If we've received anything in the nRF24L01+...
- if ( my_nrf24l01p.readable() ) {
-
- // ...read the data into the receive buffer
- rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
+ // Send the transmitbuffer via the nRF24L01+
+ my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
+
+ printf("sent");
- // Display the receive buffer contents via the host serial link
- for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
-
- pc.putc( rxData[i] );
- }
-
- // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
- myled2 = !myled2;
- }
+ // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
+ myled1 = !myled1;
}
}
