[Diao Ye learns programming] Arduino hands-on (135)---W5100 network expansion board module

The reference to 37 sensors and actuators has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, according to the concept of practicing true knowledge (must be done), for the purpose of learning and communication, I am going to try a series of experiments one by one, regardless of success (the program goes through) or not, They will be recorded - small progress or unsolvable problems, hoping to inspire others.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 135: Ethernet W5100 network expansion board SD card expansion module supports MEGA

insert image description here
Knowledge points: W5100S chip

The W5100S chip designed with hardware TCP/IP of WIZnet technology is an embedded Ethernet controller. When using W5100S, MCU can easily handle TCP/IP protocols such as IPv4, TCP, UDP, ICMP, IGMP, ARP, PPPoE, etc. W5100S has 8KB sending buffer and receiving buffer respectively, which can reduce the overhead of MCU. The host can use 4 independent hardware SOCKETs of W5100S at the same time, and develop independent Internet applications based on each hardware SOCKET. From July 30th to August 1st, 2019, WIZnet participated in the 12th International Internet of Things Exhibition (Shenzhen Station) of IOTE2019 with W5100S.

insert image description here
W5100S chip is WIZnet's latest integrated hardware TCP/IP protocol stack, which is a more cost-effective embedded Ethernet controller, which provides a simpler, faster, more stable and safer Ethernet access solution for single-chip microcomputers. The full hardware TCP/IP protocol stack simplifies the traditional software TCP/IP protocol stack, offloads the thread used by the MCU to process the TCP/IP part, and saves hardware resources such as the internal ROM of the MCU. Engineers only need to perform simple Socket programming and a small amount of The register operation can conveniently carry out the application development of the upper layer of the embedded Ethernet, reduce the product development cycle, and reduce the development cost.

W5100S supports two ways of indirect parallel bus and high-speed SPI interface to communicate with the host. It also integrates the Ethernet data link layer (MAC) and 10Base-T/100Base-T Ethernet physical layer (PHY), and supports auto-negotiation (10/100-Based full-duplex/half-duplex). Different from the traditional software protocol stack, the 4 independent hardware Sockets embedded in W5100S can carry out 4 independent communication channels. The communication efficiency of the 4 Socket channels does not affect each other, and can be flexibly defined through the 16K byte receive/transmit buffer on the W5100S chip The size of each Socket.

W5100S also provides WOL (Wake-on-LAN) and power-down mode, which is convenient for customers who have requirements on power consumption.
insert image description here
Main features of W5100S

Full hardware TCP/IP protocol stack

– Support TCP, UDP, WOL, ICMP, IGMPv1/v2, IPv4, ARP, PPPoE protocols

– Hardware network engine, immune to network attacks

Supports SPI and parallel bus interfaces

– High-speed SPI interface (MODE 0/3)

– System bus interface (2-bit address lines and 8-bit data lines)

Support embedded operating system: Linux & RTOS

Support 4 independent hardware sockets to communicate at the same time, and the communication efficiency does not affect each other

Support SOCKET-less instructions

– ARP request

– PING request

Internal 16K byte transceiver buffer for TCP/IP packet processing

Supports Ethernet power-down mode and master clock strobe power-saving mode

Support UDP-based Wake-on-LAN (WOL) function

Integrated 10BaseT / 100Base-T Ethernet PHY

Support auto-negotiation (full/half duplex, 10M/100M)

Support Auto-MDIX function (only supported in Ethernet auto-negotiation mode)

Network indicator light (full/half duplex, link indication, 10Mb/100Mb indication, transmission indication)

Industrial grade: -40℃ ~ 85℃

Working voltage 3.3V, I/O 5V withstand voltage

48-pin LQFP package and QFN package (lead-free, 7x7mm, 0.5mm pitch)

insert image description here
insert image description here
insert image description here

W5100S Main Parameters
Dimensions 7 x7mm
Ethernet I/F Physical Layer
Operating Temperature -40 to +85°C
Operating Voltage 3.3 Volts
Function 3 in 1, MCU + TCP/IP + MAC
Auto-Negotiation Yes
Number of Network Sockets 4
Internal DPRAM Buffer Memory 16 Kbytes
Package Lightweight Plan
Pin Count 48
Auto MDIX Yes
Wake On LAN Yes Power
Down Mode Yes
Typical Energy Consumption TBD
SPI (Maximum Speed) 70 MHz
MCU I/F 8 Bits (Indirect) SPI
PHY Chip W5100S
Pins Pitch 0.50 mm
Ministry of Information Industry No
Ethernet Speed ​​10/100
Parallel Memory Bus 8-bit Indirect
Manufacturer Wireless Network
insert image description here
Ethernet (Ethernet)
Ethernet is a computer local area network technology. The IEEE 802.3 standard of the IEEE organization has established the technical standard of Ethernet, which stipulates the content of the connection, electronic signal and medium access layer protocol including the physical layer. Ethernet is currently the most widely used LAN technology, replacing other LAN technologies such as Token Ring, FDDI, and ARCNET.

