How to Display Warnings on OLED Based on Object Distance Using BeagleBone Black?

Hey guys, still based on my project parking assistance system using a BeagleBone Black running Embedded Linux, VL53L0X time of flight distance sensor to detect the distance to nearby objects and a 0.96-inch OLED display to show the distance and warning messages. how can I display warning messages on the OLED screen when the detected object is too close or too far. i am getting the error Error: Display not updating i have verified timing of the time.sleep() function, ensured proper buffer clearing with disp.clear() but still getting same error. here's my code
import board
import busio
import adafruit_vl53l0x
from Adafruit_SSD1306 import SSD1306_128_64
import time

# Initialize I2C bus and devices
i2c = busio.I2C(board.SCL, board.SDA)
vl53 = adafruit_vl53l0x.VL53L0X(i2c)
disp = SSD1306_128_64(rst=None)
disp.begin()
disp.clear()
disp.display()

while True:
distance = vl53.range
print(f"Distance: {distance} mm")

disp.clear()
if distance < 100:
disp.text("Warning: Too Close!", 0, 0, 1)
elif distance > 2000:
disp.text("Warning: Too Far!", 0, 0, 1)
else:
disp.text(f"Distance: {distance} mm", 0, 0, 1)
disp.display()

time.sleep(1)
import board
import busio
import adafruit_vl53l0x
from Adafruit_SSD1306 import SSD1306_128_64
import time

# Initialize I2C bus and devices
i2c = busio.I2C(board.SCL, board.SDA)
vl53 = adafruit_vl53l0x.VL53L0X(i2c)
disp = SSD1306_128_64(rst=None)
disp.begin()
disp.clear()
disp.display()

while True:
distance = vl53.range
print(f"Distance: {distance} mm")

disp.clear()
if distance < 100:
disp.text("Warning: Too Close!", 0, 0, 1)
elif distance > 2000:
disp.text("Warning: Too Far!", 0, 0, 1)
else:
disp.text(f"Distance: {distance} mm", 0, 0, 1)
disp.display()

time.sleep(1)
Solution:
Hey @Boss lady It looks like you’ve got most things set up correctly. The issue with the display not updating is due to how the text is being rendered on the OLED screen, you could try making sure that each frame is being drawn correctly before it’s sent to the display. The Adafruit_SSD1306 library has some quirks with the text() method, and sometimes it doesn't update the display as expected. So try modifying your code to use the Image and ImageDraw modules to draw the text on...
Jump to solution
3 Replies
Solution
RED HAT
RED HAT3mo ago
Hey @Boss lady It looks like you’ve got most things set up correctly. The issue with the display not updating is due to how the text is being rendered on the OLED screen, you could try making sure that each frame is being drawn correctly before it’s sent to the display. The Adafruit_SSD1306 library has some quirks with the text() method, and sometimes it doesn't update the display as expected. So try modifying your code to use the Image and ImageDraw modules to draw the text on a buffer before displaying it
RED HAT
RED HAT3mo ago
also make sure you are using the latest version of the library, if it doesnt correct the error check that your power supply is stable
Boss lady
Boss lady3mo ago
thanks so much @RED HAT just did this and it worked its funny how a little thing as text appearnce can impact a project heavily
Want results from more Discord servers?
Add your server