diff --git a/afsk/main.c b/afsk/main.c index dc3528fe..5bfa9e1c 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) @@ -869,6 +869,46 @@ 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 + +char sensor_payload[500]; + +if (payload == ON) +{ + 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++] = '\n'; + sensor_payload[i] = '\0'; + printf("Payload string: %s", sensor_payload); + + strcat(str, sensor_payload); // append to telemetry string for transmission +} + digitalWrite (txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n"); @@ -1004,6 +1044,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 = (-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; @@ -1134,8 +1176,89 @@ 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++] = ' '; + 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++) // skipping over BME280 data + { + if (token != NULL) + 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; + 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); @@ -1179,7 +1302,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)]; 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); } diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino new file mode 100644 index 00000000..0e8b5609 --- /dev/null +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -0,0 +1,106 @@ +#include +#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.print(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.print(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); +} 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); +}