コード例 #1
0
    def test_read_value(self):
        import math

        gc.collect()
        import board

        gc.collect()

        if not (yes_no(
                "Is MMA8451 wired to SCL {} SDA {} and held still".format(
                    board.SCL, board.SDA))):
            return  # test trivially passed
        # from https://github.com/adafruit/Adafruit_CircuitPython_MMA8451/blob/29e31a0bb836367bc73763b83513105252b7b264/examples/simpletest.py
        import adafruit_mma8451

        i2c = I2C(board.SCL, board.SDA)
        sensor = adafruit_mma8451.MMA8451(i2c)

        x, y, z = sensor.acceleration
        absolute = math.sqrt(x**2 + y**2 + z**2)
        self.assertTrue(9 <= absolute <= 11, "Not earth gravity")

        orientation = sensor.orientation
        self.assertTrue(orientation in (
            adafruit_mma8451.PL_PUF,
            adafruit_mma8451.PL_PUB,
            adafruit_mma8451.PL_PDF,
            adafruit_mma8451.PL_PDB,
            adafruit_mma8451.PL_LRF,
            adafruit_mma8451.PL_LRB,
            adafruit_mma8451.PL_LLF,
            adafruit_mma8451.PL_LLB,
        ))
コード例 #2
0
ファイル: devs.py プロジェクト: h-bar/TrackSide_Pi
 def __init__(self):
     print('Initializing Accelerometer...')
     self.i2c = busio.I2C(board.SCL, board.SDA)
     time.sleep(1)
     self.accelerometer = adafruit_mma8451.MMA8451(
         self.i2c)  # Using default address
     self.accelerometer.data_rate = adafruit_mma8451.DATARATE_400HZ  #400Hz
コード例 #3
0
    def __init__(self):
        # Initialize I2C bus.
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Initialize MMA8451 module.
        self.sensor = adafruit_mma8451.MMA8451(self.i2c)
        # Optionally change the address if it's not the default:
        # sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)

        # Optionally change the range from its default of +/-4G:
        self.sensor.range = adafruit_mma8451.RANGE_2G  # +/- 2G
コード例 #4
0
    def run(self):
        i2c = busio.I2C(board.SCL, board.SDA)
        time.sleep(1)
        if Settings.acc_attached:
            sensor = adafruit_mma8451.MMA8451(i2c)
        if Settings.temp_attached:
            bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)

        while True:
            try:
                if Settings.tag_index == 0 and Settings.acc_attached:
                    accel_x, accel_y, accel_z = sensor.acceleration
                    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.temp_attached:
                    Settings.TEMP_text = "{0:.2f}".format(bme280.temperature)
                    Settings.HUD_text = "{0:.2f}".format(bme280.humidity)
                    Settings.PR_text = "{0:.2f}".format(bme280.pressure)

                self.update.emit()
                sleep(Settings.sample_time)

                if Settings.log_sensor:
                    if not Settings.sensor_flag:
                        self.logstart.emit()
                        if not os.path.isdir(Settings.prelog_dir):
                            os.umask(0)
                            os.mkdir(Settings.prelog_dir)
                        if not os.path.isdir(Settings.log_dir):
                            os.umask(0)
                            os.mkdir(Settings.log_dir)
                        log_file = open(Settings.log_dir + "/log.txt", "w")
                        Settings.sensor_flag = True
                        os.chmod(Settings.log_dir + "/log.txt", 0o777)

                    if Settings.tag_index == 0:

                        log_file.write(Settings.ACC_X_text + "\t" +
                                       Settings.ACC_Y_text + "\t" + Settings.ACC_Z_text + "\r\n")
                    else:

                        log_file.write(Settings.TEMP_text + "\t" +
                                       Settings.HUD_text + "\t" + Settings.PR_text + "\r\n")

                    if int(timeit.default_timer() - Settings.log_start_time > Settings.log_duration):
                        Settings.log_sensor = False
                        Settings.sensor_flag = False
                        log_file.close()
                        self.logdone.emit()
            except Exception as e:
                pass
コード例 #5
0
ファイル: test.py プロジェクト: Jayson-Tolleson/Devel-Wheel
def sensorsup():
	#set up sensors and gpio pins
	# Declare the GPIO settings for the power board
	GPIO.setmode(GPIO.BOARD)
	# Initialize I2C bus. for the accelerometer
	i2c = busio.I2C(board.SCL, board.SDA)
	# Initialize MMA8451 module. the accelerometer
	sensor = adafruit_mma8451.MMA8451(i2c)
	# Optionally change the address if it's not the default:
	#sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)
	sensor.range = adafruit_mma8451.RANGE_2G # +/- 2G
	sensor.data_rate = adafruit_mma8451.DATARATE_800HZ # 800Hz
	# set up GPIO pins for motor power board
	GPIO.setup(7, GPIO.OUT) # Connected to PWMA
	GPIO.setup(11, GPIO.OUT) # Connected to AIN2
	GPIO.setup(12, GPIO.OUT) # Connected to AIN1
	GPIO.setup(13, GPIO.OUT) # Connected to STBY
