def __init__(self, dataFile, connection, SaveSensorData): # Create an instance of the sensor object self.sensor = ms5837.MS5837_30BA() # Check if we were able to connect to the sensor if (self.sensor._bus == None): # There is no depth sensor connected return None else: # A is the matrix we need to create that converts the last state to the new one, in our case it's just 1 because we get depth measurements directly A = numpy.matrix([1]) # H is the matrix we need to create that converts sensors readings into state variables, since we get the readings directly from the sensor this is 1 H = numpy.matrix([1]) # B is the control matrix, since this is a 1D case and because we have no inputs that we can change we can set this to zero. B = 0 # Q is the process covariance, since we want accurate values we set this to a very low value Q = numpy.matrix([0.001]) # R is the measurement covariance, using a conservative estimate of 0.1 is fair R = numpy.matrix([0.1]) # IC is the original prediction of the depth, setting this to normal room conditions makes sense IC = self.currentDepth # P is the initial prediction of the covariance, setting it to 1 is reasonable P = numpy.matrix([1]) # We must initialize the sensor before reading it self.sensor.init() # Create the filter self._filter = KalmanFilter(A, B, H, IC, P, Q, R) # Create and start the process p = Process(target=self.UpdateValue, args=(connection, dataFile, SaveSensorData)) p.start()
def __init__(self): rospy.init_node('pressure_node') self.sensor = ms5837.MS5837_30BA() # Initiating Subscribers and Publishers self.pub_pressure = rospy.Publisher('sensors/pressure', FluidPressure, queue_size=1) self.pub_temp = rospy.Publisher('sensors/temperature', Temperature, queue_size=1) self.pub_depth = rospy.Publisher('sensors/depth', Float64, queue_size=1) if not self.sensor.init(): rospy.logfatal('Failed to initialize.') else: if not self.sensor.read(): rospy.logfatal('Failed to read.') else: rospy.loginfo('Successfully initialized with pressure: ' + str(ATM_PRESSURE_PA) + ' and gravity: ' + str(LOCAL_GRAVITY)) self.talker()
def init_pressure(self): try: self.pressure_sensor = ms5837.MS5837_30BA() self.pressure_sensor.init() except Exception: print("Pressure sensor could not be initialized") pass
def run(): # Initialize ROS rospy.init_node('bar30_node', anonymous=True) pub = rospy.Publisher('/barometer', Barometer, queue_size=1) # Connect to the Bar30 sensor on I2C bus 1 rospy.loginfo("Connecting to Bar30...") sensor = ms5837.MS5837_30BA(1) if not sensor.init(): rospy.logerr("Can't initialize Bar30") exit(1) sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) rate = rospy.Rate(10) # Max rate on the RPi3 seems to be 22 hz # Loop until Ctrl-C rospy.loginfo("Connected to Bar30, entering main loop") while not rospy.is_shutdown(): if sensor.read(): msg = Barometer() msg.header.stamp = rospy.Time.now() msg.pressure = sensor.pressure() * 100.0 # Pascals msg.temperature = sensor.temperature() # Celsius msg.depth = sensor.depth() # meters pub.publish(msg) else: rospy.logerr("Can't read Bar30") rate.sleep()
def __init__(self, emitsignal): self.emit_Signal = emitsignal self.pilot_enable = False self.enable = False self.Kp = 250 self.Ki = 53 self.Kd = 35 self.sensor = ms5837.MS5837_30BA() self.sensor.setFluidDensity(1000) # kg/m^3 self.sample_time = 0.01 self.current_time = time.time() self.last_time = self.current_time self.pwm_zero = 305 self.out_max = 400 self.out_min = 240 self.zero_offset = 305 self.fwd_zero_offset = 317 self.bwd_zero_offset = 296 try: if not self.sensor.init(): exit(1) if not self.sensor.read(): exit(1) except: pass self.depth = 0.0 self.sensor_offset = self.sensor.depth() self.SetPoint = self.sensor_offset self.clear()
def publish(): sensor = ms5837.MS5837_30BA() sensor.init() tempPub = rospy.Publisher('ExternalTemperature', Temperature, queue_size=1) depthPub = rospy.Publisher('Depth', Float32, queue_size=1) rospy.init_node('Depth') temp = Temperature() depth = Float32() freq = rospy.Rate(1) while not rospy.is_shutdown(): sensor.read() temp.temperature = sensor.temperature() depth.data = sensor.depth() tempPub.publish(temp) depthPub.publish(depth) freq.sleep()
def __init__(self): super().__init__('bar30_node') # Connect to the Bar30 sensor # RPi is bus 1, UP Board is bus 5 self.get_logger().info("connecting to Bar30...") self._sensor = ms5837.MS5837_30BA(5) if not self._sensor.init(): self.get_logger().fatal("can't initialize Bar30") exit(1) self.get_logger().info("connected to Bar30") self._sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) # Publish at 10Hz self._baro_pub = self.create_publisher(Barometer, '/barometer') self.create_timer(0.1, self.timer_callback)
def __init__(self, time): self.pressure = 0 self.ex_pressure = 0 self.pwm = 305 self.sensor = ms5837.MS5837_30BA() self.time = time print("sersnor") if not self.sensor.init(): exit(1) if not self.sensor.read(): exit(1) print("Pressure: ", self.sensor.pressure(ms5837.UNITS_atm)) print("Temperature: ", self.sensor.temperature(ms5837.UNITS_Centigrade)) self.freshwaterDepth = self.sensor.depth() # default is freshwater self.sensor.setFluidDensity(ms5837.DENSITY_SALTWATER)
def publisher(): global depthKoef, depth sensor = ms5837.MS5837_30BA() if not sensor.init(): print "Sensor could not be initialized" exit(1) rospy.init_node("ms5837", anonymous=True) pub_bar = rospy.Publisher("/ms5837/pressure", Float64, queue_size=0) pub_temp = rospy.Publisher("/ms5837/temp", Float64, queue_size=0) rospy.Subscriber("/interface/depthKoef", Bool, callback) while not rospy.is_shutdown(): if sensor.read(): depth = sensor.depth() depthKoef = depth - depthKoef temp = sensor.temperature() pub_bar.publish(data=depthKoef) pub_temp.publish(data=temp) else: print "Sensor read failed!"
def __init__(self, samplerate = 100., density = 997., baseTime = 0.): """ Constructor :type samplerate: float :type density: float :param samplerate: rate at which to sample the pressure sensor, in Hz :param density: density of the water, kg m^-3 """ #Parse the input parameters self.samplerate = samplerate self.density = density #FINAL variables self.I2CBUS = 1 self.GRAV = 9.81 #Initialize the sensor self.sensor = ms5837.MS5837_30BA() test1 = self.sensor.init() test2 = self.sensor.read() self.initialized = test1 & test2 self.running = False #Initialize output variables if (baseTime == 0.): self.baseTime = time.time() else: self.baseTime = baseTime self.basepress = [] for x in range(1,10): self.sensor.read() self.basepress += [self.sensor.pressure()] time.sleep(0.3) self.basepress = stats.mean(self.basepress) self.time = [time.time()-self.baseTime] self.temp = [self.sensor.temperature()] self.press = [self.basepress] self.depth = [0]
def __init__(self): self.fluid_pub = rospy.Publisher('fluid', FluidPressure, queue_size=1) self.depth_stamped_pub = rospy.Publisher('depth_stamped', Vector3Stamped, queue_size=1) self.depth_pub = rospy.Publisher('depth', Float64, queue_size=1) self.temp_pub = rospy.Publisher('temperature', Temperature, queue_size=1) self.sensor = ms5837.MS5837_30BA( ) # Default I2C bus is 1 (Raspberry Pi 3) self.depth = None self.depth_raw = None self.count = 0 # We must initialize the sensor before reading it if not self.sensor.init(): print("Sensor could not be initialized") exit(1) # We have to read values from sensor to update pressure and temperature if not self.sensor.read(): print("Sensor read failed!") exit(1) fluid_density = rospy.get_param('~fluid_density', 1028) self.depth_offset = rospy.get_param('~depth_offset', 0.0) sample_rate = float(rospy.get_param('~sample_rate', 10.0)) self.sensor.setFluidDensity(fluid_density) self.tare_service = rospy.Service('tare_depth_sensor', std_srvs.srv.SetBool, self.tareCallback) self.depth_offset_service = rospy.Service('set_depth_sensor_offset', floatpi.srv.SetDepthOffset, self.setOffsetCallback) rospy.Timer(rospy.Duration(1 / sample_rate), self.timerCallback)
def reset(self): self.running = False #Re-initialize the sensor self.sensor = ms5837.MS5837_30BA() self.sensor.init() #Re-initialize everything self.baseTime = time.time() self.basepress = [] for x in range(1,10): self.sensor.read() self.basepress += [self.sensor.pressure()] time.sleep(0.3) self.basepress = stats.mean(self.basepress) self.time = [time.time()-self.baseTime] self.temp = [self.sensor.temperature()] self.press = [self.basepress] self.depth = [0] #Restart the recording thread self.daemonize()
def get_pressure(water_choice): # Create sensor object sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3) # Must initialize pressure sensor before reading it if not sensor.init(): print("Error initializing pressure sensor." ) # Print not needed in final version exit(1) # Freshwater vs Saltwater depth measurements set via user input form cmd center if water_choice == "1": # Saltwater sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) freshwaterDepth = sensor.depth() # default is freshwater water_choice = "0" elif water_choice == "0": # Freshwater sensor.setFluidDensity(ms5837.DENSITY_FRESHWATER) freshwaterDepth = sensor.depth() # default is freshwater water_choice = "1" else: print("Error on water density choice." ) # Print not needed in final version if sensor.read(): depth = sensor.pressure(ms5837.UNITS_psi) # Get presure in psi #####print("P: %0.4f m \t T: %0.2f C %0.2f F\n" % ( # Print not needed in final version ###depth, # Sensor depth, either fresh or salf water depending on above ###sensor.temperature(), # Default is degrees C (no arguments) ###sensor.temperature(ms5837.UNITS_Farenheit))) # Request Farenheit else: print("Error reading pressure sensor." ) # Print not needed in final version exit(1) return depth
class DepthSensor: currentDepth = 0; # Relative to the MSL self.sensor = ms5837.MS5837_30BA() # A is the matrix we need to create that converts the last state to the new one, in our case it's just 1 because we get depth measurements directly A = numpy.matrix([1]) # H is the matrix we need to create that converts sensors readings into state variables, since we get the readings directly from the sensor this is 1 H = numpy.matrix([1]) # B is the control matrix, since this is a 1D case and because we have no inputs that we can change we can set this to zero. B = 0 # Q is the process covariance, since we want accurate values we set this to a very low value Q = numpy.matrix([0.00001]) # R is the measurement covariance, using a conservative estimate of 0.1 is fair R = numpy.matrix([0.1]) # IC is the original prediction of the depth, setting this to normal room conditions makes sense IC = self.currentDepth # P is the initial prediction of the covariance, setting it to 1 is reasonable P = numpy.matrix([1]) # We must initialize the sensor before reading it self.sensor.init() # Create the filter self._filter = KalmanFilter(A,B,H,IC,P,Q,R)
class AUV: def __init__(self): """ Instantiate the AUV object """ self.mc = MotorController() # Connection to onboard radio. try: # Jack Silberman's radio #self.radio = Radio('/dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_DN038PQU-if00-port0') # Yonder's radio self.radio = Radio( '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0') except Exception, e: print("Radio not found. Exception is: ", e) print("Exiting") exit(1) self.is_manual = True self.pressure_sensor = ms5837.MS5837_30BA() self.imu_sensor = BNO055.BNO055(serial_port='/dev/serial0', rst=18) self.controller = PID(self.mc, TARGET_HEADING, CONTROL_TOLERANCE, TARGET_TOLERANCE, IS_DEBUG_MODE, P, I, D) print("Radio is not connected.")
def depth_read(): sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3) #sensor = ms5837.MS5837_30BA(0) # Specify I2C bus #sensor = ms5837.MS5837_02BA() #sensor = ms5837.MS5837_02BA(0) #sensor = ms5837.MS5837(model=ms5837.MS5837_MODEL_30BA, bus=0) # Specify model and bus # We must initialize the sensor before reading it if not sensor.init(): print "Sensor could not be initialized" exit(1) # We have to read values from sensor to update pressure and temperature if not sensor.read(ms5837.OSR_8192): #read at .2 cm resolutin with high current and large read time print "Sensor read failed!" exit(1) ''' print("Pressure: %.2f atm %.2f Torr %.2f psi") % ( sensor.pressure(ms5837.UNITS_atm), sensor.pressure(ms5837.UNITS_Torr), sensor.pressure(ms5837.UNITS_psi)) print("Temperature: %.2f C %.2f F %.2f K") % ( sensor.temperature(ms5837.UNITS_Centigrade), sensor.temperature(ms5837.UNITS_Farenheit), sensor.temperature(ms5837.UNITS_Kelvin)) ''' #freshwaterDepth = sensor.depth() # default is freshwater #sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) #saltwaterDepth = sensor.depth() # No nead to read() again #sensor.setFluidDensity(1000) # kg/m^3 #print("Depth: %.3f m (freshwater) %.3f m (saltwater)") % (freshwaterDepth, saltwaterDepth) # fluidDensity doesn't matter for altitude() (always MSL air density) #print("MSL Relative Altitude: %.2f m") % sensor.altitude() # relative to Mean Sea Level pressure in air time.sleep(5) i=0 t=0 n = 5 # filter window length arr = [0]*n arr_bar = [0]*n # Spew readings sensor.read(ms5837.OSR_8192) init_depth = sensor.depth()*100 #to gauge atmospheric condition and substract from data init_press = sensor.pressure() while True: if sensor.read(ms5837.OSR_8192): if i == 20 or i == 0: print("Depth(in cm) \t \t Pressure(in mbar) \t \t Temperature(in deg C)") i = 0 ''' print("P: %0.1f mbar %0.3f psi\tT: %0.2f C %0.2f F") % ( sensor.pressure(), # Default is mbar (no arguments) sensor.pressure(ms5837.UNITS_psi), # Request psi sensor.temperature(), # Default is degrees C (no arguments) sensor.temperature(ms5837.UNITS_Farenheit)) # Request Farenheit ''' depth1 = sensor.depth()*100 - init_depth depth2 = sensor.pressure()-init_press # applying moving average filter for 10 values window for j in range(n-1): arr[j]=arr[j+1] arr_bar[j]=arr_bar[j+1] arr[j+1]=depth1 arr_bar[j+1]=depth2 avg = sum(arr)/n avg_bar = sum(arr_bar)/n #filter over print("{} \t \t {} \t \t \t \t {}".format(avg,avg_bar,sensor.temperature())) i=i+1 #t=t+1 #uncomment to use displaying live readings #msg = str(t)+','+str(avg)+'\n' #with open("/home/pi/buoy-codes/data files/testData 11-00(6 July 2018)mvg_avg.txt","a") as f: # f.write(msg) time.sleep(1) else: print "Sensor read failed!" exit(1)
def SensorReader(): print("SensorReader thread started.") global depth global pressure global outsideTemp global insideTemp global humidity try: # Get I2C bus number 1 bus = smbus.SMBus(1) #################################################################### # Setting up the sensor for outside pressure, temp and depth # Used i2c address 76 (0x76) sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3) # We must initialize the sensor before reading it if not sensor.init(): print("Sensor could not be initialized") exit(1) # We have to read values from sensor to update pressure and temperature if not sensor.read(): print("Sensor read failed!") exit(1) print("\nPressure: {0} mbar \t{1} atm".format( round(sensor.pressure(), 2), round(sensor.pressure(ms5837.UNITS_atm), 2))) print("Temperature: {0} C".format( round(sensor.temperature(ms5837.UNITS_Centigrade), 2))) freshwaterDepth = sensor.depth() # default is freshwater sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) saltwaterDepth = sensor.depth() # No nead to read() again #sensor.setFluidDensity(1000) # kg/m^3 print("Depth: {0} m (freshwater) {1} m (saltwater)".format( round(freshwaterDepth, 3), round(saltwaterDepth, 3))) # fluidDensity doesn't matter for altitude() (always MSL air density) print("MSL Relative Altitude: {0} m".format(round(sensor.altitude(), 2))) # relative to Mean Sea Level pressure in air ##################################################################### time.sleep(2) # Spew readings while True: bus.write_quick(0x27) # i2c address 27 time.sleep(0.1) # HIH6130 address, 0x27(39) # Read data back from 0x00(00), 4 bytes # humidity MSB, humidity LSB, temp MSB, temp LSB data = bus.read_i2c_block_data(0x27, 0x00, 4) # Convert the data to 14-bits humidity = ((((data[0] & 0x3F) * 256) + data[1]) * 100.0) / 16383.0 temp = (((data[2] & 0xFF) * 256) + (data[3] & 0xFC)) / 4 insideTemp = (temp / 16384.0) * 165.0 - 40.0 # Convert it to degrees Celsius #fTemp = cTemp * 1.8 + 32 humidity = round(humidity, 2) insideTemp = round(insideTemp, 2) #print("Relative Humidity: {0} %% \tInside Temp: {1} C".format( #round(humidity, 2), #round(insideTemp, 2))) ##print("Temperature in Celsius: {0} C".format()) ##print("Temperature in Fahrenheit: {0} F\n".format(round(fTemp, 2))) if sensor.read(): ## Sensor for outside pressure, temp and depth: pressure = round(sensor.pressure(), 2) outsideTemp = round(sensor.temperature(), 2) depth = round(sensor.depth(), 2) #print("Pressure: {0} mbar \tOutside Temp: {1} C \tDepth: {2} m\n".format( #pressure, # Default is mbar (no arguments) #outsideTemp, # Default is degrees C (no arguments) #depth)) # Default is depth in meters (no arguments) else: print("Sensor read failed!") exit(1) #time.sleep(0.1) except (Exception, KeyboardInterrupt) as e: #pass #connection.close() pwm_pitch.stop() pwm_led.stop() GPIO.cleanup() finally: # Clean up the connection #pass #connection.close() pwm_pitch.stop() pwm_led.stop() GPIO.cleanup()
def main(): global running i2c = busio.I2C(board.SCL, board.SDA) ads = ADS.ADS1115(i2c) chan = AnalogIn(ads, ADS.P0) sensor = ms5837.MS5837_30BA() sensor.init() try: server_socket = socket.socket() server_socket.bind(('192.168.137.2', 50000)) server_socket.listen(0) print('waiting a client ...') connection, address_ip = server_socket.accept() print('client accepted') stream = connection.makefile('wb') except: print("can't create a connection") t0 = time.perf_counter() t_last = 0 ## keyboard.add_hotkey('q', stop_running) i = 0 running = True while running: ADC0_value = chan.value ADC0_voltage = chan.voltage sensor.read() pressure = sensor.pressure() temperature = sensor.temperature() freshwaterDepth = sensor.depth() t = (time.perf_counter() - t0) * 1000 delta_t = t - t_last t_last = t data = str(temperature) + ',' + str(pressure) + ',' + str(freshwaterDepth) + ',' + str(ADC0_value) + ',' + str(ADC0_voltage) + '\n' i = i + 1 try: stream.write(data.encode('Utf8')) stream.flush() except: ## print("can't send data") pass time.sleep(1) try: stream.close() print('stream is closed') except: print("can't close stream") try: connection.close() print('connection socket is closed') except: print("can't close connection") try: server_socket.close() print('server socket is closed') except: print("can't close server socket") print('End of program')
def __init__(self): self.reading = False self.sensor = ms5837.MS5837_30BA(1)
def __init__(self): self.sensor = ms5837.MS5837_30BA( ) # Default I2C bus is 1 (Raspberry Pi 3) self.client = Client(ports.DEPTH_DRIVER_PORT) self.logger = Logger(filename='depth')
def depth_read(): #try: # print('Sensor Operations will start in 5 seconds !') sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3) #sensor = ms5837.MS5837_30BA(0) # Specify I2C bus #sensor = ms5837.MS5837_02BA() #sensor = ms5837.MS5837_02BA(0) #sensor = ms5837.MS5837(model=ms5837.MS5837_MODEL_30BA, bus=0) # Specify model and bus # We must initialize the sensor before reading it if not sensor.init(): print "Sensor could not be initialized" exit(1) # We have to read values from sensor to update pressure and temperature if not sensor.read( ms5837.OSR_8192 ): #read at .2 cm resolutin with high current and large read time print "Sensor read failed!" exit(1) ''' print("Pressure: %.2f atm %.2f Torr %.2f psi") % ( sensor.pressure(ms5837.UNITS_atm), sensor.pressure(ms5837.UNITS_Torr), sensor.pressure(ms5837.UNITS_psi)) print("Temperature: %.2f C %.2f F %.2f K") % ( sensor.temperature(ms5837.UNITS_Centigrade), sensor.temperature(ms5837.UNITS_Farenheit), sensor.temperature(ms5837.UNITS_Kelvin)) ''' #freshwaterDepth = sensor.depth() # default is freshwater #sensor.setFluidDensity(ms5837.DENSITY_SALTWATER) #saltwaterDepth = sensor.depth() # No nead to read() again #sensor.setFluidDensity(1000) # kg/m^3 #print("Depth: %.3f m (freshwater) %.3f m (saltwater)") % (freshwaterDepth, saltwaterDepth) # fluidDensity doesn't matter for altitude() (always MSL air density) #print("MSL Relative Altitude: %.2f m") % sensor.altitude() # relative to Mean Sea Level pressure in air time.sleep(5) i = 0 n = 0 # for time on x axis # Spew readings #file = open("sensorData.txt",'a') while True: if sensor.read(ms5837.OSR_8192): if i == 20 or i == 0: print( "Depth(in cm) \t \t Pressure(in mbar) \t \t Temperature(in deg C)" ) i = 0 ''' print("P: %0.1f mbar %0.3f psi\tT: %0.2f C %0.2f F") % ( sensor.pressure(), # Default is mbar (no arguments) sensor.pressure(ms5837.UNITS_psi), # Request psi sensor.temperature(), # Default is degrees C (no arguments) sensor.temperature(ms5837.UNITS_Farenheit)) # Request Farenheit ''' print("{} \t \t {} \t \t \t \t {}".format(sensor.depth() * 100, sensor.pressure(), sensor.temperature())) i = i + 1 n = n + 1 msg = str(n) + ',' + str(sensor.pressure()) + '\n' with open("sensorData.txt", "a") as file: file.write(msg) #animate() #ani = animation.FuncAnimation(fig, animate, interval=1000) #for 1 sec delay 1000 #plt.show() time.sleep(1) else: print "Sensor read failed!" exit(1)
kp = 29.0 ki = 0 kd = 0 direct = True sample_time = 0.01 # seconds output_value = 0.0 last_input = 0.0 out_max = 450 out_min = 250 zero_offset = 305 freshwaterDepth = 0.0 setpoint = 0.0 i_term = 0.0 windup_guard = 20.0 sensor = ms5837.MS5837_30BA() # We must initialize the sensor before reading it if not sensor.init(): exit(1) # We have to read values from sensor to update pressure and temperature if not sensor.read(): exit(1) pwm = Adafruit_PCA9685.PCA9685() pwm.set_pwm_freq(50) last_time = time.time() - sample_time sensor.setFluidDensity(1000) # kg/m^3
#!/usr/bin/python # @author: Viviana Castillo, APL UW ################################################################################## #print pressure sensor output ################################################################################## #standard imports import time #third party imports import ms5837 #------------------------------------------------------------------------------------------------- #pressure sensor #------------------------------------------------------------------------------------------------- sensor = ms5837.MS5837_30BA() #default i2c bus is 1 #initialize sensor before reading it #Pressure sensor checked if iniitialized if not sensor.init(): print("Sensor could not be initialized") exit(1) #================================================================================ #Loop Begins #================================================================================ while True: #read sensor if sensor.read(): print("P: %0.1f mbar %0.3f psi\tT: %0.2f C %0.2f F") % ( sensor.pressure(), sensor.pressure(ms5837.UNITS_psi),
#!/usr/bin/python import ms5837 #import tsys01 import time import os #sensor_temp = tsys01.TSYS01() sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3) def timesample(): global samp_time samp_time = os.popen("sudo hwclock -u -r").read() samp_time = samp_time.split('.', 1)[0] samp_time = samp_time.replace(" ", "_") samp_time = samp_time.replace(" ", "_") samp_time = samp_time.replace(":", "-") samp_count = str(len(os.listdir("/home/pi/Documents/minion_data/")) + 1) samp_time = samp_count + "-" + samp_time # print samp_time # We must initialize the sensor before reading it #if not sensor_temp.init(): # print("Error initializing sensor") # exit(1) if not sensor.init(): print "Sensor could not be initialized"
def __init__(self, n=10): self.sensor = ms5837.MS5837_30BA() self.n = n #window size for median filter self.calib_depth = 0