Ethernet is the most ubiquitous type of computer network in the real world. There are two types of Ethernet: the first type is classic Ethernet, and the second type is switched Ethernet, which uses a device called a switch to connect different computers. Classical Ethernet is the original form of Ethernet, and its operating speed ranges from 3 to 10 Mbps; while switched Ethernet is a widely used Ethernet, which can run at high rates of 100, 1000 and 10000 Mbps, respectively in the form of Fast Ethernet Ethernet, Gigabit Ethernet and 10 Gigabit Ethernet. The standard topology of Ethernet is a bus topology, but the current Fast Ethernet (100BASE-T, 1000BASE-T standard) uses hubs for network connections and organize. In this way, the topology of Ethernet becomes a star; but logically, Ethernet still uses bus topology and CSMA/CD (Carrier Sense Multiple Access/Collision Detection, that is, carrier multiple access/collision detection) bus technology. Ethernet implements the idea of ​​multiple nodes in a radio system on a network sending information, and each node must acquire a cable or channel to transmit information, sometimes called Ether. (The name comes from the electromagnetic radiation medium assumed by physicists in the 19th century-light ether. Later research proved that light ether does not exist.) Each node has a globally unique 48-bit address, which is the MAC address assigned to the network card by the manufacturer , to ensure that all nodes on the Ethernet can identify each other. Because Ethernet is so ubiquitous, many manufacturers integrate Ethernet cards directly into computer motherboards.

insert image description here
The Arduino Ethernet W5100S network expansion module can make Arduino a simple web server or control network applications such as reading and writing Arduino's digital and analog interfaces through the network. A simple Web server can be realized by directly using the Ethernet library file in the IDE. At the same time, this version supports mini SD card (TF card) reading and writing. The shield has a stackable design that plugs directly into the Arduino, along with our other shields.

insert image description here

Main parameters of W5100S network expansion module

insert image description here
Module Reference Circuit Schematic

insert image description here
insert image description here
insert image description here
W5100S network expansion module power supply

The board can also be powered from an external power supply, an optional Power over Ethernet (PoE) module, or using the FTDI cable/USB serial connector. External power can come from an AC-to-DC adapter (wall wart) or batteries. The adapter can be connected by plugging the 2.1mm center positive plug into the board's power jack. The leads from the battery can be plugged into the Gnd and Vin pin headers of the POWER connector. The board can run on an external power supply ranging from 6 to 20 volts. However, if the supply voltage is lower than 7V, the supply voltage to the 5V pin may be lower than 5V and the board may become unstable. If you use more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

The power pins are as follows:

VIN The input voltage when the Arduino board is using an external power source (as opposed to the 5 volts provided by a USB connection or other regulated power source). You can supply power through this pin, or, if you supply power through the power jack, you can supply power through this pin.

5V. This pin outputs a regulated 5V from the regulator on the board. The board can be powered from the DC power jack (7-12V), the USB connector (5V), or the board's VIN pin (7-12V). Powering through the 5V or 3.3V pins will bypass the voltage regulator and may damage the board. We do not recommend doing this.

3V3. An on-board regulator generates the 3.3 volt supply. The maximum current draw is 50 mA.

Ground pin.

IOREF. This pin on the Arduino board provides the reference voltage for the operation of the microcontroller. A properly configured shield can read the IOREF pin voltage and select the appropriate supply, or enable a voltage translator on the output to use 5V or 3.3V.

The optional PoE module is designed to extract power from traditional twisted-pair Category 5 Ethernet cables:

Conforms to IEEE802.3af

Low Output Ripple and Noise (100mVpp)

Input Voltage Range 36V to 57V

Overload and short circuit protection

9V output

High Efficiency DC/DC Converter: Typical 75% @ 50% Load

1500V isolation (input to output)

insert image description here
input Output

Each of the 14 digital pins on the Ethernet board can be used as input or output using the pinMode(), digitalWrite(), and digitalRead() functions. They work on 5 volts. Each pin can source or sink up to 40 mA and has an internal 20-50 kOhms pull-up resistor (disconnected by default). Additionally, some pins have special functions:

Serial: 0 (RX) and 1 (TX) for receiving (RX) and sending (TX) TTL serial data.

External interrupts: 2 and 3. These pins can be configured to trigger an interrupt on low value, rising or falling edge, or value change. See the attachInterrupt() function for details.

PWM: 3, 5, 6, 9 and 10. Provides 8-bit PWM output with AnalogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library.

