def __init__(self, i2c):
     self.i2c = int(i2c, 16)
     self.mux = qwiic.QwiicTCA9548A(address=self.i2c)
     self.ports = [0, 1, 2, 3, 4, 5, 6, 7]
     self.disable_port(self.ports)
     if self.mux.is_connected():
         print("Successfully connected to QwiicTCA9548A at {0}".format(hex(self.i2c)))
     else:
         print("Connection Failed for QwiicTCA9548A at {0}!".format(hex(self.i2c)))
def change_address(old_address: int, new_address):

    # Connect to Mux
    mux = qwiic.QwiicTCA9548A()
    # Initially Disable All Channels
    mux.disable_all()

    print("Running VL53L1X I2C Address Change")

    # Scans I2C addresses
    avail_addresses = qwiic.scan()

    # Check I2C addresses for Pi Servo pHat
    while 0x40 in avail_addresses:
        if 0x70 in avail_addresses:

            pca = qwiic.QwiicPCA9685()
            pca.set_addr_bit(0, 0)

            avail_addresses = qwiic.scan()

        # Remove Pi Servo pHat from avail_address list
        try:
            avail_addresses.remove(0x40)
        except ValueError:
            print(
                "Addresses for Pi Servo pHat (0x40) not in scanned addresses.")

    while 0x29 not in avail_addresses:
        print(
            "VL53L1X ToF sensor not detected on I2C bus at default address (0x29 or 41)."
        )
        mux.list_channels()

        mux.enable_channels(4)

        avail_addresses = qwiic.scan()

    print("Initializing Device")
    ToF = qwiic.QwiicVL53L1X(old_address)
    ToF.SensorInit()
    ToF.SetI2CAddress(new_address)
    print("Address change to new address (", hex(new_address),
          ") is complete.")
Example #3
0
import os
import time
import tsys01
import numpy as np
import datetime

# =============================================================================
# import busio
# import qwiic_icm20948
# import sys
# import struct
# import math
# =============================================================================

# Initialize Constructor
test = qwiic.QwiicTCA9548A()

# Test Run
#########################################
# -------------------------------
# IMU SENSOR
# -------------------------------
# Take reading from IMU on Mux Channel 0
# =============================================================================
# test.disable_channels([0,1,2,3,4,5,6,7])
# =============================================================================
# =============================================================================
# test.enable_channels([0])
# # List Channel Configuration
# test.list_channels()
#
# Author: Riley Redfern
# Date: 5/4/2021
# Purpose: This file is meant to handle the code that would be used for
# The multiplexer and its interactions with the scales hooked up to its
# The scales need to be calibrated and code needs to be adjusted a lot here

import qwiic as q
import PyNAU7802
import smbus2

multiplex = q.QwiicTCA9548A()
scale = PyNAU7802.NAU7802()
bus = smbus2.SMBus(1)

multiplex.enable_channels(4)

multiplex.list_channels()

#multiplex.disable_channels(4)

if scale.begin(bus):
    print("\nConnected scale successfully\n")
else:
    print("\nCannot connect to scale, exiting\n")
    exit()

currentReading = scale.getReading()
currentWeight = scale.getWeight()

print("Current weight is {0:0.3f}".format(currentWeight))
print("Current reading is {0:0.3f}".format(currentReading))
Example #5
0
ATdata = np.array(
    [["Temp(C)", "Year", "Month", "Day", "Hour", "Min", "Sec", "Lat", "Long"],
     ["--", "--", "--", "--", "--", "--", "--", "--",
      "--"]])  # initialize an array for storing AT data
WTdata = np.array(
    [["Temp(C)", "Year", "Month", "Day", "Hour", "Min", "Sec", "Lat", "Long"],
     ["--", "--", "--", "--", "--", "--", "--", "--",
      "--"]])  # initialize an array for storing WT data
# initialize an array for storing IMU data
IMUdata = np.array([[
    "Date", "Time", "AccelX", "AccelY", "AccelZ", "GyroX", "GyroY", "GyroZ",
    "MagX", "MagY", "MagZ", "Temp"
], ["--", "--", "--", "--", "--", "--", "--", "--", "--", "--", "--", "--"]])

# Initialize the 8-channel Qwiic Multiplexer
mux = qwiic.QwiicTCA9548A()

# Create an IMU object
IMU = qwiic_icm20948.QwiicIcm20948()
mux.disable_channels([0, 1, 2, 3, 4, 5, 6, 7])
mux.enable_channels([0])
IMU.begin()

