Arduino Mega ENC28J60以太网模块直接连接到PC,以接收/发送UDP
arduino mega + ENC28J60 ethernet module direct connection to PC to receive/send UDP
我想使用我的arduino mega(带有传感器盾牌)和enc28J60以太网模块(直接连接到我的PC)从飞行模拟器(X-Plane 11)发送和接收UDP,能够通过网络发送UDP)。
网络模块:http://www.ebay.de/itm/281353516180?__trksid=p2057872.m2749.l2749.l2649&spagename = stspagename = strk = strk;
我无法将接收到的UDP数据写入串行显示器。我什至不确定我真的会收到UDP。
,以太网模块和PC之间的连接似乎很好,因为以太网模块的i/o的绿色LED永久打开,一旦我启动飞行SIM卡并从那里发送UDP,黄色的一个灯就会闪烁。
我尝试了标准以太网电缆和跨界。
我已经尝试了两种将ENC28J60以太网模块连接到Arduino Mega Sensor Shield的方法。
-
Arduino Uno的标准布线
- enc28j60 to arduino pin 12
- enc28j60 si至arduino pin 11
- enc28j60 sck至arduino pin 13
- enc28j60 cs到arduino pin 10
- enc28j60 vcc到arduino 3v3 PIN
- enc28j60 gnd to arduino gnd pin
-
推荐Arduino Mega
的接线https://en.code-bude.net/2013/06/06/22/how-to-cus-use-enc28j60-Ethernet-shield-shield-with-arduino-mega-2560/
- gnd to gnd
- 3.3至3.3V
- pin50
- SI至PIN51
- SCK至PIN52
- CS到PIN53
我也尝试了几个libs:
-
EtherCard:建议将CS PIN设置为库文件中的53,我做到了。再加上一个人应该在草图中使用此代码(未编译。错误是与
sizeof
与Ethernet::buffer
结合使用)ether.begin(sizeof Ethernet::buffer, mac, 53)
-
uipethernet(我想我可以在这里使用标准布线,因为据说该lib使用标准以太网屏蔽设置?)
没有组合使在串行显示器中输出任何输出是可能的。
我尝试过的草图之一是:
#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销子,还是lib这样做?
草图应该正常工作吗?
https://github.com/jcw/ethercard下载此。并编译并运行udplistener示例。
https://sourceforge.net/projects/sockettest/下载此程序(Sockettest)。Sockettest是非常简单的程序。
和Arduino代码,(ether.udpServerListenOnPort(&udpSerialPrint, 1337);
)
您更改所需的端口号。" udpserialprint"是一个回调函数。" 1337"是端口号。如果存在UDP数据,则程序调用此功能。
- (Winsock) UDP 接收工作正常,但同一套接字的发送失败
- C++ 通过 UDP 发送数据包,但不接收数据包
- 如何使用 ESP8266-12E 通过 UDP 发送/接收
- OPENCV中的GSTREAMER不会通过UDP发送视频数据
- 通过UDP发送时会产生不同的结果
- 使用C++和Qt通过UDP发送float var
- 使用本地 ipv6 套接字将 UDP 发送到本地 ipv4 地址
- 通过 UDP 发送任何类型的数据
- 将结构序列化为 char * 并通过 UDP 发送
- libcurl是否能够通过UDP发送http消息
- 通过 UDP 发送 XML 数据
- UDP发送从不失败
- UDP发送()到本地主机在Winsock下丢弃数据包
- 使用winsock vc++通过UDP发送数字数组
- 用UDP发送数据报
- 为什么用于零拷贝的OpenOnload扩展API没有任何UDP发送或TCP接收的内容?
- c++ UDP发送失败,需要睡眠
- Gstreamer:为什么我不能在本地主机上通过UDP发送数据?
- 在c++中通过UDP发送整数数组
- 使用 UDP 发送和接收结构(WinSock & C++)?