LED: 9. There is a built-in LED connected on digital pin 9. When this pin is HIGH value, this LED is on; when this pin is LOW, it is off. On most other arduino boards this LED is on pin 13. It's on pin 9 on the ethernet board because pin 13 is used as part of the SPI connection.

The Ethernet board has 6 analog inputs, labeled A0 to A5, each providing 10-bit resolution (i.e. 1024 different values). By default, they measure from ground to 5 volts, although the upper end of their range can be changed using the AREF pin and the AnalogReference() function. Additionally, certain pins have special functions:

TWI: A4 (SDA) and A5 (SCL). TWI communication is supported using the Wire library.

There are several other pins on the board:

AREF. Reference voltage for analog input. Used with analogReference().

reboot. Pull this line low to reset the microcontroller. Typically used to add a reset button on a shield board to a button on the shield board.

insert image description here
Communication
Arduino Ethernet Extended has many facilities for communicating with a computer, another Arduino or other microcontrollers. A SoftwareSerial library allows serial communication with any of the Uno's digital pins. ATmega328 also supports TWI and SPI communication. The Arduino software includes a Wire library to simplify use of the TWI bus; see the associated documentation for details. For SPI communication, use the SPI library. The board can also be connected to a wired network via Ethernet. When connecting to the network, you will need to provide an IP address and a MAC address. The ethernet library fully supports it. The onboard microSD card reader is accessible via the SD library. SS is on pin 4 when using this library.

Programming
the Arduino Ethernet board can be programmed in two ways: via the 6-pin serial programming header, or using an external ISP programmer. The 6-pin serial programming header is compatible with FTDI USB cables, as well as Sparkfun and Adafruit FTDI-style basic USB-to-serial breakout boards (including the Arduino USB-serial connector). It has support for auto-reset, allowing sketches to be uploaded without pressing the reset button on the board. When an FTDI style USB adapter is plugged in, the Arduino Ethernet will power off the adapter. You can also bypass the bootloader and program the microcontroller with the ICSP (In-Circuit Serial Programming) header using an Arduino ISP or similar.

insert image description here
insert image description here
insert image description here
Install the "Ethernet.h" library-tools-manage library-search-install
Project test: By inserting the W5100 Ethernet expansion board, the Arduino NUO can be connected to the Ethernet
insert image description here

/*

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

实验一百三十五:Ethernet W5100 网络扩展板 SD卡扩展模块 支持MEGA

 安装 "Ethernet.h"库-工具-管理库-搜索-安装

 项目测试 :通过插入W5100 以太网扩展板,实现Arduino NUO 接入以太网

*/



#include <Ethernet.h>

#include <SPI.h>

//mac地址可以是随便的48位地址,只要设备间不相互冲突就行

