PR
キーワードサーチ
フリーページ
サイド自由欄
アクリル 板 2mm厚 450×600mm アクリル アクリル板 プラスチック 透明 窓 パーテーション 棚 戸 扉 建具 コレクションケース ボード コレクションラック フィギュア ケース ガラス
|
|
結晶模型表面はアクリル板をカットして作ります
カレンダー
コメント新着
##############################################################
# SSD1306 OLED Display , vl53l0x I2C Tests with the Raspberry Pi Pico
# modeified 2021/ 4/12 by cyn
# original
# https://github.com/raspberrypi/pico-micropython-examples/tree/master/i2c/1306oled
################################################################ ##
#
from machine import Pin, I2C
import framebuf,sys,time,utime,machine
from ssd1306 import SSD1306_I2C
from vl53l0x import VL53L0X
pix_res_x = 128 # SSD1306 horizontal resolution
pix_res_y = 32 # SSD1306 vertical resolution
# start I2C on I2C0 (GPIO 0/1)
i2c_dev = I2C(0,scl=Pin(1),sda=Pin(0),freq=400000)
# get I2C address in hex format
i2c_addr = [hex(ii) for ii in i2c_dev.scan()]
# oled controller
i2c = I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
#clearOLED
oled.fill(0)
oled = SSD1306_I2C(pix_res_x, pix_res_y, i2c_dev)
i2c = I2C(id=id, sda=sda, scl=scl)
# Create a VL53L0X object
tof = VL53L0X(i2c)
# Pre: 12 to 18 (initialized to 14 by default)
# Final: 8 to 14 (initialized to 10 by default)
# the measuting_timing_budget is a value in ms, the longer the budget, the more accurate the reading.
budget = tof.measurement_timing_budget_us
print("Budget was:", budget)
tof.set_measurement_timing_budget(40000)
# Sets the VCSEL (vertical cavity surface emitting laser) pulse period for the
# given period type (VL53L0X::VcselPeriodPreRange or VL53L0X::VcselPeriodFinalRange)
# to the given value (in PCLKs). Longer periods increase the potential range of the sensor.
# Valid values are (even numbers only):
# tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 18)
tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 12)
# tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 14)
tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 8)
#-------------------------------------------------------------------
while True:
# Start ranging
distance = ( tof.ping() -10)/10
oled.fill(0)
#can not measure over 50cm
if distance > 50:
oled.fill(0)
oled.text("unable over50cm",0,10)
oled.show()
else:
#oled write distance
oled.text(str(distance)+"cm",30,10)
#oled write bar graph
for i in range(distance/5):
oled.text("=",i*8,20)
#oled show
oled.show()
utime.sleep(0.5)