def get_temperature(): # Create sensor object sensor = tsys01.TSYS01() # Must initilize temp sensor object if not sensor.init(): print("Error initializing temperature sensor." ) # Print not needed in final version exit(1) # Read temp sensor once and save in c_temp variable if not sensor.read(): print("Error reading temperature sensor." ) # Print not needed in final version exit(1) c_temp = sensor.temperature() # Get celcius temp #####f_temp = sensor.temperature(tsys01.UNITS_Farenheit) # Get farenheit temp ######print("T: %.2f C\t%.2f F" % (c_temp, f_temp)) # Print not needed in final version return c_temp
depth_factor = 10 surface_offset = 0 # We have to read values from sensor to update pressure and temperature if Psensor.read(): Pres_ini = round((Psensor.pressure() * depth_factor) - surface_offset, 3) else: Pres_ini = "Broken" file.write("Pressure(dbar),Temp(C)") if iniTmp == True: sensor_temp = tsys01.TSYS01() # We must initialize the sensor before reading it if not sensor_temp.init(): print("Error initializing Temperature sensor") exit(1) file.write(", TempTSYS01(C)") file.close() if iniP100 and iniP30 == False: Pres_ini = 2000 if __name__ == '__main__':
import tsys01, ms5837 import sdcard, os from machine import I2C, SPI from machine import Pin SCL = 22 SDA = 23 i2c = I2C(-1, Pin(SCL), Pin(SDA)) p = ms5837.MS5837(model='MODEL_30BA', i2c=i2c) t = tsys01.TSYS01(i2c) p.init() temp_acc = t.getTemp() temp, pressure, depth = p.get_measurement() print(temp_acc) print(temp, pressure, depth) sck = Pin(5) mosi = Pin(18) miso = Pin(19) cs = Pin(14, Pin.OUT) spi2 = SPI(2, baudrate=5000000, sck=sck, mosi=mosi, miso=miso) sd = sdcard.SDCard(spi2, cs) os.mount(sd, '/sd') output = os.listdir('/sd') print(output)
# file_path = "~/" + filename + ".csv" # saves in the root directory # temp_file = open(file_path, "a") # opens file object for appending data # if os.stat(file_path).st_size == 0: # usr_input = ["Date (YYYYMMDD)", "Time (hhmmss.ss)", "AT (C)", "Date (YYYYMMDD)", "Time (hhmmss.ss)", "WT (C)"] # temp_file.write(usr_input + "\n") # writes headers to file # time.sleep(5) # temp_file.close() # return file_path # ------------------------------- # AIR TEMPERATURE SENSOR # ------------------------------- test.disable_channels([0, 1, 2, 3, 4, 5, 6, 7]) test.enable_channels([1]) AT = tsys01.TSYS01() AT.init() print("AT sensor initialized") test.disable_channels([1]) test.enable_channels([2]) WT = tsys01.TSYS01() WT.init() print("WT sensor initialized") test.disable_channels([2]) # List Channel Configuration # test.list_channels() # Take readings
import tsys01 import smbus2 rpi_bus_number = 1 multiplexer_address = 0x70 I2C_ch_0 = 0B00000001 I2C_ch_1 = 0B00000010 x = 1 bus = smbus2.SMBus(rpi_bus_number) i2c = busio.I2C(board.SCL, board.SDA) bus.write_byte(multiplexer_address, I2C_ch_0) sensor = tsys01.TSYS01() while x == 1: if not sensor.init(): print("Error initializing sensor") exit(1) bus.write_byte(multiplexer_address, I2C_ch_0) sleep(60) while True: if not sensor.read(): print("Error reading sensor") exit(1) print("TemperatureSens1: %.2f" % temp1.temperature(tsys01.UNITS_Farenheit))
import tsys01 from time import sleep import serial import threading import pygame def portIsUsable(): try: ser = serial.Serial("/dev/ttyACM0", 9600) return ser except: return False sensor1 = tsys01.TSYS01() sensor2 = ms5837.MS5837_02BA(0) if not sensor2.init(): print("sensor cant be initialized") exit(1) if not sensor2.read(): print("sensor read failed") exit(1) if not sensor1.init(): print("Error Initialiazing Sensor") exit(1) if pygame.joystick.get_count() == 0:
# Create variable for Temperature sensors airRecord = "No Record" waterRecord = "No Record" # Create variable for ADC sensor adc_data = "erro" # Setup Thermometer for Air Temperature using GPIO.BCM mode GPIO.setup(4, GPIO.OUT) # Pin 7 on Raspberry Pi (SCL Control) GPIO.setup(17, GPIO.OUT) # Pin 11 on Raspberry Pi (SDA Control) # Enable Air Temperature sensor GPIO.output(4, GPIO.HIGH) # Set GPIO 4 to HIGH to enable SCL GPIO.output(17, GPIO.HIGH) # Set GPIO 17 to HIGH to enable SDA sleep(0.5) # Re-Enable to turn on air temp airSensor = tsys01.TSYS01() # Make new object for air thermometer airSensor.init() # Initialize air thermometer sleep(0.5) # Disable Air Temperature Sensor communication GPIO.output(4, GPIO.LOW) # LOW to disable SCL GPIO.output(17, GPIO.LOW) # LOW to disable SDA # Setup Thermometer for Water Temperature using GPIO.BCM mode GPIO.setup(27, GPIO.OUT) # Pin 13 on Raspberry Pi (SCL Control) GPIO.setup(22, GPIO.OUT) # Pin 15 on Raspberry Pi (SDA Control) # Enable Water Temperature sensor GPIO.output(27, GPIO.HIGH) # Set GPIO 27 to HIGH to enable SCL GPIO.output(22, GPIO.HIGH) # Set GPIO 22 to HIGH to enable SDA sleep(0.5) waterSensor = tsys01.TSYS01() # Make new object for water thermometer waterSensor.init() # Initialize water thermometer
# if one hour has passed, reset IMU cycle counter if onehour - start_time >= 3600: start_time = onehour imu_cycle = onehour # -------------------------- # AIR TEMPERATURE SENSOR # -------------------------- if tempa_check - air_time >= AT_Hz: air_time = tempa_check #time.sleep(0.1) print("recording air temp") ATnow = np.array([]) mux.disable_channels([0, 1, 2, 3, 4, 5, 6, 7]) mux.enable_channels([1]) AT = tsys01.TSYS01() # Make new object for air temp sensor AT.init() # Initialize air temp sensor #time.sleep(0.1) if not AT.read(): # AT sensor can't be read ATnow = "NaN" else: # AT sensor is readable ATnow = "%.2f" % AT.temperature(tsys01.UNITS_Centigrade) temp = AT.temperature(tsys01.UNITS_Centigrade) ATsum = ATsum + temp ATsamp = ATsamp + 1 GPSdata = gps_data() # obtains gps data size array ATnow = np.append(ATnow, GPSdata) ATdata = np.append(ATdata, [ATnow], axis=0) mux.disable_channels([1]) #print(ATdata) # Displays AT data in real-time np.savetxt('AT_data.csv', ATdata, fmt='%s', delimiter=',')
#! /usr/bin/env python import tsys01 from time import sleep from sensor_connect.msg import sensor import rospy sensor_data = tsys01.TSYS01() if not sensor_data.init(): print("Error initializing sensor") exit(1) pub = rospy.Publisher('data12', sensor, queue_size=20) rospy.init_node('sender', anonymous=True) rate = rospy.Rate(1) while True: if not sensor_data.read(): print("Error reading sensor") exit(1) data = sensor_data.temperature() print("Temperature:", data) sens = sensor() sens.sensor1 = data #print(type(sensor_data.temperature())) pub.publish(sens) sleep(2)
import time import tsys01 from time import sleep sensor = tsys01.TSYS01() sensor2 = tsys01.TSYS01(4) while True: if not sensor.init(): print("Error intializing sensor 1") exit(1) while True: if not sensor.read(): print("Error reading sensor 1") exit(1) print("Temperature: %.2f" % sensor.temperature(tsys01.UNITS_Farenheit)) sleep(1) break if not sensor2.init(): print("Error intializing sensor 2") exit(1) while True: if not sensor2.read(): print("Error reading sensor 2") exit(1)
import RPi.GPIO as GPIO test = GPIO.getmode() print(test) # GPIO.BCM is used to identify pins # Safe to disable GPIO.setwarnings(False) # Thermometer Air GPIO.setup(27, GPIO.OUT) GPIO.setup(22, GPIO.OUT) GPIO.output(27, GPIO.HIGH) GPIO.output(22, GPIO.HIGH) sleep(1) air = tsys01.TSYS01() air.init() sleep(1) GPIO.output(27, GPIO.LOW) GPIO.output(22, GPIO.LOW) # Thermometer Water GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.output(23, GPIO.HIGH) GPIO.output(24, GPIO.HIGH) sleep(1) water = tsys01.TSYS01() water.init() sleep(1) GPIO.output(24, GPIO.LOW)
import time import board import busio import tsys01 # Temperture counter = 0 while True: try: blueT1 = tsys01.TSYS01() blueT1.init() except Exception: print("Error staring Temp sensor #", counter) counter += 1 continue break while True: if not blueT1.read(): print("Error reading") print("Temperature: %.2f C"%blueT1.temperature(tsys01.UNITS_Centigrade)) print("") time.sleep(0.5)