def __init__(self, polling_rate=10, decimals=3, sensor_type="MLX90393"): # user parameters self.run_time = input("Enter the desired runtime in minutes: ") if self.run_time == "": self.run_time = -1 self.run_time = float(self.run_time) filename_add = input( "Enter anything you would like to add to the filename: ") # pollingRate in Hz, max 25 self.polling_rate = polling_rate # number of decimals in sensor reading self.decimals = decimals # set up sensor, start counter, convert pollingRate to cycleTime print("Setting up, please wait") i2c_bus = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_mlx90393.MLX90393( i2c_bus, gain=adafruit_mlx90393.GAIN_1X) self.time_counter = 0 # establish event scheduler self.scheduler = sched.scheduler(time.time, time.sleep) # create file with format "MLX90393 DD-MM-YY H:M:S" time_str = time.strftime("%d-%m-%Y %H:%M:%S") self.filename = sensor_type + " " + time_str + " " + filename_add + ".csv" f = open(self.filename, "a") f.write("Polling rate " + str(polling_rate) + " Hz test run on sensor ") f.write(sensor_type + " at " + time_str + "\n") f.write("Seconds,X (uT),Y (uT),Z (uT)\n") f.close()
def initialize(self): import adafruit_mlx90393 from adafruit_extended_bus import ExtendedI2C self.sensor = adafruit_mlx90393.MLX90393( ExtendedI2C(self.input_dev.i2c_bus), address=int(str(self.input_dev.i2c_location), 16), )
def init(self): I2C_BUS = busio.I2C(board.SCL, board.SDA) try: self.sensor = adafruit_mlx90393.MLX90393(I2C_BUS, gain=self.mlx90393_gc) except Exception as e: print("MLX90393: Error setting up device - exit") print(str(e)) sys.exit(1)
def __init__(self, i2c_bus=None): if i2c_bus is None: i2c_bus = busio.I2C(board.SCL, board.SDA) self.i2c_bus = i2c_bus logger.debug("Connecting to Water Meter Sensor") self.sensor = adafruit_mlx90393.MLX90393( i2c_bus, gain=adafruit_mlx90393.GAIN_1X)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT import time import board import adafruit_mlx90393 i2c = board.I2C() # uses board.SCL and board.SDA SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X) while True: MX, MY, MZ = SENSOR.magnetic print("[{}]".format(time.monotonic())) print("X: {} uT".format(MX)) print("Y: {} uT".format(MY)) print("Z: {} uT".format(MZ)) # Display the status field if an error occured, etc. if SENSOR.last_status > adafruit_mlx90393.STATUS_OK: SENSOR.display_status() time.sleep(1.0)
# raspberry pi imports import busio import board # environment variables setup import os # raspberry pi setup I2C_BUS = busio.I2C(board.SCL, board.SDA) # magnetometer import import adafruit_mlx90393 # magnetometer setup SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X) # time imports import time from datetime import datetime import pytz # time setup zoneName = os.environ['TIMEZONE'] timezone = pytz.timezone(zoneName) currentTime = datetime.now(tz=timezone) # twilio imports from twilio.rest import Client # twilio setup accountSid = os.environ['TWILIO_ACCOUNT_SID']