# MAX7219 driver for micropython, changable font
# by Davood Hakemi @ElectroHakemi
#
# max7219.py is modified to work with user-define-able font
# used font github : https://github.com/easytarget/microPyEZfonts
from machine import I2C, SPI, SoftSPI, Pin
from micropython import const
from max7219 import Matrix8x8
import ezFBfont_5x7_ascii_07 as font
import time
import gc
import network
import socket
import ds1307
import requests
I2C_ADDR = 0x57
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
ds1307rtc = ds1307.DS1307(i2c, 0x68)
ds1307rtc.datetime = (2022, 12, 18, 18, 9, 17, 6)
print(ds1307rtc.datetime)
def do_connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
def http_get(url):
import socket
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
while True:
data = s.recv(100)
if data:
print(str(data, 'utf8'), end='')
else:
break
s.close()
do_connect()
max_clk = const(18)
max_din = const(23)
max_cs = const(5)
# spi = SoftSPI(sck=max_clk, mosi=max_din, miso=19)
spi = SPI(2)
display = Matrix8x8(spi, Pin(max_cs), 4)
text = '12345678'
# while True:
# display.scroll(text)
# while True:
# display.text(f'{ds1307rtc.datetime[5]}', 1)
# time.sleep_ms(1000)
distance = len(text) * 8
print(f'dist: {distance}')
gc.enable()
print(gc.mem_free())
# display scrolling text
display.text(text, 1, 2)
gc.collect()
print(gc.mem_free())
url = 'https://tfi.glitch.me/?loc=ethuri'
# Headers to include in the request
headers = {
'Host': 'tfi.glitch.me',
'User-Agent': 'Mozilla/5.0'
}
# Make the GET request
response = requests.get(url, headers=headers)
# Check the response
print(f'Status Code: {response.status_code}')
print('Response Body:\n', response.text)
#print(http_get('http://tfi.glitch.me/?loc=ethuri'))