def __init__(self, use_BNO=True): #Constants self.delay_time = .001 self.use_BNO = use_BNO #I2C Initialization self.i2c = busio.I2C(board.SCL, board.SDA) if use_BNO: #BNO Initialization #self.bno = adafruit_bno055.BNO055(self.i2c) self.bno = BNO055.BNO055(serial_port='/dev/serial0', rst=18) #self.bno.use_external_crystal = True else: self.bno_euler = [0, 0, 0] #MPL Initialization self.mpl = adafruit_mpl3115a2.MPL3115A2(self.i2c) self.mpl._ctrl_reg1 = adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_OS1 | adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_ALT time.sleep(1) self.zero_mpl() # self.led = LED(21) #Initialize ADXL self.adxl = adafruit_adxl34x.ADXL345(self.i2c) self.adxl.range = adafruit_adxl34x.Range.RANGE_16_G self.adxl.data_rate = adafruit_adxl34x.DataRate.RATE_100_HZ
def initializeSensors(): # Initialize the Altitude/Pressure Sensor (MPL3115A2) global altitudePressureSensor try: altitudePressureSensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x60) # You can configure the pressure at sealevel to get better altitude estimates. # This value has to be looked up from your local weather forecast or meteorlogical # reports. It will change day by day and even hour by hour with weather # changes. Remember altitude estimation from barometric pressure is not exact! # Set this to a value in pascals: altitudePressureSensor.sealevel_pressure = 101760 except (OSError, ValueError): print("Altitude sensor not detected") #Initialize the Acceleration Sensor (lsm9ds1) global accelerationSensor try: accelerationSensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c) except (OSError, ValueError): print("Acceleration sensor not detected") #Initializes the Geiger Counter global radiationSensor try: radiationSensor = RadiationWatch(24, 23) radiationSensor.setup() except (OSError, ValueError): print("Radiation sensor not detected")
def init_baro(): i2c = board.I2C() # init i2c bus try: baro = adafruit_mpl3115a2.MPL3115A2(i2c) # init barometer return baro except: print("icarus.init_baro() failed") return None
def __init__(self, sea_level): self.error = False self.offset = 0 try: # Activate to be able to address the module self.sensor = adafruit_mpl3115a2.MPL3115A2(i2c) # change this to match the location's pressure (hPa) at sea level self.sensor.sealevel_pressure = sea_level * 100 except: self.error = True
def init(): global i2c global fxos global fxas global mpl i2c = busio.I2C(board.SCL, board.SDA) fxos = adafruit_fxos8700.FXOS8700(i2c) fxas = adafruit_fxas21002c.FXAS21002C(i2c) mpl = adafruit_mpl3115a2.MPL3115A2(i2c) mpl.sealevel_pressure = 102250
def initializeSensors(): # Initialize the Altitude/Pressure/Temperature Sensor (MPL3115A2) global altitudePressureSensor try: altitudePressureSensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x60) # You can configure the pressure at sealevel to get better altitude estimates. # This value has to be looked up from your local weather forecast or meteorlogical # reports. It will change day by day and even hour by hour with weather # changes. Remember altitude estimation from barometric pressure is not exact! # Set this to a value in pascals: altitudePressureSensor.sealevel_pressure = 101760 except (OSError, ValueError): print("Altitude sensor not detected")
def __init__(self): #Constants self.delay_time = .001 #I2C Initialization self.i2c = busio.I2C(board.SCL, board.SDA) #BNO Initialization self.bno = adafruit_bno055.BNO055(i2c) #self.bno.use_external_crystal = True #MPL Initialization self.mpl = adafruit_mpl3115a2.MPL3115A2(i2c) self.mpl._ctrl_reg1 = adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_OS1 |adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_ALT time.sleep(1) self.zero_mpl() self.led = LED(21) #Initialize ADXL self.adxl = adafruit_adxl34x.ADXL345(i2c) self.adxl.range = adafruit_adxl34x.Range.RANGE_16_G self.adxl.data_rate = adafruit_adxl34x.DataRate.RATE_100_HZ #Initialize file and write header self.filename = self.gen_filename() with open(filename,'w') as f: f.write("Time ms,") #f.write("BNO X Acceleration m/s^2,") #f.write("BNO Y Acceleration m/s^2,") #f.write("BNO Z Acceleration m/s^2,") #f.write("BNO Gyro X rad/s,") #f.write("BNO Gyro Y rad/s,") #f.write("BNO Gyro Z rad/s,") f.write("BNO Euler Angle X,") f.write("BNO Euler Angle Y,") f.write("BNO Euler Angle Z,") #f.write("BNO Magnetometer X,") #f.write("BNO Magnetometer Y,") #f.write("BNO Magnetometer Z,") #f.write("BNO Gravity X,") #f.write("BNO Gravity Y,") #f.write("BNO Gravity Z,") f.write("Altitude m,") f.write("ADXL X Acceleration,") f.write("ADXL Y Acceleration,") f.write("ADXL Z Acceleration,") f.write("\n")
def initializeSensors(): # Test initializing the I2C try: i2c = busio.I2C(board.SCL, board.SDA) except: print("I2C bus could not be initialized") # Initialize the Altitude/Pressure Sensor (MPL3115A2) # Alternatively you can specify a different I2C address for the device: #sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10) global altitudePressureSensor try: altitudePressureSensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x60) # You can configure the pressure at sealevel to get better altitude estimates. # This value has to be looked up from your local weather forecast or meteorlogical # reports. It will change day by day and even hour by hour with weather # changes. Remember altitude estimation from barometric pressure is not exact! # Set this to a value in pascals: altitudePressureSensor.sealevel_pressure = 101760 except (OSError, ValueError, NameError): print( "Altitude sensor not detected. Please check the connection to the sensor.\n" ) #Initialize the Acceleration Sensor (LSM9DS1) global accelerationSensor try: accelerationSensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c) except (OSError, ValueError, NameError): print( "Acceleration sensor not detected. Please check the connection to the sensor.\n" ) global radiationSensor try: radiationSensor = RadiationWatch(24, 23) radiationSensor.setup() except (OSError, ValueError, NameError): print( "Radiation sensor not detected. Please check the connection to the sensor.\n" )
def get_altitude(): PRESSURE_SEA_LEVEL_PASCALS = 101626 # Initialize the I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialize the MPL3115A2. sensor = adafruit_mpl3115a2.MPL3115A2(i2c) # Set this to a value in pascals: sensor.sealevel_pressure = PRESSURE_SEA_LEVEL_PASCALS print('*** BEGIN MEASUREMENTS ***') if cpxWriteMode(): logger = open("/log.txt", "a") while True: altitude = sensor.altitude print('Altitude: {0:0.3f} meters'.format(altitude)) if cpxWriteMode(): logger.write('Altitude: {0:0.3f} meters\r\n'.format(altitude)) logger.flush() time.sleep(0.2) if cpx.button_a == True and cpx.button_b == True: print('*** END MEASUREMENTS ***') if cpxWriteMode(): logger.write('*** END MEASUREMENTS ***') logger.flush() logger.close() break
def __init__(self, i2c): self.i2c = i2c self.sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
# Returns appropriate distance if (ultrasonicFail): ultraDistance = -1 else: ultraDistance = echoLength * DIST_CONV_FACTOR return ultraDistance ### Configuration print('Configuration has begun.') ## I2C setup (Air quality and pressure sensors) i2c_bus = busio.I2C(board.SCL, board.SDA) ccs811 = adafruit_ccs811.CCS811(i2c_bus, AIRQ_SENS_ADDRESS) presSensor = adafruit_mpl3115a2.MPL3115A2(i2c_bus, address=PRES_SENS_ADDRESS) presSensor.sealevel_pressure = SEA_LEVEL_PRES print('I2C has been configured.') ## Camera setup print('Configuring the camera.') # Setup the UART uart = serial.Serial(UART_PORT, baudrate=UART_BAUD_RATE, timeout=UART_TIMEOUT) # Setup VC0706 camera vc0706 = adafruit_vc0706.VC0706(uart) # Print the version string from the camera. print('VC0706 version:') print(vc0706.version)
import adafruit_bno055 import adafruit_adxl34x from gpiozero import LED #Constants delay_time = .001 #I2C Initialization i2c = busio.I2C(board.SCL, board.SDA) #BNO Initialization bno = adafruit_bno055.BNO055(i2c) #bno.use_external_crystal = True #Initialize MPL mpl = adafruit_mpl3115a2.MPL3115A2(i2c) mpl._ctrl_reg1 = adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_OS1 | adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_ALT time.sleep(1) led = LED(21) total = 0 for i in range(200): #print(i) total += mpl.pressure time.sleep(.005) mpl.sealevel_pressure = int(total / 200) #Initialize ADXL adxl = adafruit_adxl34x.ADXL345(i2c) adxl.range = adafruit_adxl34x.Range.RANGE_16_G
if args.gps: gps = adafruit_gps.GPS(uart, debug=False) # Only send back GPRMC (Recommended Minimum Specific GNSS Sentence) and GPGGA (GPS Fix Data) gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') # Update once a second gps.send_command(b'PMTK220,1000') gps.update() logging.info('GPS Enabled') # Adafruit Barometric Altimeter MPL3115A2 altimeter = None if args.altimeter: altimeter = adafruit_mpl3115a2.MPL3115A2(i2c) altimeter.sealevel_pressure = 102520 logging.info('Altimeter Enabled, Pressure: %d', altimeter.sealevel_pressure) # Adafruit 9-DOF Accelerometer accelerometer = None if args.accelerometer: accelerometer = adafruit_fxos8700.FXOS8700(i2c) logging.info('9-DOF Enabled') ###################################################################### # TRANSMIT FUNCTION ######################################################################
def __init__(self): ### Configuration print('Configuration has begun.') ## I2C setup (Air quality and pressure sensors) self.i2c_bus = busio.I2C(board.SCL, board.SDA) self.ccs811 = adafruit_ccs811.CCS811(self.i2c_bus, Sensors.AIRQ_SENS_ADDRESS) self.presSensor = adafruit_mpl3115a2.MPL3115A2( self.i2c_bus, address=Sensors.PRES_SENS_ADDRESS) self.presSensor.sealevel_pressure = Sensors.SEA_LEVEL_PRES print('I2C has been configured.') ## Camera setup print('Configuring the camera.') # Setup the UART self.uart = serial.Serial(Sensors.UART_PORT, baudrate=Sensors.UART_BAUD_RATE, timeout=Sensors.UART_TIMEOUT) # Setup VC0706 camera self.vc0706 = adafruit_vc0706.VC0706(self.uart) # Print the version string from the camera. print('VC0706 version:') print(self.vc0706.version) # Set the image size. self.vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480 # Note you can also read the property and compare against those values to see the current size: imageSize = self.vc0706.image_size if imageSize == adafruit_vc0706.IMAGE_SIZE_640x480: print('Using 640x480 size image.') elif imageSize == adafruit_vc0706.IMAGE_SIZE_320x240: print('Using 320x240 size image.') elif imageSize == adafruit_vc0706.IMAGE_SIZE_160x120: print('Using 160x120 size image.') print('Camera has been configured.') ## Ultrasonic sensor setup self.echoPin = gpiozero.DigitalInputDevice(Sensors.ULTRA_ECHO_PIN_NUM) self.trigPin = gpiozero.DigitalOutputDevice(Sensors.ULTRA_TRIG_PIN_NUM) self.trigPin.off() print('Ultrasonic sensor has been configured.') ## Humidity sensor setup self.humidSensor = Adafruit_DHT.DHT22 self.humidPin = Sensors.HUMID_PIN_NUM print('Humidity sensor has been configured.') ## SPI setup # Sets up MCP3202 ADCs self.solarIrradADC = gpiozero.MCP3202( channel=0, differential=True, select_pin=Sensors.SOLAR_IRRAD_SEL_PIN_NUM) self.powerOutADC = gpiozero.MCP3202( channel=0, differential=True, select_pin=Sensors.POWER_OUT_SEL_PIN_NUM) self.surfTempADC0 = gpiozero.MCP3208(channel=0, differential=False, select_pin=13) self.surfTempADC1 = gpiozero.MCP3208(channel=1, differential=False, select_pin=13) self.surfTempADC2 = gpiozero.MCP3208(channel=2, differential=False, select_pin=13) self.surfTempADC3 = gpiozero.MCP3208(channel=3, differential=False, select_pin=13) self.surfTempADC4 = gpiozero.MCP3208(channel=4, differential=False, select_pin=13) self.surfTempADC5 = gpiozero.MCP3208(channel=5, differential=False, select_pin=13) print('SPI ADCs have been configured.') ######### Need code for MCP3208 ADCs ## Wait for the AQ sensor to be ready, then wait another few seconds for things to settle print('Waiting for sensors to be ready.') while not self.ccs811.data_ready: pass time.sleep(Sensors.INIT_WAIT_TIME) print('Sensors ready. Real time loop beginning.') print('------------------------------------------------\n')
def __init__(self): self.imu = False self.baro = False self.currentSense = False self.gps = False # I2C connection: self.i2c = busio.I2C(board.SCL, board.SDA) try: self.imu = adafruit_lsm9ds1.LSM9DS1_I2C(self.i2c) except: print("could not connect to LSM9DS1") try: self.currentSense = adafruit_ina219.INA219(self.i2c, addr=0x45) except: print("could not connect to INA219") try: self.baro = adafruit_mpl3115a2.MPL3115A2(self.i2c) # Calibrate altimeter self.baro.sealevel_pressure = 102250 except: print("could not connect to MPL3115A2") #self.RX = board.D15 #RX #self.TX = board.D14 #TX # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second). try: #self.uart = busio.UART(self.TX, self.RX, baudrate=9600, timeout=3000) self.uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3000) self.gps = adafruit_gps.GPS(self.uart, debug=False) # Initialize the GPS module by changing what data it sends and at what rate. # These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and # PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust # the GPS module behavior: # https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf # Turn on the basic GGA and RMC info (what you typically want) self.gps.send_command( b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') # Turn on just minimum info (RMC only, location): #gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') # Turn off everything: #gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') # Tuen on everything (not all of it is parsed!) #gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0') # Set update rate to once a second (1hz) which is what you typically want. self.gps.send_command(b'PMTK220,900') # Or decrease to once every two seconds by doubling the millisecond value. # Be sure to also increase your UART timeout above! #gps.send_command(b'PMTK220,2000') # You can also speed up the rate, but don't go too fast or else you can lose # data during parsing. This would be twice a second (2hz, 500ms delay): # gps.send_command(b'PMTK220,500') print(self.gps) except: print("could not connect to GPS") self.data = { 'accel': [0, 0, 0], 'gyro': [0, 0, 0], 'mag': [0, 0, 0], 'imu_temp': 0, 'temp': 0, 'pressure': 0, 'alt': 0, 'gps': 'no_fix', 'bus_voltage': 0, 'shunt_voltage': 0, 'current': 0, 'dt': 0 } self.accel_offset = [0, 0, 0] self.gyro_offset = [0, 0, 0] super(Sensors, self).__init__()
# Does not work, wiring error pops up. # Might have to download circuitpython library?? import board import busio import adafruit_mpl3115a2 import time import datetime i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x60) while True: pressure = sensor.pressure print("Pressure: {0:0.2f} pascals".format(pressure)) altitude = sensor.altitude print("Altitude: {0:0.2f} meters".format(altitude)) temperature = sensor.temperature print("Temperature: {0:0.2f} C".format(temperature)) time.sleep(1.0)
import adafruit_mpl3115a2 import adafruit_sht31d HOSTNAME=gethostname() # Output path data_root = '/home/pi' # creat serial instance for gps on uart ser = serial.Serial(port='/dev/ttyS0', baudrate=9600, timeout=3000) # create I2C instance for pressure and RH\T i2c = busio.I2C(board.SCL, board.SDA) # Create instance of Pressure sensor PP_sen = adafruit_mpl3115a2.MPL3115A2(i2c) # Create instance of Sht31D RH/T sensor SHT_sen = adafruit_sht31d.SHT31D(i2c) #create file today = datetime.utcnow().strftime('%Y-%m-%d') outfile = os.path.join(data_root, HOSTNAME + '-' + today + '.csv') f = open(outfile,'a') # append to exisiting file or creae new one f.close count = 0 while True: data = ser.readline() data_string = ''.join([chr(b) for b in data])
# Simple demo of the MPL3115A2 sensor. # Will read the pressure and temperature and print them out every second. # Author: Tony DiCola import time import board import busio import adafruit_mpl3115a2 # Initialize the I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialize the MPL3115A2. sensor = adafruit_mpl3115a2.MPL3115A2(i2c) # Alternatively you can specify a different I2C address for the device: # sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10) # You can configure the pressure at sealevel to get better altitude estimates. # This value has to be looked up from your local weather forecast or meteorlogical # reports. It will change day by day and even hour by hour with weather # changes. Remember altitude estimation from barometric pressure is not exact! # Set this to a value in pascals: sensor.sealevel_pressure = 102250 # Main loop to read the sensor values and print them every second. while True: pressure = sensor.pressure print("Pressure: {0:0.3f} pascals".format(pressure)) altitude = sensor.altitude print("Altitude: {0:0.3f} meters".format(altitude))
# Constant used for the time between writes to the file. TIME_BETWEEN_LINES = 60 # ///////////////////////////////////////////////////////////// # Set up each of the devices so that they are usable throughout the script. i2c = busio.I2C(board.SCL, board.SDA) # Create the TCA9548A object and give it the I2C bus (This is the I2C mux) tca = adafruit_tca9548a.TCA9548A(i2c) # Used to talk to the ds3231 (RTC) note, this is connected to mux channel 2 rtc = adafruit_ds3231.DS3231(tca[2]) # 1 Out of the 2 MPL sensors for pressure and heat. mpl1 = adafruit_mpl3115a2.MPL3115A2(tca[0]) # mux channel 0 mpl2 = adafruit_mpl3115a2.MPL3115A2(tca[1]) # mux channel 1 # Define LCD display dimensions and I2C address WIDTH = 128 HEIGHT = 32 # Create the digital out used for display reset rst = DigitalInOut(board.D7) display = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3c, reset=rst)