From e7940f9891c89db651580635ff132caa7956cedd Mon Sep 17 00:00:00 2001 From: 0x1abin <270995079@qq.com> Date: Wed, 27 Sep 2017 19:40:43 +0800 Subject: [PATCH] add the MPU9250 driver --- .../Lora/LoRaReceiver/LoRaReceiver.ino | 49 ------------------- .../Advanced/Lora/LoRaSender/LoRaSender.ino | 45 ----------------- src/M5Stack.cpp | 8 +++ src/M5Stack.h | 20 +++++--- src/utility/Config.h | 14 ++++-- 5 files changed, 30 insertions(+), 106 deletions(-) delete mode 100644 examples/Advanced/Lora/LoRaReceiver/LoRaReceiver.ino delete mode 100644 examples/Advanced/Lora/LoRaSender/LoRaSender.ino diff --git a/examples/Advanced/Lora/LoRaReceiver/LoRaReceiver.ino b/examples/Advanced/Lora/LoRaReceiver/LoRaReceiver.ino deleted file mode 100644 index 599549a..0000000 --- a/examples/Advanced/Lora/LoRaReceiver/LoRaReceiver.ino +++ /dev/null @@ -1,49 +0,0 @@ -//nedd to download library https://github.com/sandeepmistry/arduino-LoRa.git - -#include -#include -#include - -#define LORA_CS_PIN 5 -#define LORA_RST_PIN 26 -#define LORA_IRQ_PIN 36 - -void setup() { - - M5.begin(); - - // override the default CS, reset, and IRQ pins (optional) - LoRa.setPins(LORA_CS_PIN, LORA_RST_PIN, LORA_IRQ_PIN); // set CS, reset, IRQ pin - - Serial.println("LoRa Receiver"); - M5.Lcd.println("LoRa Receiver"); - - if (!LoRa.begin(433E6)) { - Serial.println("Starting LoRa failed!"); - M5.Lcd.println("Starting LoRa failed!"); - while (1); - } -} - -void loop() { - // try to parse packet - int packetSize = LoRa.parsePacket(); - if (packetSize) { - // received a packet - Serial.print("Received packet: \""); - M5.Lcd.print("Received packet: \""); - - // read packet - while (LoRa.available()) { - char ch = (char)LoRa.read(); - Serial.print(ch); - M5.Lcd.print(ch); - } - - // print RSSI of packet - Serial.print("\" with RSSI "); - Serial.println(LoRa.packetRssi()); - M5.Lcd.print("\" with RSSI "); - M5.Lcd.println(LoRa.packetRssi()); - } -} diff --git a/examples/Advanced/Lora/LoRaSender/LoRaSender.ino b/examples/Advanced/Lora/LoRaSender/LoRaSender.ino deleted file mode 100644 index 4bae1a0..0000000 --- a/examples/Advanced/Lora/LoRaSender/LoRaSender.ino +++ /dev/null @@ -1,45 +0,0 @@ -//nedd to download LoRa library: https://github.com/sandeepmistry/arduino-LoRa.git - -#include -#include -#include - -#define LORA_CS_PIN 5 -#define LORA_RST_PIN 26 -#define LORA_IRQ_PIN 36 - -void setup() { - - M5.begin(); - - // override the default CS, reset, and IRQ pins (optional) - LoRa.setPins(LORA_CS_PIN, LORA_RST_PIN, LORA_IRQ_PIN); // set CS, reset, IRQ pin - - Serial.println("LoRa Sender"); - // M5.Lcd.println("LoRa Receiver Callback"); - - if (!LoRa.begin(433E6)) { - Serial.println("Starting LoRa failed!"); - M5.Lcd.println("Starting LoRa failed!"); - while (1); - } - -} - -void loop() { - // try to parse packet - static uint32_t counter; - - Serial.print("Sending packet: "); - Serial.println(counter); - - // send packet - LoRa.beginPacket(); - LoRa.print("hello "); - LoRa.print(counter); - LoRa.endPacket(); - - counter++; - - delay(1000); -} \ No newline at end of file diff --git a/src/M5Stack.cpp b/src/M5Stack.cpp index bb2e564..9af1fca 100644 --- a/src/M5Stack.cpp +++ b/src/M5Stack.cpp @@ -36,6 +36,14 @@ void M5Stack::begin() { // Set wakeup button setWakeupButton(BUTTON_A_PIN); + // MPU9250 +#ifdef MPU9250_INSDE + // Wire.begin(); + // MPU.setWire(&Wire); + // MPU.beginAccel(); + // MPU.beginMag(); +#endif + Serial.println("OK."); } diff --git a/src/M5Stack.h b/src/M5Stack.h index b318162..cd94ad4 100644 --- a/src/M5Stack.h +++ b/src/M5Stack.h @@ -85,18 +85,19 @@ #include "FS.h" #include "SD.h" -#include // Graphics and font library for ILI9341 driver chip -#include -#include -#include -#include -#include +#include "utility/Display.h" // Graphics and font library for ILI9341 driver chip +#include "utility/Config.h" +#include "utility/Button.h" +#include "utility/Speaker.h" +#include "utility/MPU9250.h" +#include "utility/bmp_map.h" +#include "utility/music_8bit.h" extern "C" { -#include "esp32-hal-dac.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_deep_sleep.h" +#include "esp32-hal-dac.h" } class M5Stack { @@ -126,6 +127,11 @@ class M5Stack { HardwareSerial Serial0 = HardwareSerial(0); HardwareSerial Serial2 = HardwareSerial(2); + // MPU9250 +#ifdef MPU9250_INSDE + MPU9250 MPU; +#endif + private: uint8_t _wakeupPin; diff --git a/src/utility/Config.h b/src/utility/Config.h index 6b41c0b..b91d41e 100644 --- a/src/utility/Config.h +++ b/src/utility/Config.h @@ -1,7 +1,7 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ -//screen +// Screen #define TFT_LED_PIN 32 #define TFT_DC_PIN 27 #define TFT_CS_PIN 14 @@ -10,12 +10,10 @@ #define TFT_RST_PIN 33 #define TFT_MISO_PIN 19 -//SD card +// SD card #define TFCARD_CS_PIN 4 -//number of buttons -#define NUM_BTN 3 -//buttons ID +// Buttons #define BTN_A 0 #define BTN_B 1 #define BTN_C 2 @@ -30,6 +28,12 @@ #define SPEAKER_PIN 25 #define TONE_PIN_CHANNEL 0 +// LORA +#define LORA_CS_PIN 5 +#define LORA_RST_PIN 26 +#define LORA_IRQ_PIN 36 + +// UART #define USE_SERIAL Serial #endif /* SETTINGS_C */