time of flight sensor UL53L1X keeps cutting out

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MagicLarry
 
Posts: 5
Joined: Fri Jun 29, 2018 10:25 am

time of flight sensor UL53L1X keeps cutting out

Post by MagicLarry »

Hi. I am running the Python/Sonic Pi code below for a theremin-esque game on Raspberry Pi 4b with the UL53L1X ToF sensor and it works fine until it cuts out at random times. Usually only works for a few minutes.

I also tried using a voltage regulator at a lower voltage (2v) but that's not helping.

It is getting a consistent 3.3v.

The circuit is simply:
- pin 1 (3.3v) to Vin
- pin 14 ground to gnd
- gpio 2 (sda) to sda
- gpio3 (scl) to scl

I wondered if it might have something to do with the communication to Sonic pi. But if I unplug it for about 5 minutes it starts working again which makes me think maybe not. Just restarting doesn't work, it has to be unplugged for a bit. I also wondered if it might be overheating but I put a fan right on it and that didn't seem to help either.

Could it be some kind of stack overflow-ish kind of thing? Is there a step I need to do to empty a buffer or something?

Could someone please help me? It's driving me nuts!

Thanks (code follows),

Larry

########################################## THE CODE ######################################

Code: Select all

import qwiic
import time
from pythonosc import osc_message_builder
from pythonosc import udp_client

#object for sonic pi
sender = udp_client.SimpleUDPClient('127.0.0.1', 4560)

notes = {4.5:"C3",
         4.0:"D3",
         3.5:"E3",
         3.0:"F3",
         2.5:"G3",
         2.0:"A3",
         1.5:"B3",
         1.0:"C4",
         0.5:"D4",
         0:"E4"}

puzzle_notes = [0.5, 0, 1.0, 4.5, 2.5, 99]

win =0
last_dist = 6
current_target_tone = 0
time_target_tone_held = 0
num_hits = 0
time_since_last_change = 0
time_since_last_hit = 0
 

# ------------------- LASER INPUT --------------------------------

ToF = qwiic.QwiicVL53L1X()

def distance():
    ToF.start_ranging()  # Write configuration bytes to initiate measurement
    time.sleep(.005)
    distance = ToF.get_distance()    # Get the result of the measurement from the sensor
    time.sleep(.005) #originally .00
    ToF.stop_ranging()
    distanceInches = distance / 25.4
    distanceFeet = distanceInches / 12.0
    print("Distance(mm): %s Distance(ft): %s" % (distance, distanceFeet))
    return distanceFeet


if (ToF.sensor_init() == None):                  # Begin returns 0 on a good init
    print("Sensor online!\n")
 
    ####################### MAIN LOOP #########################

 
    try:
        while win == 0:
            dist = round(distance()*2)/2
            print ("Measured Distance = %.1f cm" % dist)

            # count how long each note is held
            time_since_last_change = time_since_last_change + 1
            print("time since change: {}".format(time_since_last_change))
            time_since_last_hit = time_since_last_hit + 1

            if dist < 4.6:  #Only play note when players are close enough to play
                #check to see if dist has changed
                if dist != last_dist:
                    print("note changed")
                    print("distance: {}  last distance: {}".format(dist, last_dist))
                    last_dist = dist
                    time_since_last_change = 0

                # if it's over 2 seconds - check if it's the current target tone
                if time_since_last_change > 20 and dist == puzzle_notes[current_target_tone]:

                  #  print("####################### CORRECT NOTE ###########")
                    # then increase the num_hits and increment current_target_tone
                    current_target_tone = current_target_tone + 1
                    num_hits = num_hits + 1
                    time_since_last_hit = 0

                    print("NUMBER OF HITS {})".format(num_hits))

                if time_since_last_hit > 150:
                    # if it's too long between correct notes reset current_target_tone to 0

                    num_hits = 0
                    current_target_tone = 0
                    print("TOO LONG BETWEEN HITS")

                # if it's > 5 go to win sequence
                if num_hits >= 5:
                    print ("******** YOU WIN!!! *****")
                    print ("******** YOU WIN!!! *****")
                    print ("******** YOU WIN!!! *****")
                    print ("******** YOU WIN!!! *****")

                    win = 1

                # send notes to sonic pi
                sender.send_message('/trigger/foo', [notes[dist], notes[puzzle_notes[current_target_tone]]])

               # print ("sending {} and {}".format(notes[dist], notes[puzzle_notes[current_target_tone]]))
                time.sleep(.05)

    except Exception as e:
        print(e)
Last edited by adafruit_support_carter on Tue Jan 24, 2023 1:15 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
MagicLarry
 
Posts: 5
Joined: Fri Jun 29, 2018 10:25 am

Re: time of flight sensor UL53L1X keeps cutting out

Post by MagicLarry »

Is anyone from Adafruit going to answer this?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: time of flight sensor UL53L1X keeps cutting out

Post by adafruit_support_carter »

Please post a photo of your setup showing how everything is connected.

Do you see the same issue using the Adafruit library and running the library example?
https://learn.adafruit.com/adafruit-vl5 ... de-3105073

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”