424 views|0 replies

33

Posts

3

Resources
The OP
 

[Digital Follow me Issue 4] + FTP server (task summary post) [Copy link]

 This post was last edited by jone5 on 2024-2-27 01:07

Getting started tasks: build the development environment, BLINK, drive the LCD display to display (if there is no serial port HelloWorld)

Matching devices: W5500-EVB-Pico , Adafruit Sharp Memory Display Breakout

1. Build a development environment

background:

I/O

Pin Name

Description

I

GPIO16

Connected to MISO on W5500

O

GPIO17

Connected to CSn on W5500

O

GPIO18

Connected to SCLK on W5500

O

GPIO19

Connected to MOSI on W5500

O

GPIO20

Connected to RSTn on W5500

I

GPIO21

Connected to INTn on W5500

I

GPIO24

VBUS sense - high if VBUS is present, else low

O

GPIO25

Connected to user LED

I

GPIO29

Used in ADC mode (ADC3) to measure VSYS/3

O

GP10

SPI0 SCK (LCD)

O

GP11

SPI0 TX(LCD)

I

GP12

SPI0 RX(LCD)

O

GP13

SPI0 Csn(LCD)

1.1 Build CircuitoPython environment

This task uses

链接已隐藏,如需查看请登录或者注册
to complete the task. First, download the latest
链接已隐藏,如需查看请登录或者注册
firmware, which can be obtained through the following link:

https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython

After the download is complete, download the uf2 firmware through Thony, the steps are as follows:

1.2 Install WIZnet library

Install the WIZnet Ethernet library, download it from https://learn.adafruit.com/ethernet-for-circuitpython/circuitpython-setup

After downloading, copy the following three folders to the

链接已隐藏,如需查看请登录或者注册
folder

1.3 Install the display library

Open the following path: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases Download the 8.x version bundle library

After the download is complete, you can put the relevant library files into the lib folder as shown below

So far we have completed the development environment setup, and now we are ready to start the most classic lighting process.

import random

import time



from adafruit_display_text.label import Label

from terminalio import FONT

from adafruit_bitmap_font import bitmap_font



import board

import displayio

import framebufferio

import sharpdisplay

import digitalio

import busio





def LCD_Init():

 #SPI1

 SPI1_SCK = board.GP10

 SPI1_TX = board.GP11

 SPI1_RX = board.GP12

 chip_select_pin = board.GP13

 # Release the existing display, if any

 displayio.release_displays()



 #display setting

 bus = busio.SPI(SPI1_SCK, MOSI=SPI1_TX, MISO=SPI1_RX)

 # Select JUST ONE of the following lines:

 # For the 400x240 display (can only be operated at 2MHz) 144*168

 framebuffer = sharpdisplay.SharpMemoryFramebuffer(bus, chip_select_pin, 144, 168)

 # For the 144x168 display (can be operated at up to 8MHz)

 #framebuffer = sharpdisplay.SharpMemoryFramebuffer(bus, chip_select_pin, width=144,height=168, baudrate=8000000)

 display = framebufferio.FramebufferDisplay(framebuffer)



 return display



def show(display):

 #creat the text label

 label = Label(font=FONT, text="BLACK\nLIVES\nMATTER", x=0, y=4, scale=1,line_spacing=1.2)

 #show it



 display.root_group = label



def LED_Init():

 led = digitalio.DigitalInOut(board.LED)

 led.direction = digitalio.Direction.OUTPUT

 return led



def led_flush(led):

 led.value = not led.value

 time.sleep(0.5)



def U_show():

 print("hello world")



if __name__ == '__main__':

 display = LCD_Init()

 led = LED_Init()

 show(display)

 while True:

 led_flush(led)

Basic Task 1: Complete the initialization of the main control board W5500 (static IP configuration), and be able to ping it using a LAN computer. At the same time, W5500 can ping Internet sites; use packet capture software (Wireshark, Sniffer, etc.) to capture the ping message of the local PC, display and analyze it.

Matching devices: W5500-EVB-Pico , Adafruit Sharp Memory Display Breakout

Added W5500 ping network function

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))

Basic Task 2: The main control board establishes a TCPIP or UDP server, and the LAN PC uses a TCPIP or UDP client to connect and send data. After the main control board receives the data, it sends it to the LCD screen for display (if not, it will be displayed through the serial port print); the interactive message is captured by the packet capture software, displayed and analyzed. (Choose one of TCP and UDP, or operate both)

Matching devices: W5500-EVB-Pico , Adafruit Sharp Memory Display Breakout

Through Task 1, we have enabled the network function of W550. Next, we enable Socket communication.

# Initialize a socket for our server

socket.set_interface(eth)

server = socket.socket() # Allocate socket for the server

server_ip = None # IP address of server

server_port = 50007 # Port to listen on

server.bind((server_ip, server_port)) # Bind to IP and Port

server.listen() # Begin listening for incoming clients



conn, addr = server.accept() # Wait for a connection from a client.

print("socket connected")

result:

1. Through the serial port printing, we can get the IP of Pico as 192.168.124.13. Then we connect to Pico through the TCP tool and send the data "123456789".

2. By capturing the data sent from IP 17 to IP 13 through Wireshark, we can know that the communication protocol is TCP protocol and the data is "123456789".

Advanced task: synchronize time from NTP server (pay attention to the parsing of data exchange format), obtain time and send it to display screen (serial port) for display.

Matching devices: W5500-EVB-Pico , Adafruit Sharp Memory Display Breakout

Note that the Ntp library does not have a recv function that does not write the received length, so the following function needs to be modified

Core code

#NTP

ntpserver_ip = eth.pretty_ip(eth.get_host_by_name("ntp.aliyun.com"))

print("NTP : %s" % ntpserver_ip) #DNS Domain

ntp = NTP(iface = eth, ntp_address =ntpserver_ip ,utc=8)

cal = ntp.get_time()

print("The date is %s %d/%d/%d" %(days[cal.tm_wday], cal.tm_mday,cal.tm_mon,cal.tm_year))

print("The time is %d:%02d:%02d" %(cal.tm_hour,cal.tm_min,cal.tm_sec))

■ Ultimate Task 2: Use external storage to build a simple FTP file server that can upload and download files normally.

Matching devices: W5500-EVB-Pico , Adafruit Sharp Memory Display Breakout

【Digi-Key Follow me Issue 4】FTP File Server

Since I don’t have an SD module, I use Pico memory to simulate memory and MicroPython as the development language (from the forum friends of Fresh Mango , I learned that CircuitPython has strict management of storage access and it is complicated to implement file storage, so I switched to MicroPython for development.

Summarize

This is the first time I use python to develop Pico, so this task is still very meaningful for me. I am very grateful to EEWORLD and Dejie for this task, which gave us many learning opportunities. Because it is the first time to use python to develop Pico, due to busy work, many interfaces are not used yet. I will continue to read and learn how to use c to develop Pico, so as to be familiar with the principles of this development method and share it.

Finally, I would like to thank EEWorld again for providing this learning opportunity and sharing platform. Thank you very much

appendix:

1. Source code path

Source code

2. Video Description


This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list