You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
|
|
#include "I2Cdev.h"
|
|
#include "MPU6050.h"
|
|
|
|
#include <SPI.h>
|
|
#include <nRF24L01.h>
|
|
#include <RF24.h>
|
|
|
|
RF24 radio(8, 9); // CE, CSN
|
|
|
|
const byte address[6] = "00001";
|
|
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
|
#include "Wire.h"
|
|
#endif
|
|
|
|
MPU6050 accelgyro;
|
|
//MPU6050 accelgyro(0x69); // <-- use for AD0 high
|
|
|
|
int16_t ax, ay, az;
|
|
int16_t gx, gy, gz;
|
|
|
|
#define OUTPUT_READABLE_ACCELGYRO
|
|
|
|
void setup() {
|
|
radio.begin();
|
|
radio.openWritingPipe(address);
|
|
radio.setPALevel(RF24_250KBPS);
|
|
radio.stopListening();
|
|
|
|
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
|
Wire.begin();
|
|
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
|
|
Fastwire::setup(400, true);
|
|
#endif
|
|
|
|
Serial.begin(9600);
|
|
|
|
// initialize device
|
|
Serial.println("Initializing I2C devices...");
|
|
accelgyro.initialize();
|
|
|
|
// verify connection
|
|
Serial.println("Testing device connections...");
|
|
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
|
|
}
|
|
|
|
void loop() {
|
|
|
|
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
|
|
|
#ifdef OUTPUT_READABLE_ACCELGYRO
|
|
Serial.print("a/g:\t");
|
|
Serial.print(ax); Serial.print("\t");
|
|
Serial.print(ay); Serial.print("\t");
|
|
Serial.print(az); Serial.print("\t");
|
|
Serial.print(gx); Serial.print("\t");
|
|
Serial.print(gy); Serial.print("\t");
|
|
Serial.println(gz);
|
|
#endif
|
|
|
|
int16_t dataL[] = {ax,
|
|
ay,
|
|
az,
|
|
gx,
|
|
gy,
|
|
gz};
|
|
|
|
radio.write(&dataL, sizeof(dataL));
|
|
delay(100);
|
|
}
|