arduino mega + ENC28J60 以太网模块直接连接到 PC 到 receive/send UDP
arduino mega + ENC28J60 ethernet module direct connection to PC to receive/send UDP
我想使用我的 Arduino Mega(带传感器屏蔽)和 ENC28J60 以太网模块(直接连接到我的 PC)从飞行模拟器(X-Plane 11,能够发送UDP 通过网络)。
网络模块:http://www.ebay.de/itm/281353516180?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
但是我无法将接收到的UDP 数据写入串口监视器。
我什至不确定我是否真的收到 UDP。
以太网模块和 PC 之间的连接似乎没有问题,因为以太网模块 I/O 的绿色 LED 常亮,而黄色 LED 在我启动我的飞行 sim 并发送时立即闪烁来自那里的 UDP。
我都试过了,标准以太网电缆和交叉。
根据 2 种不同的指南,我尝试了 2 种将 ENC28J60 以太网模块连接到 Arduino Mega 传感器扩展板的方法。
Arduino Uno 的标准接线
- Enc28j60 SO 到 Arduino 引脚 12
- Enc28j60 SI 到 Arduino 引脚 11
- Enc28j60 SCK 到 Arduino 引脚 13
- Enc28j60 CS 到 Arduino 引脚 10
- Enc28j60 VCC 到 Arduino 3V3 引脚
- Enc28j60 GND 到 Arduino Gnd 引脚
Arduino Mega 的推荐布线
https://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shield-with-arduino-mega-2560/
- GND 到 GND
- 3.3 至 3.3V
- SO 到 Pin50
- SI 转 Pin51
- SCK 到 Pin52
- CS 转 Pin53
我也尝试了几个库:
EtherCard:建议在库文件中将cs pin设置为53,我也是这样做的。另外一个应该在草图中使用这行代码(没有编译。错误是与 sizeof
结合使用 Ethernet::buffer
)
ether.begin(sizeof Ethernet::buffer, mac, 53)
UIPEthernet(我假设我可以在这里使用标准布线,因为据说这个库使用标准以太网屏蔽设置?)
None 的组合使得在串行监视器中有任何输出成为可能。
我尝试过的草图之一如下:
#include <Dhcp.h>
#include <Dns.h>
#include <ethernet_comp.h>
#include <UIPClient.h>
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 6); // local IP - address of my Arduino
unsigned int localPort = 49001; // local port to listen - default X-Plane port
byte buf = 00; // buffer for UDP packet (BYTE, not char)
EthernetUDP Udp; // An EthernetUDP instance to send and receive packets over UDP
//-------------------------------------------------------------------------------
void setup()
{
Ethernet.begin(sizeof Ethernet::buffer, mac, 53)
Ethernet.begin(mac,ip); // start the Ethernet
Udp.begin(localPort); //..and UDP:
Serial.begin(9600); // init serial port
}
void loop() {
int packetSize = Udp.parsePacket(); // Checks for the presence of a UDP packet, and returns its size
if(packetSize) // UDP packet was received and its size defined
{
Serial.println();
Serial.print("Packet size: ");
Serial.println(packetSize); // Packet Size in bytes
// When Udp.read used without parameters, it returns next char (byte in this case) :
Serial.println("Xplane Data:");
for (int i =0; i/<packetSize; i++)
{
buf = Udp.read();
Serial.print(buf);
Serial.print("-");
}
}
delay(10);
}
所以我的问题是:
测试两个连接的最简单方法是什么:
PC -> 以太网模块和
以太网模块 -> Arduino?
我需要在我的草图中设置使用过的 Arduino 引脚还是库会这样做?
草图应该可以正常工作吗?
https://github.com/jcw/ethercard 下载这个。并编译 运行 udplistener 示例。
https://sourceforge.net/projects/sockettest/ 下载这个程序(SocketTest)。 SocketTest 是一个非常简单的程序。
在arduino代码中,(ether.udpServerListenOnPort(&udpSerialPrint, 1337);
)
您更改所需的端口号。 "udpSerialPrint"是回调函数,“1337”是端口号。如果存在udp数据,程序调用此函数。
我想使用我的 Arduino Mega(带传感器屏蔽)和 ENC28J60 以太网模块(直接连接到我的 PC)从飞行模拟器(X-Plane 11,能够发送UDP 通过网络)。
网络模块:http://www.ebay.de/itm/281353516180?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
但是我无法将接收到的UDP 数据写入串口监视器。 我什至不确定我是否真的收到 UDP。
以太网模块和 PC 之间的连接似乎没有问题,因为以太网模块 I/O 的绿色 LED 常亮,而黄色 LED 在我启动我的飞行 sim 并发送时立即闪烁来自那里的 UDP。
我都试过了,标准以太网电缆和交叉。
根据 2 种不同的指南,我尝试了 2 种将 ENC28J60 以太网模块连接到 Arduino Mega 传感器扩展板的方法。
Arduino Uno 的标准接线
- Enc28j60 SO 到 Arduino 引脚 12
- Enc28j60 SI 到 Arduino 引脚 11
- Enc28j60 SCK 到 Arduino 引脚 13
- Enc28j60 CS 到 Arduino 引脚 10
- Enc28j60 VCC 到 Arduino 3V3 引脚
- Enc28j60 GND 到 Arduino Gnd 引脚
Arduino Mega 的推荐布线
https://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shield-with-arduino-mega-2560/
- GND 到 GND
- 3.3 至 3.3V
- SO 到 Pin50
- SI 转 Pin51
- SCK 到 Pin52
- CS 转 Pin53
我也尝试了几个库:
EtherCard:建议在库文件中将cs pin设置为53,我也是这样做的。另外一个应该在草图中使用这行代码(没有编译。错误是与
sizeof
结合使用Ethernet::buffer
)ether.begin(sizeof Ethernet::buffer, mac, 53)
UIPEthernet(我假设我可以在这里使用标准布线,因为据说这个库使用标准以太网屏蔽设置?)
None 的组合使得在串行监视器中有任何输出成为可能。
我尝试过的草图之一如下:
#include <Dhcp.h>
#include <Dns.h>
#include <ethernet_comp.h>
#include <UIPClient.h>
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 6); // local IP - address of my Arduino
unsigned int localPort = 49001; // local port to listen - default X-Plane port
byte buf = 00; // buffer for UDP packet (BYTE, not char)
EthernetUDP Udp; // An EthernetUDP instance to send and receive packets over UDP
//-------------------------------------------------------------------------------
void setup()
{
Ethernet.begin(sizeof Ethernet::buffer, mac, 53)
Ethernet.begin(mac,ip); // start the Ethernet
Udp.begin(localPort); //..and UDP:
Serial.begin(9600); // init serial port
}
void loop() {
int packetSize = Udp.parsePacket(); // Checks for the presence of a UDP packet, and returns its size
if(packetSize) // UDP packet was received and its size defined
{
Serial.println();
Serial.print("Packet size: ");
Serial.println(packetSize); // Packet Size in bytes
// When Udp.read used without parameters, it returns next char (byte in this case) :
Serial.println("Xplane Data:");
for (int i =0; i/<packetSize; i++)
{
buf = Udp.read();
Serial.print(buf);
Serial.print("-");
}
}
delay(10);
}
所以我的问题是:
测试两个连接的最简单方法是什么:
PC -> 以太网模块和
以太网模块 -> Arduino?我需要在我的草图中设置使用过的 Arduino 引脚还是库会这样做?
草图应该可以正常工作吗?
https://github.com/jcw/ethercard 下载这个。并编译 运行 udplistener 示例。
https://sourceforge.net/projects/sockettest/ 下载这个程序(SocketTest)。 SocketTest 是一个非常简单的程序。
在arduino代码中,(ether.udpServerListenOnPort(&udpSerialPrint, 1337);
)
您更改所需的端口号。 "udpSerialPrint"是回调函数,“1337”是端口号。如果存在udp数据,程序调用此函数。