示例#1
0
def get_accel_mag():
    theDict = {}
    i2c = busio.I2C(board.SCL, board.SDA)
    theDict["magnetic"] = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c).magnetic
    theDict["acceleration"] = adafruit_lsm303_accel.LSM303_Accel(
        i2c).acceleration
    return theDict
示例#2
0
 def open(self):
     i2c_busio = busio.I2C(board.SCL, board.SDA)
     self.sensor_mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c_busio)
     self.sensor_accel = adafruit_lsm303_accel.LSM303_Accel(i2c_busio)
     i2c_luma = luma_i2c(port=1, address=0x3c)
     self.lcd = sh1106(i2c_luma, width=128, height=64)
     self.font = ImageFont.truetype("FreeSans.ttf", 16)
     print("Opened interface")
示例#3
0
def init_magnetometer_accelerometer(configuration: Configuration):
    """Initialize the sensor for magnetic and acceleration"""
    assignments = configuration.get_pin_assignments("lsm303")
    if not assignments:
        return None, None
    i2c = busio.I2C(assignments.get("scl"), assignments.get("sda"))
    mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
    accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
    return mag, accel
示例#4
0
    def __init__(self,path):
        self.i2c=busio.I2C(board.SCL,board.SDA)
        self.accel=adafruit_lsm303_accel.LSM303_Accel(self.i2c)
        self.mag=adafruit_lsm303dlh_mag.LSM303DLH_Mag(self.i2c)

        # Creation d'une base de donnees
        self.conn=sqlite3.connect(path + 'Compas_' + str(time.time()) + '.db')
        self.c=self.conn.cursor()
        #c.execute("DROP TABLE CARBOT")
        self.c.execute('''CREATE TABLE Compas (time REAL, acc_x REAL, acc_y REAL,acc_z REAL,mag_x REAL,mag_y REAL,mag_z REAL);''')
示例#5
0
def anglesCompas() :
	#init LSM303DHL
	i2c = busio.I2C(board.SCL, board.SDA)
	mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)


	# angle between x and y
	alphaxy = math.atan2(mag.magnetic[0],mag.magnetic[1])

	rxy = math.sqrt(mag.magnetic[0]**2+mag.magnetic[1]**2)

	#angle between z and plan xy
	alphaz = math.atan2(rxy,mag.magnetic[2])
	
	return alphaxy , alphaz
示例#6
0
def init_magnetometer_accelerometer(configuration: Configuration):
    """Initialize the sensor for magnetic and acceleration"""
    try:
        logging.info("Initializing magnetometer/accelerometer")
        assignments = configuration.get_pin_assignments("lsm303")
        if not assignments:
            return None, None
        i2c = busio.I2C(assignments.get("scl"), assignments.get("sda"))
        mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
        accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
        return mag, accel
    except Exception as ex:  # pylint: disable=broad-except
        mag = DummyMag()
        accel = DummyAccel()
        logging.exception(ex)
        return mag, accel
示例#7
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Read data from the magnetometer and print it out, ASAP! """

import board
import busio
import adafruit_lsm303dlh_mag

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)

while True:
    mag_x, mag_y, mag_z = sensor.magnetic
    print("{0:10.3f} {1:10.3f} {2:10.3f}".format(mag_x, mag_y, mag_z))
示例#8
0
	def __init__(self):
		logger.info('MAG: initializing magnometer')
		i2c = busio.I2C(board.SCL, board.SDA)
		self.sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
示例#9
0
 def __init__(self):
     i2c = busio.I2C(24, 23)
     self._sensor_accel = adafruit_lsm303_accel.LSM303_Accel(i2c=i2c,
                                                             address=0x18)
     self._sensor_mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c=i2c)
示例#10
0
 def __init__(self):
     i2c = busio.I2C(board.SCL, board.SDA)
     self.mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
     self.accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
示例#11
0
import adafruit_lsm303_accel
import adafruit_lsm303dlh_mag
import math

stp = 20  #GPIO_20
dir = 21  #GPIO_21
Boardpin = 23  #GPIO_23
pot_channel = 0  #ADC channel
sleepTime = 1

spi = spidev.SpiDev()  #setup SPI bus for communicating with MCP3008 ADC
spi.open(0, 0)
spi.max_speed_hz = 1000000

i2c = busio.I2C(board.SCL, board.SDA)  #setup I2C configuration
mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)  #read LMS303 magnetomoter data

pi = pigpio.pi()  #setup dir and step as output  for Easy driver
pi.set_mode(dir, pigpio.OUTPUT)
pi.set_mode(stp, pigpio.OUTPUT)


def move(duty, direction):  #stepping motor motion function
    pi.write(dir, direction)
    pi.set_PWM_dutycycle(stp, duty)
    pi.set_PWM_frequency(stp, 500)
    sleep(.05)


def readADCch(channel):  #Read ADC data from MCP008
    adc = spi.xfer2([1, (8 + channel) << 4, 0])
# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

rfm69Celsius = rfm69.temperature
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))
def initializeHardware(display_diagnostics=False,
                       ce_pin=board.D8,
                       csn_pin=board.D17,
                       button_pin=16,
                       ch=76):
    if cfg.config['has_radio']:
        from circuitpython_nrf24l01 import RF24
        import digitalio as dio
        global address, spi, nrf
        try:
            address = b'1Node'
            ce = dio.DigitalInOut(ce_pin)
            csn = dio.DigitalInOut(csn_pin)
            spi = board.SPI()  # init spi bus object

            #Initialize the nRF24L01 on the spi bus object
            nrf = RF24(spi,
                       csn,
                       ce,
                       ard=2000,
                       arc=15,
                       data_rate=1,
                       auto_ack=True,
                       channel=ch)

            if display_diagnostics:
                nrf.what_happened(True)
            else:
                printOK("Radio Initialized")
        except:
            printCRIT("Radio required to proceed. Exiting.")
            quit()
    else:
        printCRIT("Radio required to proceed. Exiting.")
        quit()

    if cfg.config['has_accel']:
        import adafruit_lsm303_accel
        import adafruit_lsm303dlh_mag
        import busio
        global mag, accel, i2c
        try:
            i2c = busio.I2C(board.SCL, board.SDA)
            mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
            accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
            calibrateAccel(cycles=25)
            printOK("Accel Initialized")
        except:
            printERR("Accel Error, Check Connections")
    else:
        printBYP("No Accel Installed... Bypassing")

    if cfg.config['has_GPS']:
        import serial
        import adafruit_gps
        global gps
        try:
            uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=10)
            gps = adafruit_gps.GPS(uart, debug=False)
            gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
            gps.send_command(b'PMTK220,200')
            if display_diagnostics:
                gps.update()
                getGPSLock()
            else:
                printOK("GPS Initialized")
        except:
            printERROR("GPS Error, Check Connections")
    else:
        printBYP("No GPS Installed... Bypassing")

    if cfg.config['has_button']:
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        if display_diagnostics:
            print(interupt())
        else:
            printOK("Button Initialized")
    else:
        printBYP("No Button Installed... Bypassing")
    printOK("System Ready")
    print("=" * 40)