コード例 #6
0
ファイル: Raspberry_Pi_1.py プロジェクト: pauljguyett/Code
MQTT_PATH_COMMAND = "command_channel"
MQTT_PATH_REPLY = "reply_channel"

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(MQTT_SERVER, 1883, 60)

# initialize I2C bus and sensors for mma8451
i2c = busio.I2C(board.SCL, board.SDA)

# create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

# create each sensor using the TCA9548A channel instead of the I2C object
mma8451_1 = adafruit_mma8451.MMA8451(tca[0])  # MMA8451_1
mma8451_2 = adafruit_mma8451.MMA8451(tca[1])  # MMA8451_2
mma8451_3 = adafruit_mma8451.MMA8451(tca[2])  # MMA8451_3
bno055 = adafruit_bno055.BNO055(i2c)

# open files for each sensor
mma8451_1_File = open('/mnt/usb/mma8451_1.txt', 'w')
mma8451_2_File = open('/mnt/usb/mma8451_2.txt', 'w')
mma8451_3_File = open('/mnt/usb/mma8451_3.txt', 'w')
bno055_File = open('/mnt/usb/bno055.txt', 'w')


def data():
    x1, y1, z1 = mma8451_1.acceleration
    x2, y2, z2 = mma8451_2.acceleration
    x3, y3, z3 = mma8451_3.acceleration
コード例 #7
0
doMSeedDali = False
doArchive = True
doFIR = True
doMultiprocess = True
decimationFactor = 1
if doFIR:
    decimationFactor = 2

quitOnError = True

if not doFake and not doReplay:
    # Initialize I2C bus.
    i2c = busio.I2C(board.SCL, board.SDA)

    # Initialize MMA8451 module.
    sensor = adafruit_mma8451.MMA8451(i2c)
    # Optionally change the address if it's not the default:
    #sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)

    print("reset sensor")
    sensor.reset()
    print("remove gpio interrupt pin")
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.remove_event_detect(pin)
else:
    if doFake:
        sensor = fakeSensor.FakeSensor()
    else:
        ############################################
        # values to change:
        dataDir="Track_Data"
コード例 #8
0
ファイル: accel.py プロジェクト: kikipet/HALO
import board, busio, adafruit_mma8451, time

i2c = busio.I2C(board.SCL, board.SDA)
mma = adafruit_mma8451.MMA8451(i2c, address=0x1D)

x, y, z = mma.acceleration

while True:
    print((x, y, z))
    time.sleep(10)
コード例 #9
0
ファイル: mma8451.py プロジェクト: GursehajHarika/Drone_DOF
# Simple demo of reading the MMA8451 orientation every second.
# Author: Tony DiCola
import time
import smbus
import board
import busio

import adafruit_mma8451

# Initialize I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Initialize MMA8451 module.
sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)
# Optionally change the address if it's not the default:
#sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)

# Optionally change the range from its default of +/-4G:
#sensor.range = adafruit_mma8451.RANGE_2G  # +/- 2G
#sensor.range = adafruit_mma8451.RANGE_4G  # +/- 4G (default)
#sensor.range = adafruit_mma8451.RANGE_8G  # +/- 8G

# Optionally change the data rate from its default of 800hz:
#sensor.data_rate = adafruit_mma8451.DATARATE_800HZ  #  800Hz (default)
#sensor.data_rate = adafruit_mma8451.DATARATE_400HZ  #  400Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_200HZ  #  200Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_100HZ  #  100Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_50HZ   #   50Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_12_5HZ # 12.5Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_6_25HZ # 6.25Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_1_56HZ # 1.56Hz
コード例 #10
0
    def __init__(self, i2c, addressParam=0x1d):

        time.sleep(
            2
        )  # ...Apparently the sleep is necessary...not for anything else, though...
        self.sensor = adafruit_mma8451.MMA8451(i2c, addressParam)
コード例 #11
0
#!/usr/bin/env python
import time
import board
import busio
import adafruit_mma8451

i2c = busio.I2C(board.SCL, board.SDA)
accelerometer = adafruit_mma8451.MMA8451(i2c)

while True:
    print("%f %f %f" % accelerometer.acceleration)
    time.sleep(1)
