The two components this pico board is using is a ultrasonic sensor to measure distance and to display that on a tiny oled 128x32 display and it works perfectly when I click the run button on Thonny. But when i just run it on power from a usb cable nothing really happens but the board's LED blinking, which is intentional theres a line of code,: that will blink the LED so that I know the device is working. But the oled display isnt and im not even sure if the ultrasonic sensor even is too. And you also might notice that in the code just before the blinking part theres which I use to also see if the oled display will work but its not. My idea of whats happening is that the code doesnt know about the oled display or something so then it just does the and nothing else idk. I want to make the board function as is like how it does when it runs on thonny but just on a battery, the wire connections are good and the file is main.py and the driver .py file for the oled display is there too , the file is saved into the pico, and have already tried multiple power sources like I said everything works perfectly when I click Run in thonny but when I connect it to a power source it only seems to run what should I do?
Code:
def blink(timer)
Code:
def test():
Code:
def blink(timer):
Code:
def blink(timer)
Code:
from machine import Pin, Timer, I2Cfrom ssd1306 import SSD1306_I2Cimport utimetrigger = Pin(17, Pin.OUT)echo = Pin(16, Pin.IN)i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=200000)oled = SSD1306_I2C(128, 32, i2c)led = Pin(25, Pin.OUT)timer = Timer()def blink(timer): led.toggle()timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)def dist(): trigger.low() utime.sleep_us(2) trigger.high() utime.sleep_us(5) trigger.low() while echo.value() == 0: signaloff = utime.ticks_us() while echo.value() == 1: signalon = utime.ticks_us() timepassed = signalon - signaloff distance = (timepassed * 0.0343) / 2 meterdistance = distance / 100 print("{0}".format("%.3f" % meterdistance)) oled.rotate(False) oled.fill(0) #DRAW RECTANGLE oled.rect(0,0,128,32,1) #DRAW METERS DISPLAY oled.text("{0}".format("%.3f" % meterdistance), 44, 7) oled.text("METERS", 41, 18) oled.show()while True: dist() utime.sleep(.01)
Statistics: Posted by brodude — Fri May 24, 2024 5:18 pm — Replies 0 — Views 21