Dear readers, I am Cherie, and today is my first day at work. I am so excited!~(≧▽≦) (Let me quickly have a chip to calm down…)
Today, let’s take a look at Arduino Network Communication.
What is Arduino? Do you think it is just a circuit board?
No~no~no~ It’s a misunderstanding ( ̄▽ ̄)~*
Arduino is a convenient, flexible, and easy-to-use open-source electronic prototyping platform. It includes hardware (various models of Arduino boards) and software (Arduino IDE).
It is built on an open-source simple I/O interface and has a development environment similar to Java and C language called Processing/Wiring. It mainly consists of two parts: the hardware part, which is the Arduino circuit board used for circuit connections; and the other is the Arduino IDE, which is your programming development environment on your computer. You just need to write the program code in the IDE and upload it to the Arduino circuit board, and the program will tell the Arduino circuit board what to do.
Since I have finished talking about Arduino, let’s get to today’s main topic ↖(^ω^)↗ and take a look at the Arduino network communication.
Network communication is not Arduino’s strong suit; once the code is uploaded, it uses up 32% of the program storage space… However, it is still very convenient for small projects, and the key is that the costs are very low! The costs are very low! The costs are very low! (Saying it three times for emphasis!)
However, this time I will only do wired network communication. Because I am currently learning reverse engineering (I have to do a lot of practice and also rewrite many previous C++ programs in assembly.) //———————————————-
https://pan.baidu.com/s/1hq5UeKO?qq-pf-to=pcqq.group //———————————————-
Looking at the homework assigned by Teacher Qian from Cree, I should quickly go write my homework. This is why I didn’t have time to update my Arduino article last week, and now I spend even less time on Arduino. I can’t write too much each time, and the main reason for the delay in wireless network communication is that I have to wait.
The module I used for network communication is the W5100 (a network chip based on a full hardware TCP/IP protocol stack technology). The enc28j60 chip is a bit cheaper, but I bought the finished product for convenience.
Here is another image of the back.
Let’s talk about network cables.
I want to remind you: you must use a crossover cable.
Crossover cable: also known as a reverse line, the wire sequence is arranged according to one end 568A and the other end 568B standards, and clamped with RJ45 crystal heads.
This time I bought a network cable because I was too far from home. This is probably my second time encountering a network cable problem because the network cables I bought are generally parallel cables.
There are two types of network cables: one is a crossover cable, and the other is a parallel (straight-through) cable.
The crossover cable is made by using the 568A standard on one end and the 568B standard on the other end.
The parallel (straight-through) cable is made by using the same 568A standard on both ends or the same 568B standard (generally, the commonly used is the 568B parallel (straight-through) cable).
568A standard: white-green, green, white-orange, blue, white-blue, orange, white-brown, brown.
568B standard: white-orange, orange, white-green, blue, white-blue, green, white-brown, brown.
I remember the first time I encountered this problem was several years ago when connecting two computers to the network. At that time, after encountering this problem, I bought a network crimper and started making cables myself. If considering the cost, making it yourself is still much cheaper. One network cable can be counted as two. When networking, it is quite good for controlling appliances at home. One cable can be used as eight cables, how great is that? If not all eight wires are used, just leave them as interfaces.
This is the power supply; I am afraid that the computer will not have enough power, or it is inconvenient when not using the data cable. It can be optional here; if available, use it; if not, the data cable is also fine.
Example:
The examples in Arduino are very convenient; you can use them directly, making learning easier.
However, bad things are also happening:
Using Arduino Ethernet to establish a simple web server. When the Arduino server receives a browser access request, it will send a response message. The browser receives the response message and converts the HTML text included in it into a web page.
Arduino program source code: //———— net Server ———— #include <SPI.h> #include <Ethernet.h> // Set MAC address, IP address byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1,177); // HTTP default port is 80 EthernetServer server(80); void setup() { Serial.begin(9600); // Start ethernet connection and initialize as a server Ethernet.begin(mac, ip); server.begin(); Serial.print(‘server is at ‘);// For debugging Serial.println(Ethernet.localIP()); } void loop() { // Listen for data from the client EthernetClient client = server.available(); if (client) { Serial.println(‘new client’); // An Http request must end with a carriage return and a newline boolean currentLineIsBlank = true; if (client) { Serial.println(‘new client’); // An Http request must end with a carriage return and a newline boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // If a blank line is received, it means the http request has ended, and send the response message if (c == ‘
‘ && currentLineIsBlank) { // Send standard HTTP response client.println(‘HTTP/1.1 200 OK’); client.println(‘Content-Type: text/html’); client.println(‘Connection: close’); client.println(); client.println(‘<!DOCTYPE HTML>’); client.println(‘<html>’); client.println(‘<meta http-equiv=’refresh’ content=’5′>’); for (int analogChannel = 0; analogChannel < 6; analogChannel++) { int sensorReading = analogRead(analogChannel); client.print(‘analog input ‘); client.print(analogChannel); client.print(‘ is ‘); client.print(sensorReading); client.println(‘<br/>’); } client.println(‘</html>’); break; } if (c == ‘
‘) { // A new line has started currentLineIsBlank = true; } else if (c != ‘
‘) { // A character has been received in the current line currentLineIsBlank = false; } } }//if (client.available()) // Wait for the browser to receive data delay(1); // Disconnect client.stop(); Serial.println(‘client disconnected’); }//while (client.connected()) }//if (client) }//loop() //—————————————————
After the program is uploaded, the serial port should look like this, see the image below.
Image before connecting to the network cable.
Computer settings:
After connecting the network cable, the computer has not yet started the network cable connection.
The final result should look like this.
Then,
See you tomorrow!
References: https://www.arduino.cc/en/Main/ArduinoBoardEthernet
Leave a Comment
Your email address will not be published. Required fields are marked *