From 0d6c1a075bbe36e511f81036f835b64ee251b332 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Mar 2021 15:52:28 -0400 Subject: [PATCH 1/4] Back one version with println after Sensor3 --- arduino/Payload_BME280_MPU6050_XS_GPS.ino | 115 +++++++++++++--------- 1 file changed, 71 insertions(+), 44 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_XS_GPS.ino b/arduino/Payload_BME280_MPU6050_XS_GPS.ino index 7a1c651f..7b55cf3c 100644 --- a/arduino/Payload_BME280_MPU6050_XS_GPS.ino +++ b/arduino/Payload_BME280_MPU6050_XS_GPS.ino @@ -1,3 +1,10 @@ +// Payload software for CubeSatSim STEM Payload Board +// Arduino software for STM32 or Arduino Pro Micro +// +// BME280 code based on +// MPU6050 code based on +// GPS code based on TinyGPS simple_test example + #include #include #include @@ -12,13 +19,14 @@ MPU6050 mpu6050(Wire); TinyGPS gps; long timer = 0; -int bmePresent; +int bmePresent = 0; +int mpuPresent = 0; int RXLED = 17; // The RX LED has a defined Arduino pin int greenLED = 9; int blueLED = 8; -float Sensor1 = 0; -float Sensor2 = 0; -float Sensor3 = 0; +float Sensor1 = 0.0; +float Sensor2 = 0.0; +float Sensor3 = 0.0; void eeprom_word_write(int addr, int val); short eeprom_word_read(int addr); float lat = 0.0, lon = 0.0, alt = 0.0; @@ -39,14 +47,24 @@ void setup() { delay(250); blink(500); delay(250); - + + /**/ if (bme.begin(0x76)) { bmePresent = 1; } else { Serial.println("Could not find a valid BME280 sensor, check wiring!"); bmePresent = 0; } -/* +/**/ + Wire.beginTransmission(0x68); +// Serial.print(address, HEX); + byte error = Wire.endTransmission(); + if (error == 0) + mpuPresent = 1; + else + Serial.println("Could not find a valid MPU6050 sensor, check wiring!"); +/**/ +if (mpuPresent) { mpu6050.begin(); if (eeprom_word_read(0) == 0xA07) @@ -79,7 +97,9 @@ void setup() { Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); } - */ +} + pinMode(greenLED, OUTPUT); + pinMode(blueLED, OUTPUT); } void loop() { @@ -110,7 +130,10 @@ void loop() { { Serial.print("OK BME280 0.0 0.0 0.0 0.0"); } - // mpu6050.update(); + + if (mpuPresent) { + + mpu6050.update(); Serial.print(" MPU6050 "); Serial.print(mpu6050.getGyroX()); @@ -124,39 +147,27 @@ void loop() { Serial.print(" "); Serial.print(mpu6050.getAccY()); Serial.print(" "); - Serial.print(mpu6050.getAccZ()); + Serial.print(mpu6050.getAccZ()); + } else { + Serial.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0"); + } Serial.print(" XS "); Serial.print(Sensor1); Serial.print(" "); Serial.print(Sensor2); Serial.print(" "); - Serial.println(Sensor3); - - bool newData = false; - unsigned long chars; - unsigned short sentences, failed; - - // For one second we parse GPS data and report some key values - for (unsigned long start = millis(); millis() - start < 1000;) // 1000;) - { - while (Serial2.available()) - { - char c = Serial2.read(); -// 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) - { - float flon, flat; - unsigned long age; - gps.f_get_position(&flat, &flon, &age); - Sensor1 = flat; - Sensor2 = flon; - Sensor3 = (float) gps.altitude()/100.0; - } + Serial.println(Sensor3); +/* + Serial.print(" GPS "); // return previous GPS data (can't wait due to 1 sec delay) + Serial.print(lat); + Serial.print(" "); + Serial.print(lon); + Serial.print(" "); + Serial.println(alt); + */ + +/* 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); @@ -171,7 +182,8 @@ void loop() { if (rotation > 5) digitalWrite(blueLED, HIGH); else - digitalWrite(blueLED, LOW); + digitalWrite(blueLED, LOW); + */ } } @@ -202,7 +214,8 @@ void loop() { { Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); } - // mpu6050.update(); + if (mpuPresent) { + mpu6050.update(); Serial1.print(" MPU6050 "); Serial1.print(mpu6050.getGyroX()); @@ -217,14 +230,21 @@ void loop() { Serial1.print(mpu6050.getAccY()); Serial1.print(" "); Serial1.print(mpu6050.getAccZ()); - + } else { + Serial1.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0"); + + } Serial1.print(" XS "); Serial1.print(Sensor1); Serial1.print(" "); Serial1.print(Sensor2); Serial1.print(" "); - Serial1.println(Sensor3); + Serial1.println(Sensor3); +// Serial1.println(" GPS 0.0 0.0"); + + } + } bool newData = false; unsigned long chars; unsigned short sentences, failed; @@ -248,8 +268,18 @@ void loop() { Sensor1 = flat; Sensor2 = flon; Sensor3 = (float) gps.altitude()/100.0; - } +/* + Serial.print("LAT="); + Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6); + Serial.print(" LON="); + Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6); + Serial.print(" SAT="); + Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites()); + Serial.print(" PREC="); + Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop()); +*/ + } 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); @@ -265,9 +295,6 @@ void loop() { digitalWrite(blueLED, HIGH); else digitalWrite(blueLED, LOW); - } - } - // delay(100); } @@ -314,6 +341,6 @@ void blink(int length) #if defined __AVR_ATmega32U4__ digitalWrite(RXLED, HIGH); // set the RX LED OFF - TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + TXLED0; //TX LED macro to turn LED ON #endif } From 516f514681588983fce996276017dd8be3def172 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Mar 2021 17:24:58 -0400 Subject: [PATCH 2/4] fixed handling of default lat and long, beaconing every 60 seconds --- afsk/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8549311b..6dedceb0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -139,7 +139,7 @@ int sampleTime = 0, frames_sent = 0; int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; float batteryThreshold = 3.0, batteryVoltage; -float latitude = 39.027702f, longitude = -77.078064f; // 100x for now +float latitude = 40.0373f, longitude = -75.3491f; // 100x for now float lat_file, long_file; float axis[3], angle[3], volts_max[3], amps_max[3], batt, speed, period, tempS, temp_max, temp_min, eclipse; @@ -215,7 +215,11 @@ mode = AFSK; latitude = toAprsFormat(lat_file); longitude = toAprsFormat(long_file); printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); + } else { // set default + latitude = toAprsFormat(latitude); + longitude = toAprsFormat(longitude); } + wiringPiSetup(); // Check for SPI and AX-5043 Digital Transceiver Board @@ -999,7 +1003,7 @@ void get_tlm(void) { #ifdef DEBUG_LOGGING printf("Tx LED Off\n"); #endif - sleep(3); + sleep(60); digitalWrite(txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n"); @@ -2004,7 +2008,7 @@ int test_i2c_bus(int bus) } float toAprsFormat(float input) { -// converts decimal coordinate (lattitude or longitude) to APRS DDMM.MM format +// converts decimal coordinate (latitude or longitude) to APRS DDMM.MM format int dd = (int) input; int mm1 = (int)((input - dd) * 60.0); int mm2 = (int)((input - dd - (float)mm1/60.0) * 60.0 * 60.0); From b818967809f57d24f18e8ffc46290a31c4722160 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Mar 2021 17:45:37 -0400 Subject: [PATCH 3/4] reverted to working, commented back in gyro --- arduino/Payload_BME280_MPU6050_XS_GPS.ino | 110 ++++++++-------------- 1 file changed, 41 insertions(+), 69 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_XS_GPS.ino b/arduino/Payload_BME280_MPU6050_XS_GPS.ino index 7b55cf3c..5f1ca61a 100644 --- a/arduino/Payload_BME280_MPU6050_XS_GPS.ino +++ b/arduino/Payload_BME280_MPU6050_XS_GPS.ino @@ -1,10 +1,3 @@ -// Payload software for CubeSatSim STEM Payload Board -// Arduino software for STM32 or Arduino Pro Micro -// -// BME280 code based on -// MPU6050 code based on -// GPS code based on TinyGPS simple_test example - #include #include #include @@ -19,14 +12,13 @@ MPU6050 mpu6050(Wire); TinyGPS gps; long timer = 0; -int bmePresent = 0; -int mpuPresent = 0; +int bmePresent; int RXLED = 17; // The RX LED has a defined Arduino pin int greenLED = 9; int blueLED = 8; -float Sensor1 = 0.0; -float Sensor2 = 0.0; -float Sensor3 = 0.0; +float Sensor1 = 0; +float Sensor2 = 0; +float Sensor3 = 0; void eeprom_word_write(int addr, int val); short eeprom_word_read(int addr); float lat = 0.0, lon = 0.0, alt = 0.0; @@ -47,24 +39,14 @@ void setup() { delay(250); blink(500); delay(250); - - /**/ + if (bme.begin(0x76)) { bmePresent = 1; } else { Serial.println("Could not find a valid BME280 sensor, check wiring!"); bmePresent = 0; } -/**/ - Wire.beginTransmission(0x68); -// Serial.print(address, HEX); - byte error = Wire.endTransmission(); - if (error == 0) - mpuPresent = 1; - else - Serial.println("Could not find a valid MPU6050 sensor, check wiring!"); -/**/ -if (mpuPresent) { + mpu6050.begin(); if (eeprom_word_read(0) == 0xA07) @@ -98,9 +80,6 @@ if (mpuPresent) { Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); } } - pinMode(greenLED, OUTPUT); - pinMode(blueLED, OUTPUT); -} void loop() { @@ -130,9 +109,6 @@ void loop() { { Serial.print("OK BME280 0.0 0.0 0.0 0.0"); } - - if (mpuPresent) { - mpu6050.update(); Serial.print(" MPU6050 "); @@ -147,27 +123,39 @@ void loop() { Serial.print(" "); Serial.print(mpu6050.getAccY()); Serial.print(" "); - Serial.print(mpu6050.getAccZ()); - } else { - Serial.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0"); - } + Serial.print(mpu6050.getAccZ()); Serial.print(" XS "); Serial.print(Sensor1); Serial.print(" "); Serial.print(Sensor2); Serial.print(" "); - Serial.println(Sensor3); -/* - Serial.print(" GPS "); // return previous GPS data (can't wait due to 1 sec delay) - Serial.print(lat); - Serial.print(" "); - Serial.print(lon); - Serial.print(" "); - Serial.println(alt); - */ - -/* + Serial.println(Sensor3); + + bool newData = false; + unsigned long chars; + unsigned short sentences, failed; + + // For one second we parse GPS data and report some key values + for (unsigned long start = millis(); millis() - start < 1000;) // 1000;) + { + while (Serial2.available()) + { + char c = Serial2.read(); +// 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) + { + float flon, flat; + unsigned long age; + gps.f_get_position(&flat, &flon, &age); + Sensor1 = flat; + Sensor2 = flon; + Sensor3 = (float) gps.altitude()/100.0; + } 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); @@ -182,8 +170,7 @@ void loop() { if (rotation > 5) digitalWrite(blueLED, HIGH); else - digitalWrite(blueLED, LOW); - */ + digitalWrite(blueLED, LOW); } } @@ -214,7 +201,6 @@ void loop() { { Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); } - if (mpuPresent) { mpu6050.update(); Serial1.print(" MPU6050 "); @@ -230,21 +216,14 @@ void loop() { Serial1.print(mpu6050.getAccY()); Serial1.print(" "); Serial1.print(mpu6050.getAccZ()); - } else { - Serial1.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0"); - - } + Serial1.print(" XS "); Serial1.print(Sensor1); Serial1.print(" "); Serial1.print(Sensor2); Serial1.print(" "); - Serial1.println(Sensor3); + Serial1.println(Sensor3); -// Serial1.println(" GPS 0.0 0.0"); - - } - } bool newData = false; unsigned long chars; unsigned short sentences, failed; @@ -268,18 +247,8 @@ void loop() { Sensor1 = flat; Sensor2 = flon; Sensor3 = (float) gps.altitude()/100.0; + } -/* - Serial.print("LAT="); - Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6); - Serial.print(" LON="); - Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6); - Serial.print(" SAT="); - Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites()); - Serial.print(" PREC="); - Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop()); -*/ - } 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); @@ -295,6 +264,9 @@ void loop() { digitalWrite(blueLED, HIGH); else digitalWrite(blueLED, LOW); + } + } + // delay(100); } @@ -341,6 +313,6 @@ void blink(int length) #if defined __AVR_ATmega32U4__ digitalWrite(RXLED, HIGH); // set the RX LED OFF - TXLED0; //TX LED macro to turn LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF #endif } From ef06a4974ee632d59d8e6415f3b12160c63d43ab Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Mar 2021 17:51:55 -0400 Subject: [PATCH 4/4] changed to sleep 30 --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6dedceb0..7bbb728e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1003,7 +1003,7 @@ void get_tlm(void) { #ifdef DEBUG_LOGGING printf("Tx LED Off\n"); #endif - sleep(60); + sleep(30); digitalWrite(txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n");