def __init__(self, vl_trigger_pin, trigger_distance=60, debug=False): self.trigger_distance = trigger_distance self.number_triggers = 0 GPIO.setmode(GPIO.BCM) GPIO.setup(vl_trigger_pin, GPIO.OUT) GPIO.output(vl_trigger_pin, 1) time.sleep(0.5) # setup ToF ranging/ALS sensor self.tof_address = 0x29 self.tof_sensor = VL6180X(address=self.tof_address, debug=debug) self.tof_sensor.default_settings() self.is_open = False
# Sample program to read information off ST VL6180X such as identification # and I2C Address. Will add function to change I2C address. from ST_VL6180X import VL6180X # Initialize VL6180X, hereby known as sensor # Default I2C address is always 0x29 at power on. This will need to be changed # if using multiple sensors old = 0x30 new = 0x31 sensor_i2cid = old sensor = VL6180X(sensor_i2cid) sensor.change_address(old,new)
import RPi.GPIO as GPIO # Import GPIO functions import multiplex i2cbus = 1 # 0 for rev1 boards etc. address_mux = 0x70 plexer = multiplex.multiplex(i2cbus) """-- Setup --""" debug = False if len(sys.argv) > 1: if sys.argv[1] == "debug": # sys.argv[0] is the filename debug = True # setup ToF ranging/ALS sensor tof_address = 0x29 tof_sensor = VL6180X(address=tof_address, debug=False) tof_sensor.get_identification() if tof_sensor.idModel != 0xB4: print "Not a valid sensor id: %X" % tof_sensor.idModel else: print "Sensor model: %X" % tof_sensor.idModel print"Sensor model rev.: %d.%d" % \ (tof_sensor.idModelRevMajor, tof_sensor.idModelRevMinor) print"Sensor module rev.: %d.%d" % \ (tof_sensor.idModuleRevMajor, tof_sensor.idModuleRevMinor) print "Sensor date/time: %X/%X" % (tof_sensor.idDate, tof_sensor.idTime) tof_sensor.default_settings() """-- MAIN LOOP --""" while True: readings = [0, 0, 0, 0, 0, 0] for ToFaddress in range(0, 6):
# Quick and Dirty Sensor Read for multiple sensors # Assumes i2c addresses have been change prior to run import sys, time import I2C_VL6180X_Functions from ST_VL6180X import VL6180X import tkinter as tk #Initialize and report Sensor 0 sensor0_i2cid = 0x28 sensor0 = VL6180X(sensor0_i2cid) sensor0.get_identification() if sensor0.idModel != 0xB4: print("Not Valid Sensor, Id reported as ", hex(sensor0.idModel)) else: print("Valid Sensor, ID reported as ", hex(sensor0.idModel)) sensor0.default_settings() #Finish Initialize Sensor 0 #--------------------------------- #Initialize and report Sensor 1 sensor1_i2cid = 0x29 sensor1 = VL6180X(sensor1_i2cid) sensor1.get_identification() if sensor1.idModel != 0xB4: print("Not Valid Sensor, Id reported as ", hex(sensor1.idModel)) else: print("Valid Sensor, ID reported as ", hex(sensor1.idModel)) sensor1.default_settings() #Finish Initialize Sensor 1 #--------------------------------- #Initialize and report Sensor 2
def measure_10seconds(tof_sensor): for x in range(0, 10): print("Measured distance is : ", tof_sensor.get_distance(), " mm") print("Measured distance is : ", tof_sensor.get_distance(), " mm") print("Measured distance is : ", tof_sensor.get_distance(), " mm") time.sleep(1) if __name__ == '__main__': #x30 = tof1 #x29 = tof2 debug = False #init the sensor tof_address = 0x29 tof_address_new = 0x30 tof_sensor1 = VL6180X(address=tof_address, debug=debug) #readout sensordata get_sensor_data(tof_sensor1) #now change the address change_i2c_addr(tof_sensor1, tof_address, tof_address_new) #sensor nochmals auslesen get_sensor_data(tof_sensor1) print("TOF1 ready.") #tof1 muss nun deaktiviert werden sonst werden immer beide tofs überschrieben #tof2 hat jetzt übrigens auch adresse 30 #jetzt tof sensor 2 einlesen
import pygame from pygame.locals import * # ====================== PARTIE AJOUTEE ========================================= # Importation des librairies utiles from guizero import App, Text from Vumetre import Vumetre from ST_VL6180X import VL6180X SEUIL = 25 # Déclaration des objets bargraphe = Vumetre() # setup ToF ranging/ALS sensor telemetre_adresse = 0x29 telemetre = VL6180X(address=telemetre_adresse, debug=False) telemetre.get_identification() if telemetre.idModel != 0xB4: print("Capteur non valide id: {}".format(telemetre.idModel)) else: print("Modèle du capteur: {}".format(telemetre.idModel)) telemetre.default_settings() # Exctinction de toutes les LEDs au démarrage bargraphe.eteindre() # ====================== FIN PARTIE AJOUTEE ========================================= FPS = 25 SCREENWIDTH = 288 SCREENHEIGHT = 512
GPIO.output(i,True) #Wait 20 mSec between configs time.sleep(0.02) time.sleep(0.1) #Renumber I2C Addresses ## #Sensor 0 #Put Sensor 1 and 2 into standby GPIO.output(13,False) GPIO.output(15,False) time.sleep(0.100) #Configure and Change Address #Error Handler in Event that no Default I2c Addresses are present try: sensor0 = VL6180X(i2c_default) except IOError: print("No I2C Device with that address is present") else: sensor0.change_address(i2c_default,sensor0_i2c) sensor0.default_settings() print("sensor 0 is at address ",hex(sensor0_i2c)) time.sleep(0.100) #Take Sensor 1 and 2 out of Standby GPIO.output(13,True) GPIO.output(15,True) time.sleep(0.100) #### #### ###Sensor 1 ###Put Sensor 0 and 2 into standby