def __SetupSensors(self): i2c = busio.I2C(board.SCL, board.SDA) fxos = fxoslib.FXOS8700( i2c, accel_range=fxoslib.ACCEL_RANGE_2G) # accelerometer, magnetometer fxas = fxaslib.FXAS21002C(i2c) # gyro return fxos, fxas
def run(self): i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_fxos8700.FXOS8700(i2c) i2c2 = busio.I2C(board.SCL, board.SDA) sensor2 = adafruit_fxas21002c.FXAS21002C(i2c2) while True: if(Settings.tag_index == 0): accel_x, accel_y, accel_z = sensor.accelerometer Settings.ACC_X_text= "{0:.2f}".format(accel_x) Settings.ACC_Y_text= "{0:.2f}".format(accel_y) Settings.ACC_Z_text= "{0:.2f}".format(accel_z) elif(Settings.tag_index == 1): gyro_x, gyro_y, gyro_z = sensor2.gyroscope Settings.GYRO_X_text= "{0:.2f}".format(gyro_x) Settings.GYRO_Y_text= "{0:.2f}".format(gyro_y) Settings.GYRO_Z_text= "{0:.2f}".format(gyro_z) else: mag_x, mag_y, mag_z = sensor.magnetometer Settings.MAG_X_text= "{0:.2f}".format(mag_x) Settings.MAG_Y_text= "{0:.2f}".format(mag_y) Settings.MAG_Z_text= "{0:.2f}".format(mag_z) self.update.emit() sleep(0.1)
def __init__(self, config, queue, level): self._log = Logger("nxp9dof", level) if config is None: raise ValueError("no configuration provided.") self._config = config self._queue = queue _config = self._config['ros'].get('nxp9dof') self._quaternion_accept = _config.get( 'quaternion_accept') # permit Quaternion once calibrated self._loop_delay_sec = _config.get('loop_delay_sec') # verbose will print some start-up info on the IMU sensors self._imu = IMU(gs=4, dps=2000, verbose=True) # setting a bias correction for the accel only; the mags/gyros are not getting a bias correction self._imu.setBias((0.0, 0.0, 0.0), None, None) # self._imu.setBias((0.1,-0.02,.25), None, None) _i2c = busio.I2C(board.SCL, board.SDA) self._fxos = adafruit_fxos8700.FXOS8700(_i2c) self._log.info('accelerometer and magnetometer ready.') self._fxas = adafruit_fxas21002c.FXAS21002C(_i2c) self._log.info('gyroscope ready.') self._thread = None self._enabled = False self._closed = False self._heading = None self._pitch = None self._roll = None self._is_calibrated = False self._log.info('ready.')
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)
def init_gyro(i2c, dps=250): # default is 250 DPS, but you can use 500, 1000, or 2000 DPS values): if dps == 250: gyroscope = adafruit_fxas21002c.FXAS21002C(i2c) elif dps == 500: gyroscope = adafruit_fxas21002c.FXAS21002C( i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS) elif dps == 1000: gyroscope = adafruit_fxas21002c.FXAS21002C( i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS) elif dps == 2000: gyroscope = adafruit_fxas21002c.FXAS21002C( i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS) return gyroscope
def __init__(self): self.Q = [1., 0., 0., 0.] self.i2c = busio.I2C(board.SCL, board.SDA) # fxos contains data of the accelerometer and the magnetometer self.fxos = adafruit_fxos8700.FXOS8700(self.i2c) self.fxas = adafruit_fxas21002c.FXAS21002C(self.i2c) self.d2g = ahrs.common.DEG2RAD # TODO: make sure the correct frequency is set here self.madgwick = ahrs.filters.Madgwick(frequency=10.0)
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 main(): i2c = busio.I2C(board.SCL_1, board.SDA_1) print("I2C 1 ok!") acc_magn_sensor = adafruit_fxos8700.FXOS8700(i2c) print("acc magn ok!") gyro_sensor = adafruit_fxas21002c.FXAS21002C(i2c) print("gyro ok!") while True: imu_data(gyro_sensor, acc_magn_sensor) time.sleep(1.0)
def Accgyro_Init(): #initalize I2C for fxos8700 and fxas21002c i2c = busio.I2C(board.SCL, board.SDA) fxos = adafruit_fxos8700.FXOS8700(i2c) fxas = adafruit_fxas21002c.FXAS21002C(i2c) print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format( *fxos.accelerometer)) print('Magnetometer (uTesla): ({0:0.3f},{1:0.3f},{2:0.3f})'.format( *fxos.magnetometer)) print('Gyroscope (radians/s): ({0:0.3f},{1:0.3f},{2:0.3f})'.format( *fxas.gyroscope)) # time.sleep(1) return (fxos, fxas)
# program prints turning direction import board import busio import adafruit_fxos8700 import adafruit_fxas21002c import time # assign variables mag_x = 0 # initialize I2C bus and devices i2c = busio.I2C(board.SCL, board.SDA) fxos = adafruit_fxos8700.FXOS8700(i2c) fxas = adafruit_fxas21002c.FXAS21002C(i2c) # main loop reads values and prints them out while True: # read acceleration, magnetometer and gyroscope prev_mag_x = mag_x mag_x, mag_y, mag_z = fxos.magnetometer difference = mag_x - prev_mag_x # print x values if mag_x > prev_mag_x: print("Left: " + str(difference)) elif mag_x < prev_mag_x: print("Right: " + str(difference)) else: print("None") # second time delay time.sleep(1)
# The values for offset aftee this calibration were # # Gyroscope offset: (mean, std) # X: 0.1323125 0.18466651785466298 # Y: 0.2090625 0.14371279766242798 # Z: 0.143375 0.1347482057541174 # # Magnetometer offset: # X: 25.93526 7.08914 # Y: -30.51872 12.36429 # Z: -14.57492 10.45313 i2c = busio.I2C(board.SCL, board.SDA) sensor_acc_mag = adafruit_fxos8700.FXOS8700(i2c) sensor_gyro = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=2000) T, dt = 10, 0.01 gyro_x_data = [] gyro_y_data = [] gyro_z_data = [] mag_x_data = [] mag_y_data = [] mag_z_data = [] k = 0 for i in range(int(T/dt)): mag_x, mag_y, mag_z = sensor_acc_mag.magnetometer # (uTesla) gyro_x, gyro_y, gyro_z = sensor_gyro.gyroscope # (radians/s)
def __init__(self): self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor_acc_mag = adafruit_fxos8700.FXOS8700(self.i2c) self.sensor_gyro = adafruit_fxas21002c.FXAS21002C(self.i2c) self.data = {'roll': 0, 'pitch': 0, 'yaw': 0}
import board import busio import adafruit_fxos8700 import adafruit_fxas21002c i2c = busio.I2C(board.SCL, board.SDA) sensor1 = adafruit_fxos8700.FXOS8700(i2c)#accel and mag sensor2 = adafruit_fxas21002c.FXAS21002C(i2c)#gyro # class sensor1(object):#mock sensor data # accelerometer = [1,2,3] # magnetometer = [1,2,3] # class sensor2(object):#mock sensor data # gyroscope = [1,2,3] def AccelArray(): return sensor1.accelerometer def AccelX(): return sensor1.accelerometer[0] def AccelY(): return sensor1.accelerometer[1] def AccelZ(): return sensor1.accelerometer[2] def MagArray(): return sensor1.magnetometer
def __init__(self): self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_fxas21002c.FXAS21002C(self.i2c)
# To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode # bmp = BMP085(0x77, 3) # ULTRAHIRES Mode # Initialize I2C bus and device. i2c = busio.I2C(board.SCL, board.SDA) # sensor = adafruit_fxos8700.FXOS8700(i2c) # Optionally create the sensor with a different accelerometer range (the # default is 2G, but you can use 4G or 8G values): # sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G) sensor = adafruit_fxos8700.FXOS8700( i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G) sensor1 = adafruit_fxas21002c.FXAS21002C( i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS) time_start = datetime.now() file_name = 'rocket-data-' + str(datetime.now().hour) + '-' + str( datetime.now().minute) + '.csv' with open(file_name, 'w', newline='') as datafile: datawriter = csv.writer(datafile, delimiter=';') # Main loop will read the acceleration and magnetometer values every second # and print them out. while True: # Read acceleration & magnetometer. accel_x, accel_y, accel_z = sensor.accelerometer mag_x, mag_y, mag_z = sensor.magnetometer
import threading import time import math import board import busio import adafruit_fxos8700 import adafruit_fxas21002c #Temp, Humidity, Pressure Sensor import adafruit_bme280 i2c_nxp = board.I2C() mag_accel_sensor = adafruit_fxos8700.FXOS8700(i2c_nxp) gyro_sensor = adafruit_fxas21002c.FXAS21002C(i2c_nxp) #I2C address for the temp, humidity and pressure sensor is 0x76 i2c_bme = board.I2C() bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c_bme, 0x76) ############################################################################### # Parameters and global variables # Parameters update_interval = 100 # Time (ms) between polling/animation updates max_elements = 1440 # Maximum number of elements to store in plot lists # Declare global variables root = None dfont = None frame = None
def __init__(self): i2c = busio.I2C(board.SCL, board.SDA) self.fxos = adafruit_fxos8700.FXOS8700(i2c) self.fxas = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=GYRO_RANGE)
# Simple demo of the FXAS21002C gyroscope. # Will print the gyroscope values every second. import time import board import busio import adafruit_fxas21002c # Initialize I2C bus and device. i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_fxas21002c.FXAS21002C(i2c) # Optionally create the sensor with a different gyroscope range (the # default is 250 DPS, but you can use 500, 1000, or 2000 DPS values): # sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS) # sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS) # sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS) # Main loop will read the gyroscope values every second and print them out. while True: # Read gyroscope. gyro_x, gyro_y, gyro_z = sensor.gyroscope # Print values. print( "Gyroscope (radians/s): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format( gyro_x, gyro_y, gyro_z ) ) # Delay for a second. time.sleep(1.0)
rfm69Fahrenheit = round(rfm69Celsius * 1.8 + 32, 1) # Print out some RFM69 chip state: print("RFM69 Radio Data") print(' Temperature: {0}°F ({1}°C)'.format(rfm69Fahrenheit, rfm69Celsius)) print(' Frequency: {0} MHz'.format(round(rfm69.frequency_mhz, 0))) print(' Bit rate: {0} kbit/s'.format(rfm69.bitrate / 1000)) print(' Frequency deviation: {0} kHz'.format(rfm69.frequency_deviation / 1000)) # Initialize the LSM303 lsmMag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) lsmAcc = adafruit_lsm303_accel.LSM303_Accel(i2c) # Initialize the NXP IMU nxpAcc = adafruit_fxos8700.FXOS8700(i2c) nxpGyro = adafruit_fxas21002c.FXAS21002C(i2c) loopCount = 0 print() while True: blinkLED(onBoardLED) loopCount += 1 if DEBUG: print("Loop #{0:6d}".format(loopCount)) print() lsm_acc_x, lsm_acc_y, lsm_acc_z = lsmAcc.acceleration lsm_mag_x, lsm_mag_y, lsm_mag_z = lsmMag.magnetic