Update Payload_BME280_MPU6050_XS.ino cleanup to harmonize with Extended

pull/295/head
Alan Johnston 2 years ago committed by GitHub
parent 6b0ed941f2
commit c0a074acd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board // code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board
// works wih CubeSatSim software v1.3.2 or later // works wih CubeSatSim software v1.3.2 or later
// extra sensors can be added in payload_extension.cpp // extra sensors can be added in payload_extension.cpp file
#include <Wire.h> #include <Wire.h>
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
@ -13,7 +13,6 @@ UART Serial2(8, 9, 0, 0);
#include <EEPROM.h> #include <EEPROM.h>
#endif #endif
#define SEALEVELPRESSURE_HPA (1013.25) #define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; Adafruit_BME280 bme;
@ -31,10 +30,6 @@ void ee_prom_word_write(int addr, int val);
short ee_prom_word_read(int addr); short ee_prom_word_read(int addr);
int first_time = true; int first_time = true;
int first_read = true; int first_read = true;
bool check_for_wifi();
bool wifi = false;
int led_builtin_pin;
#define PICO_W // define if Pico W board. Otherwise, compilation fail for Pico or runtime fail if compile as Pico W
#if defined ARDUINO_ARCH_RP2040 #if defined ARDUINO_ARCH_RP2040
float T2 = 26.3; // Temperature data point 1 float T2 = 26.3; // Temperature data point 1
@ -70,17 +65,9 @@ extern void payload_loop(); // sensor extension read function defined in payloa
void setup() { void setup() {
#ifdef ARDUINO_ARCH_RP2040
// Serial1.setRX(1);
// delay(100);
// Serial1.setTX(0);
// delay(100);
#endif
Serial.begin(115200); // Serial Monitor for testing Serial.begin(115200); // Serial Monitor for testing
Serial1.begin(115200); // Pi UART faster spd Serial1.begin(115200); // for communication with Pi Zero
// Serial1.begin(9600); // Pi UART faster spd
delay(10000); delay(10000);
@ -91,9 +78,7 @@ void setup() {
Serial.println("Starting Serial2 for optional GPS on JP12"); Serial.println("Starting Serial2 for optional GPS on JP12");
// Serial2.begin(9600); // serial from - some modules need 115200 // Serial2.begin(9600); // serial from - some modules need 115200
Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200
// pinMode(0, INPUT);
// pinMode(1, INPUT);
// set all Pico GPIO connected pins to input // set all Pico GPIO connected pins to input
for (int i = 6; i < 22; i++) { for (int i = 6; i < 22; i++) {
@ -144,13 +129,10 @@ void setup() {
} }
else else
{ {
#ifdef ARDUINO_ARCH_RP2040
Serial.println("Calculating gyro offsets\n"); Serial.println("Calculating gyro offsets\n");
mpu6050.calcGyroOffsets(true); mpu6050.calcGyroOffsets(true);
#endif
#ifndef ARDUINO_ARCH_RP2040 #ifndef ARDUINO_ARCH_RP2040
Serial.println("Calculating gyro offsets and storing in EEPROM\n"); Serial.println("Storing gyro offsets in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07); eeprom_word_write(0, 0xA07);
eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5);
@ -330,7 +312,6 @@ void loop() {
// delay(1000); // not needed due to gps 1 second polling delay // delay(1000); // not needed due to gps 1 second polling delay
get_gps(); get_gps();
} }
void eeprom_word_write(int addr, int val) void eeprom_word_write(int addr, int val)
@ -365,23 +346,10 @@ void blink_setup()
#endif #endif
#if defined ARDUINO_ARCH_RP2040 #if defined ARDUINO_ARCH_RP2040
/* if (check_for_wifi()) {
wifi = true;
led_builtin_pin = LED_BUILTIN; // use default GPIO for Pico W
pinMode(LED_BUILTIN, OUTPUT);
// configure_wifi();
} else {
led_builtin_pin = 25; // manually set GPIO 25 for Pico board
// pinMode(25, OUTPUT);
*/
led_builtin_pin = LED_BUILTIN; // use default GPIO for Pico W
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
wifi = true; pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2
pinMode(18, OUTPUT); pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2
pinMode(19, OUTPUT);
// }
#endif #endif
} }
void blink(int length) void blink(int length)
@ -396,10 +364,7 @@ void blink(int length)
#endif #endif
#if defined ARDUINO_ARCH_RP2040 #if defined ARDUINO_ARCH_RP2040
if (wifi)
digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON
else
digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON
#endif #endif
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) #if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
@ -412,14 +377,8 @@ void blink(int length)
#endif #endif
#if defined ARDUINO_ARCH_RP2040 #if defined ARDUINO_ARCH_RP2040
if (wifi)
digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF
else
digitalWrite(led_builtin_pin, LOW); // set the built-in LED OFF
// delay(length); // wait for a lenth of time
#endif #endif
} }
void led_set(int ledPin, bool state) void led_set(int ledPin, bool state)
@ -459,38 +418,7 @@ int read_analog()
return(sensorValue); return(sensorValue);
} }
bool check_for_wifi() {
#ifndef PICO_W
Serial.println("WiFi disabled in software");
return(false); // skip check if not Pico W board or compilation will fail
#endif
pinMode(29, INPUT);
const float conversion_factor = 3.3f / (1 << 12);
uint16_t result = analogRead(29);
/*
// Serial.printf("ADC3 value: 0x%03x, voltage: %f V\n", result, result * conversion_factor);
Serial.print("ADC3 value and voltage: ");
Serial.print(result);
Serial.print(" ");
Serial.println(result * conversion_factor);
*/
if (result < 0x10) {
Serial.println("\nPico W detected!\n");
return(true);
}
else {
Serial.println("\nPico detected!\n");
return(false);
}
}
void get_gps() { void get_gps() {
//#ifndef ARDUINO_ARCH_RP2040
bool newData = false; bool newData = false;
unsigned long start = millis(); unsigned long start = millis();
@ -535,5 +463,4 @@ void get_gps() {
} else } else
// Serial.printf("GPS read no new data: %d\n", millis() - start); // Serial.printf("GPS read no new data: %d\n", millis() - start);
; ;
//#endif
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.