From ee8e8efec5c422a9cf8c0a316f17c77d763b42c8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 11:53:31 -0400 Subject: [PATCH 01/33] added payload print in AFSK mode --- afsk/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index dc3528fe..5aadc990 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -869,6 +869,30 @@ for (int j = 0; j < frameCnt; j++) //printf("Before 1st strcpy\n"); strcat(cw_str2, cw_footer2); //printf("Before 1st strcpy\n"); + +// read payload sensor if available + +if (payload == ON) +{ + char c; + unsigned int waitTime; + int i; +// for(i = 0; i < 2; i++) +// { + serialPutchar (uart_fd, '?'); + printf("Querying payload with ?\n"); + waitTime = millis() + 500; + while (millis() < waitTime) + { + int chars = serialDataAvail (uart_fd); + while (chars-- > 0) + { + printf ("%c", c = serialGetchar (uart_fd)); + fflush (stdout); + } +// } +} + digitalWrite (txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n"); From 696db56b110559df201d0a3e5983408179a7f669 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 11:57:39 -0400 Subject: [PATCH 02/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5aadc990..c31c56c0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -109,6 +109,7 @@ int rd = 0; int nrd; void write_to_buffer(int i, int symbol, int val); void write_wave(int i, short int *buffer); + int uart_fd; //#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) //#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) @@ -485,7 +486,6 @@ else if (!ax5043) // don't test if AX5043 is present { - int uart_fd; payload = OFF; if ((uart_fd = serialOpen ("/dev/ttyAMA0", 9600)) >= 0) From f93e1628639726c35ab6a789b8fa945d30429d6d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 11:59:09 -0400 Subject: [PATCH 03/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c31c56c0..440c7cec 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -890,7 +890,7 @@ if (payload == ON) printf ("%c", c = serialGetchar (uart_fd)); fflush (stdout); } -// } + } } digitalWrite (txLed, txLedOn); From 3bc0f6adde58e880ec7975b5f4ac7148055efd3a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:03:07 -0400 Subject: [PATCH 04/33] print payload string --- afsk/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 440c7cec..be2db5ca 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -870,15 +870,16 @@ for (int j = 0; j < frameCnt; j++) strcat(cw_str2, cw_footer2); //printf("Before 1st strcpy\n"); -// read payload sensor if available +// read payload sensor if available + +char sensor_payload[500]; if (payload == ON) { char c; unsigned int waitTime; - int i; -// for(i = 0; i < 2; i++) -// { + int i = 0; + serialPutchar (uart_fd, '?'); printf("Querying payload with ?\n"); waitTime = millis() + 500; @@ -888,9 +889,12 @@ if (payload == ON) while (chars-- > 0) { printf ("%c", c = serialGetchar (uart_fd)); + sensor_payload[i++] = c; fflush (stdout); } } + sensor_payload[i] = '\0'; + printf("Payload string: %s\n", sensor_payload); } digitalWrite (txLed, txLedOn); From 974c4de4d6b2c2b128f2ee5bf9d471a0f0760eb0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:07:25 -0400 Subject: [PATCH 05/33] Update main.c --- afsk/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index be2db5ca..d253f104 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -888,14 +888,17 @@ if (payload == ON) int chars = serialDataAvail (uart_fd); while (chars-- > 0) { - printf ("%c", c = serialGetchar (uart_fd)); + c = serialGetchar (uart_fd); +// printf ("%c", c); +// fflush(stdout); sensor_payload[i++] = c; - fflush (stdout); } } sensor_payload[i] = '\0'; printf("Payload string: %s\n", sensor_payload); + strcat(str, sensor_payload); // append to telemetry string for transmission } + digitalWrite (txLed, txLedOn); #ifdef DEBUG_LOGGING From 9c04919b88caecfd6619a9468e2de0621af2eeb1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:40:03 -0400 Subject: [PATCH 06/33] stop at newline --- afsk/main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d253f104..74a4a814 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -883,15 +883,23 @@ if (payload == ON) serialPutchar (uart_fd, '?'); printf("Querying payload with ?\n"); waitTime = millis() + 500; - while (millis() < waitTime) + end = false; + while ((millis() < waitTime) && !end) { int chars = serialDataAvail (uart_fd); - while (chars-- > 0) + while ((chars-- > 0) && !end) { c = serialGetchar (uart_fd); // printf ("%c", c); // fflush(stdout); - sensor_payload[i++] = c; + if (c != '\n') + { + sensor_payload[i++] = c; + } + else + { + end = true; + } } } sensor_payload[i] = '\0'; From dcc4e0211f20b17bb46bfad95b31d71cd602e723 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:42:19 -0400 Subject: [PATCH 07/33] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 74a4a814..41e98439 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -883,7 +883,7 @@ if (payload == ON) serialPutchar (uart_fd, '?'); printf("Querying payload with ?\n"); waitTime = millis() + 500; - end = false; + end = FALSE; while ((millis() < waitTime) && !end) { int chars = serialDataAvail (uart_fd); @@ -898,7 +898,7 @@ if (payload == ON) } else { - end = true; + end = TRUE; } } } From 925f2143ee22fcf72a6dddd7d44f21e3e60b6b4a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:43:35 -0400 Subject: [PATCH 08/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 41e98439..79c2c259 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -883,7 +883,7 @@ if (payload == ON) serialPutchar (uart_fd, '?'); printf("Querying payload with ?\n"); waitTime = millis() + 500; - end = FALSE; + int end = FALSE; while ((millis() < waitTime) && !end) { int chars = serialDataAvail (uart_fd); From d3e67d28e6010c609d678d8b3f9635db577079f5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:54:22 -0400 Subject: [PATCH 09/33] added TESTING flag so can test over Serial Monitor --- arduino/PayloadOK_Pro_Micro.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arduino/PayloadOK_Pro_Micro.ino b/arduino/PayloadOK_Pro_Micro.ino index 9af67fdf..345add8b 100644 --- a/arduino/PayloadOK_Pro_Micro.ino +++ b/arduino/PayloadOK_Pro_Micro.ino @@ -1,7 +1,14 @@ +//#define TESTING // Uncomment to test code on Serial Monitor + int counter = 0; int RXLED = 17; // The RX LED has a defined Arduino pin void setup() { + +#ifdef TESTING + Serial.begin(9600); +#endif + Serial1.begin(9600); digitalWrite(RXLED, LOW); // set the RX LED ON @@ -14,7 +21,20 @@ void setup() { void loop() { +#ifdef TESTING // ? is sent over Serial Monitor for testing if (Serial.available() > 0) { + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + char result = Serial.read(); + // Serial1.println(result); + Serial.println("OK"); + // Serial1.println(counter++); + } +#else // ? is sent by Pi UART + if (Serial1.available() > 0) { 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 delay(50); // wait for a second @@ -25,6 +45,7 @@ void loop() { Serial1.println("OK"); // Serial1.println(counter++); } +#endif delay(100); } From 2092c96cdfbcba9054c1196ac8072b661ebf1295 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 12:56:04 -0400 Subject: [PATCH 10/33] Create Payload_BME280_Pro_Micro.ino --- arduino/Payload_BME280_Pro_Micro.ino | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 arduino/Payload_BME280_Pro_Micro.ino diff --git a/arduino/Payload_BME280_Pro_Micro.ino b/arduino/Payload_BME280_Pro_Micro.ino new file mode 100644 index 00000000..6e07f5bd --- /dev/null +++ b/arduino/Payload_BME280_Pro_Micro.ino @@ -0,0 +1,80 @@ +#include +#include +#include +#define SEALEVELPRESSURE_HPA (1013.25) + +//#define TESTING // Define to test on Serial Monitor + +Adafruit_BME280 bme; +int counter = 0; +int RXLED = 17; // The RX LED has a defined Arduino pin + +void setup() { + + Serial.begin(9600); // Serial Monitor for testing + + Serial1.begin(9600); // Pi UART + + Serial.println("Starting!"); + + + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + + if (!bme.begin(0x76)) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } +} + +void loop() { + +#ifdef TESTING + if (Serial.available() > 0) { + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + char result = Serial.read(); + // Serial1.println(result); + Serial.print("OK BME280 "); + Serial.print(bme.readTemperature()); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.println(bme.readHumidity()); + + // Serial1.println(counter++); + } +#else + if (Serial1.available() > 0) { + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + char result = Serial1.read(); + // Serial1.println(result); +// Serial1.println("OK "); +/**/ + 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.println(bme.readHumidity()); +/**/ + // Serial1.println(counter++); + } +#endif + + delay(100); +} From d6b060135d5c74668cea521e5ec5996208678f63 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 18:29:00 -0400 Subject: [PATCH 11/33] added x, y, z angular velocity placeholders --- afsk/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 79c2c259..12382c93 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1043,6 +1043,7 @@ int get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; + int xAngularVelocity = 0, yAngularVelocity = 36, zAngularVelocity = 255; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; @@ -1218,7 +1219,11 @@ if (firstTime != ON) encodeB(b, 46 + head_offset,PSUCurrent); encodeA(b, 39 + head_offset, IHUcpuTemp); - + + encodeB(b, 40 + head_offset, xAngularVelocity); + encodeA(b, 42 + head_offset, yAngularVelocity); + encodeB(b, 43 + head_offset, zAngularVelocity); + encodeB(b, 51 + head_offset, STEMBoardFailure); short int data10[headerLen + rsFrames * (rsFrameLen + parityLen)]; From a44d8e2ad19a3d89135579f90538f1ae2728e4f0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 18:39:27 -0400 Subject: [PATCH 12/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 12382c93..5a08e2d2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1043,7 +1043,7 @@ int get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; - int xAngularVelocity = 0, yAngularVelocity = 36, zAngularVelocity = 255; // XAxisAngularVelocity + int xAngularVelocity = 1000, yAngularVelocity = 2000, zAngularVelocity = 3000; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; From 0aa830b7816509674f145d4164e398c95bb2999f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 18:57:06 -0400 Subject: [PATCH 13/33] added dps to Angular Velocity formula --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5a08e2d2..86d8b7bc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1043,7 +1043,8 @@ int get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; - int xAngularVelocity = 1000, yAngularVelocity = 2000, zAngularVelocity = 3000; // XAxisAngularVelocity +// AngularVelocity = 43.3 dps + 1960 + int xAngularVelocity = 43.3 * (-10) + 1960, yAngularVelocity = 43.3 * (-6) + 196, zAngularVelocity = 43.3 * (6) + 196; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; From edac4ead20bdb025e52e6d1cfbe73556bcb744dc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 18:59:31 -0400 Subject: [PATCH 14/33] typo in formula --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 86d8b7bc..8c6c4927 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1044,7 +1044,7 @@ int get_tlm_fox() { int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; // AngularVelocity = 43.3 dps + 1960 - int xAngularVelocity = 43.3 * (-10) + 1960, yAngularVelocity = 43.3 * (-6) + 196, zAngularVelocity = 43.3 * (6) + 196; // XAxisAngularVelocity + int xAngularVelocity = 43.3 * (-10) + 1960, yAngularVelocity = 43.3 * (-6) + 1960, zAngularVelocity = 43.3 * (6) + 1960; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; From 1e594e57128c4cb0c3c851a37d1eff3ac0ea2a58 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 19:05:22 -0400 Subject: [PATCH 15/33] refined formula about +/- 6 dps --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8c6c4927..98ae9161 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1043,8 +1043,8 @@ int get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; -// AngularVelocity = 43.3 dps + 1960 - int xAngularVelocity = 43.3 * (-10) + 1960, yAngularVelocity = 43.3 * (-6) + 1960, zAngularVelocity = 43.3 * (6) + 1960; // XAxisAngularVelocity +// AngularVelocity = 49.7 dps + 2059 + int xAngularVelocity = 49.7 * (-10) + 2059, yAngularVelocity = 49.7 * (-6) + 2059, zAngularVelocity = 49.7 * (6) + 2059; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; From b00a7db5ac7d247e8e3c5a45191aae3fb7b0f17d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 19:10:33 -0400 Subject: [PATCH 16/33] changed to polynomial formula --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 98ae9161..dd2bcac7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1044,7 +1044,7 @@ int get_tlm_fox() { int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; // AngularVelocity = 49.7 dps + 2059 - int xAngularVelocity = 49.7 * (-10) + 2059, yAngularVelocity = 49.7 * (-6) + 2059, zAngularVelocity = 49.7 * (6) + 2059; // XAxisAngularVelocity + int xAngularVelocity = (-0.69)*(-10)*(-10) + 45.3 * (-10) + 2078, yAngularVelocity = (-0.69)*(-6)*(-6) + 45.3 * (-6) + 2078, zAngularVelocity = (-0.69)*(6)*(6) + 45.3 * (6) + 2078; // XAxisAngularVelocity short int buffer_test[bufLen]; int buffSize; From e382a282ecbea9398536569ad91d4c3291481969 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 11:27:23 -0400 Subject: [PATCH 17/33] added read of Gyro X, Y, and Z from MPU6050 sensor --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 arduino/Payload_BME280_MPU6050_Pro_Micro.ino diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino new file mode 100644 index 00000000..dd01f61e --- /dev/null +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -0,0 +1,106 @@ +#include +#include +#include + +#define SEALEVELPRESSURE_HPA (1013.25) + +//#define TESTING // Define to test on Serial Monitor + +Adafruit_BME280 bme; +MPU6050 mpu6050(Wire); + +int counter = 0; +int RXLED = 17; // The RX LED has a defined Arduino pin +long timer = 0; + +void setup() { + + Serial.begin(9600); // Serial Monitor for testing + + Serial1.begin(9600); // Pi UART + + Serial.println("Starting!"); + + + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + + if (!bme.begin(0x76)) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } + + mpu6050.begin(); + mpu6050.calcGyroOffsets(true); +} + +void loop() { + +#ifdef TESTING + if (Serial.available() > 0) { + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + char result = Serial.read(); + // Serial1.println(result); + Serial.print("OK BME280 "); + Serial.print(bme.readTemperature()); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.println(bme.readHumidity()); + + mpu6050.update(); + + Serial.print(" MPU6050 "); + Serial.print(mpu6050.getGyroX()); + Serial.print(" "); + Serial.print(mpu6050.getGyroY()); + Serial.print(" "); + Serial.println(mpu6050.getGyroZ()); + + // Serial1.println(counter++); + } +#else + if (Serial1.available() > 0) { + 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 + delay(50); // wait for a second + digitalWrite(RXLED, HIGH); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF + char result = Serial1.read(); +// Serial1.println(result); +// Serial1.println("OK "); + + 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.println(bme.readHumidity()); + + mpu6050.update(); + + Serial1.print(" MPU6050 "); + Serial1.print(mpu6050.getGyroX()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroY()); + Serial1.print(" "); + Serial1.println(mpu6050.getGyroZ()); + +// Serial1.println(counter++); + } +#endif + + delay(100); +} From 48eb635ce56af8e536c14a0f99c7c78773b2bc4d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 11:35:28 -0400 Subject: [PATCH 18/33] Update Payload_BME280_MPU6050_Pro_Micro.ino --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index dd01f61e..74dee528 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -1,6 +1,6 @@ #include #include -#include #include #define SEALEVELPRESSURE_HPA (1013.25) @@ -56,7 +56,7 @@ void loop() { Serial.print(" "); Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); Serial.print(" "); - Serial.println(bme.readHumidity()); + Serial.print(bme.readHumidity()); mpu6050.update(); From aac514c882f4fca64532dbc5929fe463611bb8e9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 11:36:12 -0400 Subject: [PATCH 19/33] All on one line --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index 74dee528..0e8b5609 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -87,7 +87,7 @@ void loop() { Serial1.print(" "); Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); Serial1.print(" "); - Serial1.println(bme.readHumidity()); + Serial1.print(bme.readHumidity()); mpu6050.update(); From 6d756a766d7bdff9394eb4dfcd8a3e6febb7b0af Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:05:28 -0400 Subject: [PATCH 20/33] added tokenization of gyro string --- afsk/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index dd2bcac7..20e538a6 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -904,6 +904,40 @@ if (payload == ON) } sensor_payload[i] = '\0'; printf("Payload string: %s\n", sensor_payload); + + int count1; + char *token; +// char cmdbuffer[1000]; + +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); +// fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); +// pclose(file); + + const char space[2] = " "; + token = strtok(sensor_payload, space); + + float gyroX, gyroY, gyroZ; + + for (count1 = 0; count1 < 8; count1++) + { +// voltage[count1] = atof(token); + printf("token %s ", token); + token = strtok(NULL, space); +// current[count1] = atof(token); +// printf("current: %f\n", current[count1]); +// token = strtok(NULL, space); + } + gyroX = atof(token) + printf("gyroX %d ", gyroX); + token = strtok(NULL, space); + gyroY = atof(token) + printf("gyroY %d ", gyroY); + token = strtok(NULL, space); + gyroZ = atof(token) + printf("gyroZ %d \n", gyroZ); + token = strtok(NULL, space); + strcat(str, sensor_payload); // append to telemetry string for transmission } From a3d0be8b3d6a8ee8e362fd37a5347dfb49fa80bc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:06:45 -0400 Subject: [PATCH 21/33] typo --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 20e538a6..5c557a8d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -928,13 +928,13 @@ if (payload == ON) // printf("current: %f\n", current[count1]); // token = strtok(NULL, space); } - gyroX = atof(token) + gyroX = atof(token); printf("gyroX %d ", gyroX); token = strtok(NULL, space); - gyroY = atof(token) + gyroY = atof(token); printf("gyroY %d ", gyroY); token = strtok(NULL, space); - gyroZ = atof(token) + gyroZ = atof(token); printf("gyroZ %d \n", gyroZ); token = strtok(NULL, space); From ab442213ae0b37f699b2961b418533e0d45465d2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:11:29 -0400 Subject: [PATCH 22/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5c557a8d..48ab460e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -919,7 +919,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 8; count1++) + for (count1 = 0; count1 < 2; count1++) { // voltage[count1] = atof(token); printf("token %s ", token); From c7f09f4f1eb2c2f6d23fdc5468a012d83669467d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:18:09 -0400 Subject: [PATCH 23/33] Update main.c --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 48ab460e..3e035d2d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -919,7 +919,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 2; count1++) + for (count1 = 0; count1 < 6; count1++) { // voltage[count1] = atof(token); printf("token %s ", token); @@ -929,13 +929,13 @@ if (payload == ON) // token = strtok(NULL, space); } gyroX = atof(token); - printf("gyroX %d ", gyroX); + printf("gyroX %f ", gyroX); token = strtok(NULL, space); gyroY = atof(token); - printf("gyroY %d ", gyroY); + printf("gyroY %f ", gyroY); token = strtok(NULL, space); gyroZ = atof(token); - printf("gyroZ %d \n", gyroZ); + printf("gyroZ %f \n", gyroZ); token = strtok(NULL, space); strcat(str, sensor_payload); // append to telemetry string for transmission From 72adb1b5ad3b944fdda372e76597ef32a98864df Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:27:14 -0400 Subject: [PATCH 24/33] added gyro to FSK telemetry --- afsk/main.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 3e035d2d..f2cb9f39 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -922,20 +922,20 @@ if (payload == ON) for (count1 = 0; count1 < 6; count1++) { // voltage[count1] = atof(token); - printf("token %s ", token); +// printf("token %s ", token); token = strtok(NULL, space); // current[count1] = atof(token); // printf("current: %f\n", current[count1]); // token = strtok(NULL, space); } gyroX = atof(token); - printf("gyroX %f ", gyroX); +// printf("gyroX %f ", gyroX); token = strtok(NULL, space); gyroY = atof(token); - printf("gyroY %f ", gyroY); +// printf("gyroY %f ", gyroY); token = strtok(NULL, space); gyroZ = atof(token); - printf("gyroZ %f \n", gyroZ); +// printf("gyroZ %f \n", gyroZ); token = strtok(NULL, space); strcat(str, sensor_payload); // append to telemetry string for transmission @@ -1077,8 +1077,8 @@ int get_tlm_fox() { int posXv = 0, negXv = 0, posYv = 0, negYv = 0, posZv = 0, negZv = 0; int posXi = 0, negXi = 0, posYi = 0, negYi = 0, posZi = 0, negZi = 0; int head_offset = 0; -// AngularVelocity = 49.7 dps + 2059 - int xAngularVelocity = (-0.69)*(-10)*(-10) + 45.3 * (-10) + 2078, yAngularVelocity = (-0.69)*(-6)*(-6) + 45.3 * (-6) + 2078, zAngularVelocity = (-0.69)*(6)*(6) + 45.3 * (6) + 2078; // XAxisAngularVelocity +// int xAngularVelocity = (-0.69)*(-10)*(-10) + 45.3 * (-10) + 2078, yAngularVelocity = (-0.69)*(-6)*(-6) + 45.3 * (-6) + 2078, zAngularVelocity = (-0.69)*(6)*(6) + 45.3 * (6) + 2078; // XAxisAngularVelocity + int xAngularVelocity = 2078, yAngularVelocity = 2078, zAngularVelocity = 2078; // XAxisAngularVelocity Y and Z set to 0 short int buffer_test[bufLen]; int buffSize; @@ -1209,8 +1209,83 @@ if (firstTime != ON) PSUVoltage = (int)(reading[BUS].voltage * 100); PSUCurrent = (int)reading[BUS].current + 2048; - if (payload == ON) - STEMBoardFailure = 0; +// if (payload == ON) +// STEMBoardFailure = 0; + +// read payload sensor if available + +char sensor_payload[500]; + +if (payload == ON) +{ + STEMBoardFailure = 0; + + char c; + unsigned int waitTime; + int i = 0; + + serialPutchar (uart_fd, '?'); + printf("Querying payload with ?\n"); + waitTime = millis() + 500; + int end = FALSE; + while ((millis() < waitTime) && !end) + { + int chars = serialDataAvail (uart_fd); + while ((chars-- > 0) && !end) + { + c = serialGetchar (uart_fd); +// printf ("%c", c); +// fflush(stdout); + if (c != '\n') + { + sensor_payload[i++] = c; + } + else + { + end = TRUE; + } + } + } + sensor_payload[i] = '\0'; + printf("Payload string: %s\n", sensor_payload); + + int count1; + char *token; +// char cmdbuffer[1000]; + +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); +// fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); +// pclose(file); + + const char space[2] = " "; + token = strtok(sensor_payload, space); + + float gyroX, gyroY, gyroZ; + + for (count1 = 0; count1 < 6; count1++) + { +// voltage[count1] = atof(token); +// printf("token %s ", token); + token = strtok(NULL, space); +// current[count1] = atof(token); +// printf("current: %f\n", current[count1]); +// token = strtok(NULL, space); + } + gyroX = atof(token); + printf("gyroX %f ", gyroX); + token = strtok(NULL, space); + gyroY = atof(token); + printf("gyroY %f ", gyroY); + token = strtok(NULL, space); + gyroZ = atof(token); + printf("gyroZ %f \n", gyroZ); +// token = strtok(NULL, space); + + xAngularVelocity = (-0.69)*(gyroX)*(gyroX) + 45.3 * (gyroX) + 2078; + yAngularVelocity = (-0.69)*(gyroY)*(gyroY) + 45.3 * (gyroY) + 2078; + zAngularVelocity = (-0.69)*(gyroZ)*(gyroZ) + 45.3 * (gyroZ) + 2078; + } encodeA(b, 0 + head_offset, batt_a_v); encodeB(b, 1 + head_offset, batt_b_v); From 907d20358c4bc12cdbe52a57acde945fcbebf6c0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:37:57 -0400 Subject: [PATCH 25/33] skip BME280 Data --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f2cb9f39..b49c34e7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -919,7 +919,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 6; count1++) + for (count1 = 0; count1 < 7; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data { // voltage[count1] = atof(token); // printf("token %s ", token); From cfeee7da97ad73edf11b710f594296a1cc3b1bcc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:40:53 -0400 Subject: [PATCH 26/33] one more --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b49c34e7..22c0e246 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -919,7 +919,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 7; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data + for (count1 = 0; count1 < 8; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data { // voltage[count1] = atof(token); // printf("token %s ", token); From 8dbc43f8e4580485ba86ee0080f379e9b5882915 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:43:22 -0400 Subject: [PATCH 27/33] skipping over BME280 data --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 22c0e246..44c0598a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -919,7 +919,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 8; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data + for (count1 = 0; count1 < 7; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data { // voltage[count1] = atof(token); // printf("token %s ", token); @@ -1263,7 +1263,7 @@ if (payload == ON) float gyroX, gyroY, gyroZ; - for (count1 = 0; count1 < 6; count1++) + for (count1 = 0; count1 < 7; count1++) // skipping over BME280 data { // voltage[count1] = atof(token); // printf("token %s ", token); From e1911f3a6bec3487b6aebd608a379673fc94f63e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 12:46:48 -0400 Subject: [PATCH 28/33] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 44c0598a..d37e3507 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1277,7 +1277,7 @@ if (payload == ON) token = strtok(NULL, space); gyroY = atof(token); printf("gyroY %f ", gyroY); - token = strtok(NULL, space); +// token = strtok(NULL, space); gyroZ = atof(token); printf("gyroZ %f \n", gyroZ); // token = strtok(NULL, space); From 5899390305250c0879f565ae7f7811e18e5a1497 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 16:13:55 -0400 Subject: [PATCH 29/33] added \n before \0 --- afsk/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d37e3507..e84999e1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -902,8 +902,9 @@ if (payload == ON) } } } + sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; - printf("Payload string: %s\n", sensor_payload); + printf("Payload string: %s", sensor_payload); int count1; char *token; @@ -1246,8 +1247,9 @@ if (payload == ON) } } } + sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; - printf("Payload string: %s\n", sensor_payload); + printf("Payload string: %s", sensor_payload); int count1; char *token; @@ -1277,7 +1279,7 @@ if (payload == ON) token = strtok(NULL, space); gyroY = atof(token); printf("gyroY %f ", gyroY); -// token = strtok(NULL, space); + token = strtok(NULL, space); gyroZ = atof(token); printf("gyroZ %f \n", gyroZ); // token = strtok(NULL, space); From 88da3241a4d4669ba020adb0ecf4298d15ae7ce0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 16:17:55 -0400 Subject: [PATCH 30/33] added space at end of string --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index e84999e1..db8e243c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1247,6 +1247,7 @@ if (payload == ON) } } } + sensor_payload[i++] = ' '; sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s", sensor_payload); From 5b25abc58b68f8fd51a105f69f6048ed3fff96b9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 17:01:10 -0400 Subject: [PATCH 31/33] added NULL checking in token parsing --- afsk/main.c | 70 +++++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index db8e243c..880d7cc5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -905,44 +905,10 @@ if (payload == ON) sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s", sensor_payload); - - int count1; - char *token; -// char cmdbuffer[1000]; - -// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); -// fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); -// pclose(file); - - const char space[2] = " "; - token = strtok(sensor_payload, space); - - float gyroX, gyroY, gyroZ; - - for (count1 = 0; count1 < 7; count1++) // skip over BME280 data to get to X, Y, and Z Gyro data - { -// voltage[count1] = atof(token); -// printf("token %s ", token); - token = strtok(NULL, space); -// current[count1] = atof(token); -// printf("current: %f\n", current[count1]); -// token = strtok(NULL, space); - } - gyroX = atof(token); -// printf("gyroX %f ", gyroX); - token = strtok(NULL, space); - gyroY = atof(token); -// printf("gyroY %f ", gyroY); - token = strtok(NULL, space); - gyroZ = atof(token); -// printf("gyroZ %f \n", gyroZ); - token = strtok(NULL, space); - + strcat(str, sensor_payload); // append to telemetry string for transmission } - digitalWrite (txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n"); @@ -1268,22 +1234,26 @@ if (payload == ON) for (count1 = 0; count1 < 7; count1++) // skipping over BME280 data { -// voltage[count1] = atof(token); -// printf("token %s ", token); - token = strtok(NULL, space); -// current[count1] = atof(token); -// printf("current: %f\n", current[count1]); -// token = strtok(NULL, space); + if (token != NULL) + token = strtok(NULL, space); } - gyroX = atof(token); - printf("gyroX %f ", gyroX); - token = strtok(NULL, space); - gyroY = atof(token); - printf("gyroY %f ", gyroY); - token = strtok(NULL, space); - gyroZ = atof(token); - printf("gyroZ %f \n", gyroZ); -// token = strtok(NULL, space); + if (token != NULL) + { + gyroX = atof(token); + printf("gyroX %f ", gyroX); + token = strtok(NULL, space); + } + if (token != NULL) + { + gyroY = atof(token); + printf("gyroY %f ", gyroY); + token = strtok(NULL, space); + } + if (token != NULL) + { + gyroZ = atof(token); + printf("gyroZ %f \n", gyroZ); + } xAngularVelocity = (-0.69)*(gyroX)*(gyroX) + 45.3 * (gyroX) + 2078; yAngularVelocity = (-0.69)*(gyroY)*(gyroY) + 45.3 * (gyroY) + 2078; From d07e893d12d59c2bd1ac8148212cbb1a7d6335be Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 31 Aug 2020 17:09:39 -0400 Subject: [PATCH 32/33] removed newline in AFSK payload telemetry to avoid direwolf crash --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 880d7cc5..85aab3dd 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1214,7 +1214,7 @@ if (payload == ON) } } sensor_payload[i++] = ' '; - sensor_payload[i++] = '\n'; +// sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s", sensor_payload); From 763970b9c610357d182c5c9a80a58426527db90a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 31 Aug 2020 17:22:29 -0400 Subject: [PATCH 33/33] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 85aab3dd..5bfa9e1c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -902,7 +902,7 @@ if (payload == ON) } } } - sensor_payload[i++] = '\n'; +// sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s", sensor_payload); @@ -1214,7 +1214,7 @@ if (payload == ON) } } sensor_payload[i++] = ' '; -// sensor_payload[i++] = '\n'; + sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s", sensor_payload);