xscc

  • 2024-09-01
  • 发表了主题帖: 【2024 DigiKey 创意大赛】基于树莓派的室内CO2浓度检测仪-开箱帖

    得捷电子上下单很方便,发货挺快,美国到国内5天就到了。 发的顺丰快递 内部有塑料袋和减震泡沫 树莓派5 4G版本   SGP30空气质量传感器,用来检测CO2浓度。 开箱结束。    

  • 2024-06-29
  • 加入了学习《PI PowiGaN 系列视频》,观看 氮化镓进化史 - PI 高层座谈 - PowerUP Expo 2023

  • 2024-03-22
  • 加入了学习《【得捷电子Follow me第4期】演示视频》,观看 【得捷电子Follow me第4期】演示视频

  • 2024-03-18
  • 加入了学习《泰克MSO6B探索营》,观看 MSO6B技术介绍

  • 加入了学习《泰克MSO6B探索营》,观看 MSO6B-360度介绍

  • 2024-03-11
  • 发表了主题帖: 【得捷电子Follow me第4期】补充项目材料

    终极任务二  使用主控板内存储和以太网接口,实现轻量ftp文件服务器,可以上传、下载、删除文件        参考大佬们的方案,采用microPython 进行开发,开发板重新刷入microPython固件。然后采用相同局域网网段的PC电脑对开发板进行FTP访问。 import socket import network import uos import gc from time import localtime from machine import Pin,SPI import time 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.100','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 month_name = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] def send_list_data(path, dataclient, full): try: # whether path is a directory name for fname in uos.listdir(path): 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 uos.listdir(path): if fncmp(fname, pattern) == True: 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] tm = localtime(stat[7]) if tm[0] != localtime()[0]: description = "{} 1 owner group {:>10} {} {:2} {:>5} {}\r\n".format( file_permissions, file_size, month_name[tm[1]], tm[2], tm[0], fname) else: description = "{} 1 owner group {:>10} {} {:2} {:02}:{:02} {}\r\n".format( file_permissions, file_size, month_name[tm[1]], tm[2], tm[3], tm[4], fname) else: description = fname + "\r\n" return description def send_file_data(path, dataclient): with open(path, "r") as file: chunk = file.read(512) while len(chunk) > 0: dataclient.sendall(chunk) chunk = file.read(512) def save_file_data(path, dataclient, mode): with open(path, mode) as file: chunk = dataclient.read(512) while len(chunk) > 0: file.write(chunk) chunk = dataclient.read(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:]) == True: 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(): 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", 21)[0][4]) datasocket.bind(socket.getaddrinfo("0.0.0.0", DATA_PORT)[0][4]) ftpsocket.listen(1) datasocket.listen(1) datasocket.settimeout(10) msg_250_OK = '250 OK\r\n' msg_550_fail = '550 Failed\r\n' try: dataclient = None fromname = None while True: cl, remote_addr = ftpsocket.accept() cl.settimeout(300) cwd = '/' try: # print("FTP connection from:", remote_addr) cl.sendall("220 Hello, this is the ESP8266.\r\n") while True: gc.collect() data = cl.readline().decode("utf-8").rstrip("\r\n") if len(data) <= 0: print("Client disappeared") break command = data.split(" ")[0].upper() payload = data[len(command):].lstrip() path = get_absolute_path(cwd, payload) print("Command={}, Payload={}, Path={}".format(command, payload, path)) 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": cl.sendall('257 "{}"\r\n'.format(cwd)) elif command == "CWD": 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') break elif command == "PASV": addr = nic.ifconfig()[0] 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) elif command == "LIST" or command == "NLST": if not payload.startswith("-"): place = path else: place = cwd try: send_list_data(place, dataclient, command == "LIST" or payload == "-l") cl.sendall("150 Here comes the directory listing.\r\n") 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: send_file_data(path, dataclient) cl.sendall("150 Opening data connection.\r\n") 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, "w") cl.sendall("226 Transfer complete.\r\n") except: cl.sendall(msg_550_fail) if dataclient is not None: dataclient.close() dataclient = None elif command == "APPE": try: cl.sendall("150 Ok to send data.\r\n") save_file_data(path, dataclient, "a") 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": try: uos.rmdir(path) cl.sendall(msg_250_OK) except: cl.sendall(msg_550_fail) elif command == "MKD": 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 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 finally: datasocket.close() ftpsocket.close() if dataclient is not None: dataclient.close() nic = w5x00_init() ftpserver() 运行如图 建立了地址为192.168.1.100的ftp 在PC机上使用Xftp软件,建立连接 建立连接后传输一个文件到FTP上  将DGBCDX64.exe传输到ftp上     演示视频: https://training.eeworld.com.cn/video/39557   代码下载: 源码   总结        以前没接触过网络编程这次学到了很多网络底层的协议,提高了不少!       感谢EEWorld和DigiKey!

  • 加入了学习《【DigiKey创意大赛】人脸识别储物柜 》,观看 【DigiKey创意大赛】人脸识别储物柜

  • 上传了资料: 【得捷电子Follow me第4期】代码汇总

  • 2024-03-06
  • 发表了主题帖: 【得捷Follow me第4期】作品提交

    本帖最后由 xscc 于 2024-3-6 06:17 编辑 【得捷Follow me第4期】项目提交 硬件选用官方推荐的组合,w5500模块加Adafruit LCD显示屏。焊接好排线后,因电路比较简单,用面包板搭接电路。并刷入固件和所用到的库文件,按住boot键,同时将w5500插入U口,拖拽下好的固件至u盘即可,使用adafruit-circuitpython-wiznet_w5500_evb_pico-en_US-8.2.9.uf2。 W5500引脚图 一、入门任务: 使用circuit python进行开发工作,库文件比较全,开发简单。 基础任务1,驱动led闪烁,驱动lcd进行文字和线条测试。按照spi = GP14, MOSI=15,scs =GP13连接lcd和w5500。 写入如下程序 import sys import time import board import digitalio import busio import adafruit_sharpmemorydisplay # 打印输入到stdout print("start:xxx") # 初始化LED引脚 led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT # Initialize SPI bus and control pins spi = busio.SPI(board.GP14, MOSI=board.GP15) scs = digitalio.DigitalInOut(board.GP13) # inverted chip select # pass in the display size, width and height, as well # display = adafruit_sharpmemorydisplay.SharpMemoryDisplay(spi, scs, 96, 96) display = adafruit_sharpmemorydisplay.SharpMemoryDisplay(spi, scs, 144, 168) print("Pixel test") # Clear the display. Always call show after changing pixels to make the display # update visible! display.fill(1) display.show() # Set a pixel in the origin 0,0 position. display.pixel(0, 0, 0) # Set a pixel in the middle position. display.pixel(display.width // 2, display.width // 2, 0) # Set a pixel in the opposite corner position. display.pixel(display.width - 1, display.height - 1, 0) display.show() time.sleep(2) print("Lines test") # we'll draw from corner to corner, lets define all the pair coordinates here corners = ( (0, 0), (0, display.height - 1), (display.width - 1, 0), (display.width - 1, display.height - 1), ) display.fill(1) for corner_from in corners: for corner_to in corners: display.line(corner_from[0], corner_from[1], corner_to[0], corner_to[1], 0) display.show() time.sleep(2) print("Rectangle test") display.fill(1) w_delta = display.width / 10 h_delta = display.height / 10 for i in range(11): display.rect(0, 0, int(w_delta * i), int(h_delta * i), 0) display.show() time.sleep(2) print("Text test") display.fill(1) display.text(" hello world!", 0, 0, 0) display.text(" This is the", 0, 8, 0) display.text(" CircuitPython", 0, 16, 0) display.text("adafruit library", 0, 24, 0) display.text(" for the SHARP", 0, 32, 0) display.text(" Memory Display :) ", 0, 40, 0) display.show() # 循环使能LED点亮 while True: # 点亮LED led.value = True time.sleep(1) led.value = False time.sleep(1)   结果如图所示 文字显示 线条显示   [localvideo]cffc6364a2ef43c49165e917ade9fe33[/localvideo] 演示视频     基础任务2:完成主控板W5500初始化(静态IP配置),并能使用局域网电脑ping通,同时W5500可以ping通互联网站点;通过抓包软件(Wireshark、Sniffer等)抓取本地PC的ping报文,展示并分析。 查看本机的IP参数如下 配置w5500网络参数 IP_ADDRESS = (192, 168, 1, 123) SUBNET_MASK = (255, 255, 255, 0) GATEWAY_ADDRESS = (192, 168, 1, 1) DNS_SERVER = (8, 8, 8, 8) 代码如下 import board import busio import digitalio import time from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K ##SPI0 SPI0_SCK = board.GP18 SPI0_TX = board.GP19 SPI0_RX = board.GP16 SPI0_CSn = board.GP17 ##reset W5x00_RSTn = board.GP20 print("Wiznet5k Ping Test (no DHCP)") # Setup your network configuration below # random MAC, later should change this value on your vendor ID MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05) IP_ADDRESS = (192, 168, 1, 123) SUBNET_MASK = (255, 255, 255, 0) GATEWAY_ADDRESS = (192, 168, 1, 1) DNS_SERVER = (8, 8, 8, 8) led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT ethernetRst = digitalio.DigitalInOut(W5x00_RSTn) ethernetRst.direction = digitalio.Direction.OUTPUT # For Adafruit Ethernet FeatherWing cs = digitalio.DigitalInOut(SPI0_CSn) # For Particle Ethernet FeatherWing # cs = digitalio.DigitalInOut(board.D5) spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) # Reset W5500 first ethernetRst.value = False time.sleep(1) ethernetRst.value = True # Initialize ethernet interface with DHCP # eth = WIZNET5K(spi_bus, cs) # Initialize ethernet interface without DHCP eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC) # Set network configuration eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER) print("Chip Version:", eth.chip) print("MAC Address:", [hex(i) for i in eth.mac_address]) print("My IP address is:", eth.pretty_ip(eth.ip_address)) while True: led.value = not led.value time.sleep(1) print("Done!")   在本机上ping开发板如图所示 正常ping通。 使用wireshark进行抓包操作,用规则ip.addr == 192.168.1.123过滤出和W5500的交互数据。 进阶任务1 从NTP服务器(注意数据交互格式的解析)同步时间,获取时间送显示屏(串口)显示. 代码如下 import board import busio import digitalio import time import array import struct import adafruit_requests as requests from adafruit_wiznet5k.adafruit_wiznet5k import * import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket from adafruit_wiznet5k.adafruit_wiznet5k_ntp import NTP import adafruit_wiznet5k.adafruit_wiznet5k_dns as dns import adafruit_ntp days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") ##SPI0 SPI0_SCK = board.GP18 SPI0_TX = board.GP19 SPI0_RX = board.GP16 SPI0_CSn = board.GP17 ##reset W5x00_RSTn = board.GP20 print("Wiznet5k NTP Client (DHCP)") # Setup your network configuration below # random MAC, later should change this value on your vendor ID MY_MAC = (0x00, 0x01, 0x02, 0xFF, 0xFF, 0xFF) IP_ADDRESS = (192, 168, 1, 123) SUBNET_MASK = (255, 255, 255, 0) GATEWAY_ADDRESS = (192, 168, 1, 1) DNS_SERVER = (8, 8, 8, 8) port = 5000 ntp_server_port= 123 led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT ethernetRst = digitalio.DigitalInOut(W5x00_RSTn) ethernetRst.direction = digitalio.Direction.OUTPUT # For Adafruit Ethernet FeatherWing cs = digitalio.DigitalInOut(SPI0_CSn) # cs = digitalio.DigitalInOut(board.D5) spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) # Reset W5500 first ethernetRst.value = False time.sleep(1) ethernetRst.value = True # Initialize ethernet interface without DHCP #eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC, debug=False) # Initialize ethernet interface with DHCP eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False) print("Chip Version:", eth.chip) print("MAC Address:", [hex(i) for i in eth.mac_address]) print("My IP address is:", eth.pretty_ip(eth.ip_address)) # Initialize a socket for our server socket.set_interface(eth) # Set network configuration eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER) ntp = adafruit_ntp.NTP(socket) print(ntp.datetime)   串口输出结果如下

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

最近访客

< 1/5 >

统计信息

已有560人来访过

  • 芯积分:373
  • 好友:--
  • 主题:35
  • 回复:314

留言

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


现在还没有留言