# Main loop runs forever printing the location, etc. every second.
last_log = time.monotonic()
imu_log = time.monotonic()
h2o_time = time.monotonic()
air_time = time.monotonic()
imu_cycle = time.monotonic()
start_time = time.monotonic()
Example #6
0
async def main():
    """
    Runs the main control loop for this demo.  Uses the KeyboardHelper class to read a keypress from the terminal.

    W - Go forward.  Press multiple times to increase speed.
    A - Decrease heading by -10 degrees with each key press.
    S - Go reverse. Press multiple times to increase speed.
    D - Increase heading by +10 degrees with each key press.
    Spacebar - Reset speed and flags to 0. RVR will coast to a stop

    """
    global current_key_code
    global speed
    global heading
    global flags

    await rvr.wake()

    await rvr.reset_yaw()
    mux = qwiic.QwiicTCA9548A()
    mux.disable_all()
    mux.enable_channels([3, 4])
    results = qwiic.list_devices()

    avail_addresses = qwiic.scan()
    print(avail_addresses)

    for r in results:
        print(r)

    frontSensor = qwiic.QwiicVL53L1X(address=95)
    rearSensor = qwiic.QwiicVL53L1X(address=64)

    while True:
        rearSensor.StartRanging()
        frontSensor.StartRanging()
        time.sleep(.005)
        distance = frontSensor.GetDistance()
        time.sleep(.005)
        rDistance = rearSensor.GetDistance()
        time.sleep(.005)
        frontSensor.StopRanging()
        rearSensor.StopRanging()
        print("Front Distance: %s Rear Distance: %s" % (distance, rDistance))

        if current_key_code == 119:  # W
            # if previously going reverse, reset speed back to 64
            if flags == 1:
                speed = 64
            else:
                # else increase speed
                speed += 64
            # go forward
            flags = 0
        elif current_key_code == 97:  # A
            heading -= 10
        elif current_key_code == 115:  # S
            # if previously going forward, reset speed back to 64
            if flags == 0:
                speed = 64
            else:
                # else increase speed
                speed += 64
            # go reverse
            flags = 1
        elif current_key_code == 100:  # D
            heading += 10
        elif current_key_code == 32:  # SPACE
            # reset speed and flags, but don't modify heading.
            speed = 0
            flags = 0

        if distance < 50:
            speed = 0
            flags = 0

        # check the speed value, and wrap as necessary.
        if speed > 255:
            speed = 255
        elif speed < -255:
            speed = -255

        # check the heading value, and wrap as necessary.
        if heading > 359:
            heading = heading - 359
        elif heading < 0:
            heading = 359 + heading

        # reset the key code every loop
        current_key_code = -1

        # issue the driving command
        await rvr.drive_with_heading(speed, heading, flags)

        # sleep the infinite loop for a 10th of a second to avoid flooding the serial port.
        await asyncio.sleep(0.1)
Example #7
0
WTdata = np.array([]) # initialize an array for storing WT data
ATdata = "NaN"
WTdata = "NaN"
# =============================================================================
# ***
# ***
# =============================================================================
# Create an ADC I2C connection
#sensor_ADC = ADS.ADS1015(i2c) # Uncomment if using the ADS1015 ADC
#sensor_ADC = ADS.ADS1115(i2c) # Uncomment if using the ADS1115 ADC
# =============================================================================
# ***
# ***
# =============================================================================
# Initialize the 8-channel Qwiic Multiplexer for IMU, AT, WT, etc.
MUX8 = qwiic.QwiicTCA9548A()

# Create and IMU object
IMU = qwiic_icm20948.QwiicIcm20948()

# =============================================================================
# Sets file up for logging Sensors (not IMU)
# -- Latitude, Longitude -> degrees
# -- Temperatures -> Degrees Centigrade
# -- Time -> 24hr clock (needs to be in UTC!!!)
# -- Date -> YYYYMMDD
# =============================================================================
data_File = open("~/BuoyDAQ_Data.csv", "a") # need to append date and time to filename
if os.stat("~/BuoyDAQ_Data.csv").st_size == 0: # checks to see if file already exists
    StatsHdr_input = ["Date(YYYYMMDD)","Time(hhmmss)(UTC)","Lat","Lon","BattV","AT(C)","WT(C)",...
                     "WVH(m)","DPD(s)","MWD(deg)","MXWVH(m)"]