def draw_qr(pos_x, pos_y, qr, scale=4, border=None): border = border or scale * 2 fb.fill_rect(pos_x - (border // 2), pos_y - (border // 2), (qr.width() * scale) + (border), (qr.width() * scale) + (border), color565(*WHITE)) for x in range(qr.width()): for y in range(qr.width()): if qr.get(x, y): fb.fill_rect(pos_x + x * scale, pos_y + y * scale, scale, scale, 0) tft.blit_buffer(fb, 0, 0, tft.width, tft.height)
def handleHardWireScripts(): # matrix of connections examples global ad_oldval, ad1_oldval, ad2_oldval, it it = it + 1 if cm_Light2M8brightness: if isAD1 and isLed8: aval = get_adc_value(adc1) if abs(ad1_oldval - aval) > ADC_HYSTERESIS / 5: ad1_oldval = aval valmap = map(aval, 5, 600, 2, 15) if valmap > 15: valmap = 15 d8.brightness(valmap) if cm_Light2M8: d8.fill(0) d8.text(str(aval), 0, 0, 1) d8.show() if cm_DisplayTemp: if isLed7 and isTemp: try: tt = getTemp() / 10 d7.write_to_buffer(str(tt) + "c ") d7.display() except: print("mqtt.8x7segment.ERR") if isTft: try: fb.fill(0) fb.text('OctopusLab', 20, 15, color565(0, 0, 255)) fb.hline(3, 27, 122, color565(0, 0, 255)) # xyw fb.text('MQTT test', 3, 39, color565(255, 255, 255)) except: print("err.tft") if cm_Time2Tft: if isTft: hhmm = get_hhmm(rtc) #print(hhmm) try: fb.text(hhmm, 86, 148, color565(255, 255, 255)) fb.text(str(itt), 10, 148, color565(0, 0, 255)) sleep(0.5) except: print("err.cm_Time2Tft()") if cm_Temp2Tft: tt = getTemp() / 10 fb.text(str(tt), 86, 133, color565(0, 255, 0)) #fb.pixel(it,int(tt),color565(255,255,255)) print(str(tt)) sleep(2) if isTft: try: tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(2) except: print("err.tft")
spi = SPI(2, baudrate=20000000, sck=Pin(18), mosi=Pin(23)) cs = Pin(26, Pin.OUT) dc = Pin(25, Pin.OUT) tft = st7735fb.ST7735R(spi, cs=cs, dc=dc, rst=None) print("spi.TFT framebufer >") # Initialize FrameBuffer of TFT's size fb = framebuf.FrameBuffer(bytearray(tft.width * tft.height * 2), tft.width, tft.height, framebuf.RGB565) fbp = fb.pixel fb.fill(color565(*BLUE)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(*RED)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(*GREEN)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) # reset display fb.fill(0) tft.blit_buffer(fb, 0, 0, tft.width, tft.height)
ss = Pin(pinout.SPI_CS0_PIN, Pin.OUT) cs = Pin(5, Pin.OUT) dc = Pin(16, Pin.OUT) rst = Pin(17, Pin.OUT) tft = st7735.ST7735R(spi, cs=cs, dc=dc, rst=rst) print("spi.TFT framebufer >") printFree() import framebuf # Initialize FrameBuffer of TFT's size fb = framebuf.FrameBuffer(bytearray(tft.width * tft.height * 2), tft.width, tft.height, framebuf.RGB565) fbp = fb.pixel fb.fill(color565(255, 0, 0)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(0, 255, 0)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(0, 0, 255)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) # reset display fb.fill(0) tft.blit_buffer(fb, 0, 0, tft.width, tft.height)
def handleHardWireScripts(): # matrix of connections examples global ad_oldval, ad1_oldval, ad2_oldval, it, menuValOld it = it + 1 if cm_RunMenu: if (menuVal != menuValOld): # run olny once print("menu: " + str(menuVal)) np[0] = (BLACK) np.write() if isMqtt: publishTopic = mqtt_root_topic + "/{0}/menu/".format(esp_id) c.publish(publishTopic, str(menuVal)) if (menuVal == 1): np[0] = (RED) np.write() displMessage(get_hh_mm(rtc), 3) # hh:mm > hh-mm for 7seg if (menuVal == 2): np[0] = (GREEN) np.write() displMessage(esp_id, 3) if (menuVal == 3): np[0] = (BLUE) np.write() displMessage("octopus", 3) menuValOld = menuVal sleep(2) if cm_Light2M8brightness: if isAD1 and isLed8: aval = get_adc_value(adc1) if abs(ad1_oldval - aval) > ADC_HYSTERESIS / 5: ad1_oldval = aval valmap = map(aval, 5, 600, 2, 15) if valmap > 15: valmap = 15 d8.brightness(valmap) if cm_Light2M8: d8.fill(0) d8.text(str(aval), 0, 0, 1) d8.show() if cm_DisplayTemp: if isLed7 and isTemp: try: tt = getTemp() / 10 d7.write_to_buffer(str(tt) + "c ") d7.display() except: print("mqtt.8x7segment.ERR") if isTft: try: fb.fill(0) fb.text('OctopusLab', 20, 15, color565(0, 0, 255)) fb.hline(3, 27, 122, color565(0, 0, 255)) # xyw fb.text('MQTT test', 3, 39, color565(255, 255, 255)) except: print("err.tft") if cm_Time2Tft: if isTft: hhmm = get_hhmm(rtc) #print(hhmm) try: fb.text(hhmm, 86, 148, color565(255, 255, 255)) fb.text(str(itt), 10, 148, color565(0, 0, 255)) sleep(0.5) except: print("err.cm_Time2Tft()") if cm_Temp2Tft: tt = getTemp() / 10 fb.text(str(tt), 86, 133, color565(0, 255, 0)) #fb.pixel(it,int(tt),color565(255,255,255)) print(str(tt)) sleep(2) if isTft: try: tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(2) except: print("err.tft")
spi = SPI(2, baudrate=20000000, sck=Pin(18), mosi=Pin(23)) cs = Pin(26, Pin.OUT) dc = Pin(25, Pin.OUT) tft = st7735fb.ST7735R(spi, cs=cs, dc=dc, rst=None, rotation=3) print("spi.TFT framebufer >") # Initialize FrameBuffer of TFT's size fb = framebuf.FrameBuffer(bytearray(tft.width * tft.height * 2), tft.width, tft.height, framebuf.RGB565) fbp = fb.pixel fb.fill(color565(*BLUE)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(*RED)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) fb.fill(color565(*GREEN)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height) sleep(1) # reset display fb.fill(0) tft.blit_buffer(fb, 0, 0, tft.width, tft.height)
Installation: ./lib/rgb.py ./lib/st7735.py ampy -p /dev/ttyUSB0 put ./05-tft-st7735.py main.py # reset device """ from machine import SPI, Pin from lib import st7735 from lib.rgb import color565 import framebuf import time spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23)) cs = Pin(5, Pin.OUT) dc = Pin(16, Pin.OUT) rst = Pin(17, Pin.OUT) tft = st7735.ST7735R(spi, cs=cs, dc=dc, rst=rst) fb = framebuf.FrameBuffer(bytearray(tft.width * tft.height * 2), tft.width, tft.height, framebuf.RGB565) # reset display fb.fill(0) fb.text('OctopusLab', 20, 15, color565(255, 255, 255)) fb.text("PF 2019", 35, 55, color565(255, 255, 255)) tft.blit_buffer(fb, 0, 0, tft.width, tft.height)