Skip to content

Commit

Permalink
updated data struct with new data and pin conf for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
memeb4082 committed Aug 8, 2024
1 parent efaf7c7 commit de26c71
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 49 deletions.
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ lib_deps =
sparkfun/SparkFun BMI270 Arduino Library@^1.0.2
dfrobot/DFRobot_QMC5883@^1.0.0
dfrobot/DFRobot_BMP3XX @ ^1.0.3
mikalhart/TinyGPSPlus@^1.1.0
[env:esp32]
platform = espressif32
board = esp32-s3-devkitm-1
framework = arduino
lib_deps =
sparkfun/SparkFun BMI270 Arduino Library@^1.0.2
dfrobot/DFRobot_QMC5883@^1.0.0
dfrobot/DFRobot_BMP3XX @ ^1.0.3
dfrobot/DFRobot_BMP3XX @ ^1.0.3
mikalhart/TinyGPSPlus@^1.1.0
122 changes: 74 additions & 48 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
#include "SparkFun_BMI270_Arduino_Library.h"
// #include "DFRobot_QMC5883.h"
#include "DFRobot_BMP3XX.h"
#include "TinyGPS++.h"
#include <HardwareSerial.h>

#define I2C_SDA 20
#define I2C_SCL 21
#define UART1_TX 1
#define UART1_RX 2
#define I2C1_SCL 4
#define I2C1_SDA 5
#define SPI1_MOSI 8
#define SPI1_MISO 9
#define SPI1_CLK 10
#define SPI1_CS 11
#define I2C2_SCL 12
#define I2C2_SDA 13
#define UART2_TX 17
#define UART2_RX 18

#define SerialUSB Serial2

// put function declarations here:
Expand All @@ -23,43 +35,52 @@
// RFD900_RADIO RX ---> 13

// TwoWire WireI2C(20, 21);
// TwoWire I2C = TwoWire(0/); /* create i2c instance */
// TwoWire I2C = TwoWire(0); /* create i2c instance */
// UART RFD900_RADIO(12, 13);
TinyGPSPlus gps;
HardwareSerial RFD900_RADIO(1);
HardwareSerial GPSSerial(2);
// DFRobot_QMC5883 compass(&WireI2C, /*I2C addr*/QMC5883_ADDRESS);
DFRobot_BMP388_I2C baro(&Wire, baro.eSDOGND);
BMI270 imu;
volatile float declinationAngle = (11.0 + (7.0 / 60.0)) / (180 / PI);
volatile float declinatimonAngle = (11.0 + (7.0 / 60.0)) / (180 / PI);
uint8_t bmiAddress = BMI2_I2C_PRIM_ADDR; // 0x68
//uint8_t bmiAddress = BMI2_I2C_SEC_ADDR; // 0x69
// uint8_t bmiAddress = BMI2_I2C_SEC_ADDR; // 0x69
uint8_t ledState = 0;
struct {
// float magX;
// float magY;
// float magZ;
float accX;
float accY;
float accZ;
float gyroX;
float gyroY;
float gyroZ;
float temp;
float press;
float alt;
struct
{
// float magX;
// float magY;
// float magZ;
float accX;
float accY;
float accZ;
float gyroX;
float gyroY;
float gyroZ;
float temp;
float press;
double alt;
double lat;
double lng;
uint32_t time;
} data_combined;



void setup() {
void setup()
{
// SETUP i2c and virtual serial port and RFD900_RADIO
Wire.setPins(I2C1_SDA, I2C1_SCL);
Wire.begin();
// WireI2C.setPins(I2C_SDA, I2C_SCL);
// WireI2C.begin(4,5);
// I2C.begin(I2C_SDA, I2C_SCL); /* initialise i2c bus with sda and scl, third arg clock freq tbd*/
SerialUSB.begin(9600);
RFD900_RADIO.begin(9600, 12, 13);
RFD900_RADIO.begin(9600, UART2_RX, UART2_TX);
pinMode(25, OUTPUT);

GPSSerial.begin(9600, UART1_RX, UART1_TX);

// SETUP QMC5883L on WireI2C

// while (!compass.begin())
// {
// SerialUSB.println("Could not find a valid 5883 sensor, check wiring!");
Expand All @@ -86,36 +107,33 @@ void setup() {
// SerialUSB.println(compass.getSamples());
// }



// setup BMI270 on WireI2C
while(imu.beginI2C(bmiAddress, Wire) != BMI2_OK)
{
// Not connected, inform user
SerialUSB.println("Error: BMI270 not connected, check wiring and I2C address!");
while (imu.beginI2C(bmiAddress, Wire) != BMI2_OK)
{
// Not connected, inform user
SerialUSB.println("Error: BMI270 not connected, check wiring and I2C address!");

// Wait a bit to see if connection is established
delay(1000);
// Wait a bit to see if connection is established
delay(1000);
}





// setup BMP390 on WireI2C
int rslt;
while( ERR_OK != (rslt = baro.begin()) )
while (ERR_OK != (rslt = baro.begin()))
{
if(ERR_DATA_BUS == rslt){
if (ERR_DATA_BUS == rslt)
{
SerialUSB.println("Data bus error!!!");
}else if(ERR_IC_VERSION == rslt){
}
else if (ERR_IC_VERSION == rslt)
{
SerialUSB.println("Chip versions do not match!!!");
}
delay(3000);
}
SerialUSB.println("Begin ok!");

while( !baro.setSamplingMode(baro.eUltraPrecision) )
while (!baro.setSamplingMode(baro.eUltraPrecision))
{
SerialUSB.println("Set samping mode fail, retrying....");
delay(3000);
Expand All @@ -133,15 +151,18 @@ void setup() {
SerialUSB.println(" Hz");

SerialUSB.println();





}

void loop() {
void loop()
{
ledState ^= 1;

/* GPS data */
while (GPSSerial.available() > 0)
{
gps.encode(GPSSerial.read());
}

// read MAG data
// compass.setDeclinationAngle(declinationAngle);
// sVector_t mag = compass.readRaw();
Expand All @@ -168,6 +189,12 @@ void loop() {
data_combined.gyroY = imu.data.gyroZ;
data_combined.gyroZ = -imu.data.gyroX;

// add gps data
data_combined.lat = gps.location.lat();
data_combined.lng = gps.location.lng();
data_combined.alt = gps.altitude.meters();
data_combined.time = gps.time.value();

// // print MAG data
// SerialUSB.print("MAG X: ");
// SerialUSB.print(mag.XAxis);
Expand Down Expand Up @@ -201,6 +228,5 @@ void loop() {
SerialUSB.print(data_combined.gyroZ, 3);
SerialUSB.print("\n");

RFD900_RADIO.write((uint8_t*)&data_combined, sizeof(data_combined));
RFD900_RADIO.write((uint8_t *)&data_combined, sizeof(data_combined));
}

0 comments on commit de26c71

Please sign in to comment.