From de37a97847acae1bb682dddc25dc1acda3b3de81 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:01:37 -0400 Subject: [PATCH 01/48] Create ayload_BME280_MPU6050_AIO.ino --- .../ayload_BME280_MPU6050_AIO.ino | 658 ++++++++++++++++++ 1 file changed, 658 insertions(+) create mode 100644 stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino diff --git a/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino b/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino new file mode 100644 index 00000000..748989b7 --- /dev/null +++ b/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino @@ -0,0 +1,658 @@ +// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board +// works wih CubeSatSim software v1.3.2 or later +// extra sensors can be added in payload_extension.cpp file + +#include +#include +#include +#include +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) +#include +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Arduino Mbed OS RP2040 Boards is used in Arduino IDE +#include +TinyGPSPlus gps; +UART Serial2(8, 9, 0, 0); + +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE +#include +TinyGPSPlus gps; +bool check_for_wifi(); +bool wifi = false; +int led_builtin_pin; + +#else // if Sparkfun Pro Micro or STM32 +#include +#endif + +#define SEALEVELPRESSURE_HPA (1013.25) + +Adafruit_BME280 bme; +MPU6050 mpu6050(Wire); + +long timer = 0; +int bmePresent; +int RXLED = 17; // The RX LED has a defined Arduino pin +int greenLED = 9; +int blueLED = 8; +int Sensor1 = 0; +float Sensor2 = 0; +float temp; +int calibration = 0; + +void ee_prom_word_write(int addr, int val); +short ee_prom_word_read(int addr); +int first_time = true; +int first_read = true; + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +float T2 = 24; // Temperature data point 1 +float R2 = 169; // Reading data point 1 +float T1 = 6; // Temperature data point 2 +float R1 = 181; // Reading data point 2 +#endif +#if defined __AVR_ATmega32U4__ +float T2 = 26.3; // Temperature data point 1 +float R2 = 167; // Reading data point 1 +float T1 = 2; // Temperature data point 2 +float R1 = 179; // Reading data point 2 +#endif +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) +float T2 = 25; // Temperature data point 1 +float R2 = 671; // Reading data point 1 +float T1 = 15.5; // Temperature data point 2 +float R1 = 695; // Reading data point 2 +#endif + +int sensorValue; +float Temp; +float rest; + +char sensor_end_flag[] = "_END_FLAG_"; +char sensor_start_flag[] = "_START_FLAG_"; +bool show_gps = true; // set to false to not see all messages +float flon = 0.0, flat = 0.0, flalt = 0.0; +void get_gps(); + +extern void payload_setup(); // sensor extension setup function defined in payload_extension.cpp +extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp + +void setup() { + + Serial.begin(115200); // Serial Monitor for testing + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial1.setRX(1); + delay(100); + Serial1.setTX(0); + delay(100); +#endif + + Serial1.begin(115200); // for communication with Pi Zero + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE + EEPROM.begin(512); +#endif + + delay(2000); + +#if defined (ARDUINO_ARCH_MBED_RP2040) && (ARDUINO_ARCH_RP2040) + Serial.println("Pico with Mbed"); +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial.println("Pico with RP2040"); +#elif defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + Serial.println("STM32"); +#elif defined __AVR_ATmega32U4__ + Serial.println("Pro Micro"); +#else + Serial.println("Unknown board"); +#endif + + Serial.println("Starting!"); + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.println("Starting Serial2 for optional GPS on JP12"); +// Serial2.begin(9600); // serial from - some modules need 115200 + Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200 + + // set all Pico GPIO connected pins to input + for (int i = 10; i < 22; i++) { + pinMode(i, INPUT); + } + pinMode(26, INPUT); + pinMode(27, INPUT); + pinMode(28, INPUT); + pinMode(15, INPUT_PULLUP); // squelch +#endif + + blink_setup(); + + blink(500); + delay(250); + blink(500); + delay(250); + led_set(greenLED, HIGH); + delay(250); + led_set(greenLED, LOW); + led_set(blueLED, HIGH); + delay(250); + led_set(blueLED, LOW); + + if (bme.begin(0x76)) { + bmePresent = 1; + } else { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + bmePresent = 0; + } + + mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1)) / 100.0; + float yOffset = ((float)eeprom_word_read(2)) / 100.0; + float zOffset = ((float)eeprom_word_read(3)) / 100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + + Serial.println("\nTemperature calibration data from EEPROM\n"); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + + } + else + { + Serial.println("Calculating gyro offsets\n"); + mpu6050.calcGyroOffsets(true); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + Serial.println("Storing gyro offsets in EEPROM\n"); + + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); + + Serial.println("\nStoring temperature calibration data in EEPROM\n"); + + eeprom_word_write(4, (int)(T1 * 10.0) + 0.5); + eeprom_word_write(5, (int) R1); + eeprom_word_write(6, (int)(T2 * 10.0) + 0.5); + eeprom_word_write(7, (int) R2); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif +#endif + } + payload_setup(); // sensor extension setup function defined in payload_extension.cpp +} + +void loop() { + + blink(50); + + if (Serial1.available() > 0) { + Serial.print("Received serial data!!!\n"); + delay(10); + while (Serial1.available() > 0) { + char result = Serial1.read(); + Serial.print(result); + } + Serial.println(" "); + } + { +// if (result == '?') + { + if (bmePresent) { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 "); + Serial1.print(bme.readTemperature()); + Serial1.print(" "); + Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(" "); + Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(" "); + Serial1.print(bme.readHumidity()); + + Serial.print("OK BME280 "); + temp = bme.readTemperature(); + Serial.print(temp); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.print(bme.readHumidity()); + } else + { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + } + mpu6050.update(); + + Serial1.print(" MPU6050 "); + Serial1.print(mpu6050.getGyroX()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroY()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" "); + Serial1.print(mpu6050.getAccX()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccY()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccZ()); + + Serial.print(" MPU6050 "); + Serial.print(mpu6050.getGyroX()); + Serial.print(" "); + Serial.print(mpu6050.getGyroY()); + Serial.print(" "); + Serial.print(mpu6050.getGyroZ()); + + Serial.print(" "); + Serial.print(mpu6050.getAccX()); + Serial.print(" "); + Serial.print(mpu6050.getAccY()); + Serial.print(" "); + Serial.print(mpu6050.getAccZ()); + + sensorValue = read_analog(); + +// Serial.println(sensorValue); + Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); + +// Serial1.print(" GPS 0 0 0 TMP "); + + Serial1.print(" GPS "); + Serial1.print(flat,4); + Serial1.print(" "); + Serial1.print(flon,4); + Serial1.print(" "); + Serial1.print(flalt,2); + + Serial1.print(" TMP "); + Serial1.print(Temp); + +// Serial1.print(" "); +// Serial1.println(Sensor2); + + Serial.print(" GPS "); + Serial.print(flat,4); + Serial.print(" "); + Serial.print(flon,4); + Serial.print(" "); + Serial.print(flalt,2); + +// Serial.print(" GPS 0 0 0 TMP "); + Serial.print(" TMP "); + Serial.print(Temp); +// Serial.print(" "); +// Serial.println(Sensor2); + + float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); +// Serial.print(rotation); +// Serial.print(" "); +// Serial.println(acceleration); + + if (first_read == true) { + first_read = false; + rest = acceleration; + } + + if (acceleration > 1.2 * rest) + led_set(greenLED, HIGH); + else + led_set(greenLED, LOW); + + if (rotation > 5) + led_set(blueLED, HIGH); + else + led_set(blueLED, LOW); + } + + payload_loop(); // sensor extension read function defined in payload_extension.cpp + +// Serial1.println(" "); + Serial1.println(sensor_end_flag); + Serial.println(" "); + + } + + if (Serial.available() > 0) { + blink(50); + char result = Serial.read(); +// Serial.println(result); +// Serial.println("OK"); +// Serial.println(counter++); +//#if !defined (ARDUINO_ARCH_RP2040) + if (result == 'R' || result == 'r') { +// Serial1.println("OK"); +// delay(100); + Serial.println("Resetting\n"); + first_read = true; + setup(); + } + else if (result == 'D' || result == 'd') { + Serial.println("\nCurrent temperature calibration data\n"); + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + + Serial.println("\nCurrent raw temperature reading\n"); + Serial.println(sensorValue, DEC); + Serial.println(" "); + } + else if (result == 'C' || result == 'c') { + Serial.println("\nClearing stored gyro offsets in EEPROM\n"); + eeprom_word_write(0, 0x00); +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + first_time = true; + setup(); + } + else if (result == 'S' || result == 's') { + Serial.print("\nStoring temperature calibration data point "); // in EEPROM\n"); + Serial.print(calibration + 1); + Serial.print(" in EEPROM\n"); + + Serial.println(temp); + Serial.println(sensorValue); + Serial.println(" "); + + eeprom_word_write(calibration * 2 + 4 , (int)(temp * 10.0) + 0.5); + eeprom_word_write(calibration * 2 + 5, sensorValue); + + if (calibration == 0) { + T1 = temp; + R1 = sensorValue; + calibration = 1; + } else { + T2 = temp; + R2 = sensorValue; + calibration = 0; + } + +// calibration = (calibration + 1) % 2; +// Serial.println(calibration + 1); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + + } +//#endif + } + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.print("Squelch: "); + Serial.println(digitalRead(15)); + + get_gps(); +#else + delay(1000); // not needed due to gps 1 second polling delay + +#endif +} + +void eeprom_word_write(int addr, int val) +{ +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); +#endif +} + +short eeprom_word_read(int addr) +{ + int result = 0; +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + result = ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +#endif + return result; +} + +void blink_setup() +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + // initialize digital pin PB1 as an output. + pinMode(PC13, OUTPUT); + pinMode(PB9, OUTPUT); + pinMode(PB8, OUTPUT); +#endif + +#if defined __AVR_ATmega32U4__ + pinMode(RXLED, OUTPUT); // Set RX LED as an output + // TX LED is set as an output behind the scenes + pinMode(greenLED, OUTPUT); + pinMode(blueLED,OUTPUT); +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + pinMode(LED_BUILTIN, OUTPUT); + pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2 + pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2 +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && 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); + pinMode(led_builtin_pin, OUTPUT); + } + pinMode(18, OUTPUT); + pinMode(19, OUTPUT); +#endif +} + +void blink(int length) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, LOW); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON +#endif + +delay(length); + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, HIGH); // set the RX LED OFF + TXLED0; //TX LED macro to turn LED ON +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, LOW); // set the built-in LED ON +#endif +} + +void led_set(int ledPin, bool state) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + if (ledPin == greenLED) + digitalWrite(PB9, state); + else if (ledPin == blueLED) + digitalWrite(PB8, state); +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(ledPin, state); +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + if (ledPin == greenLED) + digitalWrite(19, state); + else if (ledPin == blueLED) + digitalWrite(18, state); +#endif +} + +int read_analog() +{ + int sensorValue; + #if defined __AVR_ATmega32U4__ + sensorValue = analogRead(A3); +#endif + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + sensorValue = analogRead(PA7); +#endif +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + sensorValue = analogRead(28); +#endif + return(sensorValue); +} + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) +bool check_for_wifi() { + + 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); + + if (result < 0x10) { + Serial.println("\nPico W detected!\n"); + return(true); + } + else { + Serial.println("\nPico detected!\n"); + return(false); + } +} +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +void get_gps() { +// Serial.println("Getting GPS data"); + bool newData = false; + unsigned long start = millis(); + +// for (unsigned long start = millis(); millis() - start < 1000;) // 5000;) + while ((millis() - start) < 1000) // 5000;) + { + while (Serial2.available()) + { + char c = Serial2.read(); + if (show_gps) + Serial.write(c); // uncomment this line if you want to see the GPS data flowing + if (gps.encode(c)) // Did a new valid sentence come in? + newData = true; + } + } + if (newData) { + Serial.print("GPS read new data in ms: "); + Serial.println(millis() - start); + +// float flon = 0.0, flat = 0.0, flalt = 0.0; +// unsigned long age; +// starting = millis(); +// gps.f_get_position(&flat, &flon, &age); + + Serial.print(F("Location: ")); + if (gps.location.isValid()) + { + Serial.print(gps.location.lat(), 6); + Serial.print(F(",")); + Serial.print(gps.location.lng(), 6); + + flat = gps.location.lat(); + flon = gps.location.lng(); + flalt = gps.altitude.meters(); + } + else + { + Serial.print(F("INVALID")); + } + Serial.print("\r\n"); + + } else +// Serial.printf("GPS read no new data: %d\n", millis() - start); + ; +} +#endif From e2680042f2fa6f563d8ef82115ab3b358724756e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:02:36 -0400 Subject: [PATCH 02/48] Create payload_extension.cpp --- .../payload_extension.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp diff --git a/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp b/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp new file mode 100644 index 00000000..b88dd680 --- /dev/null +++ b/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp @@ -0,0 +1,71 @@ +// Use this template for adding additional sensors + +// put your library includes here +#include "Adafruit_SI1145.h" +#include + +// put your globals here +Adafruit_SI1145 uv = Adafruit_SI1145(); +Adafruit_LIS3MDL lis3mdl; + +int uvPresent; +int magPresent; + +float magRaw = 0; +float magRawAbs = 0; + +// put your setup code here +void payload_setup() { + + Serial.println("Starting Si1145 sensor!"); + + if (! uv.begin()) { + Serial.println("Si1145 sensor fault"); + uvPresent = 0; + } else { + uvPresent = 1; + } + + Serial.println("Starting LIS3MDL sensor!"); + + if (! lis3mdl.begin_I2C()) { + Serial.println("LIS3MDL sensor fault"); + magPresent = 0; + } else { + magPresent = 1; + } +} + +// put your loop code here +// Very Important: only use print, not println!! +void payload_loop() { + + if (uvPresent) { + Serial1.print(" SI "); // chose a 2-3 letter hint for your sensor + Serial1.print(uv.readVisible()); // Serial1 sends the sensor data to the Pi Zero for transmission + Serial1.print(" "); + Serial1.print(uv.readIR()); + + Serial.print(" SI "); + Serial.print(uv.readVisible()); // Serial sends the sensor data to the Serial Monitor for debugging + Serial.print(" "); + Serial.print(uv.readIR()); + } else { + Serial1.print(" SI 0.0 0.0"); + Serial.print(" SI 0.0 0.0"); + } + if (magPresent) { + lis3mdl.read(); + magRaw = (((lis3mdl.x + lis3mdl.y + lis3mdl.z) / 3)); + magRawAbs = abs(magRaw); + + Serial1.print(" LI "); + Serial1.print(magRawAbs); + + Serial1.print(" LI "); + Serial.print(magRawAbs); + } else { + Serial1.print(" LI 0.0"); + Serial.print(" LI 0.0"); + } +} From 2faa6ba4abd12798d4cdc604c92c457a44f38a04 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:03:54 -0400 Subject: [PATCH 03/48] Create Payload_BME280_MPU6050_AIO.ino --- .../Payload_BME280_MPU6050_AIO.ino | 658 ++++++++++++++++++ 1 file changed, 658 insertions(+) create mode 100644 stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino diff --git a/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino new file mode 100644 index 00000000..748989b7 --- /dev/null +++ b/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -0,0 +1,658 @@ +// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board +// works wih CubeSatSim software v1.3.2 or later +// extra sensors can be added in payload_extension.cpp file + +#include +#include +#include +#include +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) +#include +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Arduino Mbed OS RP2040 Boards is used in Arduino IDE +#include +TinyGPSPlus gps; +UART Serial2(8, 9, 0, 0); + +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE +#include +TinyGPSPlus gps; +bool check_for_wifi(); +bool wifi = false; +int led_builtin_pin; + +#else // if Sparkfun Pro Micro or STM32 +#include +#endif + +#define SEALEVELPRESSURE_HPA (1013.25) + +Adafruit_BME280 bme; +MPU6050 mpu6050(Wire); + +long timer = 0; +int bmePresent; +int RXLED = 17; // The RX LED has a defined Arduino pin +int greenLED = 9; +int blueLED = 8; +int Sensor1 = 0; +float Sensor2 = 0; +float temp; +int calibration = 0; + +void ee_prom_word_write(int addr, int val); +short ee_prom_word_read(int addr); +int first_time = true; +int first_read = true; + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +float T2 = 24; // Temperature data point 1 +float R2 = 169; // Reading data point 1 +float T1 = 6; // Temperature data point 2 +float R1 = 181; // Reading data point 2 +#endif +#if defined __AVR_ATmega32U4__ +float T2 = 26.3; // Temperature data point 1 +float R2 = 167; // Reading data point 1 +float T1 = 2; // Temperature data point 2 +float R1 = 179; // Reading data point 2 +#endif +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) +float T2 = 25; // Temperature data point 1 +float R2 = 671; // Reading data point 1 +float T1 = 15.5; // Temperature data point 2 +float R1 = 695; // Reading data point 2 +#endif + +int sensorValue; +float Temp; +float rest; + +char sensor_end_flag[] = "_END_FLAG_"; +char sensor_start_flag[] = "_START_FLAG_"; +bool show_gps = true; // set to false to not see all messages +float flon = 0.0, flat = 0.0, flalt = 0.0; +void get_gps(); + +extern void payload_setup(); // sensor extension setup function defined in payload_extension.cpp +extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp + +void setup() { + + Serial.begin(115200); // Serial Monitor for testing + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial1.setRX(1); + delay(100); + Serial1.setTX(0); + delay(100); +#endif + + Serial1.begin(115200); // for communication with Pi Zero + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE + EEPROM.begin(512); +#endif + + delay(2000); + +#if defined (ARDUINO_ARCH_MBED_RP2040) && (ARDUINO_ARCH_RP2040) + Serial.println("Pico with Mbed"); +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial.println("Pico with RP2040"); +#elif defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + Serial.println("STM32"); +#elif defined __AVR_ATmega32U4__ + Serial.println("Pro Micro"); +#else + Serial.println("Unknown board"); +#endif + + Serial.println("Starting!"); + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.println("Starting Serial2 for optional GPS on JP12"); +// Serial2.begin(9600); // serial from - some modules need 115200 + Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200 + + // set all Pico GPIO connected pins to input + for (int i = 10; i < 22; i++) { + pinMode(i, INPUT); + } + pinMode(26, INPUT); + pinMode(27, INPUT); + pinMode(28, INPUT); + pinMode(15, INPUT_PULLUP); // squelch +#endif + + blink_setup(); + + blink(500); + delay(250); + blink(500); + delay(250); + led_set(greenLED, HIGH); + delay(250); + led_set(greenLED, LOW); + led_set(blueLED, HIGH); + delay(250); + led_set(blueLED, LOW); + + if (bme.begin(0x76)) { + bmePresent = 1; + } else { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + bmePresent = 0; + } + + mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1)) / 100.0; + float yOffset = ((float)eeprom_word_read(2)) / 100.0; + float zOffset = ((float)eeprom_word_read(3)) / 100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + + Serial.println("\nTemperature calibration data from EEPROM\n"); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + + } + else + { + Serial.println("Calculating gyro offsets\n"); + mpu6050.calcGyroOffsets(true); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + Serial.println("Storing gyro offsets in EEPROM\n"); + + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); + + Serial.println("\nStoring temperature calibration data in EEPROM\n"); + + eeprom_word_write(4, (int)(T1 * 10.0) + 0.5); + eeprom_word_write(5, (int) R1); + eeprom_word_write(6, (int)(T2 * 10.0) + 0.5); + eeprom_word_write(7, (int) R2); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif +#endif + } + payload_setup(); // sensor extension setup function defined in payload_extension.cpp +} + +void loop() { + + blink(50); + + if (Serial1.available() > 0) { + Serial.print("Received serial data!!!\n"); + delay(10); + while (Serial1.available() > 0) { + char result = Serial1.read(); + Serial.print(result); + } + Serial.println(" "); + } + { +// if (result == '?') + { + if (bmePresent) { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 "); + Serial1.print(bme.readTemperature()); + Serial1.print(" "); + Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(" "); + Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(" "); + Serial1.print(bme.readHumidity()); + + Serial.print("OK BME280 "); + temp = bme.readTemperature(); + Serial.print(temp); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.print(bme.readHumidity()); + } else + { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + } + mpu6050.update(); + + Serial1.print(" MPU6050 "); + Serial1.print(mpu6050.getGyroX()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroY()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" "); + Serial1.print(mpu6050.getAccX()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccY()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccZ()); + + Serial.print(" MPU6050 "); + Serial.print(mpu6050.getGyroX()); + Serial.print(" "); + Serial.print(mpu6050.getGyroY()); + Serial.print(" "); + Serial.print(mpu6050.getGyroZ()); + + Serial.print(" "); + Serial.print(mpu6050.getAccX()); + Serial.print(" "); + Serial.print(mpu6050.getAccY()); + Serial.print(" "); + Serial.print(mpu6050.getAccZ()); + + sensorValue = read_analog(); + +// Serial.println(sensorValue); + Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); + +// Serial1.print(" GPS 0 0 0 TMP "); + + Serial1.print(" GPS "); + Serial1.print(flat,4); + Serial1.print(" "); + Serial1.print(flon,4); + Serial1.print(" "); + Serial1.print(flalt,2); + + Serial1.print(" TMP "); + Serial1.print(Temp); + +// Serial1.print(" "); +// Serial1.println(Sensor2); + + Serial.print(" GPS "); + Serial.print(flat,4); + Serial.print(" "); + Serial.print(flon,4); + Serial.print(" "); + Serial.print(flalt,2); + +// Serial.print(" GPS 0 0 0 TMP "); + Serial.print(" TMP "); + Serial.print(Temp); +// Serial.print(" "); +// Serial.println(Sensor2); + + float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); +// Serial.print(rotation); +// Serial.print(" "); +// Serial.println(acceleration); + + if (first_read == true) { + first_read = false; + rest = acceleration; + } + + if (acceleration > 1.2 * rest) + led_set(greenLED, HIGH); + else + led_set(greenLED, LOW); + + if (rotation > 5) + led_set(blueLED, HIGH); + else + led_set(blueLED, LOW); + } + + payload_loop(); // sensor extension read function defined in payload_extension.cpp + +// Serial1.println(" "); + Serial1.println(sensor_end_flag); + Serial.println(" "); + + } + + if (Serial.available() > 0) { + blink(50); + char result = Serial.read(); +// Serial.println(result); +// Serial.println("OK"); +// Serial.println(counter++); +//#if !defined (ARDUINO_ARCH_RP2040) + if (result == 'R' || result == 'r') { +// Serial1.println("OK"); +// delay(100); + Serial.println("Resetting\n"); + first_read = true; + setup(); + } + else if (result == 'D' || result == 'd') { + Serial.println("\nCurrent temperature calibration data\n"); + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + + Serial.println("\nCurrent raw temperature reading\n"); + Serial.println(sensorValue, DEC); + Serial.println(" "); + } + else if (result == 'C' || result == 'c') { + Serial.println("\nClearing stored gyro offsets in EEPROM\n"); + eeprom_word_write(0, 0x00); +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + first_time = true; + setup(); + } + else if (result == 'S' || result == 's') { + Serial.print("\nStoring temperature calibration data point "); // in EEPROM\n"); + Serial.print(calibration + 1); + Serial.print(" in EEPROM\n"); + + Serial.println(temp); + Serial.println(sensorValue); + Serial.println(" "); + + eeprom_word_write(calibration * 2 + 4 , (int)(temp * 10.0) + 0.5); + eeprom_word_write(calibration * 2 + 5, sensorValue); + + if (calibration == 0) { + T1 = temp; + R1 = sensorValue; + calibration = 1; + } else { + T2 = temp; + R2 = sensorValue; + calibration = 0; + } + +// calibration = (calibration + 1) % 2; +// Serial.println(calibration + 1); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + + } +//#endif + } + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.print("Squelch: "); + Serial.println(digitalRead(15)); + + get_gps(); +#else + delay(1000); // not needed due to gps 1 second polling delay + +#endif +} + +void eeprom_word_write(int addr, int val) +{ +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); +#endif +} + +short eeprom_word_read(int addr) +{ + int result = 0; +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + result = ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +#endif + return result; +} + +void blink_setup() +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + // initialize digital pin PB1 as an output. + pinMode(PC13, OUTPUT); + pinMode(PB9, OUTPUT); + pinMode(PB8, OUTPUT); +#endif + +#if defined __AVR_ATmega32U4__ + pinMode(RXLED, OUTPUT); // Set RX LED as an output + // TX LED is set as an output behind the scenes + pinMode(greenLED, OUTPUT); + pinMode(blueLED,OUTPUT); +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + pinMode(LED_BUILTIN, OUTPUT); + pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2 + pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2 +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && 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); + pinMode(led_builtin_pin, OUTPUT); + } + pinMode(18, OUTPUT); + pinMode(19, OUTPUT); +#endif +} + +void blink(int length) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, LOW); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON +#endif + +delay(length); + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, HIGH); // set the RX LED OFF + TXLED0; //TX LED macro to turn LED ON +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, LOW); // set the built-in LED ON +#endif +} + +void led_set(int ledPin, bool state) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + if (ledPin == greenLED) + digitalWrite(PB9, state); + else if (ledPin == blueLED) + digitalWrite(PB8, state); +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(ledPin, state); +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + if (ledPin == greenLED) + digitalWrite(19, state); + else if (ledPin == blueLED) + digitalWrite(18, state); +#endif +} + +int read_analog() +{ + int sensorValue; + #if defined __AVR_ATmega32U4__ + sensorValue = analogRead(A3); +#endif + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + sensorValue = analogRead(PA7); +#endif +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + sensorValue = analogRead(28); +#endif + return(sensorValue); +} + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) +bool check_for_wifi() { + + 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); + + if (result < 0x10) { + Serial.println("\nPico W detected!\n"); + return(true); + } + else { + Serial.println("\nPico detected!\n"); + return(false); + } +} +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +void get_gps() { +// Serial.println("Getting GPS data"); + bool newData = false; + unsigned long start = millis(); + +// for (unsigned long start = millis(); millis() - start < 1000;) // 5000;) + while ((millis() - start) < 1000) // 5000;) + { + while (Serial2.available()) + { + char c = Serial2.read(); + if (show_gps) + Serial.write(c); // uncomment this line if you want to see the GPS data flowing + if (gps.encode(c)) // Did a new valid sentence come in? + newData = true; + } + } + if (newData) { + Serial.print("GPS read new data in ms: "); + Serial.println(millis() - start); + +// float flon = 0.0, flat = 0.0, flalt = 0.0; +// unsigned long age; +// starting = millis(); +// gps.f_get_position(&flat, &flon, &age); + + Serial.print(F("Location: ")); + if (gps.location.isValid()) + { + Serial.print(gps.location.lat(), 6); + Serial.print(F(",")); + Serial.print(gps.location.lng(), 6); + + flat = gps.location.lat(); + flon = gps.location.lng(); + flalt = gps.altitude.meters(); + } + else + { + Serial.print(F("INVALID")); + } + Serial.print("\r\n"); + + } else +// Serial.printf("GPS read no new data: %d\n", millis() - start); + ; +} +#endif From b7469b666c889fd08e3709df1cc03876373dd656 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:04:23 -0400 Subject: [PATCH 04/48] Delete stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino --- .../ayload_BME280_MPU6050_AIO.ino | 658 ------------------ 1 file changed, 658 deletions(-) delete mode 100644 stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino diff --git a/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino b/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino deleted file mode 100644 index 748989b7..00000000 --- a/stempayload/ayload_BME280_MPU6050_AIO/ayload_BME280_MPU6050_AIO.ino +++ /dev/null @@ -1,658 +0,0 @@ -// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board -// works wih CubeSatSim software v1.3.2 or later -// extra sensors can be added in payload_extension.cpp file - -#include -#include -#include -#include -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) -#include -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Arduino Mbed OS RP2040 Boards is used in Arduino IDE -#include -TinyGPSPlus gps; -UART Serial2(8, 9, 0, 0); - -#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE -#include -TinyGPSPlus gps; -bool check_for_wifi(); -bool wifi = false; -int led_builtin_pin; - -#else // if Sparkfun Pro Micro or STM32 -#include -#endif - -#define SEALEVELPRESSURE_HPA (1013.25) - -Adafruit_BME280 bme; -MPU6050 mpu6050(Wire); - -long timer = 0; -int bmePresent; -int RXLED = 17; // The RX LED has a defined Arduino pin -int greenLED = 9; -int blueLED = 8; -int Sensor1 = 0; -float Sensor2 = 0; -float temp; -int calibration = 0; - -void ee_prom_word_write(int addr, int val); -short ee_prom_word_read(int addr); -int first_time = true; -int first_read = true; - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) -float T2 = 24; // Temperature data point 1 -float R2 = 169; // Reading data point 1 -float T1 = 6; // Temperature data point 2 -float R1 = 181; // Reading data point 2 -#endif -#if defined __AVR_ATmega32U4__ -float T2 = 26.3; // Temperature data point 1 -float R2 = 167; // Reading data point 1 -float T1 = 2; // Temperature data point 2 -float R1 = 179; // Reading data point 2 -#endif -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) -float T2 = 25; // Temperature data point 1 -float R2 = 671; // Reading data point 1 -float T1 = 15.5; // Temperature data point 2 -float R1 = 695; // Reading data point 2 -#endif - -int sensorValue; -float Temp; -float rest; - -char sensor_end_flag[] = "_END_FLAG_"; -char sensor_start_flag[] = "_START_FLAG_"; -bool show_gps = true; // set to false to not see all messages -float flon = 0.0, flat = 0.0, flalt = 0.0; -void get_gps(); - -extern void payload_setup(); // sensor extension setup function defined in payload_extension.cpp -extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp - -void setup() { - - Serial.begin(115200); // Serial Monitor for testing - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - Serial1.setRX(1); - delay(100); - Serial1.setTX(0); - delay(100); -#endif - - Serial1.begin(115200); // for communication with Pi Zero - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE - EEPROM.begin(512); -#endif - - delay(2000); - -#if defined (ARDUINO_ARCH_MBED_RP2040) && (ARDUINO_ARCH_RP2040) - Serial.println("Pico with Mbed"); -#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - Serial.println("Pico with RP2040"); -#elif defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - Serial.println("STM32"); -#elif defined __AVR_ATmega32U4__ - Serial.println("Pro Micro"); -#else - Serial.println("Unknown board"); -#endif - - Serial.println("Starting!"); - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - Serial.println("Starting Serial2 for optional GPS on JP12"); -// Serial2.begin(9600); // serial from - some modules need 115200 - Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200 - - // set all Pico GPIO connected pins to input - for (int i = 10; i < 22; i++) { - pinMode(i, INPUT); - } - pinMode(26, INPUT); - pinMode(27, INPUT); - pinMode(28, INPUT); - pinMode(15, INPUT_PULLUP); // squelch -#endif - - blink_setup(); - - blink(500); - delay(250); - blink(500); - delay(250); - led_set(greenLED, HIGH); - delay(250); - led_set(greenLED, LOW); - led_set(blueLED, HIGH); - delay(250); - led_set(blueLED, LOW); - - if (bme.begin(0x76)) { - bmePresent = 1; - } else { - Serial.println("Could not find a valid BME280 sensor, check wiring!"); - bmePresent = 0; - } - - mpu6050.begin(); - - if (eeprom_word_read(0) == 0xA07) - { - Serial.println("Reading gyro offsets from EEPROM\n"); - - float xOffset = ((float)eeprom_word_read(1)) / 100.0; - float yOffset = ((float)eeprom_word_read(2)) / 100.0; - float zOffset = ((float)eeprom_word_read(3)) / 100.0; - - Serial.println(xOffset, DEC); - Serial.println(yOffset, DEC); - Serial.println(zOffset, DEC); - - mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); - - Serial.println("\nTemperature calibration data from EEPROM\n"); - - T1 = ((float)eeprom_word_read(4)) / 10.0; - R1 = ((float)eeprom_word_read(5)); - T2 = ((float)eeprom_word_read(6)) / 10.0; - R2 = ((float)eeprom_word_read(7)); - - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - Serial.println(" "); - - } - else - { - Serial.println("Calculating gyro offsets\n"); - mpu6050.calcGyroOffsets(true); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - Serial.println("Storing gyro offsets in EEPROM\n"); - - eeprom_word_write(0, 0xA07); - eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); - eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); - eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); - - Serial.println(eeprom_word_read(0), HEX); - Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); - Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); - Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); - - Serial.println("\nStoring temperature calibration data in EEPROM\n"); - - eeprom_word_write(4, (int)(T1 * 10.0) + 0.5); - eeprom_word_write(5, (int) R1); - eeprom_word_write(6, (int)(T2 * 10.0) + 0.5); - eeprom_word_write(7, (int) R2); - - T1 = ((float)eeprom_word_read(4)) / 10.0; - R1 = ((float)eeprom_word_read(5)); - T2 = ((float)eeprom_word_read(6)) / 10.0; - R2 = ((float)eeprom_word_read(7)); - - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - Serial.println(" "); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif -#endif - } - payload_setup(); // sensor extension setup function defined in payload_extension.cpp -} - -void loop() { - - blink(50); - - if (Serial1.available() > 0) { - Serial.print("Received serial data!!!\n"); - delay(10); - while (Serial1.available() > 0) { - char result = Serial1.read(); - Serial.print(result); - } - Serial.println(" "); - } - { -// if (result == '?') - { - if (bmePresent) { - Serial1.print(sensor_start_flag); - Serial1.print("OK BME280 "); - Serial1.print(bme.readTemperature()); - Serial1.print(" "); - Serial1.print(bme.readPressure() / 100.0F); - Serial1.print(" "); - Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); - Serial1.print(" "); - Serial1.print(bme.readHumidity()); - - Serial.print("OK BME280 "); - temp = bme.readTemperature(); - Serial.print(temp); - Serial.print(" "); - Serial.print(bme.readPressure() / 100.0F); - Serial.print(" "); - Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); - Serial.print(" "); - Serial.print(bme.readHumidity()); - } else - { - Serial1.print(sensor_start_flag); - Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); - - Serial.print("OK BME280 0.0 0.0 0.0 0.0"); - } - mpu6050.update(); - - Serial1.print(" MPU6050 "); - Serial1.print(mpu6050.getGyroX()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroY()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroZ()); - - Serial1.print(" "); - Serial1.print(mpu6050.getAccX()); - Serial1.print(" "); - Serial1.print(mpu6050.getAccY()); - Serial1.print(" "); - Serial1.print(mpu6050.getAccZ()); - - Serial.print(" MPU6050 "); - Serial.print(mpu6050.getGyroX()); - Serial.print(" "); - Serial.print(mpu6050.getGyroY()); - Serial.print(" "); - Serial.print(mpu6050.getGyroZ()); - - Serial.print(" "); - Serial.print(mpu6050.getAccX()); - Serial.print(" "); - Serial.print(mpu6050.getAccY()); - Serial.print(" "); - Serial.print(mpu6050.getAccZ()); - - sensorValue = read_analog(); - -// Serial.println(sensorValue); - Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); - -// Serial1.print(" GPS 0 0 0 TMP "); - - Serial1.print(" GPS "); - Serial1.print(flat,4); - Serial1.print(" "); - Serial1.print(flon,4); - Serial1.print(" "); - Serial1.print(flalt,2); - - Serial1.print(" TMP "); - Serial1.print(Temp); - -// Serial1.print(" "); -// Serial1.println(Sensor2); - - Serial.print(" GPS "); - Serial.print(flat,4); - Serial.print(" "); - Serial.print(flon,4); - Serial.print(" "); - Serial.print(flalt,2); - -// Serial.print(" GPS 0 0 0 TMP "); - Serial.print(" TMP "); - Serial.print(Temp); -// Serial.print(" "); -// Serial.println(Sensor2); - - float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); - float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); -// Serial.print(rotation); -// Serial.print(" "); -// Serial.println(acceleration); - - if (first_read == true) { - first_read = false; - rest = acceleration; - } - - if (acceleration > 1.2 * rest) - led_set(greenLED, HIGH); - else - led_set(greenLED, LOW); - - if (rotation > 5) - led_set(blueLED, HIGH); - else - led_set(blueLED, LOW); - } - - payload_loop(); // sensor extension read function defined in payload_extension.cpp - -// Serial1.println(" "); - Serial1.println(sensor_end_flag); - Serial.println(" "); - - } - - if (Serial.available() > 0) { - blink(50); - char result = Serial.read(); -// Serial.println(result); -// Serial.println("OK"); -// Serial.println(counter++); -//#if !defined (ARDUINO_ARCH_RP2040) - if (result == 'R' || result == 'r') { -// Serial1.println("OK"); -// delay(100); - Serial.println("Resetting\n"); - first_read = true; - setup(); - } - else if (result == 'D' || result == 'd') { - Serial.println("\nCurrent temperature calibration data\n"); - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - - Serial.println("\nCurrent raw temperature reading\n"); - Serial.println(sensorValue, DEC); - Serial.println(" "); - } - else if (result == 'C' || result == 'c') { - Serial.println("\nClearing stored gyro offsets in EEPROM\n"); - eeprom_word_write(0, 0x00); -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif - first_time = true; - setup(); - } - else if (result == 'S' || result == 's') { - Serial.print("\nStoring temperature calibration data point "); // in EEPROM\n"); - Serial.print(calibration + 1); - Serial.print(" in EEPROM\n"); - - Serial.println(temp); - Serial.println(sensorValue); - Serial.println(" "); - - eeprom_word_write(calibration * 2 + 4 , (int)(temp * 10.0) + 0.5); - eeprom_word_write(calibration * 2 + 5, sensorValue); - - if (calibration == 0) { - T1 = temp; - R1 = sensorValue; - calibration = 1; - } else { - T2 = temp; - R2 = sensorValue; - calibration = 0; - } - -// calibration = (calibration + 1) % 2; -// Serial.println(calibration + 1); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif - - } -//#endif - } - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - Serial.print("Squelch: "); - Serial.println(digitalRead(15)); - - get_gps(); -#else - delay(1000); // not needed due to gps 1 second polling delay - -#endif -} - -void eeprom_word_write(int addr, int val) -{ -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - EEPROM.write(addr * 2, lowByte(val)); - EEPROM.write(addr * 2 + 1, highByte(val)); -#endif -} - -short eeprom_word_read(int addr) -{ - int result = 0; -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - result = ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); -#endif - return result; -} - -void blink_setup() -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - // initialize digital pin PB1 as an output. - pinMode(PC13, OUTPUT); - pinMode(PB9, OUTPUT); - pinMode(PB8, OUTPUT); -#endif - -#if defined __AVR_ATmega32U4__ - pinMode(RXLED, OUTPUT); // Set RX LED as an output - // TX LED is set as an output behind the scenes - pinMode(greenLED, OUTPUT); - pinMode(blueLED,OUTPUT); -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - pinMode(LED_BUILTIN, OUTPUT); - pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2 - pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2 -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && 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); - pinMode(led_builtin_pin, OUTPUT); - } - pinMode(18, OUTPUT); - pinMode(19, OUTPUT); -#endif -} - -void blink(int length) -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(RXLED, LOW); // set the RX LED ON - TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - if (wifi) - digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON - else - digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON -#endif - -delay(length); - -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(RXLED, HIGH); // set the RX LED OFF - TXLED0; //TX LED macro to turn LED ON -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - if (wifi) - digitalWrite(LED_BUILTIN, LOW); // set the built-in LED ON - else - digitalWrite(led_builtin_pin, LOW); // set the built-in LED ON -#endif -} - -void led_set(int ledPin, bool state) -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - if (ledPin == greenLED) - digitalWrite(PB9, state); - else if (ledPin == blueLED) - digitalWrite(PB8, state); -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(ledPin, state); -#endif - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - if (ledPin == greenLED) - digitalWrite(19, state); - else if (ledPin == blueLED) - digitalWrite(18, state); -#endif -} - -int read_analog() -{ - int sensorValue; - #if defined __AVR_ATmega32U4__ - sensorValue = analogRead(A3); -#endif - -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - sensorValue = analogRead(PA7); -#endif -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - sensorValue = analogRead(28); -#endif - return(sensorValue); -} - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) -bool check_for_wifi() { - - 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); - - if (result < 0x10) { - Serial.println("\nPico W detected!\n"); - return(true); - } - else { - Serial.println("\nPico detected!\n"); - return(false); - } -} -#endif - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) -void get_gps() { -// Serial.println("Getting GPS data"); - bool newData = false; - unsigned long start = millis(); - -// for (unsigned long start = millis(); millis() - start < 1000;) // 5000;) - while ((millis() - start) < 1000) // 5000;) - { - while (Serial2.available()) - { - char c = Serial2.read(); - if (show_gps) - Serial.write(c); // uncomment this line if you want to see the GPS data flowing - if (gps.encode(c)) // Did a new valid sentence come in? - newData = true; - } - } - if (newData) { - Serial.print("GPS read new data in ms: "); - Serial.println(millis() - start); - -// float flon = 0.0, flat = 0.0, flalt = 0.0; -// unsigned long age; -// starting = millis(); -// gps.f_get_position(&flat, &flon, &age); - - Serial.print(F("Location: ")); - if (gps.location.isValid()) - { - Serial.print(gps.location.lat(), 6); - Serial.print(F(",")); - Serial.print(gps.location.lng(), 6); - - flat = gps.location.lat(); - flon = gps.location.lng(); - flalt = gps.altitude.meters(); - } - else - { - Serial.print(F("INVALID")); - } - Serial.print("\r\n"); - - } else -// Serial.printf("GPS read no new data: %d\n", millis() - start); - ; -} -#endif From 93a9218b0361feafcea2e53f8c10ab2c5f0fda66 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:05:07 -0400 Subject: [PATCH 05/48] Delete stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino --- .../Payload_BME280_MPU6050_AIO.ino | 658 ------------------ 1 file changed, 658 deletions(-) delete mode 100644 stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino diff --git a/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino deleted file mode 100644 index 748989b7..00000000 --- a/stempayload/ayload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ /dev/null @@ -1,658 +0,0 @@ -// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board -// works wih CubeSatSim software v1.3.2 or later -// extra sensors can be added in payload_extension.cpp file - -#include -#include -#include -#include -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) -#include -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Arduino Mbed OS RP2040 Boards is used in Arduino IDE -#include -TinyGPSPlus gps; -UART Serial2(8, 9, 0, 0); - -#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE -#include -TinyGPSPlus gps; -bool check_for_wifi(); -bool wifi = false; -int led_builtin_pin; - -#else // if Sparkfun Pro Micro or STM32 -#include -#endif - -#define SEALEVELPRESSURE_HPA (1013.25) - -Adafruit_BME280 bme; -MPU6050 mpu6050(Wire); - -long timer = 0; -int bmePresent; -int RXLED = 17; // The RX LED has a defined Arduino pin -int greenLED = 9; -int blueLED = 8; -int Sensor1 = 0; -float Sensor2 = 0; -float temp; -int calibration = 0; - -void ee_prom_word_write(int addr, int val); -short ee_prom_word_read(int addr); -int first_time = true; -int first_read = true; - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) -float T2 = 24; // Temperature data point 1 -float R2 = 169; // Reading data point 1 -float T1 = 6; // Temperature data point 2 -float R1 = 181; // Reading data point 2 -#endif -#if defined __AVR_ATmega32U4__ -float T2 = 26.3; // Temperature data point 1 -float R2 = 167; // Reading data point 1 -float T1 = 2; // Temperature data point 2 -float R1 = 179; // Reading data point 2 -#endif -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) -float T2 = 25; // Temperature data point 1 -float R2 = 671; // Reading data point 1 -float T1 = 15.5; // Temperature data point 2 -float R1 = 695; // Reading data point 2 -#endif - -int sensorValue; -float Temp; -float rest; - -char sensor_end_flag[] = "_END_FLAG_"; -char sensor_start_flag[] = "_START_FLAG_"; -bool show_gps = true; // set to false to not see all messages -float flon = 0.0, flat = 0.0, flalt = 0.0; -void get_gps(); - -extern void payload_setup(); // sensor extension setup function defined in payload_extension.cpp -extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp - -void setup() { - - Serial.begin(115200); // Serial Monitor for testing - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - Serial1.setRX(1); - delay(100); - Serial1.setTX(0); - delay(100); -#endif - - Serial1.begin(115200); // for communication with Pi Zero - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE - EEPROM.begin(512); -#endif - - delay(2000); - -#if defined (ARDUINO_ARCH_MBED_RP2040) && (ARDUINO_ARCH_RP2040) - Serial.println("Pico with Mbed"); -#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - Serial.println("Pico with RP2040"); -#elif defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - Serial.println("STM32"); -#elif defined __AVR_ATmega32U4__ - Serial.println("Pro Micro"); -#else - Serial.println("Unknown board"); -#endif - - Serial.println("Starting!"); - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - Serial.println("Starting Serial2 for optional GPS on JP12"); -// Serial2.begin(9600); // serial from - some modules need 115200 - Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200 - - // set all Pico GPIO connected pins to input - for (int i = 10; i < 22; i++) { - pinMode(i, INPUT); - } - pinMode(26, INPUT); - pinMode(27, INPUT); - pinMode(28, INPUT); - pinMode(15, INPUT_PULLUP); // squelch -#endif - - blink_setup(); - - blink(500); - delay(250); - blink(500); - delay(250); - led_set(greenLED, HIGH); - delay(250); - led_set(greenLED, LOW); - led_set(blueLED, HIGH); - delay(250); - led_set(blueLED, LOW); - - if (bme.begin(0x76)) { - bmePresent = 1; - } else { - Serial.println("Could not find a valid BME280 sensor, check wiring!"); - bmePresent = 0; - } - - mpu6050.begin(); - - if (eeprom_word_read(0) == 0xA07) - { - Serial.println("Reading gyro offsets from EEPROM\n"); - - float xOffset = ((float)eeprom_word_read(1)) / 100.0; - float yOffset = ((float)eeprom_word_read(2)) / 100.0; - float zOffset = ((float)eeprom_word_read(3)) / 100.0; - - Serial.println(xOffset, DEC); - Serial.println(yOffset, DEC); - Serial.println(zOffset, DEC); - - mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); - - Serial.println("\nTemperature calibration data from EEPROM\n"); - - T1 = ((float)eeprom_word_read(4)) / 10.0; - R1 = ((float)eeprom_word_read(5)); - T2 = ((float)eeprom_word_read(6)) / 10.0; - R2 = ((float)eeprom_word_read(7)); - - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - Serial.println(" "); - - } - else - { - Serial.println("Calculating gyro offsets\n"); - mpu6050.calcGyroOffsets(true); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - Serial.println("Storing gyro offsets in EEPROM\n"); - - eeprom_word_write(0, 0xA07); - eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); - eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); - eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); - - Serial.println(eeprom_word_read(0), HEX); - Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); - Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); - Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); - - Serial.println("\nStoring temperature calibration data in EEPROM\n"); - - eeprom_word_write(4, (int)(T1 * 10.0) + 0.5); - eeprom_word_write(5, (int) R1); - eeprom_word_write(6, (int)(T2 * 10.0) + 0.5); - eeprom_word_write(7, (int) R2); - - T1 = ((float)eeprom_word_read(4)) / 10.0; - R1 = ((float)eeprom_word_read(5)); - T2 = ((float)eeprom_word_read(6)) / 10.0; - R2 = ((float)eeprom_word_read(7)); - - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - Serial.println(" "); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif -#endif - } - payload_setup(); // sensor extension setup function defined in payload_extension.cpp -} - -void loop() { - - blink(50); - - if (Serial1.available() > 0) { - Serial.print("Received serial data!!!\n"); - delay(10); - while (Serial1.available() > 0) { - char result = Serial1.read(); - Serial.print(result); - } - Serial.println(" "); - } - { -// if (result == '?') - { - if (bmePresent) { - Serial1.print(sensor_start_flag); - Serial1.print("OK BME280 "); - Serial1.print(bme.readTemperature()); - Serial1.print(" "); - Serial1.print(bme.readPressure() / 100.0F); - Serial1.print(" "); - Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); - Serial1.print(" "); - Serial1.print(bme.readHumidity()); - - Serial.print("OK BME280 "); - temp = bme.readTemperature(); - Serial.print(temp); - Serial.print(" "); - Serial.print(bme.readPressure() / 100.0F); - Serial.print(" "); - Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); - Serial.print(" "); - Serial.print(bme.readHumidity()); - } else - { - Serial1.print(sensor_start_flag); - Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); - - Serial.print("OK BME280 0.0 0.0 0.0 0.0"); - } - mpu6050.update(); - - Serial1.print(" MPU6050 "); - Serial1.print(mpu6050.getGyroX()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroY()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroZ()); - - Serial1.print(" "); - Serial1.print(mpu6050.getAccX()); - Serial1.print(" "); - Serial1.print(mpu6050.getAccY()); - Serial1.print(" "); - Serial1.print(mpu6050.getAccZ()); - - Serial.print(" MPU6050 "); - Serial.print(mpu6050.getGyroX()); - Serial.print(" "); - Serial.print(mpu6050.getGyroY()); - Serial.print(" "); - Serial.print(mpu6050.getGyroZ()); - - Serial.print(" "); - Serial.print(mpu6050.getAccX()); - Serial.print(" "); - Serial.print(mpu6050.getAccY()); - Serial.print(" "); - Serial.print(mpu6050.getAccZ()); - - sensorValue = read_analog(); - -// Serial.println(sensorValue); - Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); - -// Serial1.print(" GPS 0 0 0 TMP "); - - Serial1.print(" GPS "); - Serial1.print(flat,4); - Serial1.print(" "); - Serial1.print(flon,4); - Serial1.print(" "); - Serial1.print(flalt,2); - - Serial1.print(" TMP "); - Serial1.print(Temp); - -// Serial1.print(" "); -// Serial1.println(Sensor2); - - Serial.print(" GPS "); - Serial.print(flat,4); - Serial.print(" "); - Serial.print(flon,4); - Serial.print(" "); - Serial.print(flalt,2); - -// Serial.print(" GPS 0 0 0 TMP "); - Serial.print(" TMP "); - Serial.print(Temp); -// Serial.print(" "); -// Serial.println(Sensor2); - - float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); - float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); -// Serial.print(rotation); -// Serial.print(" "); -// Serial.println(acceleration); - - if (first_read == true) { - first_read = false; - rest = acceleration; - } - - if (acceleration > 1.2 * rest) - led_set(greenLED, HIGH); - else - led_set(greenLED, LOW); - - if (rotation > 5) - led_set(blueLED, HIGH); - else - led_set(blueLED, LOW); - } - - payload_loop(); // sensor extension read function defined in payload_extension.cpp - -// Serial1.println(" "); - Serial1.println(sensor_end_flag); - Serial.println(" "); - - } - - if (Serial.available() > 0) { - blink(50); - char result = Serial.read(); -// Serial.println(result); -// Serial.println("OK"); -// Serial.println(counter++); -//#if !defined (ARDUINO_ARCH_RP2040) - if (result == 'R' || result == 'r') { -// Serial1.println("OK"); -// delay(100); - Serial.println("Resetting\n"); - first_read = true; - setup(); - } - else if (result == 'D' || result == 'd') { - Serial.println("\nCurrent temperature calibration data\n"); - Serial.println(T1, DEC); - Serial.println(R1, DEC); - Serial.println(" "); - Serial.println(T2, DEC); - Serial.println(R2, DEC); - - Serial.println("\nCurrent raw temperature reading\n"); - Serial.println(sensorValue, DEC); - Serial.println(" "); - } - else if (result == 'C' || result == 'c') { - Serial.println("\nClearing stored gyro offsets in EEPROM\n"); - eeprom_word_write(0, 0x00); -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif - first_time = true; - setup(); - } - else if (result == 'S' || result == 's') { - Serial.print("\nStoring temperature calibration data point "); // in EEPROM\n"); - Serial.print(calibration + 1); - Serial.print(" in EEPROM\n"); - - Serial.println(temp); - Serial.println(sensorValue); - Serial.println(" "); - - eeprom_word_write(calibration * 2 + 4 , (int)(temp * 10.0) + 0.5); - eeprom_word_write(calibration * 2 + 5, sensorValue); - - if (calibration == 0) { - T1 = temp; - R1 = sensorValue; - calibration = 1; - } else { - T2 = temp; - R2 = sensorValue; - calibration = 0; - } - -// calibration = (calibration + 1) % 2; -// Serial.println(calibration + 1); - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - - if (EEPROM.commit()) { - Serial.println("EEPROM successfully committed\n"); - } else { - Serial.println("ERROR! EEPROM commit failed\n"); - } -#endif - - } -//#endif - } - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - Serial.print("Squelch: "); - Serial.println(digitalRead(15)); - - get_gps(); -#else - delay(1000); // not needed due to gps 1 second polling delay - -#endif -} - -void eeprom_word_write(int addr, int val) -{ -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - EEPROM.write(addr * 2, lowByte(val)); - EEPROM.write(addr * 2 + 1, highByte(val)); -#endif -} - -short eeprom_word_read(int addr) -{ - int result = 0; -#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE - result = ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); -#endif - return result; -} - -void blink_setup() -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - // initialize digital pin PB1 as an output. - pinMode(PC13, OUTPUT); - pinMode(PB9, OUTPUT); - pinMode(PB8, OUTPUT); -#endif - -#if defined __AVR_ATmega32U4__ - pinMode(RXLED, OUTPUT); // Set RX LED as an output - // TX LED is set as an output behind the scenes - pinMode(greenLED, OUTPUT); - pinMode(blueLED,OUTPUT); -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - pinMode(LED_BUILTIN, OUTPUT); - pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2 - pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2 -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && 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); - pinMode(led_builtin_pin, OUTPUT); - } - pinMode(18, OUTPUT); - pinMode(19, OUTPUT); -#endif -} - -void blink(int length) -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(RXLED, LOW); // set the RX LED ON - TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - if (wifi) - digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON - else - digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON -#endif - -delay(length); - -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(RXLED, HIGH); // set the RX LED OFF - TXLED0; //TX LED macro to turn LED ON -#endif - -#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF -#endif - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) - if (wifi) - digitalWrite(LED_BUILTIN, LOW); // set the built-in LED ON - else - digitalWrite(led_builtin_pin, LOW); // set the built-in LED ON -#endif -} - -void led_set(int ledPin, bool state) -{ -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - if (ledPin == greenLED) - digitalWrite(PB9, state); - else if (ledPin == blueLED) - digitalWrite(PB8, state); -#endif - -#if defined __AVR_ATmega32U4__ - digitalWrite(ledPin, state); -#endif - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - if (ledPin == greenLED) - digitalWrite(19, state); - else if (ledPin == blueLED) - digitalWrite(18, state); -#endif -} - -int read_analog() -{ - int sensorValue; - #if defined __AVR_ATmega32U4__ - sensorValue = analogRead(A3); -#endif - -#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) - sensorValue = analogRead(PA7); -#endif -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) - sensorValue = analogRead(28); -#endif - return(sensorValue); -} - -#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) -bool check_for_wifi() { - - 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); - - if (result < 0x10) { - Serial.println("\nPico W detected!\n"); - return(true); - } - else { - Serial.println("\nPico detected!\n"); - return(false); - } -} -#endif - -#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) -void get_gps() { -// Serial.println("Getting GPS data"); - bool newData = false; - unsigned long start = millis(); - -// for (unsigned long start = millis(); millis() - start < 1000;) // 5000;) - while ((millis() - start) < 1000) // 5000;) - { - while (Serial2.available()) - { - char c = Serial2.read(); - if (show_gps) - Serial.write(c); // uncomment this line if you want to see the GPS data flowing - if (gps.encode(c)) // Did a new valid sentence come in? - newData = true; - } - } - if (newData) { - Serial.print("GPS read new data in ms: "); - Serial.println(millis() - start); - -// float flon = 0.0, flat = 0.0, flalt = 0.0; -// unsigned long age; -// starting = millis(); -// gps.f_get_position(&flat, &flon, &age); - - Serial.print(F("Location: ")); - if (gps.location.isValid()) - { - Serial.print(gps.location.lat(), 6); - Serial.print(F(",")); - Serial.print(gps.location.lng(), 6); - - flat = gps.location.lat(); - flon = gps.location.lng(); - flalt = gps.altitude.meters(); - } - else - { - Serial.print(F("INVALID")); - } - Serial.print("\r\n"); - - } else -// Serial.printf("GPS read no new data: %d\n", millis() - start); - ; -} -#endif From f58c964927d5dda6418ee1e81aeb70f308f96077 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:05:19 -0400 Subject: [PATCH 06/48] Delete stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp --- .../payload_extension.cpp | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp diff --git a/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp b/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp deleted file mode 100644 index b88dd680..00000000 --- a/stempayload/ayload_BME280_MPU6050_AIO/payload_extension.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Use this template for adding additional sensors - -// put your library includes here -#include "Adafruit_SI1145.h" -#include - -// put your globals here -Adafruit_SI1145 uv = Adafruit_SI1145(); -Adafruit_LIS3MDL lis3mdl; - -int uvPresent; -int magPresent; - -float magRaw = 0; -float magRawAbs = 0; - -// put your setup code here -void payload_setup() { - - Serial.println("Starting Si1145 sensor!"); - - if (! uv.begin()) { - Serial.println("Si1145 sensor fault"); - uvPresent = 0; - } else { - uvPresent = 1; - } - - Serial.println("Starting LIS3MDL sensor!"); - - if (! lis3mdl.begin_I2C()) { - Serial.println("LIS3MDL sensor fault"); - magPresent = 0; - } else { - magPresent = 1; - } -} - -// put your loop code here -// Very Important: only use print, not println!! -void payload_loop() { - - if (uvPresent) { - Serial1.print(" SI "); // chose a 2-3 letter hint for your sensor - Serial1.print(uv.readVisible()); // Serial1 sends the sensor data to the Pi Zero for transmission - Serial1.print(" "); - Serial1.print(uv.readIR()); - - Serial.print(" SI "); - Serial.print(uv.readVisible()); // Serial sends the sensor data to the Serial Monitor for debugging - Serial.print(" "); - Serial.print(uv.readIR()); - } else { - Serial1.print(" SI 0.0 0.0"); - Serial.print(" SI 0.0 0.0"); - } - if (magPresent) { - lis3mdl.read(); - magRaw = (((lis3mdl.x + lis3mdl.y + lis3mdl.z) / 3)); - magRawAbs = abs(magRaw); - - Serial1.print(" LI "); - Serial1.print(magRawAbs); - - Serial1.print(" LI "); - Serial.print(magRawAbs); - } else { - Serial1.print(" LI 0.0"); - Serial.print(" LI 0.0"); - } -} From de1429f26e7bfc6f3ac47b285c5a574f15d5612c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:16:24 -0400 Subject: [PATCH 07/48] Create Payload_BME280_MPU6050_AIO.ino --- .../Payload_BME280_MPU6050_AIO.ino | 664 ++++++++++++++++++ 1 file changed, 664 insertions(+) create mode 100644 stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino new file mode 100644 index 00000000..808039d1 --- /dev/null +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -0,0 +1,664 @@ +// code for Pico or Pro Micro or STM32 on the CubeSat Simulator STEM Payload board +// works wih CubeSatSim software v1.3.2 or later +// extra sensors can be added in payload_extension.cpp file + +#include +#include +#include +#include +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) +#include +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Arduino Mbed OS RP2040 Boards is used in Arduino IDE +#include +TinyGPSPlus gps; +UART Serial2(8, 9, 0, 0); + +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE +#include +TinyGPSPlus gps; +bool check_for_wifi(); +bool wifi = false; +int led_builtin_pin; + +#else // if Sparkfun Pro Micro or STM32 +#include +#endif + +#define SEALEVELPRESSURE_HPA (1013.25) + +Adafruit_BME280 bme; +MPU6050 mpu6050(Wire); + +long timer = 0; +int bmePresent; +int RXLED = 17; // The RX LED has a defined Arduino pin +int greenLED = 9; +int blueLED = 8; +int Sensor1 = 0; +float Sensor2 = 0; +float temp; +int calibration = 0; + +void ee_prom_word_write(int addr, int val); +short ee_prom_word_read(int addr); +int first_time = true; +int first_read = true; + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +float T2 = 24; // Temperature data point 1 +float R2 = 169; // Reading data point 1 +float T1 = 6; // Temperature data point 2 +float R1 = 181; // Reading data point 2 +#endif +#if defined __AVR_ATmega32U4__ +float T2 = 26.3; // Temperature data point 1 +float R2 = 167; // Reading data point 1 +float T1 = 2; // Temperature data point 2 +float R1 = 179; // Reading data point 2 +#endif +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) +float T2 = 25; // Temperature data point 1 +float R2 = 671; // Reading data point 1 +float T1 = 15.5; // Temperature data point 2 +float R1 = 695; // Reading data point 2 +#endif + +int sensorValue; +float Temp; +float rest; + +char sensor_end_flag[] = "_END_FLAG_"; +char sensor_start_flag[] = "_START_FLAG_"; +bool show_gps = true; // set to false to not see all messages +float flon = 0.0, flat = 0.0, flalt = 0.0; +void get_gps(); + +extern void payload_setup(); // sensor extension setup function defined in payload_extension.cpp +extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp + +extern void aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp +extern void aio_loop(); // Adafruit IO loop code defined in adafruitio_00_publish.cpp + +void setup() { + + Serial.begin(115200); // Serial Monitor for testing + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial1.setRX(1); + delay(100); + Serial1.setTX(0); + delay(100); +#endif + + Serial1.begin(115200); // for communication with Pi Zero + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards in Arduino IDE + EEPROM.begin(512); +#endif + + delay(2000); + +#if defined (ARDUINO_ARCH_MBED_RP2040) && (ARDUINO_ARCH_RP2040) + Serial.println("Pico with Mbed"); +#elif !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + Serial.println("Pico with RP2040"); +#elif defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + Serial.println("STM32"); +#elif defined __AVR_ATmega32U4__ + Serial.println("Pro Micro"); +#else + Serial.println("Unknown board"); +#endif + + Serial.println("Starting!"); + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.println("Starting Serial2 for optional GPS on JP12"); +// Serial2.begin(9600); // serial from - some modules need 115200 + Serial2.begin(9600); // serial from GPS or other serial sensor. Some GPS need 115200 + + // set all Pico GPIO connected pins to input + for (int i = 10; i < 22; i++) { + pinMode(i, INPUT); + } + pinMode(26, INPUT); + pinMode(27, INPUT); + pinMode(28, INPUT); + pinMode(15, INPUT_PULLUP); // squelch +#endif + + blink_setup(); + + blink(500); + delay(250); + blink(500); + delay(250); + led_set(greenLED, HIGH); + delay(250); + led_set(greenLED, LOW); + led_set(blueLED, HIGH); + delay(250); + led_set(blueLED, LOW); + + if (bme.begin(0x76)) { + bmePresent = 1; + } else { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + bmePresent = 0; + } + + mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1)) / 100.0; + float yOffset = ((float)eeprom_word_read(2)) / 100.0; + float zOffset = ((float)eeprom_word_read(3)) / 100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + + Serial.println("\nTemperature calibration data from EEPROM\n"); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + + } + else + { + Serial.println("Calculating gyro offsets\n"); + mpu6050.calcGyroOffsets(true); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + Serial.println("Storing gyro offsets in EEPROM\n"); + + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); + + Serial.println("\nStoring temperature calibration data in EEPROM\n"); + + eeprom_word_write(4, (int)(T1 * 10.0) + 0.5); + eeprom_word_write(5, (int) R1); + eeprom_word_write(6, (int)(T2 * 10.0) + 0.5); + eeprom_word_write(7, (int) R2); + + T1 = ((float)eeprom_word_read(4)) / 10.0; + R1 = ((float)eeprom_word_read(5)); + T2 = ((float)eeprom_word_read(6)) / 10.0; + R2 = ((float)eeprom_word_read(7)); + + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + Serial.println(" "); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif +#endif + } + payload_setup(); // sensor extension setup function defined in payload_extension.cpp + aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp + +} + +void loop() { + + blink(50); + + if (Serial1.available() > 0) { + Serial.print("Received serial data!!!\n"); + delay(10); + while (Serial1.available() > 0) { + char result = Serial1.read(); + Serial.print(result); + } + Serial.println(" "); + } + { +// if (result == '?') + { + if (bmePresent) { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 "); + Serial1.print(bme.readTemperature()); + Serial1.print(" "); + Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(" "); + Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(" "); + Serial1.print(bme.readHumidity()); + + Serial.print("OK BME280 "); + temp = bme.readTemperature(); + Serial.print(temp); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.print(bme.readHumidity()); + } else + { + Serial1.print(sensor_start_flag); + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + } + mpu6050.update(); + + Serial1.print(" MPU6050 "); + Serial1.print(mpu6050.getGyroX()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroY()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" "); + Serial1.print(mpu6050.getAccX()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccY()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccZ()); + + Serial.print(" MPU6050 "); + Serial.print(mpu6050.getGyroX()); + Serial.print(" "); + Serial.print(mpu6050.getGyroY()); + Serial.print(" "); + Serial.print(mpu6050.getGyroZ()); + + Serial.print(" "); + Serial.print(mpu6050.getAccX()); + Serial.print(" "); + Serial.print(mpu6050.getAccY()); + Serial.print(" "); + Serial.print(mpu6050.getAccZ()); + + sensorValue = read_analog(); + +// Serial.println(sensorValue); + Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1)); + +// Serial1.print(" GPS 0 0 0 TMP "); + + Serial1.print(" GPS "); + Serial1.print(flat,4); + Serial1.print(" "); + Serial1.print(flon,4); + Serial1.print(" "); + Serial1.print(flalt,2); + + Serial1.print(" TMP "); + Serial1.print(Temp); + +// Serial1.print(" "); +// Serial1.println(Sensor2); + + Serial.print(" GPS "); + Serial.print(flat,4); + Serial.print(" "); + Serial.print(flon,4); + Serial.print(" "); + Serial.print(flalt,2); + +// Serial.print(" GPS 0 0 0 TMP "); + Serial.print(" TMP "); + Serial.print(Temp); +// Serial.print(" "); +// Serial.println(Sensor2); + + float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); +// Serial.print(rotation); +// Serial.print(" "); +// Serial.println(acceleration); + + if (first_read == true) { + first_read = false; + rest = acceleration; + } + + if (acceleration > 1.2 * rest) + led_set(greenLED, HIGH); + else + led_set(greenLED, LOW); + + if (rotation > 5) + led_set(blueLED, HIGH); + else + led_set(blueLED, LOW); + } + + payload_loop(); // sensor extension read function defined in payload_extension.cpp + aio_loop(); // Adafruit IO loop code defined in adafruitio_00_publish.cpp + +// Serial1.println(" "); + Serial1.println(sensor_end_flag); + Serial.println(" "); + + } + + if (Serial.available() > 0) { + blink(50); + char result = Serial.read(); +// Serial.println(result); +// Serial.println("OK"); +// Serial.println(counter++); +//#if !defined (ARDUINO_ARCH_RP2040) + if (result == 'R' || result == 'r') { +// Serial1.println("OK"); +// delay(100); + Serial.println("Resetting\n"); + first_read = true; + setup(); + } + else if (result == 'D' || result == 'd') { + Serial.println("\nCurrent temperature calibration data\n"); + Serial.println(T1, DEC); + Serial.println(R1, DEC); + Serial.println(" "); + Serial.println(T2, DEC); + Serial.println(R2, DEC); + + Serial.println("\nCurrent raw temperature reading\n"); + Serial.println(sensorValue, DEC); + Serial.println(" "); + } + else if (result == 'C' || result == 'c') { + Serial.println("\nClearing stored gyro offsets in EEPROM\n"); + eeprom_word_write(0, 0x00); +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + first_time = true; + setup(); + } + else if (result == 'S' || result == 's') { + Serial.print("\nStoring temperature calibration data point "); // in EEPROM\n"); + Serial.print(calibration + 1); + Serial.print(" in EEPROM\n"); + + Serial.println(temp); + Serial.println(sensorValue); + Serial.println(" "); + + eeprom_word_write(calibration * 2 + 4 , (int)(temp * 10.0) + 0.5); + eeprom_word_write(calibration * 2 + 5, sensorValue); + + if (calibration == 0) { + T1 = temp; + R1 = sensorValue; + calibration = 1; + } else { + T2 = temp; + R2 = sensorValue; + calibration = 0; + } + +// calibration = (calibration + 1) % 2; +// Serial.println(calibration + 1); + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + + if (EEPROM.commit()) { + Serial.println("EEPROM successfully committed\n"); + } else { + Serial.println("ERROR! EEPROM commit failed\n"); + } +#endif + + } +//#endif + } + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + Serial.print("Squelch: "); + Serial.println(digitalRead(15)); + + get_gps(); +#else + delay(1000); // not needed due to gps 1 second polling delay + +#endif +} + +void eeprom_word_write(int addr, int val) +{ +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); +#endif +} + +short eeprom_word_read(int addr) +{ + int result = 0; +#if !defined(ARDUINO_ARCH_MBED_RP2040) // && defined(ARDUINO_ARCH_RP2040) // if Raspberry Pi RP2040 Boards is used in Arduino IDE + result = ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +#endif + return result; +} + +void blink_setup() +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + // initialize digital pin PB1 as an output. + pinMode(PC13, OUTPUT); + pinMode(PB9, OUTPUT); + pinMode(PB8, OUTPUT); +#endif + +#if defined __AVR_ATmega32U4__ + pinMode(RXLED, OUTPUT); // Set RX LED as an output + // TX LED is set as an output behind the scenes + pinMode(greenLED, OUTPUT); + pinMode(blueLED,OUTPUT); +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + pinMode(LED_BUILTIN, OUTPUT); + pinMode(18, OUTPUT); // blue LED on STEM Payload Board v1.3.2 + pinMode(19, OUTPUT); // green LED on STEM Payload Board v1.3.2 +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && 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); + pinMode(led_builtin_pin, OUTPUT); + } + pinMode(18, OUTPUT); + pinMode(19, OUTPUT); +#endif +} + +void blink(int length) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, LOW); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, HIGH); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, HIGH); // set the built-in LED ON +#endif + +delay(length); + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, HIGH); // set the RX LED OFF + TXLED0; //TX LED macro to turn LED ON +#endif + +#if defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED OFF +#endif + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) + if (wifi) + digitalWrite(LED_BUILTIN, LOW); // set the built-in LED ON + else + digitalWrite(led_builtin_pin, LOW); // set the built-in LED ON +#endif +} + +void led_set(int ledPin, bool state) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + if (ledPin == greenLED) + digitalWrite(PB9, state); + else if (ledPin == blueLED) + digitalWrite(PB8, state); +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(ledPin, state); +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + if (ledPin == greenLED) + digitalWrite(19, state); + else if (ledPin == blueLED) + digitalWrite(18, state); +#endif +} + +int read_analog() +{ + int sensorValue; + #if defined __AVR_ATmega32U4__ + sensorValue = analogRead(A3); +#endif + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + sensorValue = analogRead(PA7); +#endif +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) + sensorValue = analogRead(28); +#endif + return(sensorValue); +} + +#if !defined(ARDUINO_ARCH_MBED_RP2040) && defined(ARDUINO_ARCH_RP2040) +bool check_for_wifi() { + + 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); + + if (result < 0x10) { + Serial.println("\nPico W detected!\n"); + return(true); + } + else { + Serial.println("\nPico detected!\n"); + return(false); + } +} +#endif + +#if defined (ARDUINO_ARCH_MBED_RP2040) || (ARDUINO_ARCH_RP2040) +void get_gps() { +// Serial.println("Getting GPS data"); + bool newData = false; + unsigned long start = millis(); + +// for (unsigned long start = millis(); millis() - start < 1000;) // 5000;) + while ((millis() - start) < 1000) // 5000;) + { + while (Serial2.available()) + { + char c = Serial2.read(); + if (show_gps) + Serial.write(c); // uncomment this line if you want to see the GPS data flowing + if (gps.encode(c)) // Did a new valid sentence come in? + newData = true; + } + } + if (newData) { + Serial.print("GPS read new data in ms: "); + Serial.println(millis() - start); + +// float flon = 0.0, flat = 0.0, flalt = 0.0; +// unsigned long age; +// starting = millis(); +// gps.f_get_position(&flat, &flon, &age); + + Serial.print(F("Location: ")); + if (gps.location.isValid()) + { + Serial.print(gps.location.lat(), 6); + Serial.print(F(",")); + Serial.print(gps.location.lng(), 6); + + flat = gps.location.lat(); + flon = gps.location.lng(); + flalt = gps.altitude.meters(); + } + else + { + Serial.print(F("INVALID")); + } + Serial.print("\r\n"); + + } else +// Serial.printf("GPS read no new data: %d\n", millis() - start); + ; +} +#endif From 7759b6379b35058a20888affd1420b761fdaf5a5 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:17:19 -0400 Subject: [PATCH 08/48] Create payload_extension.cpp --- .../payload_extension.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 stempayload/Payload_BME280_MPU6050_AIO/payload_extension.cpp diff --git a/stempayload/Payload_BME280_MPU6050_AIO/payload_extension.cpp b/stempayload/Payload_BME280_MPU6050_AIO/payload_extension.cpp new file mode 100644 index 00000000..5b8dd2ec --- /dev/null +++ b/stempayload/Payload_BME280_MPU6050_AIO/payload_extension.cpp @@ -0,0 +1,25 @@ +// Use this template for adding additional sensors +// see Payload_BME280_MPU6050_XS_Extended for an example + +// put your library includes here +#include "Arduino.h" + +// put your globals here + +// put your setup code here +void payload_setup() { + +// Serial.println("Starting new sensor!"); + +} + +// put your loop code here +// Very Important: only use print, not println!! +void payload_loop() { + +/* + Serial1.print(" NEW 0.0"); // send sensor data over serial to Pi Zero + Serial.print(" NEW 0.0"); // send sensor data over serial monitor for testing +*/ + +} From aa579e0be8e982123bd9c0714e11802bef318997 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:19:59 -0400 Subject: [PATCH 09/48] Create adafruitio_00_publish_modified.cpp --- .../adafruitio_00_publish_modified.cpp | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp new file mode 100644 index 00000000..9ac33dce --- /dev/null +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -0,0 +1,78 @@ +// Mods to this file by Alan B Johnston KU2Y +// +// changed setup to aio_setup and loop to aio_loop +// +// Adafruit IO Publish Example +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Todd Treece for Adafruit Industries +// Copyright (c) 2016 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/************************ Example Starts Here *******************************/ + +// this int will hold the current count for our sketch +int count = 0; + +// set up the 'counter' feed +AdafruitIO_Feed *counter = io.feed("counter"); + +void aio_setup() { + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + Serial.print("Connecting to Adafruit IO"); + + // connect to io.adafruit.com + io.connect(); + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); + +} + +void aio_loop() { + + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + + // save count to the 'counter' feed on Adafruit IO + Serial.print("sending -> "); + Serial.println(count); + counter->save(count); + + // increment the count by 1 + count++; + + // Adafruit IO is rate limited for publishing, so a delay is required in + // between feed->save events. In this example, we will wait three seconds + // (1000 milliseconds == 1 second) during each loop. + delay(3000); + +} From 9d23d19ef45cf5ce5aa0b61b796d63b7c59c9ed7 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:29:31 -0400 Subject: [PATCH 10/48] Update Payload_BME280_MPU6050_AIO.ino added tlm array --- .../Payload_BME280_MPU6050_AIO.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 808039d1..704d47ff 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -21,6 +21,7 @@ TinyGPSPlus gps; bool check_for_wifi(); bool wifi = false; int led_builtin_pin; +float tlm[20]; #else // if Sparkfun Pro Micro or STM32 #include @@ -79,7 +80,7 @@ extern void payload_setup(); // sensor extension setup function defined in payl extern void payload_loop(); // sensor extension read function defined in payload_extension.cpp extern void aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp -extern void aio_loop(); // Adafruit IO loop code defined in adafruitio_00_publish.cpp +extern void aio_loop(float telem[]); // Adafruit IO loop code defined in adafruitio_00_publish.cpp void setup() { @@ -228,7 +229,10 @@ void setup() { } payload_setup(); // sensor extension setup function defined in payload_extension.cpp aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp - + + for (int i = 0; i++; i < 20) + tlm[i] = 0.0; + tlm[0] = 23.1; } void loop() { @@ -360,7 +364,7 @@ void loop() { } payload_loop(); // sensor extension read function defined in payload_extension.cpp - aio_loop(); // Adafruit IO loop code defined in adafruitio_00_publish.cpp + aio_loop(tlm); // Adafruit IO loop code defined in adafruitio_00_publish.cpp // Serial1.println(" "); Serial1.println(sensor_end_flag); From 52a1fe24415bd03aaff3b09bb1359ec88edb6e60 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:31:34 -0400 Subject: [PATCH 11/48] Update adafruitio_00_publish_modified.cpp add tlm --- .../adafruitio_00_publish_modified.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 9ac33dce..35dbc7fc 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -54,7 +54,7 @@ void aio_setup() { } -void aio_loop() { +void aio_loop(float tlm[]) { // io.run(); is required for all sketches. // it should always be present at the top of your loop @@ -65,7 +65,8 @@ void aio_loop() { // save count to the 'counter' feed on Adafruit IO Serial.print("sending -> "); Serial.println(count); - counter->save(count); +// counter->save(count); + counter->save(tlm[0]); // increment the count by 1 count++; From 65e487944e691da8e1882d7138c5dc7bdaba9e40 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:35:55 -0400 Subject: [PATCH 12/48] Update Payload_BME280_MPU6050_AIO.ino added tlm[1] --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 704d47ff..e913cf56 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -231,8 +231,9 @@ void setup() { aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp for (int i = 0; i++; i < 20) - tlm[i] = 0.0; + i] = 0.0; tlm[0] = 23.1; + tlm[1] = 1000.2; } void loop() { From 4d7da69e6f931b60d892fa0055c34c5a44bd465e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:37:51 -0400 Subject: [PATCH 13/48] Update adafruitio_00_publish_modified.cpp send tlm[1] --- .../adafruitio_00_publish_modified.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 35dbc7fc..18597ebb 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -63,11 +63,13 @@ void aio_loop(float tlm[]) { io.run(); // save count to the 'counter' feed on Adafruit IO - Serial.print("sending -> "); - Serial.println(count); + Serial.print("\nsending to Adafruit IO -> "); +// Serial.println(count); // counter->save(count); + Serial.println(tlm[0]); counter->save(tlm[0]); - + Serial.println(tlm[1]); + counter->save(tlm[1]); // increment the count by 1 count++; From c227067d953ec44af1553d77a6dac93f50dcde1c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:38:47 -0400 Subject: [PATCH 14/48] Update Payload_BME280_MPU6050_AIO.ino typo --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index e913cf56..b03c8553 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -231,7 +231,7 @@ void setup() { aio_setup(); // Adafruit IO setup code defined in adafruitio_00_publish.cpp for (int i = 0; i++; i < 20) - i] = 0.0; + tlm[i] = 0.0; tlm[0] = 23.1; tlm[1] = 1000.2; } From 507546714eba463ca956d9b5b63e1b96d99ef945 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:47:07 -0400 Subject: [PATCH 15/48] Update adafruitio_00_publish_modified.cpp added temperature and pressure --- .../adafruitio_00_publish_modified.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 18597ebb..3afdb951 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -27,7 +27,11 @@ int count = 0; // set up the 'counter' feed -AdafruitIO_Feed *counter = io.feed("counter"); +//AdafruitIO_Feed *counter = io.feed("counter"); +AdafruitIO_Feed *temperature = io.feed("temperature"); +AdafruitIO_Feed *pressure = io.feed("pressure"); +AdafruitIO_Feed *altitude = io.feed("altitude"); +AdafruitIO_Feed *humidity = io.feed("humidity"); void aio_setup() { @@ -66,10 +70,13 @@ void aio_loop(float tlm[]) { Serial.print("\nsending to Adafruit IO -> "); // Serial.println(count); // counter->save(count); - Serial.println(tlm[0]); - counter->save(tlm[0]); - Serial.println(tlm[1]); - counter->save(tlm[1]); + Serial.print(tlm[0]); + temperature->save(tlm[0]); + Serial.print(" "); + Serial.print(tlm[1]); + pressure->save(tlm[1]); + + Serial.println(" "); // increment the count by 1 count++; From 1dadfd82c90af2196e372dd701b655703829ca8e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:54:38 -0400 Subject: [PATCH 16/48] Update Payload_BME280_MPU6050_AIO.ino with tlm 0-3 from BME --- .../Payload_BME280_MPU6050_AIO.ino | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index b03c8553..86f19b98 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -233,7 +233,9 @@ void setup() { for (int i = 0; i++; i < 20) tlm[i] = 0.0; tlm[0] = 23.1; - tlm[1] = 1000.2; + tlm[1] = 1000.2; + tlm[2] = 84.2; + tlm[3] = 100.8; } void loop() { @@ -253,25 +255,30 @@ void loop() { // if (result == '?') { if (bmePresent) { + + tlm[0] = bme.readTemperature(); + tlm[1] = bme.readPressure() / 100.0F; + tlm[2] = bme.readAltitude(SEALEVELPRESSURE_HPA); + tlm[3] = bme.readHumidity(); + Serial1.print(sensor_start_flag); Serial1.print("OK BME280 "); - Serial1.print(bme.readTemperature()); + Serial1.print(tlm[0]); Serial1.print(" "); - Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(tlm[1]); Serial1.print(" "); - Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(tlm[2]); Serial1.print(" "); - Serial1.print(bme.readHumidity()); + Serial1.print(tlm[3]); Serial.print("OK BME280 "); - temp = bme.readTemperature(); - Serial.print(temp); + Serial.print(tlm[0]); Serial.print(" "); - Serial.print(bme.readPressure() / 100.0F); + Serial.print(tlm[1]); Serial.print(" "); - Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(tlm[2]); Serial.print(" "); - Serial.print(bme.readHumidity()); + Serial.print(tlm[3]); } else { Serial1.print(sensor_start_flag); From 4fed2caf77cb7bbed0e0c425a37e63e9f068f118 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 08:55:51 -0400 Subject: [PATCH 17/48] Update adafruitio_00_publish_modified.cpp added altitude and humidity --- .../adafruitio_00_publish_modified.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 3afdb951..064b0588 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -75,8 +75,14 @@ void aio_loop(float tlm[]) { Serial.print(" "); Serial.print(tlm[1]); pressure->save(tlm[1]); - + Serial.print(" "); + Serial.print(tlm[2]); + altitude->save(tlm[2]); Serial.println(" "); + Serial.print(" "); + Serial.print(tlm[3]); + humidity->save(tlm[3]); + // increment the count by 1 count++; From 505e18d6b5b06c77b5307460b7b7a203996cf3b6 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:01:01 -0400 Subject: [PATCH 18/48] Update Payload_BME280_MPU6050_AIO.ino fixed default vals --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 86f19b98..b549d3b0 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -234,8 +234,8 @@ void setup() { tlm[i] = 0.0; tlm[0] = 23.1; tlm[1] = 1000.2; - tlm[2] = 84.2; - tlm[3] = 100.8; + tlm[2] = 122; + tlm[3] = 56.8; } void loop() { From 85c7852db32f1f1bd1d7ef3be86628713cda28a2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:06:57 -0400 Subject: [PATCH 19/48] Update adafruitio_00_publish_modified.cpp added delay --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 064b0588..dd168926 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -89,6 +89,6 @@ void aio_loop(float tlm[]) { // Adafruit IO is rate limited for publishing, so a delay is required in // between feed->save events. In this example, we will wait three seconds // (1000 milliseconds == 1 second) during each loop. - delay(3000); + delay(15000); // 3000 } From 30b49d7783735b0db226f5418dbb51e2b8692315 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:27:05 -0400 Subject: [PATCH 20/48] Update adafruitio_00_publish_modified.cpp move connecting to loop --- .../adafruitio_00_publish_modified.cpp | 74 +++++++++++-------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index dd168926..d8529dea 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -25,6 +25,7 @@ // this int will hold the current count for our sketch int count = 0; +bool aio_connected = false; // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -46,7 +47,7 @@ void aio_setup() { // connect to io.adafruit.com io.connect(); - // wait for a connection +/* // wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); @@ -55,40 +56,49 @@ void aio_setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - +*/ } void aio_loop(float tlm[]) { - // io.run(); is required for all sketches. - // it should always be present at the top of your loop - // function. it keeps the client connected to - // io.adafruit.com, and processes any incoming data. - io.run(); - - // save count to the 'counter' feed on Adafruit IO - Serial.print("\nsending to Adafruit IO -> "); -// Serial.println(count); -// counter->save(count); - Serial.print(tlm[0]); - temperature->save(tlm[0]); - Serial.print(" "); - Serial.print(tlm[1]); - pressure->save(tlm[1]); - Serial.print(" "); - Serial.print(tlm[2]); - altitude->save(tlm[2]); - Serial.println(" "); - Serial.print(" "); - Serial.print(tlm[3]); - humidity->save(tlm[3]); + if (!aio_connected) { + if (io.status() < AIO_CONNECTED) { + Serial.println("Connecting to Adafruit IO..."); + } else { + Serial.println(); + Serial.println(io.statusText()); + aio_connected = true; + } + } else { + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); - // increment the count by 1 - count++; - - // Adafruit IO is rate limited for publishing, so a delay is required in - // between feed->save events. In this example, we will wait three seconds - // (1000 milliseconds == 1 second) during each loop. - delay(15000); // 3000 - + // save count to the 'counter' feed on Adafruit IO + Serial.print("\nSending to Adafruit IO -> "); + // Serial.println(count); + // counter->save(count); + Serial.print(tlm[0]); + temperature->save(tlm[0]); + Serial.print(" "); + Serial.print(tlm[1]); + pressure->save(tlm[1]); + Serial.print(" "); + Serial.print(tlm[2]); + altitude->save(tlm[2]); + Serial.println(" "); + Serial.print(" "); + Serial.print(tlm[3]); + humidity->save(tlm[3]); + + // increment the count by 1 + count++; + + // Adafruit IO is rate limited for publishing, so a delay is required in + // between feed->save events. In this example, we will wait three seconds + // (1000 milliseconds == 1 second) during each loop. + delay(3000); // 15000 + } } From 5ff210a0a17ea4c79c9fafffc299df51db33bf33 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:33:11 -0400 Subject: [PATCH 21/48] Update adafruitio_00_publish_modified.cpp 5 sec delay --- .../adafruitio_00_publish_modified.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index d8529dea..41de7c21 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -42,7 +42,7 @@ void aio_setup() { // wait for serial monitor to open while(! Serial); - Serial.print("Connecting to Adafruit IO"); + Serial.print("\nConnecting to Adafruit IO"); // connect to io.adafruit.com io.connect(); @@ -63,7 +63,7 @@ void aio_loop(float tlm[]) { if (!aio_connected) { if (io.status() < AIO_CONNECTED) { - Serial.println("Connecting to Adafruit IO..."); + Serial.println("\nConnecting to Adafruit IO..."); } else { Serial.println(); Serial.println(io.statusText()); @@ -99,6 +99,6 @@ void aio_loop(float tlm[]) { // Adafruit IO is rate limited for publishing, so a delay is required in // between feed->save events. In this example, we will wait three seconds // (1000 milliseconds == 1 second) during each loop. - delay(3000); // 15000 + delay(5000); // 1000 } } From d1dd5c32116ae99261c87ddb2e0526902df6b768 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:36:31 -0400 Subject: [PATCH 22/48] Create edit_this_config_and_rename.h config file needing your info --- .../edit_this_config_and_rename.h | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 stempayload/Payload_BME280_MPU6050_AIO/edit_this_config_and_rename.h diff --git a/stempayload/Payload_BME280_MPU6050_AIO/edit_this_config_and_rename.h b/stempayload/Payload_BME280_MPU6050_AIO/edit_this_config_and_rename.h new file mode 100644 index 00000000..b6c47fa3 --- /dev/null +++ b/stempayload/Payload_BME280_MPU6050_AIO/edit_this_config_and_rename.h @@ -0,0 +1,74 @@ +// Edit this config file with your IO Username, Key, WiFi SSID and Password, then save as config.h + +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "your_username" +#define IO_KEY "your_key" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 +// - Adafruit PyPortal -> https://www.adafruit.com/product/4116 +// - Adafruit Metro M4 Express AirLift Lite -> +// https://www.adafruit.com/product/4000 +// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201 +// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285 +// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// uncomment the following line if you are using airlift +// #define USE_AIRLIFT + +// uncomment the following line if you are using winc1500 +// #define USE_WINC1500 + +// uncomment the following line if you are using mrk1010 or nano 33 iot +//#define ARDUINO_SAMD_MKR1010 + +// comment out the following lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" + +#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \ + defined(ADAFRUIT_PYPORTAL) +// Configure the pins used for the ESP32 connection +#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant +// Don't change the names of these #define's! they match the variant ones +#define SPIWIFI SPI +#define SPIWIFI_SS 10 // Chip select pin +#define NINA_ACK 9 // a.k.a BUSY or READY pin +#define NINA_RESETN 6 // Reset pin +#define NINA_GPIO0 -1 // Not connected +#endif +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, + NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI); +#else +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); +#endif +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); From a93bf3f462672a71417b72478e2dee28c1e61dcd Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:38:23 -0400 Subject: [PATCH 23/48] Update adafruitio_00_publish_modified.cpp --- .../adafruitio_00_publish_modified.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 41de7c21..5fd51dc9 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -2,6 +2,8 @@ // // changed setup to aio_setup and loop to aio_loop // +// You must put your account and WiFi info and rename config file as config.h +// // Adafruit IO Publish Example // // Adafruit invests time and resources providing this open source code. From bd1557da5bb1d861fd863c1679eecd061c86e3f9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:40:38 -0400 Subject: [PATCH 24/48] Update adafruitio_00_publish_modified.cpp prints --- .../adafruitio_00_publish_modified.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 5fd51dc9..8e18bf4e 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -67,7 +67,8 @@ void aio_loop(float tlm[]) { if (io.status() < AIO_CONNECTED) { Serial.println("\nConnecting to Adafruit IO..."); } else { - Serial.println(); + Serial.print("\nSuccessfully connected to Adafruit IO! Status: "); +// Serial.println(); Serial.println(io.statusText()); aio_connected = true; } @@ -101,6 +102,6 @@ void aio_loop(float tlm[]) { // Adafruit IO is rate limited for publishing, so a delay is required in // between feed->save events. In this example, we will wait three seconds // (1000 milliseconds == 1 second) during each loop. - delay(5000); // 1000 + delay(10000); // 1000 } } From 37be5021902b6cda4f44f8767834df30bdedea7c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:44:26 -0400 Subject: [PATCH 25/48] Update adafruitio_00_publish_modified.cpp --- .../adafruitio_00_publish_modified.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 8e18bf4e..e92fa4d8 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -37,13 +37,13 @@ AdafruitIO_Feed *altitude = io.feed("altitude"); AdafruitIO_Feed *humidity = io.feed("humidity"); void aio_setup() { - +/* // start the serial connection Serial.begin(115200); // wait for serial monitor to open while(! Serial); - +*/ Serial.print("\nConnecting to Adafruit IO"); // connect to io.adafruit.com From f74e958227e51bf75b15653d7fbf520c3234a3d3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 09:49:21 -0400 Subject: [PATCH 26/48] Update adafruitio_00_publish_modified.cpp move newline --- .../adafruitio_00_publish_modified.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index e92fa4d8..bb592ec2 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -91,10 +91,11 @@ void aio_loop(float tlm[]) { Serial.print(" "); Serial.print(tlm[2]); altitude->save(tlm[2]); - Serial.println(" "); Serial.print(" "); Serial.print(tlm[3]); humidity->save(tlm[3]); + + Serial.println(" "); // increment the count by 1 count++; From 200868b6fb26ee62916e4a68156394c8618eed8b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:08:30 -0400 Subject: [PATCH 27/48] Update adafruitio_00_publish_modified.cpp use millis instead of delay --- .../adafruitio_00_publish_modified.cpp | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index bb592ec2..0b919596 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -28,6 +28,7 @@ // this int will hold the current count for our sketch int count = 0; bool aio_connected = false; +unsigned long delay; // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -59,6 +60,7 @@ void aio_setup() { Serial.println(); Serial.println(io.statusText()); */ + delay = millis(); } void aio_loop(float tlm[]) { @@ -78,31 +80,34 @@ void aio_loop(float tlm[]) { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - - // save count to the 'counter' feed on Adafruit IO - Serial.print("\nSending to Adafruit IO -> "); - // Serial.println(count); - // counter->save(count); - Serial.print(tlm[0]); - temperature->save(tlm[0]); - Serial.print(" "); - Serial.print(tlm[1]); - pressure->save(tlm[1]); - Serial.print(" "); - Serial.print(tlm[2]); - altitude->save(tlm[2]); - Serial.print(" "); - Serial.print(tlm[3]); - humidity->save(tlm[3]); - Serial.println(" "); - - // increment the count by 1 - count++; + if ((millis() - delay) > 8000) { // Only send if 8 seconds have passed + delay = millis(); + // save count to the 'counter' feed on Adafruit IO + Serial.print("\nSending to Adafruit IO -> "); + // Serial.println(count); + // counter->save(count); + Serial.print(tlm[0]); + temperature->save(tlm[0]); + Serial.print(" "); + Serial.print(tlm[1]); + pressure->save(tlm[1]); + Serial.print(" "); + Serial.print(tlm[2]); + altitude->save(tlm[2]); + Serial.print(" "); + Serial.print(tlm[3]); + humidity->save(tlm[3]); - // Adafruit IO is rate limited for publishing, so a delay is required in - // between feed->save events. In this example, we will wait three seconds - // (1000 milliseconds == 1 second) during each loop. - delay(10000); // 1000 + Serial.println(" "); + + // increment the count by 1 + count++; + + // Adafruit IO is rate limited for publishing, so a delay is required in + // between feed->save events. In this example, we will wait three seconds + // (1000 milliseconds == 1 second) during each loop. + // delay(10000); // 1000 + } } } From 8786c298aea77e9f9a337c093e70b2ffb2e75191 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:09:35 -0400 Subject: [PATCH 28/48] Update adafruitio_00_publish_modified.cpp time_stamp --- .../adafruitio_00_publish_modified.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 0b919596..c2a61c5a 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -28,7 +28,7 @@ // this int will hold the current count for our sketch int count = 0; bool aio_connected = false; -unsigned long delay; +unsigned long time_stamp; // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -60,7 +60,7 @@ void aio_setup() { Serial.println(); Serial.println(io.statusText()); */ - delay = millis(); + time_stamp = millis(); } void aio_loop(float tlm[]) { @@ -81,8 +81,8 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - delay) > 8000) { // Only send if 8 seconds have passed - delay = millis(); + if ((millis() - time_stamp) > 8000) { // Only send if 8 seconds have passed + time_stamp = millis(); // save count to the 'counter' feed on Adafruit IO Serial.print("\nSending to Adafruit IO -> "); // Serial.println(count); From cbb967cbbd37b7c55337cfd32ecf4c5320b455c0 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:13:13 -0400 Subject: [PATCH 29/48] Update adafruitio_00_publish_modified.cpp print waiting --- .../adafruitio_00_publish_modified.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index c2a61c5a..2befc28d 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -81,7 +81,10 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) > 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < 8000) { // Only send if 8 seconds have passed + Serial.print("\nWaiting to send Adafruit IO\n"); + } + else { time_stamp = millis(); // save count to the 'counter' feed on Adafruit IO Serial.print("\nSending to Adafruit IO -> "); From bc1ec2790e17f253eeb2a2179b41592f3cf9df6a Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:25:43 -0400 Subject: [PATCH 30/48] Update adafruitio_00_publish_modified.cpp added accel x y z --- .../adafruitio_00_publish_modified.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 2befc28d..8e311d40 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -26,16 +26,22 @@ /************************ Example Starts Here *******************************/ // this int will hold the current count for our sketch -int count = 0; +// int count = 0; bool aio_connected = false; unsigned long time_stamp; +// should match the number of feeds define below so throttling delay is set correctly +#define FEEDS = 7 + // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); AdafruitIO_Feed *temperature = io.feed("temperature"); AdafruitIO_Feed *pressure = io.feed("pressure"); AdafruitIO_Feed *altitude = io.feed("altitude"); AdafruitIO_Feed *humidity = io.feed("humidity"); +AdafruitIO_Feed *accel_x = io.feed("accel_x"); +AdafruitIO_Feed *accel_y = io.feed("accel_y"); +AdafruitIO_Feed *accel_z = io.feed("accel_z"); void aio_setup() { /* @@ -81,7 +87,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < (2000 * FEEDS)) // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { @@ -101,11 +107,19 @@ void aio_loop(float tlm[]) { Serial.print(" "); Serial.print(tlm[3]); humidity->save(tlm[3]); + Serial.print(tlm[4]); + accel_x->save(tlm[4]); + Serial.print(" "); + Serial.print(tlm[5]); + accel_y->save(tlm[5]); + Serial.print(" "); + Serial.print(tlm[6]); + accel_z->save(tlm[6]); Serial.println(" "); // increment the count by 1 - count++; +// count++; // Adafruit IO is rate limited for publishing, so a delay is required in // between feed->save events. In this example, we will wait three seconds From 93db3f148c848178b13fe449b34014658906be0b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:31:46 -0400 Subject: [PATCH 31/48] Update Payload_BME280_MPU6050_AIO.ino added MPU info --- .../Payload_BME280_MPU6050_AIO.ino | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index b549d3b0..bfb0c344 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -232,10 +232,10 @@ void setup() { for (int i = 0; i++; i < 20) tlm[i] = 0.0; - tlm[0] = 23.1; - tlm[1] = 1000.2; - tlm[2] = 122; - tlm[3] = 56.8; +// tlm[0] = 23.1; // uncomment for non-zero test values if no BME or MPU sensor is attached. +// tlm[1] = 1000.2; +// tlm[2] = 122; +// tlm[3] = 56.8; } void loop() { @@ -287,34 +287,41 @@ void loop() { Serial.print("OK BME280 0.0 0.0 0.0 0.0"); } mpu6050.update(); - + + tlm[4] = mpu6050.getGyroX(); + tlm[5] = mpu6050.getGyroY(); + tlm[6] = mpu6050.getGyroZ(); + tlm[7] = mpu6050.getAccX(); + tlm[8] = mpu6050.getAccY(); + tlm[9] = mpu6050.getAccZ(); + Serial1.print(" MPU6050 "); - Serial1.print(mpu6050.getGyroX()); + Serial1.print(tlm[4]); Serial1.print(" "); - Serial1.print(mpu6050.getGyroY()); + Serial1.print(tlm[5]); Serial1.print(" "); - Serial1.print(mpu6050.getGyroZ()); + Serial1.print(tlm[6]); Serial1.print(" "); - Serial1.print(mpu6050.getAccX()); + Serial1.print(tlm[7]); Serial1.print(" "); - Serial1.print(mpu6050.getAccY()); + Serial1.print(tlm[8]); Serial1.print(" "); - Serial1.print(mpu6050.getAccZ()); + Serial1.print(tlm[9]); Serial.print(" MPU6050 "); - Serial.print(mpu6050.getGyroX()); + Serial.print(tlm[4]); Serial.print(" "); - Serial.print(mpu6050.getGyroY()); + Serial.print(tlm[5]); Serial.print(" "); - Serial.print(mpu6050.getGyroZ()); + Serial.print(tlm[6]); Serial.print(" "); - Serial.print(mpu6050.getAccX()); + Serial.print(tlm[7]); Serial.print(" "); - Serial.print(mpu6050.getAccY()); + Serial.print(tlm[8]); Serial.print(" "); - Serial.print(mpu6050.getAccZ()); + Serial.print(tlm[9]); sensorValue = read_analog(); From 0654c42fea2b7023f0e35bd126930217c595b1d9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:34:35 -0400 Subject: [PATCH 32/48] Update adafruitio_00_publish_modified.cpp added MPU --- .../adafruitio_00_publish_modified.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 8e311d40..e03d2fcc 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -31,7 +31,7 @@ bool aio_connected = false; unsigned long time_stamp; // should match the number of feeds define below so throttling delay is set correctly -#define FEEDS = 7 +#define FEEDS = 10 // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -39,9 +39,12 @@ AdafruitIO_Feed *temperature = io.feed("temperature"); AdafruitIO_Feed *pressure = io.feed("pressure"); AdafruitIO_Feed *altitude = io.feed("altitude"); AdafruitIO_Feed *humidity = io.feed("humidity"); -AdafruitIO_Feed *accel_x = io.feed("accel_x"); -AdafruitIO_Feed *accel_y = io.feed("accel_y"); -AdafruitIO_Feed *accel_z = io.feed("accel_z"); +AdafruitIO_Feed *accel_x = io.feed("Acceleration X Axis"); +AdafruitIO_Feed *accel_y = io.feed("Acceleration Y Axis"); +AdafruitIO_Feed *accel_z = io.feed("Acceleration Z Axis"); +AdafruitIO_Feed *gyro_x = io.feed("Rotation X Axis"); +AdafruitIO_Feed *gyro_y = io.feed("Rotation Y Axis"); +AdafruitIO_Feed *gyro_z = io.feed("Rotation Z Axis"); void aio_setup() { /* @@ -108,13 +111,21 @@ void aio_loop(float tlm[]) { Serial.print(tlm[3]); humidity->save(tlm[3]); Serial.print(tlm[4]); - accel_x->save(tlm[4]); + gyro_x->save(tlm[4]); Serial.print(" "); Serial.print(tlm[5]); - accel_y->save(tlm[5]); + gyro_y->save(tlm[5]); Serial.print(" "); Serial.print(tlm[6]); - accel_z->save(tlm[6]); + gyro_z->save(tlm[6]); + Serial.print(tlm[7]); + accel_x->save(tlm[7]); + Serial.print(" "); + Serial.print(tlm[8]); + accel_y->save(tlm[8]); + Serial.print(" "); + Serial.print(tlm[9]); + accel_z->save(tlm[9]); Serial.println(" "); From 352181a7bb63854928a5bfc2737165da6f964976 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:36:46 -0400 Subject: [PATCH 33/48] Update adafruitio_00_publish_modified.cpp missing { --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index e03d2fcc..7996ec89 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < (2000 * FEEDS)) // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < (2000 * FEEDS)) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From ffe6eec9bdfe1eb2db3079108dfaa72d01393005 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:37:46 -0400 Subject: [PATCH 34/48] Update adafruitio_00_publish_modified.cpp fix def --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 7996ec89..2922f97c 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -31,7 +31,7 @@ bool aio_connected = false; unsigned long time_stamp; // should match the number of feeds define below so throttling delay is set correctly -#define FEEDS = 10 +#define FEEDS 10 // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); From 9a86fd90cefa73939988d27bab00734b98db584c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:44:13 -0400 Subject: [PATCH 35/48] Update adafruitio_00_publish_modified.cpp removed gyro feeds --- .../adafruitio_00_publish_modified.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 2922f97c..4a4a29f9 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -31,7 +31,7 @@ bool aio_connected = false; unsigned long time_stamp; // should match the number of feeds define below so throttling delay is set correctly -#define FEEDS 10 +#define FEEDS 7 // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -42,9 +42,9 @@ AdafruitIO_Feed *humidity = io.feed("humidity"); AdafruitIO_Feed *accel_x = io.feed("Acceleration X Axis"); AdafruitIO_Feed *accel_y = io.feed("Acceleration Y Axis"); AdafruitIO_Feed *accel_z = io.feed("Acceleration Z Axis"); -AdafruitIO_Feed *gyro_x = io.feed("Rotation X Axis"); -AdafruitIO_Feed *gyro_y = io.feed("Rotation Y Axis"); -AdafruitIO_Feed *gyro_z = io.feed("Rotation Z Axis"); +// AdafruitIO_Feed *gyro_x = io.feed("Rotation X Axis"); +// AdafruitIO_Feed *gyro_y = io.feed("Rotation Y Axis"); +// AdafruitIO_Feed *gyro_z = io.feed("Rotation Z Axis"); void aio_setup() { /* @@ -111,21 +111,21 @@ void aio_loop(float tlm[]) { Serial.print(tlm[3]); humidity->save(tlm[3]); Serial.print(tlm[4]); - gyro_x->save(tlm[4]); +// gyro_x->save(tlm[4]); +// Serial.print(" "); +// Serial.print(tlm[5]); +// gyro_y->save(tlm[5]); +// Serial.print(" "); +// Serial.print(tlm[6]); +// gyro_z->save(tlm[6]); + Serial.print(tlm[4]); + accel_x->save(tlm[4]); Serial.print(" "); Serial.print(tlm[5]); - gyro_y->save(tlm[5]); + accel_y->save(tlm[5]); Serial.print(" "); Serial.print(tlm[6]); - gyro_z->save(tlm[6]); - Serial.print(tlm[7]); - accel_x->save(tlm[7]); - Serial.print(" "); - Serial.print(tlm[8]); - accel_y->save(tlm[8]); - Serial.print(" "); - Serial.print(tlm[9]); - accel_z->save(tlm[9]); + accel_z->save(tlm[6]); Serial.println(" "); From 1e8ec55d86d9f65c001a0e91a94efabd7f688f2f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:49:06 -0400 Subject: [PATCH 36/48] Update adafruitio_00_publish_modified.cpp changed to FEEDS + 1 --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 4a4a29f9..9a0979fc 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < (2000 * FEEDS)) { // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < (2000 * (FEEDS+1))) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From 7b33dca4ff2f1a68c0a30e28dc97e6320f9c6e37 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:52:50 -0400 Subject: [PATCH 37/48] Update adafruitio_00_publish_modified.cpp fixed spacing --- .../adafruitio_00_publish_modified.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 9a0979fc..ba9c7a18 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -110,7 +110,8 @@ void aio_loop(float tlm[]) { Serial.print(" "); Serial.print(tlm[3]); humidity->save(tlm[3]); - Serial.print(tlm[4]); + Serial.print(" "); +// Serial.print(tlm[4]); // gyro_x->save(tlm[4]); // Serial.print(" "); // Serial.print(tlm[5]); From e85278fcdcf6ed0bc62bd9787e9a589d1ee07b12 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:53:47 -0400 Subject: [PATCH 38/48] Update adafruitio_00_publish_modified.cpp fixed numbering --- .../adafruitio_00_publish_modified.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index ba9c7a18..74a89494 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -119,14 +119,14 @@ void aio_loop(float tlm[]) { // Serial.print(" "); // Serial.print(tlm[6]); // gyro_z->save(tlm[6]); - Serial.print(tlm[4]); - accel_x->save(tlm[4]); + Serial.print(tlm[7]); + accel_x->save(tlm[7]); Serial.print(" "); - Serial.print(tlm[5]); - accel_y->save(tlm[5]); + Serial.print(tlm[8]); + accel_y->save(tlm[8]); Serial.print(" "); - Serial.print(tlm[6]); - accel_z->save(tlm[6]); + Serial.print(tlm[9]); + accel_z->save(tlm[9]); Serial.println(" "); From e06090b300a1eb2f916513deb3a3cfdbf481d415 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:58:55 -0400 Subject: [PATCH 39/48] Update adafruitio_00_publish_modified.cpp --- .../adafruitio_00_publish_modified.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 74a89494..0176eabf 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -39,9 +39,9 @@ AdafruitIO_Feed *temperature = io.feed("temperature"); AdafruitIO_Feed *pressure = io.feed("pressure"); AdafruitIO_Feed *altitude = io.feed("altitude"); AdafruitIO_Feed *humidity = io.feed("humidity"); -AdafruitIO_Feed *accel_x = io.feed("Acceleration X Axis"); -AdafruitIO_Feed *accel_y = io.feed("Acceleration Y Axis"); -AdafruitIO_Feed *accel_z = io.feed("Acceleration Z Axis"); +AdafruitIO_Feed *accel_x = io.feed("Acceleration: X Axis"); +AdafruitIO_Feed *accel_y = io.feed("Acceleration: Y Axis"); +AdafruitIO_Feed *accel_z = io.feed("Acceleration: Z Axis"); // AdafruitIO_Feed *gyro_x = io.feed("Rotation X Axis"); // AdafruitIO_Feed *gyro_y = io.feed("Rotation Y Axis"); // AdafruitIO_Feed *gyro_z = io.feed("Rotation Z Axis"); From e7e79cace91b188fcf31446760b7155554e74644 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 11:01:29 -0400 Subject: [PATCH 40/48] Update adafruitio_00_publish_modified.cpp --- .../adafruitio_00_publish_modified.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 0176eabf..4e056082 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -39,9 +39,9 @@ AdafruitIO_Feed *temperature = io.feed("temperature"); AdafruitIO_Feed *pressure = io.feed("pressure"); AdafruitIO_Feed *altitude = io.feed("altitude"); AdafruitIO_Feed *humidity = io.feed("humidity"); -AdafruitIO_Feed *accel_x = io.feed("Acceleration: X Axis"); -AdafruitIO_Feed *accel_y = io.feed("Acceleration: Y Axis"); -AdafruitIO_Feed *accel_z = io.feed("Acceleration: Z Axis"); +AdafruitIO_Feed *accel_x = io.feed("Acceleration - X Axis"); +AdafruitIO_Feed *accel_y = io.feed("Acceleration - Y Axis"); +AdafruitIO_Feed *accel_z = io.feed("Acceleration - Z Axis"); // AdafruitIO_Feed *gyro_x = io.feed("Rotation X Axis"); // AdafruitIO_Feed *gyro_y = io.feed("Rotation Y Axis"); // AdafruitIO_Feed *gyro_z = io.feed("Rotation Z Axis"); From 8dc6c087c541c9e3ff07add6a311e96889e58db3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 12:20:33 -0400 Subject: [PATCH 41/48] Update adafruitio_00_publish_modified.cpp changed to 2*FEEDS plus 1 --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 4e056082..3f9f84f6 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < (2000 * (FEEDS+1))) { // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < ((2000 * FEEDS) + 1000)) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From a85858dd93ad2c4ca7a3d2526d22c6cbd60144e5 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 14:01:42 -0400 Subject: [PATCH 42/48] Update Payload_BME280_MPU6050_AIO.ino put tlm in sqrt --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index bfb0c344..950f5363 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -356,8 +356,8 @@ void loop() { // Serial.print(" "); // Serial.println(Sensor2); - float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ()); - float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); + float rotation = sqrt(tlm[4]*tlm[4] + tlm[5]tlm[5] + tlm[6]*tlm[6]); + float acceleration = qrt(tlm[7]*tlm[7] + tlm[8]tlm[8] + tlm[9]*tlm[9]); // Serial.print(rotation); // Serial.print(" "); // Serial.println(acceleration); From b4a115852e45ff3fa5d3a78a9d72153462fc6ca8 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 06:51:06 -0400 Subject: [PATCH 43/48] Update adafruitio_00_publish_modified.cpp increase interval --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 3f9f84f6..27deb5fa 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < ((2000 * FEEDS) + 1000)) { // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < ((2000 * (FEEDS+1)) + 1000)) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From edc463328cd3a0520129bd6b1d34c07ec3f432d1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 07:00:35 -0400 Subject: [PATCH 44/48] Update adafruitio_00_publish_modified.cpp 3 sec --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 27deb5fa..73c4c14c 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < ((2000 * (FEEDS+1)) + 1000)) { // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < ((3000 * (FEEDS)) + 1000)) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From 7de351387bb2844836e783090f2ed1b62a16e0a3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 07:01:03 -0400 Subject: [PATCH 45/48] Update adafruitio_00_publish_modified.cpp back to + 1 --- .../adafruitio_00_publish_modified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index 73c4c14c..27deb5fa 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -90,7 +90,7 @@ void aio_loop(float tlm[]) { // io.adafruit.com, and processes any incoming data. io.run(); - if ((millis() - time_stamp) < ((3000 * (FEEDS)) + 1000)) { // 8000) { // Only send if 8 seconds have passed + if ((millis() - time_stamp) < ((2000 * (FEEDS+1)) + 1000)) { // 8000) { // Only send if 8 seconds have passed Serial.print("\nWaiting to send Adafruit IO\n"); } else { From 37b247c9e739f002220ae210ad382635a8388eed Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 07:03:23 -0400 Subject: [PATCH 46/48] Update Payload_BME280_MPU6050_AIO.ino typo missing s --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 950f5363..8a602672 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -357,7 +357,7 @@ void loop() { // Serial.println(Sensor2); float rotation = sqrt(tlm[4]*tlm[4] + tlm[5]tlm[5] + tlm[6]*tlm[6]); - float acceleration = qrt(tlm[7]*tlm[7] + tlm[8]tlm[8] + tlm[9]*tlm[9]); + float acceleration = sqrt(tlm[7]*tlm[7] + tlm[8]tlm[8] + tlm[9]*tlm[9]); // Serial.print(rotation); // Serial.print(" "); // Serial.println(acceleration); From ac0af6f1e6a501d32089d685f95ac96b5bf52d89 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 07:04:34 -0400 Subject: [PATCH 47/48] Update Payload_BME280_MPU6050_AIO.ino missing * --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 8a602672..75aa95d0 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -357,7 +357,7 @@ void loop() { // Serial.println(Sensor2); float rotation = sqrt(tlm[4]*tlm[4] + tlm[5]tlm[5] + tlm[6]*tlm[6]); - float acceleration = sqrt(tlm[7]*tlm[7] + tlm[8]tlm[8] + tlm[9]*tlm[9]); + float acceleration = sqrt(tlm[7]*tlm[7] + tlm[8]*tlm[8] + tlm[9]*tlm[9]); // Serial.print(rotation); // Serial.print(" "); // Serial.println(acceleration); From 2dea929f51be8f233a4016efb1190b9549378964 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 23 Jun 2024 07:05:29 -0400 Subject: [PATCH 48/48] Update Payload_BME280_MPU6050_AIO.ino another one --- .../Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino index 75aa95d0..a1022069 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino +++ b/stempayload/Payload_BME280_MPU6050_AIO/Payload_BME280_MPU6050_AIO.ino @@ -356,7 +356,7 @@ void loop() { // Serial.print(" "); // Serial.println(Sensor2); - float rotation = sqrt(tlm[4]*tlm[4] + tlm[5]tlm[5] + tlm[6]*tlm[6]); + float rotation = sqrt(tlm[4]*tlm[4] + tlm[5]*tlm[5] + tlm[6]*tlm[6]); float acceleration = sqrt(tlm[7]*tlm[7] + tlm[8]*tlm[8] + tlm[9]*tlm[9]); // Serial.print(rotation); // Serial.print(" ");