From 41167346c6eed66243b5ede12f97748d3f7c238b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 10:23:25 -0400 Subject: [PATCH 01/59] Rename PayloadOK.ino to PayloadOK_STM32.ino --- arduino/{PayloadOK.ino => PayloadOK_STM32.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arduino/{PayloadOK.ino => PayloadOK_STM32.ino} (100%) diff --git a/arduino/PayloadOK.ino b/arduino/PayloadOK_STM32.ino similarity index 100% rename from arduino/PayloadOK.ino rename to arduino/PayloadOK_STM32.ino From ddcbf71bbb2e50cfd8f2501257818566bbf2541a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 10:23:54 -0400 Subject: [PATCH 02/59] Rename PayloadOK_STM32.ino to PayloadOK_STM32_PC13.ino --- arduino/{PayloadOK_STM32.ino => PayloadOK_STM32_PC13.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arduino/{PayloadOK_STM32.ino => PayloadOK_STM32_PC13.ino} (100%) diff --git a/arduino/PayloadOK_STM32.ino b/arduino/PayloadOK_STM32_PC13.ino similarity index 100% rename from arduino/PayloadOK_STM32.ino rename to arduino/PayloadOK_STM32_PC13.ino From c5a211f5658c933c9dc7f249ad3dfcc5e6040835 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 10:27:02 -0400 Subject: [PATCH 03/59] Update README.md --- arduino/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arduino/README.md b/arduino/README.md index 816a040e..2688d675 100644 --- a/arduino/README.md +++ b/arduino/README.md @@ -1,15 +1,17 @@ This code is for the STM32 or Pro Micro acting as a payload to the CubeSatSim. -Code includes: - -i2c_scanner.ino A handy utility for scanning the I2C bus that displays the results in the Serial Monitor at 9600 baud. If the sensors are installed and the jumpers set to the correct position, the two sensors should be displayed. +Code includes (in rough order of testing): Blink_STM32_PC13.ino and Blink_Pro_Micro.ino The usual Arduino "Hello World" application that blinks the LED for each board. +i2c_scanner.ino A handy utility for scanning the I2C bus that displays the results in the Serial Monitor at 9600 baud. If the sensors are installed and the jumpers set to the correct position, the two sensors should be displayed. + bme280test.ino Displays the results of reading the BME280 sensor: Temperature, Pressure, Altitude, and Humidity and displays on Serial Monitor 9600 baud. Requires the following libraries: Adadruit Unified Sensor (specify version 1.0.3), Adafruit_BME280 (specify version 1.1.0) GetAllData.ino Displays the results of reading the MPU6050 sensor: Temperature, X, Y, and Z Axes: Acceleration, Gyor (Rotation Rate), and Angle. Requires the following libraries: MPU6050_tockn. +PayloadOK_STM32_PC13.ino and PayloadOK_Pro_Micro.ino This code answers the query from the Raspberry Pi CubeSatSim software over the UART so that the STEM Payload is marked "OK" in the FoxTelem CubeSatSim-FSK Health tab. + The STM32 can be programmed using the Arduino IDE with the Generic STM32F103C series board and STM32duino bootloader, Maple Mini port. The Sparkfun Pro Micro can also be programed using the Arduino IDE with the Sparkfun Pro Micro board and AVRISP mkII Programmer. From 8f99fe4a0d8b48696c7bc86d39535bedace528c8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 10:50:02 -0400 Subject: [PATCH 04/59] Create STEM_Payload_Test.ino --- arduino/STEM_Payload_Test.ino | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 arduino/STEM_Payload_Test.ino diff --git a/arduino/STEM_Payload_Test.ino b/arduino/STEM_Payload_Test.ino new file mode 100644 index 00000000..7a9d4734 --- /dev/null +++ b/arduino/STEM_Payload_Test.ino @@ -0,0 +1,50 @@ +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + Most Arduinos have an on-board LED you can control. On the Uno and + Leonardo, it is attached to digital pin 13. If you're unsure what + pin the on-board LED is connected to on your Arduino model, check + the documentation at http://arduino.cc + + This example code is in the public domain. + + modified 8 May 2014 + by Scott Fitzgerald + + Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13 + + Added CubeSatSim Payload tests by Alan Johnston, KU2Y + + */ + +int sensorValue = 0; + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin PB1 as an output. + pinMode(PB9, OUTPUT); + pinMode(PB8, OUTPUT); + pinMode(PA0, INPUT_ANALOG); + pinMode(PA1, INPUT_ANALOG); + pinMode(PA2, INPUT_ANALOG); + + Serial.begin(9600); + } + +// the loop function runs over and over again forever +void loop() { + digitalWrite(PB9, HIGH); // turn the LED on (HIGH is the voltage level) + digitalWrite(PB8, LOW); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(PB9, LOW); // turn the LED off by making the voltage LOW + digitalWrite(PB8, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + + sensorValue = analogRead(PA0); + Serial.println(sensorValue); + sensorValue = analogRead(PA1); + Serial.println(sensorValue); + sensorValue = analogRead(PA2); + Serial.println(sensorValue); +} From 98b52d475503b3d74f70e29aa8e2f0bb227d9f7f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 10:54:55 -0400 Subject: [PATCH 05/59] Rename STEM_Payload_Test.ino to STEM_Payload_Test_STM32.ino --- arduino/{STEM_Payload_Test.ino => STEM_Payload_Test_STM32.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arduino/{STEM_Payload_Test.ino => STEM_Payload_Test_STM32.ino} (100%) diff --git a/arduino/STEM_Payload_Test.ino b/arduino/STEM_Payload_Test_STM32.ino similarity index 100% rename from arduino/STEM_Payload_Test.ino rename to arduino/STEM_Payload_Test_STM32.ino From 7b46c5061e314e606726a1281216cb3e5338ed4f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 11:11:16 -0400 Subject: [PATCH 06/59] Create STEM_Payload_Test_Pro_Micro --- arduino/STEM_Payload_Test_Pro_Micro | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 arduino/STEM_Payload_Test_Pro_Micro diff --git a/arduino/STEM_Payload_Test_Pro_Micro b/arduino/STEM_Payload_Test_Pro_Micro new file mode 100644 index 00000000..51b2f666 --- /dev/null +++ b/arduino/STEM_Payload_Test_Pro_Micro @@ -0,0 +1,46 @@ +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + Most Arduinos have an on-board LED you can control. On the Uno and + Leonardo, it is attached to digital pin 13. If you're unsure what + pin the on-board LED is connected to on your Arduino model, check + the documentation at http://arduino.cc + This example code is in the public domain. + modified 8 May 2014 + by Scott Fitzgerald + + Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13 + + Added CubeSatSim Payload tests by Alan Johnston, KU2Y + + */ + +int sensorValue = 0; +int D9 = 9; +int D8 = 8; + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin PB1 as an output. + pinMode(D9, OUTPUT); + pinMode(D8, OUTPUT); + + Serial.begin(9600); + } + +// the loop function runs over and over again forever +void loop() { + digitalWrite(D9, HIGH); // turn the LED on (HIGH is the voltage level) + digitalWrite(D8, LOW); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(D9, LOW); // turn the LED off by making the voltage LOW + digitalWrite(D8, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + + sensorValue = analogRead(A0); + Serial.println(sensorValue); + sensorValue = analogRead(A1); + Serial.println(sensorValue); + sensorValue = analogRead(A2); + Serial.println(sensorValue); +} From 8a7e42846adae63b2a7da487bbe9c9bbc569d055 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 11:11:45 -0400 Subject: [PATCH 07/59] Rename STEM_Payload_Test_Pro_Micro to STEM_Payload_Test_Pro_Micro.ino --- ...TEM_Payload_Test_Pro_Micro => STEM_Payload_Test_Pro_Micro.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arduino/{STEM_Payload_Test_Pro_Micro => STEM_Payload_Test_Pro_Micro.ino} (100%) diff --git a/arduino/STEM_Payload_Test_Pro_Micro b/arduino/STEM_Payload_Test_Pro_Micro.ino similarity index 100% rename from arduino/STEM_Payload_Test_Pro_Micro rename to arduino/STEM_Payload_Test_Pro_Micro.ino From e2dc16b8d8ad8cc73ac6abb78ef5712f23b528a7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 11:14:50 -0400 Subject: [PATCH 08/59] Update README.md --- arduino/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arduino/README.md b/arduino/README.md index 2688d675..697f89c0 100644 --- a/arduino/README.md +++ b/arduino/README.md @@ -6,6 +6,8 @@ Blink_STM32_PC13.ino and Blink_Pro_Micro.ino The usual Arduino "Hello World" ap i2c_scanner.ino A handy utility for scanning the I2C bus that displays the results in the Serial Monitor at 9600 baud. If the sensors are installed and the jumpers set to the correct position, the two sensors should be displayed. +STEM_Payload_Test_STM32.ino and STEM_Payload_Test_Pro_Micro.ino Blinks the Blue and Green LEDs on the STEM Payload Board and also reads the Temperature and Voltage sensors. + bme280test.ino Displays the results of reading the BME280 sensor: Temperature, Pressure, Altitude, and Humidity and displays on Serial Monitor 9600 baud. Requires the following libraries: Adadruit Unified Sensor (specify version 1.0.3), Adafruit_BME280 (specify version 1.1.0) GetAllData.ino Displays the results of reading the MPU6050 sensor: Temperature, X, Y, and Z Axes: Acceleration, Gyor (Rotation Rate), and Angle. Requires the following libraries: MPU6050_tockn. From e47d8979939e2b89313e89203b02ae9fc17e0542 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 15:08:35 -0400 Subject: [PATCH 09/59] added 4 second delay in AFSK mode to wait for CW ID to complete --- afsk/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index d5a17302..6c20c5b3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -530,6 +530,9 @@ else //uint8_t data[1024]; tx_freq_hz -= tx_channel * 50000; + + if (mode == AFSK) + sleep(4); // delay awaiting CW ID completion /* if (transmit == FALSE) { From ca0acfb3c37f993cfc54215ae8cf2179651bfc20 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 15:10:05 -0400 Subject: [PATCH 10/59] increased sleep to 10 sec --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6c20c5b3..d4300919 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -532,7 +532,7 @@ else tx_freq_hz -= tx_channel * 50000; if (mode == AFSK) - sleep(4); // delay awaiting CW ID completion + sleep(10); // delay awaiting CW ID completion /* if (transmit == FALSE) { From 24ffb1faf9a2187f9b155843e39bbe57fa465b6c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 13 Aug 2020 16:38:15 -0400 Subject: [PATCH 11/59] Fixed AFSK transmit frequency --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index d4300919..dc3528fe 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -828,7 +828,7 @@ for (int j = 0; j < frameCnt; j++) char header_str2[] = ">CQ:hi hi "; char header_str4[] = "hi hi "; char footer_str1[] = "\' > t.txt && echo \'"; - char footer_str[] = ">CQ:hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3 > /dev/null 2>&1"; + char footer_str[] = ">CQ:hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1"; if (ax5043) { From bae88ca5d19fd151d9e7d79886bedc48a8222611 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 15 Aug 2020 08:33:26 -0400 Subject: [PATCH 12/59] Update README.md --- README.md | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index a40d8112..c277d5fb 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,5 @@ # CubeSatSim -To test out the PD120 SSTV image transmit after performing the software install steps below: - - -`cd ~/CubeSatSim` - -`git checkout dev` - -`git pull` - -`echo "ARG1=s" > .mode` - -`cd ~/pi-power-button` - -`git checkout dev` - -`git pull` - -`./script/install` - -`sudo systemctl restart cubesatsim` - - - - -You can also press and hold the push button and release on 4 flashes to switch to SSTV mode! - The CubeSat Simulator https://github.com/alanbjohnston/CubeSatSim/wiki is a low cost satellite emulator that runs on solar panels and batteries, transmits UHF radio telemetry, has a 3D printed frame, and can be extended by additional sensors and modules. This project is sponsored by the not-for-profit [Radio Amateur Satellite Corporation, AMSATĀ®](https://amsat.org). There are several hardware versions and software branches to go with them - see below for information. @@ -182,11 +156,13 @@ Press and release after two blinks of green LED: switches to FSK mode. After abo Press and release after three blinks of green LED: switches to BPSK mode. After about 5 seconds, the telemetry mode will switch to BPSK. +Press and release after four blinks of green LED: switches to SSTV mode. SSTV images in PD120 mode will be transmitted instead of telemetry. + Press and release after green LED begins slow blinking: shuts down CubeSatSim. Once the CubeSatSim shuts down, the RBF pin can then be safely inserted. Removing the RBF pin or pressing the push button will cause the CubeSatSim to start up again. It will use the same mode it was running when it was shutdown. -You can also change the telemetry mode using the command line. Edit the CubeSatSim/.mode file and change the value to change the mode. A value of ARG1=a will give you AFSK, ARG1=f will give you FSK, and ARG2=b gives BPSK. After saving the .mode file, restart the cubesatsim service to switch the mode by typing: +You can also change the telemetry mode using the command line. Edit the CubeSatSim/.mode file and change the value to change the mode. A value of ARG1=a will give you AFSK, ARG1=f will give you FSK, ARG1=b gives BPSK, and ARG1=s gives SSTV. After saving the .mode file, restart the cubesatsim service to switch the mode by typing: `sudo systemctl restart cubesatsim` From 6b432a46983a46963a5f4c5332fd69aa07ce209a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 15 Aug 2020 08:36:11 -0400 Subject: [PATCH 13/59] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c277d5fb..2ffa77ed 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ you should see two I2C buses: `i2c-1 i2c-3` +Note, you might see these two I2C buses - this is fine to: + +`i2c-1 i2c-11` + Continue the install by typing: `cd` From 062f37f55832146171837455d74e8ee6ce9e6d16 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 15 Aug 2020 09:39:35 -0400 Subject: [PATCH 14/59] changed for continuous SSTV to avoid frequency changing --- rpitx.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rpitx.py b/rpitx.py index ba90e7e0..4b45a87d 100644 --- a/rpitx.py +++ b/rpitx.py @@ -51,14 +51,14 @@ if __name__ == "__main__": time.sleep(5) elif (('s' == sys.argv[1]) or ('sstv' in sys.argv[1])): print("SSTV") -# os.system("(while true; do (sleep 10 && cat /home/pi/CubeSatSim/wav/sstv.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3); done)") - while True: - GPIO.output(txLed, txLedOff); - print("Sleeping") - time.sleep(10) - print("Transmitting SSTV") - GPIO.output(txLed, txLedOn); - os.system("cat /home/pi/CubeSatSim/wav/sstv.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") + os.system("(while true; do (sleep 5 && cat /home/pi/CubeSatSim/wav/sstv.wav); done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") +# while True: +# GPIO.output(txLed, txLedOff); +# print("Sleeping") +# time.sleep(10) +# print("Transmitting SSTV") +# GPIO.output(txLed, txLedOn); +# os.system("cat /home/pi/CubeSatSim/wav/sstv.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") elif (('b' == sys.argv[1]) or ('bpsk' in sys.argv[1])): print("BPSK") os.system("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float") From c264be655552b9e1e8d51b65a5c714ff837c1f7e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 15 Aug 2020 10:20:46 -0400 Subject: [PATCH 15/59] Turned on Blue Tx LED for SSTV bash call --- rpitx.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rpitx.py b/rpitx.py index 4b45a87d..1db4dbb2 100644 --- a/rpitx.py +++ b/rpitx.py @@ -51,6 +51,7 @@ if __name__ == "__main__": time.sleep(5) elif (('s' == sys.argv[1]) or ('sstv' in sys.argv[1])): print("SSTV") + GPIO.output(txLed, txLedOn); os.system("(while true; do (sleep 5 && cat /home/pi/CubeSatSim/wav/sstv.wav); done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # while True: # GPIO.output(txLed, txLedOff); From d11c59540418dbd3396081a4ceb2730220f806a3 Mon Sep 17 00:00:00 2001 From: CMehner-space <69016840+CMehner-space@users.noreply.github.com> Date: Mon, 17 Aug 2020 08:52:03 -0400 Subject: [PATCH 16/59] Update bme280test.ino --- arduino/bme280test.ino | 94 ++++++++++-------------------------------- 1 file changed, 21 insertions(+), 73 deletions(-) diff --git a/arduino/bme280test.ino b/arduino/bme280test.ino index 9fb8c432..d21be5a1 100644 --- a/arduino/bme280test.ino +++ b/arduino/bme280test.ino @@ -1,89 +1,37 @@ -/*************************************************************************** - This is a library for the BME280 humidity, temperature & pressure sensor - - Designed specifically to work with the Adafruit BME280 Breakout - ----> http://www.adafruit.com/products/2650 - - These sensors use I2C or SPI to communicate, 2 or 4 pins are required - to interface. The device's I2C address is either 0x76 or 0x77. - - Adafruit invests time and resources providing this open source code, - please support Adafruit andopen-source hardware by purchasing products - from Adafruit! - - Written by Limor Fried & Kevin Townsend for Adafruit Industries. - BSD license, all text above must be included in any redistribution - See the LICENSE file for details. - ***************************************************************************/ - #include -#include #include #include -#define BME_SCK 13 -#define BME_MISO 12 -#define BME_MOSI 11 -#define BME_CS 10 - #define SEALEVELPRESSURE_HPA (1013.25) -Adafruit_BME280 bme; // I2C -//Adafruit_BME280 bme(BME_CS); // hardware SPI -//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI - -unsigned long delayTime; +Adafruit_BME280 bme; void setup() { - Serial.begin(9600); - while(!Serial); // time to get serial running - Serial.println(F("BME280 test")); + Serial.begin(9600); - unsigned status; - - // default settings - // (you can also pass in a Wire library object like &Wire2) - status = bme.begin(); - if (!status) { - Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!"); - Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16); - Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); - Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); - Serial.print(" ID of 0x60 represents a BME 280.\n"); - Serial.print(" ID of 0x61 represents a BME 680.\n"); - while (1); - } - - Serial.println("-- Default Test --"); - delayTime = 1000; - - Serial.println(); -} - - -void loop() { - printValues(); - delay(delayTime); + if (!bme.begin(0x76)) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } } +void loop() { + Serial.print("Temperature = "); + Serial.print(bme.readTemperature()); + Serial.println("*C"); -void printValues() { - Serial.print("Temperature = "); - Serial.print(bme.readTemperature()); - Serial.println(" *C"); - - Serial.print("Pressure = "); - - Serial.print(bme.readPressure() / 100.0F); - Serial.println(" hPa"); + Serial.print("Pressure = "); + Serial.print(bme.readPressure() / 100.0F); + Serial.println("hPa"); - Serial.print("Approx. Altitude = "); - Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); - Serial.println(" m"); + Serial.print("Approx. Altitude = "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.println("m"); - Serial.print("Humidity = "); - Serial.print(bme.readHumidity()); - Serial.println(" %"); + Serial.print("Humidity = "); + Serial.print(bme.readHumidity()); + Serial.println("%"); - Serial.println(); + Serial.println(); + delay(1000); } From ee8e8efec5c422a9cf8c0a316f17c77d763b42c8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 11:53:31 -0400 Subject: [PATCH 17/59] 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 18/59] 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 19/59] 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 20/59] 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 21/59] 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 22/59] 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 23/59] 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 24/59] 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 25/59] 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 26/59] 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 27/59] 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 28/59] 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 29/59] 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 30/59] 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 31/59] 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 32/59] 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 4a635386fed59267d284e4f21e9198a8a8d2c364 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 23 Aug 2020 19:59:32 -0400 Subject: [PATCH 33/59] updated gpio overlay to specify bus 3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ffa77ed..7a09fe68 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Use the down arrow key to go down in the file until you find this line: Add the following two lines under it: (NOTE: there seems to be an issue with the i2c-gpio.dtbo file in the latest kernal. I'm investigating this temporary fix: https://github.com/raspberrypi/firmware/issues/1401. If adding dtoverlay=i2c-gpio in this step causes your Pi not to boot, then you are encountering this issue) -`dtoverlay=i2c-gpio` +`dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24` `dtoverlay=pi3-miniuart-bt` From e382a282ecbea9398536569ad91d4c3291481969 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 24 Aug 2020 11:27:23 -0400 Subject: [PATCH 34/59] 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 35/59] 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 36/59] 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 37/59] 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 38/59] 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 39/59] 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 40/59] 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 41/59] 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 42/59] 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 43/59] 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 44/59] 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 45/59] 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 46/59] 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 47/59] 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 48/59] 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 49/59] 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 50/59] 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); From b15e131740cf6f65e0a05071ca6c50f202d499f9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 31 Aug 2020 23:21:58 -0400 Subject: [PATCH 51/59] Not working yet --- arduino/Payload_BME280_MPU6050_STM32.ino | 103 +++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 arduino/Payload_BME280_MPU6050_STM32.ino diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino new file mode 100644 index 00000000..56bddc74 --- /dev/null +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -0,0 +1,103 @@ +#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; +long timer = 0; + +void setup() { + + Serial.begin(9600); // Serial Monitor for testing + + Serial1.begin(9600); // Pi UART + + Serial.println("Starting!"); + + pinMode(PC13, OUTPUT); + digitalWrite(PC13, LOW); // turn the LED on + delay(50); // wait for a second + digitalWrite(PC13, HIGH); // turn the 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(PC13, LOW); // turn the LED on + delay(50); // wait for a second + digitalWrite(PC13, HIGH); // turn the 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(PC13, LOW); // turn the LED on + delay(50); // wait for a second + digitalWrite(PC13, HIGH); // turn the 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); +} From f14c98bc169310c8ab756d5ba3bbf130c2cefcc0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 09:35:32 -0400 Subject: [PATCH 52/59] took out while loop on no bme280 detected --- 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 0e8b5609..ad7d3a28 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -31,7 +31,7 @@ void setup() { if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); - while (1); +// while (1); } mpu6050.begin(); From 3a34db7414f2134e258b9c0a502114924e6aa44f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 09:44:47 -0400 Subject: [PATCH 53/59] if no bme280 present, send all 0's --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 48 ++++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index ad7d3a28..5136fe63 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -13,6 +13,7 @@ MPU6050 mpu6050(Wire); int counter = 0; int RXLED = 17; // The RX LED has a defined Arduino pin long timer = 0; +bmePresent = TRUE; void setup() { @@ -31,7 +32,7 @@ void setup() { if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); -// while (1); + bmePresent = FALSE; } mpu6050.begin(); @@ -49,15 +50,19 @@ void loop() { 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()); - + if (bmePresent) { + 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()); + } else + { + Serial.println("OK BME280 0.0 0.0 0.0 0.0"); + } mpu6050.update(); Serial.print(" MPU6050 "); @@ -79,16 +84,19 @@ void loop() { 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()); - + if (bmePresent) { + 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()); + } else + { + Serial1.println("OK BME280 0.0 0.0 0.0 0.0"); + } mpu6050.update(); Serial1.print(" MPU6050 "); From 3e798814443f0ca22f4a4b6096f7739708d12508 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 10:05:30 -0400 Subject: [PATCH 54/59] removed println --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index 5136fe63..0c9054e1 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -13,7 +13,7 @@ MPU6050 mpu6050(Wire); int counter = 0; int RXLED = 17; // The RX LED has a defined Arduino pin long timer = 0; -bmePresent = TRUE; +bmePresent = 1; void setup() { @@ -32,7 +32,7 @@ void setup() { if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); - bmePresent = FALSE; + bmePresent = 0; } mpu6050.begin(); @@ -61,7 +61,7 @@ void loop() { Serial.print(bme.readHumidity()); } else { - Serial.println("OK BME280 0.0 0.0 0.0 0.0"); + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); } mpu6050.update(); @@ -95,7 +95,7 @@ void loop() { Serial1.print(bme.readHumidity()); } else { - Serial1.println("OK BME280 0.0 0.0 0.0 0.0"); + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); } mpu6050.update(); From 3e93f9bebbc00e6a83bfd62f17282ceac8762688 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 10:14:17 -0400 Subject: [PATCH 55/59] If receive a R, reset payload --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index 0c9054e1..0847a2a6 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -50,6 +50,8 @@ void loop() { 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); + if (result == 'R') + setup(); if (bmePresent) { Serial.print("OK BME280 "); Serial.print(bme.readTemperature()); @@ -83,7 +85,8 @@ void loop() { 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 "); + if (result == 'R') + setup(); if (bmePresent) { Serial1.print("OK BME280 "); Serial1.print(bme.readTemperature()); From 4f0e0ca66ef74d97777854308b8e134f72c17a77 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 10:20:26 -0400 Subject: [PATCH 56/59] first payload UART query with R instead of ? to reset payload --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5bfa9e1c..9fa7aff7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -495,8 +495,8 @@ else int i; for(i = 0; i < 2; i++) { - serialPutchar (uart_fd, '?'); - printf("Querying payload with ?\n"); + serialPutchar (uart_fd, 'R'); + printf("Querying payload with R to reset\n"); waitTime = millis() + 500; while ((millis() < waitTime) && (payload != ON)) { From 0f3fe767c26a54d2fb24fefde1e670f8a2488491 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 11:20:39 -0400 Subject: [PATCH 57/59] resets at start with R, sends 0's if no sensor present --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 27 +++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index 0847a2a6..d234f6cf 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -13,7 +13,7 @@ MPU6050 mpu6050(Wire); int counter = 0; int RXLED = 17; // The RX LED has a defined Arduino pin long timer = 0; -bmePresent = 1; +int bmePresent; void setup() { @@ -23,14 +23,15 @@ void setup() { 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)) { + if (bme.begin(0x76)) { + bmePresent = 1; + } else { Serial.println("Could not find a valid BME280 sensor, check wiring!"); bmePresent = 0; } @@ -49,9 +50,13 @@ void loop() { 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); - if (result == 'R') - setup(); + // Serial.println(result); + + if (result == 'R') { + Serial.println("OK"); + delay(500); + setup(); + } if (bmePresent) { Serial.print("OK BME280 "); Serial.print(bme.readTemperature()); @@ -85,8 +90,12 @@ void loop() { 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); - if (result == 'R') - setup(); + + if (result == 'R') { + Serial1.println("OK"); + delay(500); + setup(); + } if (bmePresent) { Serial1.print("OK BME280 "); Serial1.print(bme.readTemperature()); @@ -112,6 +121,6 @@ void loop() { // Serial1.println(counter++); } #endif - + delay(100); } From 107553e85513e5dd7f3f214f5836858ad14c95b6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 17:05:30 -0400 Subject: [PATCH 58/59] working with R and 0's when no sensor present --- arduino/Payload_BME280_MPU6050_STM32.ino | 73 +++++++++++++++--------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index 56bddc74..45d9783a 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -12,6 +12,7 @@ MPU6050 mpu6050(Wire); int counter = 0; long timer = 0; +int bmePresent; void setup() { @@ -25,10 +26,12 @@ void setup() { digitalWrite(PC13, LOW); // turn the LED on delay(50); // wait for a second digitalWrite(PC13, HIGH); // turn the LED off - - if (!bme.begin(0x76)) { + + if (bme.begin(0x76)) { + bmePresent = 1; + } else { Serial.println("Could not find a valid BME280 sensor, check wiring!"); - while (1); + bmePresent = 0; } mpu6050.begin(); @@ -39,22 +42,30 @@ void loop() { #ifdef TESTING if (Serial.available() > 0) { - digitalWrite(PC13, LOW); // turn the LED on delay(50); // wait for a second digitalWrite(PC13, HIGH); // turn the 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()); - + // Serial.println(result); + + if (result == 'R') { + Serial.println("OK"); + delay(500); + setup(); + } + if (bmePresent) { + 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()); + } else + { + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + } mpu6050.update(); Serial.print(" MPU6050 "); @@ -68,24 +79,30 @@ void loop() { } #else if (Serial1.available() > 0) { - digitalWrite(PC13, LOW); // turn the LED on delay(50); // wait for a second digitalWrite(PC13, HIGH); // turn the 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()); + if (result == 'R') { + Serial1.println("OK"); + delay(500); + setup(); + } + if (bmePresent) { + 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()); + } else + { + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + } mpu6050.update(); Serial1.print(" MPU6050 "); @@ -98,6 +115,6 @@ void loop() { // Serial1.println(counter++); } #endif - + delay(100); } From 33d46cebd672b5ae982839e8897bd4842906594c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 17:18:24 -0400 Subject: [PATCH 59/59] Update README.md --- arduino/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arduino/README.md b/arduino/README.md index 697f89c0..06d66aa7 100644 --- a/arduino/README.md +++ b/arduino/README.md @@ -14,6 +14,8 @@ GetAllData.ino Displays the results of reading the MPU6050 sensor: Temperature, PayloadOK_STM32_PC13.ino and PayloadOK_Pro_Micro.ino This code answers the query from the Raspberry Pi CubeSatSim software over the UART so that the STEM Payload is marked "OK" in the FoxTelem CubeSatSim-FSK Health tab. +Payload_BME280_MPU6050_Pro_Micro.ino and Payload_BME280_MPU6050_STM32.ino This code answers the query from the Raspberry Pi CubeSatSim software over the UART so that the STEM Payload is marked "OK" in the FoxTelem CubeSatSim-FSK Health tab and also replies withe BME280 and MPU6050 sensor data. In FoxTelem, this is displayed as the X, Y, and Z Gyro (dps) and in AFSK mode, it is appended to the telemetry string. + The STM32 can be programmed using the Arduino IDE with the Generic STM32F103C series board and STM32duino bootloader, Maple Mini port. The Sparkfun Pro Micro can also be programed using the Arduino IDE with the Sparkfun Pro Micro board and AVRISP mkII Programmer.