999|2

862

帖子

2

TA的资源

纯净的硅(初级)

楼主
 

【得捷Follow me第4期】W5500-EVB-Pico platform IO下使用Ethernet3库设置静态IP [复制链接]

 

本篇完成任务:使用arduino Ethernet3库,设置静态IP,连接远端服务器测试

1. Ethernet3库的获取

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

打开以上网址,克隆仓库文件到本地。

2. 新建项目

打开vs code,打开左侧的platform IO插件

图标,打开home页。

在home页中,选择新建工程 

 

输入关键字“pico”,然后在下边的列表中选择“Raspberry Pi Pico”,然后在name一栏中输入项目/工程名称:(如:pico_telnet_test)。

 

等一小会,待工程创建完毕。

3. 添加第三方库Ethernet3到工程中

工程创建完毕后,复制Ethernet3库文件夹至项目文件夹下的lib子文件夹下(在项目列表中,在任一文件上鼠标右键,选择在文件资源管理器中显示)。

 

添加完成后,可见code中资源管理器该工程下的lib子项下显示Ethernet3目录,说明添加成功。

4. 代码编写

在工程main.cpp中编辑如下代码:

  • #include <Arduino.h>
  • #include <SPI.h>
  • #include <Ethernet3.h>
  • // Enter a MAC address and IP address for your controller below.
  • // The IP address will be dependent on your local network:
  • byte mac[] = {
  • 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  • };
  • IPAddress ip(192, 168, 2, 186);
  • // Enter the IP address of the server you're connecting to:
  • IPAddress server(180,101,50,188); //www.baidu.com
  • // Initialize the Ethernet client library
  • // with the IP address and port of the server
  • // that you want to connect to (port 23 is default for telnet;
  • // if you're using Processing's ChatServer, use port 10002):
  • EthernetClient client;
  • void setup() {
  • // start the Ethernet connection:
  • Ethernet.setCsPin(17);
  • Ethernet.setRstPin(20);
  • Ethernet.begin(mac, ip);
  • Serial.begin(115200);
  • // give the Ethernet shield a second to initialize:
  • delay(1000);
  • Serial.println("connecting...");
  • // if you get a connection, report back via serial:
  • if (client.connect(server, 80)) {
  • Serial.println("connected");
  • }
  • else {
  • // if you didn't get a connection to the server:
  • Serial.println("connection failed");
  • }
  • }
  • void loop() {
  • /* *********** Telnet client test*********** */
  • // if there are incoming bytes available
  • // from the server, read them and print them:
  • if (client.available()) {
  • char c = client.read();
  • Serial.print(c);
  • }
  • // as long as there are bytes in the serial queue,
  • // read them and send them out the socket if it's open:
  • while (Serial.available() > 0) {
  • char inChar = Serial.read();
  • if (client.connected()) {
  • client.print(inChar);
  • }
  • }
  • // if the server's disconnected, stop the client:
  • if (!client.connected()) {
  • Serial.println();
  • Serial.println("disconnecting.");
  • client.stop();
  • // do nothing:
  • while (true);
  • }
  • }

 说明:

第一步:引用头文件

第二步:定义mac地址(w5500)、IP静态地址、要连接的服务器IP地址(这里使用百度的ip)、

 

第三步:新建一个EthernetClient类型对象

第四步:在setup初始化函数中设置CS和rst引脚,并调用begin()函数/方法初始化W5500的网络参数。

初始化之后,使用connect函数连接远端服务器的指定端口,并输出连接情况、如果连接成功,输出服务器返回内容。

 

最新回复

第四步:在setup初始化函数中设置CS和rst引脚,并调用begin()函数/方法初始化W5500的网络参数。 初始化之后,使用connect函数连接远端服务器的指定端口,并输出连接情况、如果连接成功,输出服务器返回内容。 四步完成任务,挺简单的。   详情 回复 发表于 2024-3-9 16:22
点赞 关注
个人签名水不撩不知深浅 人不拼怎知输赢
 
 

回复
举报

7143

帖子

11

TA的资源

版主

沙发
 

第四步:在setup初始化函数中设置CS和rst引脚,并调用begin()函数/方法初始化W5500的网络参数。

初始化之后,使用connect函数连接远端服务器的指定端口,并输出连接情况、如果连接成功,输出服务器返回内容。

四步完成任务,挺简单的。

点评

是的 主要是有人造好了轮子  详情 回复 发表于 2024-3-20 17:55
 
 
 

回复

862

帖子

2

TA的资源

纯净的硅(初级)

板凳
 
lugl4313820 发表于 2024-3-9 16:22 第四步:在setup初始化函数中设置CS和rst引脚,并调用begin()函数/方法初始化W5500的网络参数。 初始化 ...

是的

主要是有人造好了轮子

个人签名水不撩不知深浅 人不拼怎知输赢
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
福禄克有奖直播:高精度测温赋能电子制造 报名中!
直播时间:2025年2月28日(周五)上午10:00
直播主题:高精度测温赋能电子制造
小伙伴们儿快来报名直播吧~好礼等你拿!

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表