byte mac[] = {
    
     0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress staticIP(192, 168, 31, 159);

EthernetServer server(80);

void connectToInternet()

{
    
    

 if (Ethernet.begin(mac) == 0)//看看DHCP是否能动态分配ip给Arduino

 {
    
    

  Serial.print("[ERROR] Failed to Configure Ethernet using DHCP");

  Ethernet.begin(mac, staticIP);//DHCP不能动态分配,就静态设置ip给Arduino

 }

 delay(1000);

 Serial.println("[INFO] Connection Successsful");

 Serial.print("");

 printConnectionInformation();

 Serial.println("-------------------------");

 Serial.println("");

}

void printConnectionInformation()

{
    
    

 Serial.print("[INFO] IP Address: ");

 Serial.println(Ethernet.localIP());

 Serial.print("[INFO] Subnet Mask: ");

 Serial.println(Ethernet.subnetMask());

 Serial.print("[INFO] Gateway: ");

 Serial.println(Ethernet.gatewayIP());

 Serial.print("[INFO] DNS: ");

 Serial.println(Ethernet.dnsServerIP());

}

void setup() {
    
    

 // 将设置代码放在此处,运行一次:

 Serial.begin(9600);

 connectToInternet();

 server.begin();

}

void loop()

{
    
    

 //当有客户连接服务器时,服务器available函数会返回一个客户端对象用以向客户反馈信息

 EthernetClient client = server.available();

 if (client) {
    
    

  // http请求以空行结束

  boolean current_line_is_blank = true;

  while (client.connected()) {
    
    

   if (client.available()) {
    
    

    char c = client.read();

    // 如果我们排到了队伍的尽头

    // (字符)且该行为空,则http请求已结束,

    // 所以我们可以回复

    if (c == 'n' && current_line_is_blank) {
    
    

     // 发送标准http响应头

     client.println("HTTP/1.1 200 OK");

     client.println("Content-Type: text/html");

     client.println();

     // 输出每个模拟输入引脚的值

     client.print("welcome to tinyos electronics");

     client.println("<br />");

     client.print("//*************************************");

     client.println("<br />");

     client.print("");

     client.println("<br />");

     client.print("//*************************************");

     client.println("<br />");

     for (int i = 0; i < 6; i++) {
    
    

      client.print("analog input ");

      client.print(i);

      client.print(" is ");

      client.print(analogRead(i));

      client.println("<br />");

     }

     break;

    }

    //有的教程里也有用(c == '\n')和 (c != '\r')的

    //用(c == '\n')和 (c != '\r')的话,客户端连接不上服务器,不能用

    if (c == 'n') {
    
    

     // 我们要开始新的生产线

     current_line_is_blank = true;

    } else if (c != 'r') {
    
    

     // 我们在当前行中找到了一个角色

     current_line_is_blank = false;

    }

   }

  }

  client.stop();

 }

}

Experimental serial port return

insert image description here
insert image description here
The analog values ​​read from A0 to A5 are displayed on the web page, and you can also display other types of data by modifying the above program.

The above program is modified from the Web Server routine that comes with Arduino IDE, which is completed by constantly refreshing the web page to obtain Arduino feedback. In fact, in today's web development, almost all communicate with the server through ajax without refreshing the web page.

insert image description here
ARDUINO W5100 WebClient test
Basic work: W5100 expansion board is plugged into ARDUINO. Connect the W5100 to your home router with a network cable. After plugging in the network cable, you can see that the side network port indicator lights up. The router turns on the DHCP service (usually it is turned on).
1. Open the Ethernet->WebClient in the official routine.
2. Modify the Google server inside to Baidu.
3. Modify the IP address to the local LAN number segment, for example, your computer is 192.168.1.100. Then set your w5100, also to 192.168.1.x. The following x cannot be repeated with other devices in the LAN.

/*

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

 实验一百三十五:Ethernet W5100 网络扩展板 SD卡扩展模块 支持MEGA

 安装 "Ethernet.h"库-工具-管理库-搜索-安装

 项目测试之二 :ARDUINO W5100 WebClient 测试

*/



#include <SPI.h>

#include <Ethernet.h>

// Enter a MAC address for your controller below.

// Newer Ethernet shields have a MAC address printed on a sticker on the shield

byte mac[] = {
    
     0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// if you don't want to use DNS (and reduce your sketch size)

// use the numeric IP instead of the name for the server:

//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)

char server[] = "www.baidu.com";  // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign

IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet client library

// with the IP address and port of the server

// that you want to connect to (port 80 is default for HTTP):

EthernetClient client;

void setup() {
    
    

 // Open serial communications and wait for port to open:

 Serial.begin(9600);

 while (!Serial) {
    
    

  ; // wait for serial port to connect. Needed for Leonardo only

 }

 // start the Ethernet connection:

 if (Ethernet.begin(mac) == 0) {
    
    

  Serial.println("Failed to configure Ethernet using DHCP");

  // no point in carrying on, so do nothing forevermore:

  // try to congifure using IP address instead of DHCP:

  Ethernet.begin(mac, ip);

 }

 // 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");

  // Make a HTTP request:

  client.println("GET /search?q=arduino HTTP/1.1");

  client.println("Host: www.baidu.com");

  client.println("Connection: close");

  client.println();

 }

 else {
    
    

  // kf you didn't get a connection to the server:

  Serial.println("connection failed");

 }

}

void loop()

{
    
    

 // if there are incoming bytes available

 // from the server, read them and print them:

 if (client.available()) {
    
    

  char c = client.read();

  Serial.print(c);

 }

 // if the server's disconnected, stop the client:

 if (!client.connected()) {
    
    

  Serial.println();

  Serial.println("disconnecting.");

  client.stop();

  // do nothing forevermore:

  while (true);

 }

}

The data returned by the server can be displayed to prove that the communication is successful.

insert image description here
Ethernet Library

Enable network connectivity (local and internet) via Arduino Ethernet board or shield.

For more information, refer to [size=13.3333px]https://www.arduino.cc/en/Reference/Ethernet.

Compatible with all Arduino development boards.

Advanced Chat Server: Build a simple chat server.
Barometric Pressure Web Server: Outputs the value transmitted from the barometric pressure sensor as a web page.
Chat Server: Build a simple chat server.
Dhcp Address Printer: Obtain an IP address through DHCP and print it out.
Dhcp Chat Server: A simple DHCP chat server
Telnet Client: A simple telnet client.
UDP Ntp Client: Query Network Time Protocol (NTP) servers via UDP.
UDP Send Receive String: Send and receive text strings via UDP.
Web Client: Make an HTTP request.
Web Client Repeating: Repeat HTTP requests.
Web Server: Create a simple HTML page to display the values ​​of the simulated sensors.

insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131448850