Add log prints and clean python recording scripts
This commit is contained in:
parent
1e7048717a
commit
163e75cccc
@ -6,19 +6,18 @@ import time
|
|||||||
import busio
|
import busio
|
||||||
import adafruit_ads1x15.ads1015 as ADS
|
import adafruit_ads1x15.ads1015 as ADS
|
||||||
from adafruit_ads1x15.analog_in import AnalogIn
|
from adafruit_ads1x15.analog_in import AnalogIn
|
||||||
from time import sleep, strftime
|
# from rpi_lcd import LCD
|
||||||
from rpi_lcd import LCD
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='GPS Logger')
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
parser.add_argument('-o', '--output', help='Output file', required=True)
|
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
||||||
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
lcd = LCD(bus=2)
|
# lcd = LCD(bus=2)
|
||||||
except OSError:
|
# except OSError:
|
||||||
lcd = None
|
# lcd = None
|
||||||
|
|
||||||
# Create the I2C bus
|
# Create the I2C bus
|
||||||
i2c = busio.I2C(board.SCL, board.SDA)
|
i2c = busio.I2C(board.SCL, board.SDA)
|
||||||
@ -26,46 +25,47 @@ i2c = busio.I2C(board.SCL, board.SDA)
|
|||||||
# Create the ADC object using the I2C bus
|
# Create the ADC object using the I2C bus
|
||||||
ads = ADS.ADS1015(i2c)
|
ads = ADS.ADS1015(i2c)
|
||||||
|
|
||||||
# Create single-ended input on channel 0
|
|
||||||
# tmp36 = AnalogIn(ads, ADS.P0)
|
|
||||||
|
|
||||||
# Create a single-ended input on channel 1
|
# Create a single-ended input on channel 1
|
||||||
depthS = AnalogIn(ads, ADS.P1)
|
depthS = AnalogIn(ads, ADS.P1)
|
||||||
|
|
||||||
|
# Create single-ended input on channel 0
|
||||||
|
# tmp36 = AnalogIn(ads, ADS.P0)
|
||||||
|
|
||||||
# Subtract the offset from the sensor voltage
|
# Subtract the offset from the sensor voltage
|
||||||
# and convert chan.voltage * (1 degree C / 0.01V) = Degrees Celcius
|
# and convert chan.voltage * (1 degree C / 0.01V) = Degrees Celcius
|
||||||
# temperatureC = (tmp36.voltage - 0.5) / 0.01
|
# temperatureC = (tmp36.voltage - 0.5) / 0.01
|
||||||
|
|
||||||
# File to write down the results
|
# File to write down the results
|
||||||
filename = args.output + time.strftime("%Y-%m-%dT%H-%M-%S") + "_depth_data.csv"
|
filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_depth_data.csv"
|
||||||
|
|
||||||
#depthM = ((depthS.voltage * 31.848) - 22.93)
|
interval = int(args.interval) if args.interval else 5
|
||||||
|
|
||||||
#Attempting to round the figure to a more intelligible figure
|
#Attempting to round the figure to a more intelligible figure
|
||||||
#rounddepth = round(depthM, ndigits)
|
#rounddepth = round(depthM, ndigits)
|
||||||
#psi = depthS.voltage * 104.1666667 - 75
|
#psi = depthS.voltage * 104.1666667 - 75
|
||||||
|
|
||||||
#bar = psi * 14.503773800722
|
#bar = psi * 14.503773800722
|
||||||
|
|
||||||
with open(filename, "w", 1) as f:
|
with open(filename, "w", 1) as f:
|
||||||
|
print(f"Writing pressure/depth output to {filename}, interval {interval} seconds")
|
||||||
f.write("time and date, Voltage of depth sensor (V), Depth (m)\n")
|
f.write("time and date, Voltage of depth sensor (V), Depth (m)\n")
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
voltage = depthS.voltage
|
while True:
|
||||||
depthM = ((voltage * 31.848) - 22.93)
|
voltage = depthS.voltage
|
||||||
rounddepth = round(depthM, 2)
|
depthM = ((voltage * 31.848) - 22.93)
|
||||||
# roundtemp = round(temperatureC, 2)
|
rounddepth = round(depthM, 2)
|
||||||
roundvolts = round(voltage, 3)
|
roundvolts = round(voltage, 3)
|
||||||
|
# roundtemp = round(temperatureC, 2)
|
||||||
|
|
||||||
print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"))
|
print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"))
|
||||||
|
|
||||||
if lcd:
|
# if lcd:
|
||||||
lcd.clear()
|
# lcd.clear()
|
||||||
lcd.text((str(roundvolts) + " V ") + (str(rounddepth) + " m"), 1)
|
# lcd.text((str(roundvolts) + " V ") + (str(rounddepth) + " m"), 1)
|
||||||
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + ",")
|
|
||||||
f.write(str(roundvolts) + "," + str(rounddepth) + "\n")
|
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + "," + str(roundvolts) + "," + str(rounddepth) + "\n")
|
||||||
|
|
||||||
if args.interval:
|
time.sleep(interval)
|
||||||
time.sleep(int(args.interval))
|
|
||||||
else:
|
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
||||||
time.sleep(5)
|
print("Exiting depth recording.")
|
||||||
|
@ -5,15 +5,19 @@ import time
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='GPS Logger')
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
parser.add_argument('-o', '--output', help='Output file', required=True)
|
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
||||||
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv"
|
filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv"
|
||||||
|
|
||||||
|
interval = int(args.interval) if args.interval else 5
|
||||||
|
|
||||||
with open(filename, "w", 1) as f:
|
with open(filename, "w", 1) as f:
|
||||||
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
|
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
|
||||||
|
|
||||||
|
print(f"Writing GPS output to {filename}, interval {interval} seconds")
|
||||||
f.write("GPStime utc,latitude,longitude,speed,sats in view\n")
|
f.write("GPStime utc,latitude,longitude,speed,sats in view\n")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -28,11 +32,7 @@ with open(filename, "w", 1) as f:
|
|||||||
|
|
||||||
f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n")
|
f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n")
|
||||||
|
|
||||||
if args.interval:
|
time.sleep(interval)
|
||||||
time.sleep(int(args.interval))
|
|
||||||
else:
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
||||||
print("Done.\nExiting.")
|
print("Exiting GPS recording.")
|
||||||
f.close()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user