#import qwiic module import qwiic #capture a list of all supported qwiic boards on the i2c bus results = qwiic.list_devices() #print the listed results of the supported qwiic boards on the i2c bus print(results) # Select a device from the list and creat an instance of it mydevice = qwiic.create_device(results[0][0]) #print out the specific device print(mydevice)
import qwiic import qwiic_joystick import time import sys import subprocess as sp print() print() print("----------") print("Qwiic I2C Python Demo with Binho Multi-Protocol USB Host Adapter from Win/Mac/Ubuntu") print("----------") print() print("Scanning for Qwiic Devices...") print() devices = qwiic.list_devices() if len(devices) == 0: print("No Devices Found!") exit(1) print("Found the following device(s):") for device in devices: print(device[1]) myJoystick = qwiic_joystick.QwiicJoystick() if myJoystick.connected == True: useJoystick = True myJoystick.begin()
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)