from machine import Pin,SPI,PWM
import framebuf
import time
import os
import gc
##################### FIREBASE ########################
import network
import urequests
BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9
'2inch frames'
class LCD_2inch(framebuf.FrameBuffer):
def __init__(self):
self.width = 300 #actual size was 320, but decreased since of memory
self.height = 220 #actual size of 240, but decreased since of memory
self.cs = Pin(CS,Pin.OUT)
self.rst = Pin(RST,Pin.OUT)
self.cs(1)
self.spi = SPI(1)
self.spi = SPI(1,1000_000)
self.spi = SPI(1,1000_000_00,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None)
self.dc = Pin(DC,Pin.OUT)
self.dc(1)
self.buffer = bytearray(self.height * self.width*2)
super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
self.init_display()
self.RED = 0x07E0
self.GREEN = 0x001F
self.BLUE = 0xF800
self.WHITE = 0xffff
self.BLACK = 0x0000
//after several def(unimportant codes)
if __name__=='__main__':
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# connecting to wifi
if not wlan.isconnected():
wlan.connect("KT_GiGA_89C2", "9bc27xf161") # wifi_data
print("Waiting for Wi-Fi connection", end="...")
while not wlan.isconnected():
print(".", end="")
time.sleep(1)
else:
print(wlan.ifconfig())
print("WiFi is Connected")
print("Wifi is connected")
# URL for Firebase
url = "https://embeded-system-e8163-default-rtdb.firebaseio.com/"
initial_string = "0"
# updating initial state
initial_state = {'phone': initial_string}
urequests.patch(url+"/embeded_system.json", json = initial_state).json()
phone_number = "0"
# first string
response = urequests.get(url+"/embeded_system.json").json()
while (response["phone"] == phone_number):
response = urequests.get(url+"/embeded_system.json").json()
print("Waiting for the update of phone number...")
phone_number = response['phone']
print(f"Updated phone number to {phone_number}")
pwm = PWM(Pin(BL))
pwm.freq(1000)
pwm.duty_u16(32768)#max 65535
LCD = LCD_2inch()
#color BRG
LCD.fill(LCD.WHITE)
while(1):
if wlan.isconnected(): # phone number update only the data has changed
response = urequests.get(url+"/embeded_system.json").json()
if (phone_number != response['phone']):
phone_number = response['phone']
for i, number in enumerate(phone_number):
x = (i % 6) * (50)+5
y = (i // 6) * (90 + 20)+10
LCD.draw_number(number, x, y, LCD.BLACK)
'''for i in range(len(phone_number)): #for the lens(unimportant)
number = phone_number[-(i + 1)]
x = (i % 6) * 50 + 5
y = ((1 if i < 6 else 0)) * (90 + 20) + 10
LCD.draw_number(number, x, y, LCD.BLACK)'''
LCD.show()
LCD.rst()
time.sleep(1)
I'm now handling simple Picowh project, receives string data(ints) from Firebase, and write out them in LCD panel. Since picowh doesn't have enough RAM, so I reduced size of height to decrease buffer size.
It still receives
OSError: [Errno 12] ENOME
at the line "response = urequests.get(url+"/embeded_system.json").json()" I tried sort of gc.collect() or response.close() , but I'm not so good at Micropython, so it doesn't work well.. What should I do??