コード例 #12
0
class acroMeter:

    posOneG = float(9.8)
    negOneG = float(-9.8)

    xPosThreshold = float(format(9.8, '.3f'))
    yPosThreshold = float(format(9.8, '.3f'))
    xNegThreshold = float(format(-9.8, '.3f'))
    yNegThreshold = float(format(-9.8, '.3f'))

    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_mma8451.MMA8451(i2c)

    sensor.range = adafruit_mma8451.RANGE_2G  #2G is the lowest so we can update it the fastest
    sensor.data_rate = adafruit_mma8451.DATARATE_800HZ  #800HZ is the fastest it can update

    #List of all outputs. Increase list to increase amount of outputs. (Left side of Raspi pins)
    out1 = digitalio.DigitalInOut(board.D17)  #Red LED (Going Left)
    out2 = digitalio.DigitalInOut(
        board.D27
    )  #Blue LED (Going forward) Both Red and Green (Braking or reverse)
    out3 = digitalio.DigitalInOut(board.D22)  #Green LED (Going Right)

    #uncomment for more outputs. Output list going downwards. (DO NOT USE) = unusable output
    #DO NOT USE (3.3V)
    #out4 = digitalio.DigitalInOut(board.D10)#reserved
    #out5 = digitalio.DigitalInOut(board.D9)#reserved
    #out6 = digitalio.DigitalInOut(board.D11)#reserved
    #DO NOT USE (gnd)
    #DO NOT USE (reserved)
    #out7 = digitalio.DigitalInOut(board.D5) #reserved
    #out8 = digitalio.DigitalInOut(board.D6) #reserved
    #out9 = digitalio.DigitalInOut(board.D13) #reserved
    #out10 = digitalio.DigitalInOut(board.D19) #reserved
    #out11 = digitalio.DigitalInOut(board.D26) #reserved
    #DO NOT USE (gnd)

    out1.direction = digitalio.Direction.OUTPUT
    out2.direction = digitalio.Direction.OUTPUT
    out3.direction = digitalio.Direction.OUTPUT
    #out4.direction = digitalio.Direction.OUTPUT
    #out5.direction = digitalio.Direction.OUTPUT
    #out6.direction = digitalio.Direction.OUTPUT
    #out7.direction = digitalio.Direction.OUTPUT
    #out8.direction = digitalio.Direction.OUTPUT
    #out9.direction = digitalio.Direction.OUTPUT
    #out10.direction = digitalio.Direction.OUTPUT
    #out11.direction = digitalio.Direction.OUTPUT

    out1.value = True
    out2.value = True
    out3.value = True

    def auto():
        this = acroMeter  #cuz I'm lazy
        x, y, z = this.sensor.acceleration
        if (x > this.xPosThreshold):  #Left turn
            print("x = {0:0.3f} Left turn".format(x))
            this.out1.value = False
        if (y > this.yPosThreshold):  #Forward (gas)
            print("y = {0:0.3f} Forward (Gas)".format(y))
            this.out2.value = False
        if (x < this.xNegThreshold):  #Right turn
            print("x = {0:0.3f} Right turn".format(x))
            this.out3.value = False
        if (y < this.yNegThreshold):  #brake
            print("y = {0:0.3f} Reverse or braking".format(y))
            this.out3.value = False
            this.out1.value = False
        elif (not (y < this.yNegThreshold)
              ):  #Makes sure that if braking it doesn't turn of the leds
            if (not (y > this.yPosThreshold)):  #Not Forward (gas)
                this.out2.value = True
            if (not (x > this.xPosThreshold)
                    and not (x < this.xNegThreshold)):  #Not turning
                this.out1.value = True
                this.out3.value = True
        if (z < -7.8):
            print("Ooh shit!")

    def fullWing():
        this = acroMeter  #cuz I'm lazy
        this.out1.value = False
        this.out3.value = False

    def noWing():
        this = acroMeter  #cuz I'm lazy
        this.out1.value = True
        this.out3.value = True
コード例 #13
0
ファイル: Mma8451.py プロジェクト: jaredcuteri/mbst
 def __init__(self):
     self.imu = mma.MMA8451(busio.I2C(board.SCL, board.SDA))
     super().__init__()
コード例 #14
0
# Configure LoRa Radio
CS = DigitalInOut(board.D5)
RESET = DigitalInOut(board.D6)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
packet_num = 0

#Configure BMP (0x77)and MMA (0x1d)
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
bmp280.sea_level_pressure = 1013.25

#Configure Accelerometer
mma= adafruit_mma8451.MMA8451(i2c)
mma.range = adafruit_mma8451.RANGE_8G
mma.data_rate = adafruit_mma8451.DATARATE_400HZ

#configure file to werite to
file=open("rocketdata.txt", "a")
file.write("Intern Space Program\n")
file.write(datetime.now().strftime('%Y -%m-%d %H:%M:%S'))
file.write("\n\n")
file.close()


# GPS Code
# Will wait for a fix and print a message every second with the current location
# and other details.
import adafruit_gps