- 2024-11-28
-
加入了学习《littlefulse 多元新技术赋能安全可靠和高效》,观看 LIT-3762-09 CSR Series_Captions-CN
-
加入了学习《littlefulse 多元新技术赋能安全可靠和高效》,观看 LIT-3762-23_TTapeCaptions-CN
-
加入了学习《littlefulse 多元新技术赋能安全可靠和高效》,观看 LIT-3762-20-SIDACtor-Captions_CN
-
加入了学习《littlefulse 多元新技术赋能安全可靠和高效》,观看 LIT-3762-22-25_MATE12B-MITI7L-ReedSwitches-Captions-CN
- 2024-09-27
-
发表了主题帖:
【2024 DigiKey创意大赛】+创意氛围灯+开箱
由于手机绑定问题无法发帖,现在解决了,补上开箱贴。根据需要选了树莓派和2个传感器。
- 2024-03-17
-
加入了学习《泰克MSO6B探索营》,观看 MSO6B强大的测试和分析功能
-
加入了学习《泰克MSO6B探索营》,观看 MSO6B多通道同步频谱分析
-
加入了学习《泰克MSO6B探索营》,观看 如何完成AI芯片电源噪声测试
-
加入了学习《泰克MSO6B探索营》,观看 MSO6B系列低噪声演示
-
加入了学习《泰克MSO6B探索营》,观看 MSO6B技术介绍
-
加入了学习《泰克MSO6B探索营》,观看 MSO6B-360度介绍
-
回复了主题帖:
汽车VCU知识问答第一站:了解VCU系统框图和功能清单
1 VCU是纯电动汽车的电控系统。这套系统是纯电动汽车的核心部件,相当于汽油车的ecu。Vcu可以控制纯电动汽车的电动机的运行,也可以控制纯电动汽车上其他电子设备的运行,于纯电动车的大脑。
2 驱动力矩控制、制动能量的优化控制、整车的能量管理
3 诊断和标定、网关
- 2024-03-11
-
发表了主题帖:
【得捷Follow me第4期】视频和代码
现将视频和代码补充如下
1代码:
https://download.eeworld.com.cn/detail/leihaozhuce/631463
2视频:
https://training.eeworld.com.cn/course/68467/learn?preview=1#lesson/39558
-
上传了资料:
【得捷Follow me第4期】代码
- 2024-03-04
-
发表了主题帖:
【得捷电子Follow me第4期】交作业
代码:
https://download.eeworld.com.cn/detail/leihaozhuce/631463
视频:
https://training.eeworld.com.cn/video/39558
按照官方要求使用W5500-EVB-Pico、 Adafruit Sharp Memory Display两种器件完成开发。软件选用python语言进行编程,circuit python的库很全,更新也很快,非常好用,大大降低了开发难度。
在树莓派平台上进行开发,体验还不错。
编译器用树莓派自带的Thonny,简单易用。
首先搭建开发环境,去官网下载最新固件,写入到w5500中,常规操作就不再重复写了。
第一步电灯,代码如下:
import machine
import time
# 初始化LED引脚为输出模式
led = machine.Pin('LED', machine.Pin.OUT)
while True:
# 点亮LED
led.on()
time.sleep(1) # 等待1秒钟
# 熄灭LED
led.off()
time.sleep(1) # 等待1秒钟
运行程序
效果见下图
驱动lcd显示屏,先安装好必要的库文件,去官网下载,比较慢,费了大劲才下载下来。
将adafruit_sharpmemorydisplay.mpy和adafruit_framebuf.mpy两个库文件拷贝到w5500的lib目录下。
连接lcd显示器,接线如下,还有3.3v和GND
GP15
显示模块DI
GP14
显示模块CLK
GP13
显示模块CS
如图所示
代码如下
import time
import board
import busio
import digitalio
import adafruit_sharpmemorydisplay
def led_flush():
led.value = not led.value
time.sleep(0.5)
def clear_disp():
# Clear the display. Always call show after changing pixels to make the display
# update visible!
display.fill(1)
display.show()
def disp_helloworld():
print("hello EEWORLD")
display.fill(1)
display.text(" hello EEWORLD!", 30, 50, 0)
display.show()
if __name__ == '__main__':
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)
clear_disp()
disp_helloworld()
while True:
led_flush()
完成主控板W5500初始化(静态IP配置),并能使用局域网电脑ping通,同时W5500可以ping通互联网站点;通过抓包软件(Wireshark、Sniffer等)抓取本地PC的ping报文,展示并分析。
通过网线将w5500接入到交换机上。
安装树莓派版的wireshark软件
安装好后用
$ sudo wireshark &
命令取得root权限,才能看到端口。
因为树莓派用的无线链接,这里选择 wlan0 ,就可以开始抓包了。
配置代码如下
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, 100)
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!")
运行结果如下图
下显示开发板地址为192.168.1.100,下面进行ping测试,
能ping到开发板。抓包结果如下图。
抓包结果
主控板建立TCPIP或UDP服务器,局域网PC使用TCPIP或UDP客户端进行连接并发送数据,主控板接收到数据后,送液晶屏显示(没有则通过串口打印显示);通过抓包软件抓取交互报文,展示并分析。(TCP和UDP二选一,或者全都操作)
采用基础任务一的软件为基础,完成TCP和UDP服务器,服务器IP = 172.17.100.101,端口号Port = 40001 。
利用adafruit_wiznet5k_socket库,创建一个TCP服务器。函数输入参数为服务器端口。
接收到的信息会显示到LCD显示器上,显示分为三个区域:
区域1:以太网参数区,区域2:TCP连接信息显示区,区域3:接收到的信息显示区,显示函数的输入参数为待显示的字符串和显示的位置。
代码如下:
import time
import board
import busio
import digitalio
import array
import struct
import adafruit_sharpmemorydisplay
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
IP_ADDRESS = (172, 17, 100, 101)
SUBNET_MASK = (255, 255, 0, 0)
GATEWAY_ADDRESS = (172, 17, 64, 1)
DNS_SERVER = (218, 203, 59, 116)
def init():
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)
return led,display
def led_flush():
led.value = not led.value
time.sleep(0.5)
def clear_disp():
# Clear the display. Always call show after changing pixels to make the display
# update visible!
display.fill(1)
display.show()
def disp_helloworld():
print("hello world")
display.fill(1)
display.text(" hello world!", 30, 50, 0)
display.show()
def init_w5500(ip, subnet, gateway, dns):
##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)")
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 without DHCP
eth = WIZNET5K(spi_bus, cs, is_dhcp=False)
# Set network configuration
eth.ifconfig = (ip, subnet, gateway, dns)
print("Chip Version:", eth.chip)
print("My IP address is:", eth.pretty_ip(eth.ip_address))
return eth
def disp_w5500():
clear_disp()
display.fill(1)
cst = "chip version:" + eth.chip
display.text(cst, 0, 0, 0)
cst = "ip:" + eth.pretty_ip(eth.ip_address)
display.text(cst, 0, 10, 0)
cst = "mac:" + eth.pretty_mac(eth.mac_address)
display.text(cst, 0, 20, 0)
display.show()
def disp_str(s, addr):
display.fill_rect(0,addr,144,10,1)
display.text(s, 0, addr, 0)
display.show()
def inCksum(packet):
if len(packet) & 1:
packet = packet + '\0'
words = array.array('h', packet)
sum = 0
for word in words:
sum += (word & 0xffff)
sum = (sum>>16) + (sum & 0xffff)
sum = sum + (sum >> 16)
return (~sum) & 0xffff
def create_tcpserver(port):
# Initialize a socket for our server
socket.set_interface(eth)
sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Allocate socket for the server
sc_ip = None # IP address of server
sc_port = port # Port to listen on
sc.bind((sc_ip, sc_port)) # Bind to IP and Port
sc.listen() # Begin listening for incoming clients
return sc
def create_udpserver(port):
# Initialize a socket for our server
socket.set_interface(eth)
sc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Allocate socket for the server
# sc_ip = None # IP address of server
sc_port = port # Port to listen on
sc.bind((eth.pretty_ip(eth.ip_address), sc_port)) # Bind to IP and Port
return sc
if __name__ == '__main__':
# 初始化led和显示模块
led,display = init()
clear_disp()
#静态初始化w5500
eth = init_w5500(IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)
disp_w5500()
# 创建一个tcp服务器
# server = create_tcpserver(40001)
# 创建一个udp服务器
server = create_udpserver(40001)
# conn, addr = server.accept() # Wait for a connection from a client.
print("socket connected")
# print(addr)
disp_str("UDP Server TEST", 30)
disp_str("socket connected", 40)
# disp_str('cli:'+addr[0]+','+str(addr[1]), 50)
disp_str('receive:', 60)
linenum = 70
while True:
led_flush()
with server:
while True:
# data = conn.recv(20)
data,addr = server.recvfrom(20)
disp_str('cli:'+addr[0]+','+str(addr[1]), 50)
if data:
print(data)
disp_str(data.decode('utf-8'),linenum)
linenum += 10
if linenum > 150:
linenum = 70
# conn.send(data) # Echo message back to client
运行结果如下图:
服务器建立起来。
但目前还未找到树莓派上用的TCP和UDP首发软件,具体测试还未进行。
搭建一个sntp的客户端从ntp授时服务器获取时间。
代码如下
import ntptime
import time
for i in range(10):
try:
ntptime.settime()
t = time.localtime(time.time() + 8*3600)
print("ntp time(BeiJing): %s-%s-%s %s:%s:%s" % (t[0],t[1],t[2],t[3],t[4],t[5]))
break
except:
print("Can not get time!")
time.sleep_ms(1000)
运行结果如下图
心得体会
python的开发库维护的挺好,器件种类很全,大大加快的开发进度,是开发的选择,网络编程要学习的还有很多,难度还是挺高的。
最后感谢得捷,感谢EEWORLD提。
- 2024-03-03
-
加入了学习《Follow me 第4期任务视频》,观看 Follow me 第4期任务视频