eew_uscYT9

  • 2024-02-23
  • 加入了学习《fm4任务展示》,观看 fm4任务展示

  • 2024-02-22
  • 加入了学习《follow me 4视频》,观看 follow me 4视频

  • 上传了资料: fm4的rp5040+w5500的代码

  • 2024-02-21
  • 加入了学习《【得捷电子Follow me第4期】使用micropython完成全部任务》,观看 【得捷电子Follow me第4期】使用micropython完成全部任务

  • 回复了主题帖: 【得捷电子Follow me第4期】终极任务

            能够上传和下载文件

  • 发表了主题帖: 【得捷电子Follow me第4期】任务汇总

    本帖最后由 eew_uscYT9 于 2024-2-23 23:27 编辑 第一部 必须提交的任务一:3-5分钟短视频 https://training.eeworld.com.cn/video/39284   第二部分 必须提交的任务二:任务/项目总结报告 入门任务:开发环境搭建,BLINK,驱动液晶显示器进行显示(没有则串口HelloWorld) 【得捷电子Follow me第4期】入门任务:开发环境搭建,BLINK,驱动液晶显示器进行显示 https://bbs.eeworld.com.cn/thread-1271848-1-1.html   基础任务一:完成主控板W5500初始化(静态IP配置),并能使用局域网电脑ping通,同时W5500可以ping通互联网站点;通过抓包软件(Wireshark、Sniffer等)抓取本地PC的ping报文,展示并分析。 【得捷电子Follow me第4期】基础任务一 https://bbs.eeworld.com.cn/thread-1271849-1-1.html   基础任务二:主控板建立TCPIP或UDP服务器,局域网PC使用TCPIP或UDP客户端进行连接并发送数据,主控板接收到数据后,送液晶屏显示(没有则通过串口打印显示);通过抓包软件抓取交互报文,展示并分析。(TCP和UDP二选一,或者全都操作) 【得捷电子Follow me第4期】基础任务二 https://bbs.eeworld.com.cn/thread-1271851-1-1.html   进阶任务:从NTP服务器(注意数据交互格式的解析)同步时间,获取时间送显示屏(串口)显示。 【得捷电子Follow me第4期】进阶任务 https://bbs.eeworld.com.cn/thread-1271850-1-1.html   终极任务二:使用外部存储器,组建简易FTP文件服务器,并能正常上传下载文件。 【得捷电子Follow me第4期】终极任务 https://bbs.eeworld.com.cn/thread-1271852-1-1.html   第三部分 必须提交任务三:可编译下载的代码 https://download.eeworld.com.cn/detail/eew_uscYT9/631270   心得:通过这次的活动我体会到了micropython的便利,学习到了tcp 、udp相关的知识,了解到了怎么搭建ftp文件服务器,也学会了wireshark软件的使用, 非常感谢得捷和电子工程世界一起举办的follow me活动,希望下次也能参加活动学习到相关知识。    

  • 加入了学习《【得捷电子Follow me第3期】任务汇总视频》,观看 【得捷电子Follow me第3期】任务汇总视频

  • 2024-02-14
  • 发表了主题帖: 【得捷电子Follow me第4期】终极任务

    本帖最后由 eew_uscYT9 于 2024-2-21 19:42 编辑 ■  终极任务:使用外部存储器,组建简易FTP文件服务器,并能正常上传下载文件。   通过网上开源代码,建立了ftp服务器,代码如下: # # Small ftp server for ESP8266 ans ESP32 Micropython # # Based on the work of chrisgp - Christopher Popp and pfalcon - Paul Sokolovsky # # The server accepts passive mode only. # It runs in foreground and quits, when it receives a quit command # Start the server with: # # import ftp # # Copyright (c) 2016 Christopher Popp (initial ftp server framework) # Copyright (c) 2016 Robert Hammelrath (putting the pieces together # and a few extensions) # Distributed under MIT License # import socket import network import uos import gc #from usocket import socket from machine import Pin,SPI,UART,PWM import time, network,framebuf ''' static netinfo ''' ip = '192.168.1.20' sn = '255.255.255.0' gw = '192.168.1.1' dns= '8.8.8.8' BL = 13 DC = 8 RST = 12 MOSI = 11 SCK = 10 CS = 9 netinfo=(ip, sn, gw, dns) localip = '' localport = 8000 listen_info = (localip, localport) conn_flag = False def w5x00_init(): global localip spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18)) nic = network.WIZNET5K(spi,Pin(17),Pin(20)) nic.active(True) # use dhcp, if fail use static netinfo #try: # nic.ifconfig('dhcp') #except: nic.ifconfig(netinfo) localip = nic.ifconfig()[0] print('ip :', nic.ifconfig()[0]) print('sn :', nic.ifconfig()[1]) print('gw :', nic.ifconfig()[2]) print('dns:', nic.ifconfig()[3]) while not nic.isconnected(): time.sleep(1) # print(nic.regs()) print('no link') return nic def send_list_data(path, dataclient, full): try: # whether path is a directory name for fname in sorted(uos.listdir(path), key=str.lower): dataclient.sendall(make_description(path, fname, full)) except: # path may be a file name or pattern pattern = path.split("/")[-1] path = path[:-(len(pattern) + 1)] if path == "": path = "/" for fname in sorted(uos.listdir(path), key=str.lower): if fncmp(fname, pattern): dataclient.sendall(make_description(path, fname, full)) def make_description(path, fname, full): if full: stat = uos.stat(get_absolute_path(path, fname)) file_permissions = ("drwxr-xr-x" if (stat[0] & 0o170000 == 0o040000) else "-rw-r--r--") file_size = stat[6] description = "{} 1 owner group {:>10} Jan 1 2000 {}\r\n".format( file_permissions, file_size, fname) else: description = fname + "\r\n" return description def send_file_data(path, dataclient): with open(path, "rb") as file: chunk = file.read(512) while len(chunk) > 0: dataclient.sendall(chunk) chunk = file.read(512) def save_file_data(path, dataclient): with open(path, "wb") as file: chunk = dataclient.recv(512) while len(chunk) > 0: file.write(chunk) chunk = dataclient.recv(512) def get_absolute_path(cwd, payload): # Just a few special cases "..", "." and "" # If payload start's with /, set cwd to / # and consider the remainder a relative path if payload.startswith('/'): cwd = "/" for token in payload.split("/"): if token == '..': if cwd != '/': cwd = '/'.join(cwd.split('/')[:-1]) if cwd == '': cwd = '/' elif token != '.' and token != '': if cwd == '/': cwd += token else: cwd = cwd + '/' + token return cwd # compare fname against pattern. Pattern may contain # wildcards ? and *. def fncmp(fname, pattern): pi = 0 si = 0 while pi < len(pattern) and si < len(fname): if (fname[si] == pattern[pi]) or (pattern[pi] == '?'): si += 1 pi += 1 else: if pattern[pi] == '*': # recurse if (pi + 1) == len(pattern): return True while si < len(fname): if fncmp(fname[si:], pattern[pi+1:]): return True else: si += 1 return False else: return False if pi == len(pattern.rstrip("*")) and si == len(fname): return True else: return False def ftpserver(net, port=21, timeout=None): DATA_PORT = 13333 ftpsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) datasocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ftpsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) datasocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ftpsocket.bind(socket.getaddrinfo("0.0.0.0", port)[0][4]) datasocket.bind(socket.getaddrinfo("0.0.0.0", DATA_PORT)[0][4]) ftpsocket.listen(1) ftpsocket.settimeout(timeout) datasocket.listen(1) datasocket.settimeout(None) msg_250_OK = '250 OK\r\n' msg_550_fail = '550 Failed\r\n' addr = net.ifconfig()[0] print("FTP Server started on ", addr) try: dataclient = None fromname = None do_run = True while do_run: cl, remote_addr = ftpsocket.accept() cl.settimeout(300) cwd = '/' try: # print("FTP connection from:", remote_addr) cl.sendall("220 Hello, this is Micropython.\r\n") while True: gc.collect() data = cl.readline().decode("utf-8").rstrip("\r\n") if len(data) <= 0: print("Client disappeared") do_run = False break command = data.split(" ")[0].upper() payload = data[len(command):].lstrip() path = get_absolute_path(cwd, payload) print("Command={}, Payload={}".format(command, payload)) if command == "USER": cl.sendall("230 Logged in.\r\n") elif command == "SYST": cl.sendall("215 UNIX Type: L8\r\n") elif command == "NOOP": cl.sendall("200 OK\r\n") elif command == "FEAT": cl.sendall("211 no-features\r\n") elif command == "PWD" or command == "XPWD": cl.sendall('257 "{}"\r\n'.format(cwd)) elif command == "CWD" or command == "XCWD": try: files = uos.listdir(path) cwd = path cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) elif command == "CDUP": cwd = get_absolute_path(cwd, "..") cl.sendall(msg_250_OK) elif command == "TYPE": # probably should switch between binary and not cl.sendall('200 Transfer mode set\r\n') elif command == "SIZE": try: size = uos.stat(path)[6] cl.sendall('213 {}\r\n'.format(size)) except: cl.sendall(msg_550_fail) elif command == "QUIT": cl.sendall('221 Bye.\r\n') do_run = False break elif command == "PASV": cl.sendall('227 Entering Passive Mode ({},{},{}).\r\n'. format(addr.replace('.', ','), DATA_PORT >> 8, DATA_PORT % 256)) dataclient, data_addr = datasocket.accept() print("FTP Data connection from:", data_addr) DATA_PORT = 13333 active = False elif command == "PORT": items = payload.split(",") if len(items) >= 6: data_addr = '.'.join(items[:4]) # replace by command session addr if data_addr == "127.0.1.1": data_addr = remote_addr DATA_PORT = int(items[4]) * 256 + int(items[5]) dataclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dataclient.settimeout(10) dataclient.connect((data_addr, DATA_PORT)) print("FTP Data connection with:", data_addr) cl.sendall('200 OK\r\n') active = True else: cl.sendall('504 Fail\r\n') elif command == "LIST" or command == "NLST": if not payload.startswith("-"): place = path else: place = cwd try: cl.sendall("150 Here comes the directory listing.\r\n") send_list_data(place, dataclient, command == "LIST" or payload == "-l") cl.sendall("226 Listed.\r\n") except: cl.sendall(msg_550_fail) if dataclient is not None: dataclient.close() dataclient = None elif command == "RETR": try: cl.sendall("150 Opening data connection.\r\n") send_file_data(path, dataclient) cl.sendall("226 Transfer complete.\r\n") except: cl.sendall(msg_550_fail) if dataclient is not None: dataclient.close() dataclient = None elif command == "STOR": try: cl.sendall("150 Ok to send data.\r\n") save_file_data(path, dataclient) cl.sendall("226 Transfer complete.\r\n") except: cl.sendall(msg_550_fail) if dataclient is not None: dataclient.close() dataclient = None elif command == "DELE": try: uos.remove(path) cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) elif command == "RMD" or command == "XRMD": try: uos.rmdir(path) cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) elif command == "MKD" or command == "XMKD": try: uos.mkdir(path) cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) elif command == "RNFR": fromname = path cl.sendall("350 Rename from\r\n") elif command == "RNTO": if fromname is not None: try: uos.rename(fromname, path) cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) else: cl.sendall(msg_550_fail) fromname = None elif command == "MDTM": try: tm=localtime(uos.stat(path)[8]) cl.sendall('213 {:04d}{:02d}{:02d}{:02d}{:02d}{:02d}\r\n'.format(*tm[0:6])) except: cl.sendall('550 Fail\r\n') elif command == "STAT": if payload == "": cl.sendall("211-Connected to ({})\r\n" " Data address ({})\r\n" "211 TYPE: Binary STRU: File MODE:" " Stream\r\n".format( remote_addr[0], addr)) else: cl.sendall("213-Directory listing:\r\n") send_list_data(path, cl, True) cl.sendall("213 Done.\r\n") else: cl.sendall("502 Unsupported command.\r\n") print("Unsupported command {} with payload {}".format( command, payload)) except Exception as err: print(err) finally: cl.close() cl = None except Exception as e: print(e) finally: datasocket.close() ftpsocket.close() if dataclient is not None: dataclient.close() if __name__ == "__main__": nic = w5x00_init() ftpserver(nic) 启动后,先与w5500建立网络连接,然后在设置ftp   在window的文件夹内搜索ftp服务器       访问成功

  • 发表了主题帖: 【得捷电子Follow me第4期】基础任务二

    本帖最后由 eew_uscYT9 于 2024-2-16 00:58 编辑 任务要求:主控板建立TCPIP或UDP服务器,局域网PC使用TCPIP或UDP客户端进行连接并发送数据,主控板接收到数据后,送液晶屏显示(没有则通过串口打印显示);通过抓包软件抓取交互报文,展示并分析。(TCP和UDP二选一,或者全都操作)   参考官方代码建立了tcp服务器,代码如下 ''' TCP Server example. date: 2023-11-23 ''' from usocket import socket from machine import Pin,SPI,UART,PWM import time, network,framebuf ''' static netinfo ''' ip = '192.168.1.20' sn = '255.255.255.0' gw = '192.168.1.1' dns= '8.8.8.8' BL = 13 DC = 8 RST = 12 MOSI = 11 SCK = 10 CS = 9 netinfo=(ip, sn, gw, dns) localip = '' localport = 8000 listen_info = (localip, localport) conn_flag = False ''' uart0 init baudrate: 115200 tx pin : gpio0 rx pin : gpio1 ''' uart = UART(0, 115200, tx=Pin(0), rx=Pin(1)) uart.init(115200, bits=8, parity=None, stop=1) uart.write('WIZnet chip tcp server example.\r\n') class LCD_1inch14(framebuf.FrameBuffer): def __init__(self): self.width = 240 self.height = 135 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,10000_000,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 def write_cmd(self, cmd): self.cs(1) self.dc(0) self.cs(0) self.spi.write(bytearray([cmd])) self.cs(1) def write_data(self, buf): self.cs(1) self.dc(1) self.cs(0) self.spi.write(bytearray([buf])) self.cs(1) def init_display(self): """Initialize dispaly""" self.rst(1) self.rst(0) self.rst(1) self.write_cmd(0x36) self.write_data(0x70) self.write_cmd(0x3A) self.write_data(0x05) self.write_cmd(0xB2) self.write_data(0x0C) self.write_data(0x0C) self.write_data(0x00) self.write_data(0x33) self.write_data(0x33) self.write_cmd(0xB7) self.write_data(0x35) self.write_cmd(0xBB) self.write_data(0x19) self.write_cmd(0xC0) self.write_data(0x2C) self.write_cmd(0xC2) self.write_data(0x01) self.write_cmd(0xC3) self.write_data(0x12) self.write_cmd(0xC4) self.write_data(0x20) self.write_cmd(0xC6) self.write_data(0x0F) self.write_cmd(0xD0) self.write_data(0xA4) self.write_data(0xA1) self.write_cmd(0xE0) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0D) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2B) self.write_data(0x3F) self.write_data(0x54) self.write_data(0x4C) self.write_data(0x18) self.write_data(0x0D) self.write_data(0x0B) self.write_data(0x1F) self.write_data(0x23) self.write_cmd(0xE1) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0C) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2C) self.write_data(0x3F) self.write_data(0x44) self.write_data(0x51) self.write_data(0x2F) self.write_data(0x1F) self.write_data(0x1F) self.write_data(0x20) self.write_data(0x23) self.write_cmd(0x21) self.write_cmd(0x11) self.write_cmd(0x29) def show(self): self.write_cmd(0x2A) self.write_data(0x00) self.write_data(0x28) self.write_data(0x01) self.write_data(0x17) self.write_cmd(0x2B) self.write_data(0x00) self.write_data(0x35) self.write_data(0x00) self.write_data(0xBB) self.write_cmd(0x2C) self.cs(1) self.dc(1) self.cs(0) self.spi.write(self.buffer) self.cs(1) def w5x00_init(): global localip ''' spi0 init baudrate: 2000000 mosi pin: gpio19 miso pin: gpio16 sck pin: gpio18 cs pin: gpio17 rst pin: gpio20 ''' spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18)) nic = network.WIZNET5K(spi,Pin(17),Pin(20)) nic.active(True) # use dhcp, if fail use static netinfo #try: # nic.ifconfig('dhcp') #except: nic.ifconfig(netinfo) localip = nic.ifconfig()[0] print('ip :', nic.ifconfig()[0]) print('sn :', nic.ifconfig()[1]) print('gw :', nic.ifconfig()[2]) print('dns:', nic.ifconfig()[3]) uart.write('ip :{0}\r\n'.format(nic.ifconfig()[0])) uart.write('sn :{0}\r\n'.format(nic.ifconfig()[1])) uart.write('gw :{0}\r\n'.format(nic.ifconfig()[2])) uart.write('dns:{0}\r\n'.format(nic.ifconfig()[3])) while not nic.isconnected(): time.sleep(1) # print(nic.regs()) print('no link') uart.write('no link\r\n') if __name__ == "__main__": pwm = PWM(Pin(BL)) pwm.freq(1000) pwm.duty_u16(32768)#max 65535 LCD = LCD_1inch14() #color BRG LCD.fill(LCD.white) LCD.text("Follow me NO.4",50,2,LCD.red) LCD.show() w5x00_init() while True: if(conn_flag == False): s = socket() s.bind(listen_info) # Source IP Address and Port s.listen(5) # max conncet counts conn_flag = True print("TEST TCP server ") conn, addr = s.accept() print('Connect from %s' % str(addr)) LCD.text('Connect from',20,20,LCD.blue) LCD.text('%s' % str(addr),20,40,LCD.blue) LCD.show() else: try: data = conn.recv(2048) data = data.decode('utf-8') data+='\r\n' if data != 'NULL': #conn.send(data) LCD.text('data:',20,60,LCD.blue) LCD.text(data,20,80,LCD.blue) LCD.show() except: conn_flag = False time.sleep(1) LCD.fill(0xFFFF)            电脑进行发送消息,服务器能接收到 wireshark抓取信息如下图,抓取信息与发送信息一致   屏幕上显示接收到的信息   然后我在esp32s3上搭建了tcp客户端,进行数据的发送   服务器访问成功发送helloword     屏幕成功接收到信息,并显示出来    

  • 发表了主题帖: 【得捷电子Follow me第4期】进阶任务

    本帖最后由 eew_uscYT9 于 2024-2-14 23:25 编辑 任务要求:从NTP服务器(注意数据交互格式的解析)同步时间,获取时间送显示屏(串口)显示。   NTP服务器:NTP 是用于同步网络中计算机时间的协议,全称为网络时间协议(Network Time Protocol)。在我们日常使用的电子设备中,只要能联网的,大都需要连接到 NTP 服务器,确保自己的时间和世界上的一致。     借鉴了@StreakingJerry大佬的帖子和电子烂人的帖子完成了ntp服务器时间的同步 代码如下 import ntptime #import library from machine import Pin,SPI,PWM import framebuf import usocket import network import time #LED define led = Pin(25, Pin.OUT) BL = 13 DC = 8 RST = 12 MOSI = 11 SCK = 10 CS = 9 """ W5x00 chip initialization. param: None returns: None """ def w5x00_init(): #spi init spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18)) nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin nic.active(True)#network active nic.ifconfig(('192.168.1.20','255.255.255.0','192.168.1.1','8.8.8.8'))#Set static network address information while not nic.isconnected(): time.sleep(1) print(nic.regs())#Print register information #Print network address information print("IP Address:",nic.ifconfig()[0]) print("Subnet Mask:",nic.ifconfig()[1]) print("Gateway:",nic.ifconfig()[2]) print("DNS:",nic.ifconfig()[3]) return nic def dns_query(domain): ip = usocket.getaddrinfo(domain, 80,0, usocket.SOCK_STREAM) return ip[0][4][0] class LCD_1inch14(framebuf.FrameBuffer): def __init__(self): self.width = 240 self.height = 135 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,10000_000,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 def write_cmd(self, cmd): self.cs(1) self.dc(0) self.cs(0) self.spi.write(bytearray([cmd])) self.cs(1) def write_data(self, buf): self.cs(1) self.dc(1) self.cs(0) self.spi.write(bytearray([buf])) self.cs(1) def init_display(self): """Initialize dispaly""" self.rst(1) self.rst(0) self.rst(1) self.write_cmd(0x36) self.write_data(0x70) self.write_cmd(0x3A) self.write_data(0x05) self.write_cmd(0xB2) self.write_data(0x0C) self.write_data(0x0C) self.write_data(0x00) self.write_data(0x33) self.write_data(0x33) self.write_cmd(0xB7) self.write_data(0x35) self.write_cmd(0xBB) self.write_data(0x19) self.write_cmd(0xC0) self.write_data(0x2C) self.write_cmd(0xC2) self.write_data(0x01) self.write_cmd(0xC3) self.write_data(0x12) self.write_cmd(0xC4) self.write_data(0x20) self.write_cmd(0xC6) self.write_data(0x0F) self.write_cmd(0xD0) self.write_data(0xA4) self.write_data(0xA1) self.write_cmd(0xE0) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0D) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2B) self.write_data(0x3F) self.write_data(0x54) self.write_data(0x4C) self.write_data(0x18) self.write_data(0x0D) self.write_data(0x0B) self.write_data(0x1F) self.write_data(0x23) self.write_cmd(0xE1) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0C) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2C) self.write_data(0x3F) self.write_data(0x44) self.write_data(0x51) self.write_data(0x2F) self.write_data(0x1F) self.write_data(0x1F) self.write_data(0x20) self.write_data(0x23) self.write_cmd(0x21) self.write_cmd(0x11) self.write_cmd(0x29) def show(self): self.write_cmd(0x2A) self.write_data(0x00) self.write_data(0x28) self.write_data(0x01) self.write_data(0x17) self.write_cmd(0x2B) self.write_data(0x00) self.write_data(0x35) self.write_data(0x00) self.write_data(0xBB) self.write_cmd(0x2C) self.cs(1) self.dc(1) self.cs(0) self.spi.write(self.buffer) self.cs(1) def main(): pwm = PWM(Pin(BL)) pwm.freq(1000) pwm.duty_u16(32768)#max 65535 LCD = LCD_1inch14() nic = w5x00_init() #color BRG #ip = dns_query("www.baidu.com") #print("IP address is %s"%(ip)) LCD.fill(LCD.white) print(rtc.datetime()) LCD.show() time.sleep(1) LCD.fill(0xFFFF) while True: try: ntptime.settime() t = time.localtime(time.time() + 8*3600) time.sleep_ms(1000) break except: print("Can not get time!") print("time: %s-%s-%s %s:%s:%s" % (t[0],t[1],t[2],t[3],t[4],t[5])) LCD.text("Follow me NO.4",20,20,LCD.red) LCD.text("%s-%s-%s"% (t[0],t[1],t[2]),20,40,LCD.blue) LCD.text('%s:%s:%s'% (t[3],t[4],t[5]),20,60,LCD.blue) LCD.show() if __name__ == "__main__": main() 效果如下图所示      

  • 发表了主题帖: 【得捷电子Follow me第4期】基础任务一

    任务要求:完成主控板W5500初始化(静态IP配置),并能使用局域网电脑ping通,同时W5500可以ping通互联网站点;通过抓包软件(Wireshark、Sniffer等)抓取本地PC的ping报文,展示并分析。   通过修改官方代码可以实现上诉要求   官方代码链接W5100S_W5500+RP2040 Micro Python Examples: 使用W5100S或W5500芯片让树莓派RP2040接入到以太网中的应用示例。 - Gitee.com   静态IP配置,代码如下 def w5x00_init(): #spi init spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18)) nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin nic.active(True)#network active nic.ifconfig(('192.168.1.20','255.255.255.0','192.168.1.1','8.8.8.8'))#Set static network address information while not nic.isconnected(): time.sleep(1) print(nic.regs())#Print register information #Print network address information print("IP Address:",nic.ifconfig()[0]) print("Subnet Mask:",nic.ifconfig()[1]) print("Gateway:",nic.ifconfig()[2]) print("DNS:",nic.ifconfig()[3]) return nic nic = w5x00_init() #w5500初始化  设置板子的静态IP为192.168.1.20,在电脑上通过命令窗口可以ping通板子,证明静态IP设置成功,效果如下图所示       完成W5500可以ping通互联网站点需要设置dns 设置dns代码如下 def dns_query(domain): ip = usocket.getaddrinfo(domain, 80,0, usocket.SOCK_STREAM) return ip[0][4][0] 效果如下        板子ping百度   通过抓包软件Wireshark抓取本地PC的ping报文   在筛选框内输入板子IP地址   总体代码如下所示 #import library from machine import Pin,SPI,PWM import framebuf import usocket import network import time #LED define led = Pin(25, Pin.OUT) BL = 13 DC = 8 RST = 12 MOSI = 11 SCK = 10 CS = 9 """ W5x00 chip initialization. param: None returns: None """ def w5x00_init(): #spi init spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18)) nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin nic.active(True)#network active nic.ifconfig(('192.168.1.20','255.255.255.0','192.168.1.1','8.8.8.8'))#Set static network address information while not nic.isconnected(): time.sleep(1) print(nic.regs())#Print register information #Print network address information print("IP Address:",nic.ifconfig()[0]) print("Subnet Mask:",nic.ifconfig()[1]) print("Gateway:",nic.ifconfig()[2]) print("DNS:",nic.ifconfig()[3]) return nic def dns_query(domain): ip = usocket.getaddrinfo(domain, 80,0, usocket.SOCK_STREAM) return ip[0][4][0] class LCD_1inch14(framebuf.FrameBuffer): def __init__(self): self.width = 240 self.height = 135 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,10000_000,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 def write_cmd(self, cmd): self.cs(1) self.dc(0) self.cs(0) self.spi.write(bytearray([cmd])) self.cs(1) def write_data(self, buf): self.cs(1) self.dc(1) self.cs(0) self.spi.write(bytearray([buf])) self.cs(1) def init_display(self): """Initialize dispaly""" self.rst(1) self.rst(0) self.rst(1) self.write_cmd(0x36) self.write_data(0x70) self.write_cmd(0x3A) self.write_data(0x05) self.write_cmd(0xB2) self.write_data(0x0C) self.write_data(0x0C) self.write_data(0x00) self.write_data(0x33) self.write_data(0x33) self.write_cmd(0xB7) self.write_data(0x35) self.write_cmd(0xBB) self.write_data(0x19) self.write_cmd(0xC0) self.write_data(0x2C) self.write_cmd(0xC2) self.write_data(0x01) self.write_cmd(0xC3) self.write_data(0x12) self.write_cmd(0xC4) self.write_data(0x20) self.write_cmd(0xC6) self.write_data(0x0F) self.write_cmd(0xD0) self.write_data(0xA4) self.write_data(0xA1) self.write_cmd(0xE0) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0D) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2B) self.write_data(0x3F) self.write_data(0x54) self.write_data(0x4C) self.write_data(0x18) self.write_data(0x0D) self.write_data(0x0B) self.write_data(0x1F) self.write_data(0x23) self.write_cmd(0xE1) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0C) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2C) self.write_data(0x3F) self.write_data(0x44) self.write_data(0x51) self.write_data(0x2F) self.write_data(0x1F) self.write_data(0x1F) self.write_data(0x20) self.write_data(0x23) self.write_cmd(0x21) self.write_cmd(0x11) self.write_cmd(0x29) def show(self): self.write_cmd(0x2A) self.write_data(0x00) self.write_data(0x28) self.write_data(0x01) self.write_data(0x17) self.write_cmd(0x2B) self.write_data(0x00) self.write_data(0x35) self.write_data(0x00) self.write_data(0xBB) self.write_cmd(0x2C) self.cs(1) self.dc(1) self.cs(0) self.spi.write(self.buffer) self.cs(1) def main(): pwm = PWM(Pin(BL)) pwm.freq(1000) pwm.duty_u16(32768)#max 65535 LCD = LCD_1inch14() nic = w5x00_init() #color BRG ip = dns_query("www.baidu.com") print("IP address is %s"%(ip)) LCD.fill(LCD.white) LCD.show() LCD.text("Follow me NO.4",20,20,LCD.red) LCD.text("www.baidu.com:",20,40,LCD.green) LCD.text("IP address is %s"%(ip),20,60,LCD.red) LCD.show() time.sleep(1) LCD.fill(0xFFFF) while True: led.value(1) time.sleep(1) led.value(0) time.sleep(1) print("try ping",nic.ifconfig()[0]) if __name__ == "__main__": main()  

  • 发表了主题帖: 【得捷电子Follow me第4期】入门任务:开发环境搭建,BLINK,驱动液晶显示器进行显示

    本帖最后由 eew_uscYT9 于 2024-2-14 21:54 编辑 本次是用的板子是WIZnet家的W5500-EVB-Pico,它是基树莓派pico和w5500与一身的板子,能够方便的连接上互联网,实物如下图所示   由于排针焊接错了方向,暂时通过杜邦线连接 开发环境是micropython ,micropython简单易上手,对新手友好教程也比较多 引脚图     参考了Pico LCD 1.14 - Waveshare Wiki的资料成功点亮了屏幕和blink   代码如下   from machine import Pin,SPI,PWM import framebuf import time,utime BL = 13 DC = 8 RST = 12 MOSI = 11 SCK = 10 CS = 9 led = machine.Pin(25,machine.Pin.OUT) class LCD_1inch14(framebuf.FrameBuffer): def __init__(self): self.width = 240 self.height = 135 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,10000_000,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 def write_cmd(self, cmd): self.cs(1) self.dc(0) self.cs(0) self.spi.write(bytearray([cmd])) self.cs(1) def write_data(self, buf): self.cs(1) self.dc(1) self.cs(0) self.spi.write(bytearray([buf])) self.cs(1) def init_display(self): """Initialize dispaly""" self.rst(1) self.rst(0) self.rst(1) self.write_cmd(0x36) self.write_data(0x70) self.write_cmd(0x3A) self.write_data(0x05) self.write_cmd(0xB2) self.write_data(0x0C) self.write_data(0x0C) self.write_data(0x00) self.write_data(0x33) self.write_data(0x33) self.write_cmd(0xB7) self.write_data(0x35) self.write_cmd(0xBB) self.write_data(0x19) self.write_cmd(0xC0) self.write_data(0x2C) self.write_cmd(0xC2) self.write_data(0x01) self.write_cmd(0xC3) self.write_data(0x12) self.write_cmd(0xC4) self.write_data(0x20) self.write_cmd(0xC6) self.write_data(0x0F) self.write_cmd(0xD0) self.write_data(0xA4) self.write_data(0xA1) self.write_cmd(0xE0) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0D) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2B) self.write_data(0x3F) self.write_data(0x54) self.write_data(0x4C) self.write_data(0x18) self.write_data(0x0D) self.write_data(0x0B) self.write_data(0x1F) self.write_data(0x23) self.write_cmd(0xE1) self.write_data(0xD0) self.write_data(0x04) self.write_data(0x0C) self.write_data(0x11) self.write_data(0x13) self.write_data(0x2C) self.write_data(0x3F) self.write_data(0x44) self.write_data(0x51) self.write_data(0x2F) self.write_data(0x1F) self.write_data(0x1F) self.write_data(0x20) self.write_data(0x23) self.write_cmd(0x21) self.write_cmd(0x11) self.write_cmd(0x29) def show(self): self.write_cmd(0x2A) self.write_data(0x00) self.write_data(0x28) self.write_data(0x01) self.write_data(0x17) self.write_cmd(0x2B) self.write_data(0x00) self.write_data(0x35) self.write_data(0x00) self.write_data(0xBB) self.write_cmd(0x2C) self.cs(1) self.dc(1) self.cs(0) self.spi.write(self.buffer) self.cs(1) if __name__=='__main__': pwm = PWM(Pin(BL)) pwm.freq(1000) pwm.duty_u16(32768)#max 65535 LCD = LCD_1inch14() #color BRG LCD.fill(LCD.white) LCD.show() LCD.text("Hello Word !!",90,40,LCD.red) LCD.show() while(1): led.value(1) utime.sleep(2) led.value(0) utime.sleep(2) time.sleep(1) LCD.fill(0xFFFF) 点亮效果图      

  • 2024-02-13
  • 加入了学习《直播回放: FollowMe 4 W5500-EVB-Pico 使用入门》,观看 W5500-EVB-Pico 使用入门

最近访客

< 1/1 >

统计信息

已有4人来访过

  • 芯积分:33
  • 好友:--
  • 主题:6
  • 回复:1

留言

你需要登录后才可以留言 登录 | 注册


现在还没有留言