Browse Source

Gyro, Baro, RX OK. OSD - Not tested yet

master
Englebert 3 years ago
parent
commit
a428e6e1c9
  1. 7
      README.md
  2. 79
      src/baro.cpp
  3. 13
      src/baro.h
  4. 99
      src/main.cpp
  5. 5
      src/main.h

7
README.md

@ -1,6 +1,13 @@
### TODO
1. The shunt resistor R31 and R32 might need to change the values.
### STATUS
BMP280 -- [ IN PROGRESS ]
GYRO ---- [ WORKING ]
RX ------ [ WORKING ]
OSD ----- [ ]
VMETER -- [ WORKING ]
CMETER -- [ WORKING ]
### REFERENCES

79
src/baro.cpp

@ -11,6 +11,7 @@
// #define BMP_MOSI 23
// #define BMP_CS 32
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
// Adafruit_BMP280 bmp(BARO_CS);
// Adafruit_BMP280 bmp(BARO_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
// BMP280_DEV bmp(BARO_CS);
@ -23,9 +24,8 @@ BARO::BARO(void) {
pinMode(BARO_CS, OUTPUT);
// For now we use digitalWrite, later change to DMA
digitalWrite(BARO_CS, LOW);
delay(10);
digitalWrite(BARO_CS, HIGH); // Temporary set to unselect
// digitalWrite(BARO_CS, HIGH); // Temporary set to unselect
}
@ -69,8 +69,12 @@ int8_t BARO::bmp280_init(void) {
uint8_t try_count = 5;
while(try_count) {
result = bmp280_get_regs(BMP280_REGISTER_CHIPID, BMP280_CHIP_ID1);
// result = bmp280_get_regs(BMP280_REGISTER_CHIPID, BMP280_CHIP_ID1);
beginTransaction();
result = read_register(BMP280_REGISTER_CHIPID);
endTransaction();
Serial.print("BMP280 Retry #"); Serial.print(try_count); Serial.print(" "); Serial.println(result);
delay(10);
try_count--;
}
@ -88,14 +92,37 @@ void BARO::begin(void) {
// bit 7
// bmp280_soft_reset();
// delay(3000);
bmp280_init();
// bmp280_init();
// bmp280_init();
// beginTransaction();
beginTransaction();
delayMicroseconds(100);
uint8_t status = _SPI.transfer(BMP280_REGISTER_CHIPID);
status = _SPI.transfer(0xFF);
Serial.print("BMP280: "); Serial.println(status);
endTransaction();
if(!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
// uint8_t status = read_register(BMP280_REGISTER_CHIPID);
// Serial.print("BMP280: "); Serial.println(status);
// endTransaction();
/***
if(!bmp.begin()) {
@ -127,15 +154,47 @@ void BARO::get_reading(void) {
**/
// pressure = bmp.readPressure() / 100.0;
// Serial.print(F("BMP280 ")); Serial.print(pressure); Serial.println(F("hPa "));
Serial.println(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
vTaskDelay(500);
}
inline void BARO::beginTransaction() {
_SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
digitalWrite(BARO_CS, LOW);
delayMicroseconds(10);
}
inline void BARO::endTransaction() {
digitalWrite(BARO_CS, HIGH);
delayMicroseconds(100);
_SPI.endTransaction();
}
uint8_t BARO::read_register(uint8_t addr) {
int8_t status;
uint8_t result;
beginTransaction();
status = _SPI.transfer(0x80 | addr);
result = _SPI.transfer(0xFF);
result = _SPI.transfer(0xFF);
endTransaction();
return result;
}
uint8_t BARO::write_register(uint8_t addr, const uint8_t data) {
int8_t status;
uint8_t result;
beginTransaction();
status = _SPI.transfer(addr);
result = _SPI.transfer(data);
endTransaction();
return result;
}

13
src/baro.h

@ -1,9 +1,9 @@
#ifndef BARO_H_
#define BARO_H_
// ## REF: https://www.best-microcontroller-projects.com/bmp280.html
#include <Arduino.h>
// #include <Adafruit_Sensor.h>
// #include <Adafruit_BMP280.h>
#include <Adafruit_BMP280.h>
#include <SPI.h>
// #include <BMP280_DEV.h>
#include "main.h"
@ -28,8 +28,8 @@
class BARO {
public:
BARO(void);
inline void beginTransaction();
inline void endTransaction();
// inline void beginTransaction();
// inline void endTransaction();
void begin(void);
void get_reading(void);
uint8_t bmp280_soft_reset();
@ -38,6 +38,11 @@ class BARO {
int8_t bmp280_get_power_mode(void);
int8_t bmp280_init(void);
void beginTransaction(void);
void endTransaction(void);
uint8_t read_register(uint8_t addr);
uint8_t write_register(uint8_t addr, const uint8_t data);
private:
float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables

99
src/main.cpp

@ -2,26 +2,29 @@
#include "main.h"
BATTERY battery;
// BARO baro;
BARO baro;
GYRO gyro;
// NRF24L01 rx(RX_CE_PIN, RX_CSN_PIN); // Setting up receiver module
NRF24L01 rx(RX_CE_PIN, RX_CSN_PIN); // Setting up receiver module
WIFI wifi;
WEB web;
// Seetting up Motors
Motors motors = Motors(MOTOR1, MOTOR2, MOTOR3, MOTOR4);
// RXMessage rxMessage;
RXMessage rxMessage;
void setup() {
Serial.begin(115200);
// Delay 200mS for waiting for all the peripheral devices settle down
delay(2000);
// baro.begin();
// delay(2000);
baro.begin();
for(uint8_t i = 0; i < 20; i++)
battery.get_reading();
Serial.print(" BATTERY(VOLTS): "); Serial.print(battery.volt); Serial.println("V");
gyro.begin();
// rx.begin();
rx.begin();
// Serial.print("FREE RAM: "); Serial.print(ESP.getFreeHeap()); Serial.println(" MB");
@ -68,7 +71,6 @@ void setup() {
APP_CPU
);
/**** TEMPORARY DISABLE
xTaskCreatePinnedToCore(
taskBaro,
"TaskBaro", // Name of the process
@ -79,6 +81,7 @@ void setup() {
APP_CPU
);
/**** TEMPORARY DISABLE
xTaskCreatePinnedToCore(
taskGyro,
"TaskGyro", // Name of the process
@ -88,6 +91,7 @@ void setup() {
NULL,
PRO_CPU
);
****/
xTaskCreatePinnedToCore(
taskReceiver,
@ -98,7 +102,6 @@ void setup() {
NULL,
PRO_CPU
);
****/
}
@ -136,44 +139,42 @@ void taskWebHandler(void *pvParameters) {
}
//void taskReceiver(void *pvParameters) {
// (void) pvParameters;
//
// vTaskDelay(5000);
//
// // Setup
// rx.stopListening();
// rx.setAutoAck(false);
// rx.setChannel(8); /***** Temporary on 8 ... later make it auto *****/
// rx.setPayloadSize(sizeof(RXMessage));
// rx.setDataRate(RF24_250KBPS);
// rx.setPALevel(RF24_PA_MAX);
// rx.openReadingPipe(1, pipeIn);
// rx.startListening();
//
// for(;;) {
// if(rx.available()) {
// // Getting signals from Receiver
// rx.read(&rxMessage, sizeof(RXMessage));
//
// Serial.print(rxMessage.Byte00);
// Serial.print(" ");
// Serial.print(rxMessage.Byte01);
// Serial.print(" ");
// Serial.print(rxMessage.Byte02);
// Serial.print(" ");
// Serial.print(rxMessage.Byte03);
// Serial.print(" ");
// Serial.print(rxMessage.Byte04);
// Serial.print(" ");
// Serial.print(rxMessage.Byte05);
// Serial.println(" ");
//
// }
// vTaskDelay(100);
// }
//}
//
void taskReceiver(void *pvParameters) {
(void) pvParameters;
vTaskDelay(5000);
// Setup
rx.stopListening();
rx.setAutoAck(false);
rx.setChannel(8); // ************* Temporary on 8 ... later make it auto ***************************
rx.setPayloadSize(sizeof(RXMessage));
rx.setDataRate(RF24_250KBPS);
rx.setPALevel(RF24_PA_MAX);
rx.openReadingPipe(1, pipeIn);
rx.startListening();
for(;;) {
if(rx.available()) {
// Getting signals from Receiver
rx.read(&rxMessage, sizeof(RXMessage));
Serial.print(rxMessage.Byte00);
Serial.print(" ");
Serial.print(rxMessage.Byte01);
Serial.print(" ");
Serial.print(rxMessage.Byte02);
Serial.print(" ");
Serial.print(rxMessage.Byte03);
Serial.print(" ");
Serial.print(rxMessage.Byte04);
Serial.print(" ");
Serial.print(rxMessage.Byte05);
Serial.println(" ");
}
vTaskDelay(100);
}
}
void taskBatteryMonitor(void *pvParameters) {
(void) pvParameters;
@ -182,7 +183,7 @@ void taskBatteryMonitor(void *pvParameters) {
for(;;) {
// Reading more to get precesions
battery.get_reading();
//battery.get_reading();
i++;
// DEBUG ONLY - TO BE REMOVED
@ -243,7 +244,7 @@ void taskBaro(void *pvParameters) {
for(;;) {
// Reading more to get precesions
// baro.get_reading();
baro.get_reading();
i++;

5
src/main.h

@ -30,6 +30,11 @@ const uint64_t pipeIn = 0xE8E8F0F0E1LL; // Must be same as the transmission
// Baro BMP280
#define BARO_CS 32
// HARDWARE VSPI - Baro BMP280
#define BMP_SCK (18) // SCL
#define BMP_MISO (19) // SD0
#define BMP_MOSI (23) // SDA
#define BMP_CS (32) // CSB
// Gyro ICM20602
#define GYRO_CS 2

Loading…
Cancel
Save