diff --git a/groundstation/aprs-cubesatsim.sh b/groundstation/aprs-cubesatsim.sh index 2b80439f..4599d9b4 100755 --- a/groundstation/aprs-cubesatsim.sh +++ b/groundstation/aprs-cubesatsim.sh @@ -1,10 +1,10 @@ #!/bin/bash # script to auto decode APRS packets from CubeSatSim -sudo modprobe snd-aloop - sudo systemctl stop openwebrx +sudo modprobe snd-aloop + sudo systemctl stop rtl_tcp pkill -o chromium &>/dev/null @@ -25,14 +25,17 @@ sudo killall -9 CubicSDR &>/dev/null echo -e "Script to auto decode APRS packets from CubeSatSim on 434.90 MHz\n" -sleep 1 - #sudo rtl_fm -f 144.39M -s 22050 -g 48 - | multimon-ng -a AFSK1200 -A -t raw - -direwolf -t 0 & +direwolf -r 48000 -t 0 & + +sleep 5 + +value=`aplay -l | grep "Loopback"` +echo "$value" > /dev/null +set -- $value -#rtl_fm -M fm -f 144.39M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 -rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 +rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:${2:0:1},0,0 -r 48000 -t raw -f S16_LE -c 1 diff --git a/groundstation/aprs.sh b/groundstation/aprs.sh index 15d9c2df..315a6ba0 100755 --- a/groundstation/aprs.sh +++ b/groundstation/aprs.sh @@ -25,13 +25,17 @@ sudo killall -9 CubicSDR &>/dev/null echo -e "Script to auto decode APRS packets on 144.390 MHz\n" -sleep 1 - #sudo rtl_fm -f 144.39M -s 22050 -g 48 - | multimon-ng -a AFSK1200 -A -t raw - -direwolf -t 0 & +direwolf -r 48000 -t 0 & + +sleep 5 + +value=`aplay -l | grep "Loopback"` +echo "$value" > /dev/null +set -- $value -rtl_fm -M fm -f 144.39M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 +rtl_fm -M fm -f 144.39M -s 48k | aplay -D hw:${2:0:1},0,0 -r 48000 -t raw -f S16_LE -c 1 diff --git a/groundstation/autostart/autostart b/groundstation/autostart/autostart new file mode 100644 index 00000000..2510c6e4 --- /dev/null +++ b/groundstation/autostart/autostart @@ -0,0 +1,5 @@ +@lxpanel --profile LXDE-pi +@pcmanfm --desktop --profile LXDE-pi +@lxterminal --command "/home/pi/CubeSatSim/groundstation/fox-startup.sh" +@xscreensaver -no-splash + diff --git a/groundstation/autostart/chromium.desktop b/groundstation/autostart/chromium.desktop new file mode 100644 index 00000000..fc57834e --- /dev/null +++ b/groundstation/autostart/chromium.desktop @@ -0,0 +1,5 @@ + +[Desktop Entry] +Type=Application +Name=Chromium with WebSDR +Exec=chromium-browser --check-for-update-interval=1 --simulate-critical-update --noerrdialogs --disable-infobars http://127.0.0.1:8073 diff --git a/groundstation/autostart/foxtelem.desktop b/groundstation/autostart/foxtelem.desktop new file mode 100644 index 00000000..b71a6436 --- /dev/null +++ b/groundstation/autostart/foxtelem.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Application +Name=FoxTelem +Terminal=true +Exec=/home/pi/CubeSatSim/groundstation/fox-startup.sh diff --git a/groundstation/cubicsdr.sh b/groundstation/cubicsdr.sh index f2e0c92e..9e9e6be0 100755 --- a/groundstation/cubicsdr.sh +++ b/groundstation/cubicsdr.sh @@ -9,6 +9,8 @@ echo "Note: Select Generic RTL2832 device then click Start to begin" echo +sudo systemctl stop openwebrx + sudo killall -9 java &>/dev/null sudo killall -9 rtl_fm &>/dev/null @@ -19,7 +21,7 @@ sudo systemctl stop rtl_tcp sudo killall -9 rtl_tcp &>/dev/null -sudo systemctl stop openwebrx +sleep 5 CubicSDR diff --git a/groundstation/fox-profile.desktop b/groundstation/fox-profile.desktop new file mode 100644 index 00000000..c03f40d4 --- /dev/null +++ b/groundstation/fox-profile.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Exec=/home/pi/CubeSatSim/groundstation/fox-profile.sh +Name=Change FoxTelem Profile +Comment=FIAB-v3 +Icon=/home/pi/Downloads/foxtelem.png +Path=/home/pi +Terminal=true +Categories=HamRadio +Keywords=Ham Radio;AMSAT diff --git a/groundstation/fox-profile.sh b/groundstation/fox-profile.sh new file mode 100755 index 00000000..be0074e4 --- /dev/null +++ b/groundstation/fox-profile.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# script to change FoxTelem default profile + +echo "Script to change your default FoxTelem profile for FIAB v3" + +echo + +sudo rm /home/pi/FoxTelemetryData/.foxprofile + +/home/pi/CubeSatSim/groundstation/fox-startup.sh + +$SHELL diff --git a/groundstation/fox-startup.sh b/groundstation/fox-startup.sh index a0ade800..b4504388 100755 --- a/groundstation/fox-startup.sh +++ b/groundstation/fox-startup.sh @@ -1,14 +1,114 @@ #!/bin/bash # script to run FoxTelem -echo "Script to run FoxTelem for ARISS Radio Pi" +echo "Startup script to run FoxTelem for FIAB v3" echo +sudo killall -9 FoxTelem &>/dev/null -sudo killall -9 foxtelem &>/dev/null +FILE=/home/pi/FoxTelemetryData/.foxprofile +if [ ! -f "$FILE" ]; then + echo "You need to choose your default FoxTelem profile." + echo + echo "The choices are:" + echo + echo "1. Fox-in-a-Box. Use this profile if you want to receive and decode telemetry from the AMSAT Fox satellites. If you enter a callsign and a grid square, you can upload to the AMSAT telemetry server." + echo + echo "2. CubeSatSim Ground Station. Use this profile if you want to receive and decode telemetry from an AMSAT CubeSatSim or CubeSatSim Lite." + echo + echo "Which profile do you choose? Enter 1 or 2" + + read -r ANS -/home/pi/Downloads/FoxTelem/FoxTelem & + if [ "$ANS" = "1" ]; then + echo "You have chosen the Fox-in-a-Box profile." + echo "b" > /home/pi/FoxTelemetryData/.foxprofile + echo + + FILE=/home/pi/FoxTelemetryData/FoxTelem.properties.0 + if [ ! -f "$FILE" ]; then + cp /home/pi/FoxTelemetryData/FoxTelem.properties /home/pi/FoxTelemetryData/FoxTelem.properties.0 + fi + + python3 /home/pi/CubeSatSim/groundstation/loc-foxtelem.py + + if [ $? -eq 1 ]; then + + echo "Enter your CALLSIGN. If you don't have a callsign, enter a text string that will be displayed on the FoxTelem leader board at https://amsat.org/tlm" + read callsign + + if [ -n "$callsign" ]; then + sudo sed -i "s/callsign=.*/callsign=$callsign/g" /home/pi/FoxTelemetryData/FoxTelem.properties + fi + + echo + + sudo sed -i "s/uploadToServer=false/uploadToServer=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/foxTelemCalcsDoppler=false/foxTelemCalcsDoppler=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/foxTelemCalcsPosition=false/foxTelemCalcsPosition=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/uploadToServer=false/uploadToServer=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/whenAboveHorizon=false/whenAboveHorizon=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/retuneCenterFrequency=false/retuneCenterFrequency=true/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + sudo sed -i "s/stationDetails=.*/stationDetails=FoxInABox/g" /home/pi/FoxTelemetryData/FoxTelem.properties + + # sudo sed -i "s/soundCard=NONE/soundCard=RTL SDR/g" /home/pi/FoxTelemetryData/FoxTelem.properties # change to FunCube + sudo sed -i "s/soundCard=NONE/soundCard=Direct Audio Device\: FUNcube Dongle V2.0, USB Audi/g" /home/pi/FoxTelemetryData/FoxTelem.properties # change to FunCube + + + + # echo "Enter your Maidenhead grid square. It is two letters followed by two numbers followed by two letters with no spaces. If you don't know your gridsquare, you can look it up here https://dxcluster.ha8tks.hu/hamgeocoding/" + # read grid + # sudo sed -i "s/maidenhead=XX00xx/maidenhead=$grid/g" /home/pi/Documents/FITB/FoxTelem.properties + # echo + + fi + + elif [ "$ANS" = "2" ]; then + + echo "You have chosen the CubeSatSim Ground Station profile." + echo "c" > /home/pi/FoxTelemetryData/.foxprofile + + cp /home/pi/FoxTelemetryData-CubeSatSim/FoxTelem.properties /home/pi/FoxTelemetryData-CubeSatSim/FoxTelem.properties.0 + + sudo sed -i "s/useCostas=false/useCostas=true/g" /home/pi/FoxTelemetryData-CubeSatSim/FoxTelem.properties + + sudo sed -i "s/findSignal=false/findSignal=true/g" /home/pi/FoxTelemetryData-CubeSatSim/FoxTelem.properties + + else + + echo "Please enter only 1 or 2" + + fi + +fi + +value=`cat /home/pi/FoxTelemetryData/.foxprofile` +echo "$value" > /dev/null +set -- $value + +sudo killall -9 java &>/dev/null + +if [ "$1" = "c" ]; then + echo "CubeSatSim Ground Station profile is set!" + echo + /home/pi/CubeSatSim/groundstation/fox.sh +else + echo "Fox-in-a-box profile is set!" + echo +# /home/pi/FoxTelem/FoxTelem /home/pi/FoxTelemetryData + SCRIPTPATH=$(dirname "$0") + cd /home/pi/FoxTelem + echo Starting $SCRIPTPATH/current_foxtelem/FoxTelem.jar + java -Xmx512M -jar FoxTelem.jar "/home/pi/FoxTelemetryData" < /dev/null > /dev/null & + +fi $SHELL diff --git a/groundstation/fox.sh b/groundstation/fox.sh index af7853b7..eb2289dd 100755 --- a/groundstation/fox.sh +++ b/groundstation/fox.sh @@ -21,8 +21,8 @@ sudo killall -9 CubicSDR &>/dev/null sudo killall -9 qsstv &>/dev/null -/home/pi/Downloads/FoxTelem/FoxTelem & +sleep 5 -#/usr/bin/chromium-browser --noerrdialogs --disable-infobars http://localhost:8073 &>/dev/null & +/home/pi/FoxTelem/FoxTelem /home/pi/FoxTelemetryData-CubeSatSim $SHELL diff --git a/groundstation/foxtelem.desktop b/groundstation/foxtelem.desktop index 59a186c7..e8e5b548 100644 --- a/groundstation/foxtelem.desktop +++ b/groundstation/foxtelem.desktop @@ -1,10 +1,10 @@ [Desktop Entry] Type=Application -Exec=/home/pi/CubeSatSim/groundstation/fox.sh +Exec=/home/pi/CubeSatSim/groundstation/fox-startup.sh Name=FoxTelem -Comment=Test Version 1.09 for CubeSatSim +Comment=FIAB-v3 Icon=/home/pi/Downloads/foxtelem.png Path=/home/pi -#Terminal=true +Terminal=true Categories=HamRadio Keywords=Ham Radio;AMSAT diff --git a/groundstation/foxtelem.desktop.autostart.bk b/groundstation/foxtelem.desktop.autostart.bk deleted file mode 100644 index 6b24d049..00000000 --- a/groundstation/foxtelem.desktop.autostart.bk +++ /dev/null @@ -1,4 +0,0 @@ -[Desktop Entry] -Type=Application -Name=FoxTelem -Exec=/home/pi/CubeSatSim/groundstation/fox.sh diff --git a/groundstation/loc-add-foxtelem.py b/groundstation/loc-add-foxtelem.py index 6fdf3b5d..98a16a19 100644 --- a/groundstation/loc-add-foxtelem.py +++ b/groundstation/loc-add-foxtelem.py @@ -4,35 +4,124 @@ import requests from os import system +import re +import sys -URL = "https://geocode.search.hereapi.com/v1/geocode" -print("\nIn order to upload your satellite telemetry data to the AMSAT servers, we need to know your location\n") -print("Enter your location including country. \n\n") -location = input("Type your location: ") #taking user input -api_key = '' # Acquire from developer.here.com -PARAMS = {'apikey':api_key,'q':location} +latitude = 0 +longitude = 0 +grid = "" +return_value = 0 -# sending get request and saving the response as response object -r = requests.get(url = URL, params = PARAMS) -data = r.json() +print("\nIn order to track the satellites as they fly over your location and upload your satellite telemetry data to the AMSAT servers, we need to know your location") +print("\nYou can enter:\n") +print("1. Location name (e.g. country or city, state, etc)") +print("2. Grid square (e.g. FM29ha)") +print("3. Latitude and longitude") +print("4. No location\n") -#print(data) +choice = input ("Enter your choice (1 -4): ") -latitude = data['items'][0]['position']['lat'] -longitude = data['items'][0]['position']['lng'] +if (choice == '2'): + regex = '[A-Z]+[A-Z]+[0-9]+[0-9]+[a-z]+[a-z]' -print(latitude) -print(longitude) + grid = input("\nType your 6 character character grid square (i.e. FM29ha): ") + if re.search(regex, grid): + print("grid is valid!") + else: + print("grid is not valid!") + grid = "" + +elif (choice == '3'): + + lat = input("\nType your latitude: ") + try: + latitude = float(lat) + print(latitude) + except ValueError: + print("Not a number!") + long = input("\nType your longitude: ") + try: + longitude = float(long) + print(longitude) + except ValueError: + print("Not a number!") + +elif (choice == '1'): + URL = "https://geocode.search.hereapi.com/v1/geocode" + + print("\nEnter your location including country. \n\n") + location = input("Type your location: ") #taking user input + api_key = '' # Acquire from developer.here.com + PARAMS = {'apikey':api_key,'q':location} + + try: + # sending get request and saving the response as response object + r = requests.get(url = URL, params = PARAMS) + data = r.json() + + #print(data) + + latitude = data['items'][0]['position']['lat'] + longitude = data['items'][0]['position']['lng'] + + print(latitude) + print(longitude) + + except: + print("There is a problem with the location API. Please try again") + +else: + print("\nYou have chosen not to enter your location.") + print("To track satellites and upload telemetry data,") + print("you can set your location in Settings in FoxTelem.") + #file = open(r"/home/pi/CubeSatSim/groundstation/.profile","w+") -latSedStr = 'sed -i "s/latitude=0.0/latitude=' + str(latitude) + '/g" /home/pi/Documents/FITB/FoxTelem.properties' -#print (latSedStr) -system(latSedStr) +if ((latitude != 0) and (longitude != 0) or grid): + + if not grid: + latSedStr = 'sed -i "s/latitude=.*/latitude=' + str(latitude) + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (latSedStr) + system(latSedStr) + + longSedStr = 'sed -i "s/longitude=.*/longitude=' + str(longitude) + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (longSedStr) + system(longSedStr) + + print("\nFoxTelem configuration updated with your latitude and longitude") + + return_value = 1 + + else: + latSedStr = 'sed -i "s/latitude=.*/latitude=' + str(latitude) + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (latSedStr) + system(latSedStr) + + longSedStr = 'sed -i "s/longitude=.*/longitude=' + str(longitude) + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (longSedStr) + system(longSedStr) -longSedStr = 'sed -i "s/longitude=0.0/longitude=' + str(longitude) + '/g" /home/pi/Documents/FITB/FoxTelem.properties' -#print (longSedStr) -system(longSedStr) -print("\nFoxTelem configuration updated with your latitude and longitude") + gridSedStr = 'sed -i "s/maidenhead=.*/maidenhead=' + grid + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (gridSedStr) + system(gridSedStr) + + print("\nFoxTelem configuration updated with your maidenhead grid square") + + return_value = 1 + alt = input("\nType your altitude in integer meters: ") + try: + altitude = int(alt) + #print(altitude) + altSedStr = 'sed -i "s/altitude=.*/altitude=' + str(altitude) + '/g" /home/pi/FoxTelemetryData/FoxTelem.properties' + #print (altSedStr) + system(altSedStr) + + print("\nFoxTelem configuration updated with your alitude") + + except ValueError: + print("Not an integer!") + +sys.exit(return_value) diff --git a/groundstation/rtl-tcp-d.sh b/groundstation/rtl-tcp-d.sh index 4fbaede4..5fdd67d7 100755 --- a/groundstation/rtl-tcp-d.sh +++ b/groundstation/rtl-tcp-d.sh @@ -17,6 +17,8 @@ echo "Note: you need to be on the Wifi network: $ssid" echo +sudo systemctl stop openwebrx + sudo killall -9 java &>/dev/null sudo killall -9 rtl_fm &>/dev/null @@ -27,7 +29,7 @@ sudo killall -9 qsstv &>/dev/null sudo systemctl stop rtl_tcp -sudo systemctl stop openwebrx +sleep 5 sudo /bin/sh -c '/usr/local/bin/rtl_tcp -a $(hostname -I|cut -f1 -d " ") -D 2' diff --git a/groundstation/rtl-tcp.sh b/groundstation/rtl-tcp.sh index 1078db39..3e267f34 100755 --- a/groundstation/rtl-tcp.sh +++ b/groundstation/rtl-tcp.sh @@ -23,6 +23,10 @@ echo "Note: you need to be on the Wifi network: $ssid" echo +sudo systemctl stop openwebrx + +sleep 2 + pkill -o chromium &>/dev/null sudo killall -9 java &>/dev/null @@ -31,8 +35,6 @@ sudo killall -9 rtl_fm &>/dev/null sudo killall -9 CubicSDR &>/dev/null -sudo systemctl stop openwebrx - sudo killall -9 rtl_tcp &>/dev/null sudo killall -9 qsstv &>/dev/null diff --git a/groundstation/satnogs_readme.txt b/groundstation/satnogs_readme.txt deleted file mode 100644 index 21f0ef05..00000000 --- a/groundstation/satnogs_readme.txt +++ /dev/null @@ -1,19 +0,0 @@ -This image has the SatNOGS client pre installed. It allows you to join the Satellite Network Operators Group network: - -https://network.satnogs.org - -To join, all you have to do is follow the instructions starting at SatNOGS Client Setup - -https://wiki.satnogs.org/SatNOGS_Client_Ansible#SatNOGS_Client_Setup - -You will need to Sign Up and create an account: - -https://network.satnogs.org/login/auth0 - -Maybe include "ARISS" in your SatNOGS station name? For example: Joe's ARISS GS - -Once you have an account and have logged in, click on the upper right corner and select Dashboard. Click on the API Key button to copy and paste your API Key which you will need to configure using sudo satnogs-setup Basic Configuration SATNOGS_API_TOKEN - -Good luck and feel free to message me ku2y on SatNOGS! - - diff --git a/groundstation/sdr.sh b/groundstation/sdr.sh index 46e8593e..27aa41c7 100755 --- a/groundstation/sdr.sh +++ b/groundstation/sdr.sh @@ -29,6 +29,8 @@ sudo systemctl stop rtl_tcp sudo systemctl restart openwebrx +sleep 10 + chromium-browser --check-for-update-interval=1 --simulate-critical-update --noerrdialogs --disable-infobars http://127.0.0.1:8073 &>/dev/null & $SHELL diff --git a/groundstation/sstv_decode.sh b/groundstation/sstv_decode.sh index 85308325..c7afae2e 100755 --- a/groundstation/sstv_decode.sh +++ b/groundstation/sstv_decode.sh @@ -5,12 +5,12 @@ echo "Script to decode SSTV from the CubeSatSim for ARISS Radio Pi" echo +sudo systemctl stop openwebrx + sudo modprobe snd-aloop sudo killall -9 qsstv &>/dev/null -sudo systemctl stop openwebrx - sudo systemctl stop rtl_tcp pkill -o chromium &>/dev/null @@ -23,8 +23,10 @@ sudo killall -9 rtl_fm &>/dev/null sudo killall -9 CubicSDR &>/dev/null -rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 & - qsstv & +sleep 5 + +rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 & + $SHELL diff --git a/groundstation/sstv_decode_iss.sh b/groundstation/sstv_decode_iss.sh index dcf26181..da19a72b 100755 --- a/groundstation/sstv_decode_iss.sh +++ b/groundstation/sstv_decode_iss.sh @@ -5,6 +5,8 @@ echo "Script to decode SSTV from the CubeSatSim for ARISS Radio Pi" echo +sudo systemctl stop openwebrx + sudo modprobe snd-aloop sudo killall -9 qsstv &>/dev/null @@ -15,8 +17,6 @@ sudo killall -9 aplay &>/dev/null sudo killall -9 direwolf &>/dev/null -sudo systemctl stop openwebrx - sudo systemctl stop rtl_tcp pkill -o chromium &>/dev/null @@ -31,5 +31,11 @@ sudo killall -9 CubicSDR &>/dev/null qsstv & -rtl_fm -M fm -f 145.8M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 +sleep 5 + +value=`aplay -l | grep "Loopback"` +echo "$value" > /dev/null +set -- $value + +rtl_fm -M fm -f 145.8M -s 48k | aplay -D hw:${2:0:1},0,0 -r 48000 -t raw -f S16_LE -c 1 $SHELL diff --git a/groundstation/sstv_decode_sim.sh b/groundstation/sstv_decode_sim.sh index f45754c3..300895ee 100755 --- a/groundstation/sstv_decode_sim.sh +++ b/groundstation/sstv_decode_sim.sh @@ -5,6 +5,8 @@ echo "Script to decode SSTV from the CubeSatSim for ARISS Radio Pi" echo +sudo systemctl stop openwebrx + sudo modprobe snd-aloop sudo killall -9 qsstv &>/dev/null @@ -15,8 +17,6 @@ sudo killall -9 aplay &>/dev/null sudo killall -9 direwolf &>/dev/null -sudo systemctl stop openwebrx - sudo systemctl stop rtl_tcp pkill -o chromium &>/dev/null @@ -29,12 +29,18 @@ sudo killall -9 java &>/dev/null sudo killall -9 CubicSDR &>/dev/null -echo "ARG1=s" >> .mode +#echo "s" >> .mode qsstv & +sleep 5 + #sudo systemctl restart cubesatsim -rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:2,0,0 -r 48000 -t raw -f S16_LE -c 1 +value=`aplay -l | grep "Loopback"` +echo "$value" > /dev/null +set -- $value + +rtl_fm -M fm -f 434.9M -s 48k | aplay -D hw:${2:0:1},0,0 -r 48000 -t raw -f S16_LE -c 1 $SHELL diff --git a/stempayload/Payload_BME280_MPU6050_XS_Extended/Payload_BME280_MPU6050_XS_Extended.ino b/stempayload/Payload_BME280_MPU6050_XS_Extended/Payload_BME280_MPU6050_XS_Extended.ino new file mode 100644 index 00000000..f7b391b4 --- /dev/null +++ b/stempayload/Payload_BME280_MPU6050_XS_Extended/Payload_BME280_MPU6050_XS_Extended.ino @@ -0,0 +1,359 @@ +#include +#include +#include +#include +#include +#include "Adafruit_SI1145.h" +#include + +#define SEALEVELPRESSURE_HPA (1013.25) + +Adafruit_BME280 bme; +MPU6050 mpu6050(Wire); +Adafruit_SI1145 uv = Adafruit_SI1145(); +Adafruit_LIS3MDL lis3mdl; + +long timer = 0; +int bmePresent; +int uvPresent; +int magPresent; +int RXLED = 17; // The RX LED has a defined Arduino pin +int greenLED = 9; +int blueLED = 8; +void eeprom_word_write(int addr, int val); +short eeprom_word_read(int addr); +int first_time = true; +int first_read = true; +float T2 = 26.3; // Temperature data point 1 +float R2 = 167; // Reading data point 1 +float T1 = 2; // Temperature data point 2 +float R1 = 179; // Reading data point 2 +int sensorValue; +float Temp; +float rest; +float magRaw = 0; +float magRawAbs = 0; + +void setup() { + + Serial.begin(9600); // Serial Monitor for testing + + Serial1.begin(115200); // Pi UART faster speed + + Serial.println("Starting!"); + + blink_setup(); + + blink(500); + delay(250); + blink(500); + delay(250); + led_set(greenLED, HIGH); + delay(250); + led_set(greenLED, LOW); + led_set(blueLED, HIGH); + delay(250); + led_set(blueLED, LOW); + + if (bme.begin(0x76)) { + bmePresent = 1; + } else { + Serial.println("BME280 sensor fault"); + bmePresent = 0; + } + + if (! uv.begin()) { + Serial.println("Si1145 sensor fault"); + uvPresent = 0; + } else { + uvPresent = 1; + } + + if (! lis3mdl.begin_I2C()) { + Serial.println("LIS3MDL sensor fault"); + magPresent = 0; + } else { + magPresent = 1; + } + + mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1)) / 100.0; + float yOffset = ((float)eeprom_word_read(2)) / 100.0; + float zOffset = ((float)eeprom_word_read(3)) / 100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + } + else + { + Serial.println("Calculating gyro offsets and storing in EEPROM\n"); + + mpu6050.calcGyroOffsets(true); + + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); + } + pinMode(greenLED, OUTPUT); + pinMode(blueLED, OUTPUT); +} + +void loop() { + + if ((Serial.available() > 0) || first_time == true) { + blink(50); + char result = Serial.read(); + + if (result == 'R') { + Serial.println("OK"); + delay(100); + first_time = true; + setup(); + } + else if (result == 'C') { + Serial.println("Clearing stored gyro offsets in EEPROM\n"); + eeprom_word_write(0, 0x00); + first_time = true; + setup(); + } + if ((result == '?') || first_time == true) + { + first_time = false; + 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 "); + Serial.print(mpu6050.getGyroX()); + Serial.print(" "); + Serial.print(mpu6050.getGyroY()); + Serial.print(" "); + Serial.print(mpu6050.getGyroZ()); + + Serial.print(" "); + Serial.print(mpu6050.getAccX()); + Serial.print(" "); + Serial.print(mpu6050.getAccY()); + Serial.print(" "); + Serial.print(mpu6050.getAccZ()); + + sensorValue = analogRead(A3); + Temp = T1 + (sensorValue - R1) * ((T2 - T1) / (R2 - R1)); + + Serial.print(" XS "); + Serial.print(Temp); + Serial.print(" "); + if (uvPresent) { + Serial.print(uv.readVisible()); + Serial.print(" "); + Serial.print(uv.readIR()); + Serial.print(" "); + } else + { + Serial.print("0.0 0.0 "); + } + if (magPresent) { + lis3mdl.read(); + magRaw = (((lis3mdl.x + lis3mdl.y + lis3mdl.z) / 3)); + magAbs = abs(magRaw); + Serial.println(magAbs); + } else + { + Serial.println("0.0"); + } + + float rotation = sqrt(mpu6050.getGyroX() * mpu6050.getGyroX() + mpu6050.getGyroY() * mpu6050.getGyroY() + mpu6050.getGyroZ() * mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX() * mpu6050.getAccX() + mpu6050.getAccY() * mpu6050.getAccY() + mpu6050.getAccZ() * mpu6050.getAccZ()); + + if (acceleration > 1.2) + led_set(greenLED, HIGH); + else + led_set(greenLED, LOW); + + if (rotation > 5) + led_set(blueLED, HIGH); + else + led_set(blueLED, LOW); + } + } + + if (Serial1.available() > 0) { + + blink(50); + char result = Serial1.read(); + + if (result == 'R') { + Serial1.println("OK"); + delay(100); + first_read = true; + setup(); + } + + if (result == '?') + { + 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 "); + Serial1.print(mpu6050.getGyroX()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroY()); + Serial1.print(" "); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" "); + Serial1.print(mpu6050.getAccX()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccY()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccZ()); + + sensorValue = analogRead(A3); + Temp = T1 + (sensorValue - R1) * ((T2 - T1) / (R2 - R1)); + + Serial1.print(" XS "); + Serial1.print(Temp); + Serial1.print(" "); + if (uvPresent) { + Serial1.print(uv.readVisible()); + Serial1.print(" "); + Serial1.print(uv.readIR()); + Serial1.print(" "); + } else + { + Serial1.print("0.0 0.0 "); + } + if (magPresent) { + lis3mdl.read(); + magRaw = (((lis3mdl.x + lis3mdl.y + lis3mdl.z) / 3)); + magAbs = abs(magRaw); + Serial1.println(magAbs); + } else + { + Serial1.println("0.0"); + } + + + float rotation = sqrt(mpu6050.getGyroX() * mpu6050.getGyroX() + mpu6050.getGyroY() * mpu6050.getGyroY() + mpu6050.getGyroZ() * mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX() * mpu6050.getAccX() + mpu6050.getAccY() * mpu6050.getAccY() + mpu6050.getAccZ() * mpu6050.getAccZ()); + + if (first_read == true) { + first_read = false; + rest = acceleration; + } + + if (acceleration > 1.2 * rest) + led_set(greenLED, HIGH); + else + led_set(greenLED, LOW); + + if (rotation > 5) + led_set(blueLED, HIGH); + else + led_set(blueLED, LOW); + } + } + +} + +void eeprom_word_write(int addr, int val) +{ + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); +} + +short eeprom_word_read(int addr) +{ + return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +} + +void blink_setup() +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + // initialize digital pin PB1 as an output. + pinMode(PC13, OUTPUT); + pinMode(PB9, OUTPUT); + pinMode(PB8, OUTPUT); +#endif + +#if defined __AVR_ATmega32U4__ + pinMode(RXLED, OUTPUT); // Set RX LED as an output + // TX LED is set as an output behind the scenes + pinMode(greenLED, OUTPUT); + pinMode(blueLED, OUTPUT); +#endif +} + +void blink(int length) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level) +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, LOW); // set the RX LED ON + TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF +#endif + + delay(length); // wait for a lenth of time + +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(RXLED, HIGH); // set the RX LED OFF + TXLED0; //TX LED macro to turn LED ON +#endif +} + +void led_set(int ledPin, bool state) +{ +#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4) + if (ledPin == greenLED) + digitalWrite(PB9, state); + else if (ledPin == blueLED) + digitalWrite(PB8, state); +#endif + +#if defined __AVR_ATmega32U4__ + digitalWrite(ledPin, state); +#endif +}