|
|
@@ -1,41 +1,77 @@
|
|
|
+//oled
|
|
|
|
|
|
-//radio
|
|
|
-#include <SPI.h>
|
|
|
-#include <nRF24L01.h>
|
|
|
-#include <RF24.h>
|
|
|
-RF24 radio(7, 10); // CE, CSN
|
|
|
-const byte address[6] = "00001";
|
|
|
|
|
|
+//#define HAS_18x4LCD
|
|
|
|
|
|
+#define HAS_u8x8log
|
|
|
|
|
|
-// #include "I2Cdev.h"
|
|
|
-#include "MPU6050.h"
|
|
|
|
|
|
+#if defined(HAS_u8x8log)
|
|
|
+ #include <Arduino.h>
|
|
|
+ // #include <U8g2lib.h>
|
|
|
+ #include <U8x8lib.h>
|
|
|
|
|
|
-//#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
|
|
- #include "Wire.h"
|
|
|
-//#endif
|
|
|
+
|
|
|
+ //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display
|
|
|
+ U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
|
|
|
|
|
|
-#include <LiquidCrystal_I2C.h>
|
|
|
-LiquidCrystal_I2C lcd(0x27,16,4); // set the LCD address to 0x27 or 0x20
|
|
|
+ // U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
|
|
|
+
|
|
|
+ #define U8LOG_WIDTH 16
|
|
|
+ #define U8LOG_HEIGHT 8
|
|
|
+ uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
|
|
|
+ U8X8LOG u8x8log;
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
-// #include "struct.h"
|
|
|
+#include "progmem__const.h"
|
|
|
+
|
|
|
+#define HAS_nRF24L01
|
|
|
|
|
|
-#include <QMC5883LCompass.h>
|
|
|
-QMC5883LCompass compass;
|
|
|
+//radio
|
|
|
+#if defined(HAS_nRF24L01)
|
|
|
+ #include <SPI.h>
|
|
|
+ #include <nRF24L01.h>
|
|
|
+ #include <RF24.h>
|
|
|
+ RF24 radio(7, 10); // CE, CSN
|
|
|
+const byte address[6] = "00001";
|
|
|
+#endif
|
|
|
|
|
|
+ #include "Wire.h"
|
|
|
|
|
|
-const int MPU=0x68;
|
|
|
-int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
|
|
|
|
|
|
-MPU6050 accelgyro(MPU);
|
|
|
+#define HAS_MPU6050
|
|
|
+#if defined(HAS_MPU6050)
|
|
|
+// #include "I2Cdev.h"
|
|
|
+ #include "MPU6050.h"
|
|
|
+ //#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
|
|
+ #include "Wire.h"
|
|
|
+ //#endif
|
|
|
+#endif
|
|
|
|
|
|
- int16_t ax, ay, az;
|
|
|
- int16_t gx, gy, gz;
|
|
|
-#define OUTPUT_READABLE_ACCELGYRO
|
|
|
-//#define OUTPUT_BINARY_ACCELGYRO
|
|
|
+ #if defined(HAS_18x4LCD)
|
|
|
+ #include <LiquidCrystal_I2C.h>
|
|
|
+ LiquidCrystal_I2C lcd(0x27,16,4); // set the LCD address to 0x27 or 0x20
|
|
|
+ #endif
|
|
|
|
|
|
+// #include "struct.h"
|
|
|
+#define HAS_QMC5883LCompass
|
|
|
+#if defined(QMC5883LCompass)
|
|
|
+ #include <QMC5883LCompass.h>
|
|
|
+ QMC5883LCompass compass;
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(HAS_MPU6050)
|
|
|
+ const int MPU=0x68;
|
|
|
+ int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
|
|
|
+
|
|
|
+ MPU6050 accelgyro(MPU);
|
|
|
+
|
|
|
+ int16_t ax, ay, az;
|
|
|
+ int16_t gx, gy, gz;
|
|
|
+ #define OUTPUT_READABLE_ACCELGYRO
|
|
|
+ //#define OUTPUT_BINARY_ACCELGYRO
|
|
|
+#endif
|
|
|
|
|
|
#define LED_PIN 13
|
|
|
bool blinkState = false;
|
|
|
@@ -43,88 +79,108 @@ bool blinkState = false;
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
|
+ #if defined(HAS_u8x8log)
|
|
|
+ #include "u8g2__setup.h"
|
|
|
+ #endif
|
|
|
//#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
|
|
- Wire.begin();
|
|
|
+ // Wire.begin();
|
|
|
//#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
|
|
|
// Fastwire::setup(400, true);
|
|
|
//#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Serial.begin(115200);
|
|
|
while (!Serial); // Waiting for Serial Monitor
|
|
|
- Serial.println("\nCompass ang gyro test ");
|
|
|
+ //Serial.println("\nCompass ang gyro test ");
|
|
|
+ SPFT(title);
|
|
|
+
|
|
|
#include "scan.h"
|
|
|
-
|
|
|
- Serial.println("compass.init()");
|
|
|
- compass.init();
|
|
|
- Serial.println("accelgyro.initialize()");
|
|
|
- accelgyro.initialize();
|
|
|
- Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
|
|
|
- accelgyro.setMotionDetectionDuration(80);
|
|
|
-
|
|
|
+ #if defined(QMC5883LCompass)
|
|
|
+ Serial.println("compass.init()");
|
|
|
+ compass.init();
|
|
|
+ #endif
|
|
|
+ #if defined(HAS_MPU6050)
|
|
|
+ Serial.println("accelgyro.initialize()");
|
|
|
+ accelgyro.initialize();
|
|
|
+ Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
|
|
|
+ accelgyro.setMotionDetectionDuration(80);
|
|
|
+ #endif
|
|
|
|
|
|
pinMode(LED_PIN, OUTPUT);
|
|
|
|
|
|
//lcd.backlight();
|
|
|
//lcd.setCursor(3,0);
|
|
|
//lcd.print("Hello, world!");
|
|
|
- #include "LiquidCrystal_I2C_setup.h"
|
|
|
+ #if defined(HAS_18x4LCD)
|
|
|
+ #include "LiquidCrystal_I2C_setup.h"
|
|
|
+ #endif
|
|
|
// setZeroMotionDetectionThreshold(154);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-radio.begin();
|
|
|
-radio.openWritingPipe(address);
|
|
|
-radio.setPALevel(RF24_PA_MIN);
|
|
|
-radio.stopListening();
|
|
|
-
|
|
|
+
|
|
|
+#if defined(HAS_nRF24L01)
|
|
|
+ radio.begin();
|
|
|
+ radio.openWritingPipe(address);
|
|
|
+ radio.setPALevel(RF24_PA_MIN);
|
|
|
+ radio.stopListening();
|
|
|
+#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
{
|
|
|
- int x, y, z;
|
|
|
-Serial.println();
|
|
|
- // Read compass values
|
|
|
- compass.read();
|
|
|
-
|
|
|
- x = compass.getX();
|
|
|
- y = compass.getY();
|
|
|
- z = compass.getZ();
|
|
|
-
|
|
|
- Serial.print("Comp X: ");
|
|
|
- Serial.print(x);
|
|
|
- Serial.print(" Y: ");
|
|
|
- Serial.print(y);
|
|
|
- Serial.print(" Z: ");
|
|
|
- Serial.print(z);
|
|
|
-
|
|
|
- accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
|
|
- // these methods (and a few others) are also available
|
|
|
- //accelgyro.getAcceleration(&ax, &ay, &az);
|
|
|
- //accelgyro.getRotation(&gx, &gy, &gz);
|
|
|
-#ifdef OUTPUT_READABLE_ACCELGYRO
|
|
|
- // display tab-separated accel/gyro x/y/z values
|
|
|
- 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.print(gz);
|
|
|
- #endif
|
|
|
|
|
|
- #ifdef OUTPUT_BINARY_ACCELGYRO
|
|
|
- Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
|
|
|
- Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
|
|
|
- Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
|
|
|
- Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
|
|
|
- Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
|
|
|
- Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
|
|
|
+ // u8x8log.print("millis=");
|
|
|
+
|
|
|
+
|
|
|
+#if defined(QMC5883LCompass)
|
|
|
+ int x, y, z;
|
|
|
+ Serial.println();
|
|
|
+ // Read compass values
|
|
|
+ compass.read();
|
|
|
+
|
|
|
+ x = compass.getX();
|
|
|
+ y = compass.getY();
|
|
|
+ z = compass.getZ();
|
|
|
+ SPFT(compass);
|
|
|
+ SPFT2(x,x);
|
|
|
+ Serial.print(" Y: ");
|
|
|
+ Serial.print(y);
|
|
|
+ Serial.print(" Z: ");
|
|
|
+ Serial.print(z);
|
|
|
+#endif
|
|
|
+#if defined(HAS_MPU6050)
|
|
|
+ accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
|
|
+ // these methods (and a few others) are also available
|
|
|
+ //accelgyro.getAcceleration(&ax, &ay, &az);
|
|
|
+ //accelgyro.getRotation(&gx, &gy, &gz);
|
|
|
+ #ifdef OUTPUT_READABLE_ACCELGYRO
|
|
|
+ // display tab-separated accel/gyro x/y/z values
|
|
|
+ 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.print(gz);
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #ifdef OUTPUT_BINARY_ACCELGYRO
|
|
|
+ Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
|
|
|
+ Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
|
|
|
+ Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
|
|
|
+ Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
|
|
|
+ Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
|
|
|
+ Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
|
|
|
+ #endif
|
|
|
+#endif
|
|
|
+ #if defined(HAS_18x4LCD)
|
|
|
+ #include "LiquidCrystal_I2C_loop.h"
|
|
|
+ #endif
|
|
|
+ #if defined(HAS_nRF24L01)
|
|
|
+ #include "radio_loop.h"
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
- #include "LiquidCrystal_I2C_loop.h"
|
|
|
- #include "radio_loop.h"
|
|
|
delay(1500);
|
|
|
|
|
|
}
|