【发布时间】:2022-08-17 04:27:50
【问题描述】:
当我尝试运行代码时,会出现此错误。
Traceback (most recent call last):
File \"<stdin>\", line 35, in <module>
TypeError: can\'t convert \'float\' object to str implicitly
这是我要运行的代码。
import framebuf
import os
import time
import lcd
import machine
import utime
BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9
#lcd prep
if __name__==\'__main__\':
# Setup the LCD display
pwm = PWM(Pin(BL))
pwm.freq(1000)
pwm.duty_u16(32768)#max 65535
lcd_display = lcd.LCD_2inch()
#temp
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
while True:
reading = sensor_temp.read_u16() * conversion_factor
temp = 27 - (reading - 0.706)/0.001721
print(temp)
utime.sleep(2)
lcd_display.fill(lcd_display.black)
lcd_display.text(temp, 0, 0, lcd_display.white) #heres where there error sends me to
lcd_display.show()
-
看来您必须先将
temp转换为字符串,然后再将其传递给lcd_display.text。
标签: python micropython raspberry-pi-pico