[英]Arduino - how can i make the ethernet + led on off module working? led is not reacting when ethernet module is used
When i use Ethernet.begin(mac,ip) then the led is not turning on and off. 当我使用Ethernet.begin(mac,ip)时,LED不会打开和关闭。 But when i not use that line it works. 但是,当我不使用该行时。 But i need to have led on and off by using that Ethernet and UPP modules. 但是我需要通过使用以太网和UPP模块进行引导和关闭。 How can i ? 我怎样才能 ?
Board model: Ethernet 08 Twinker kit, Twinker relay 主板型号:以太网08 Twinker套件,Twinker中继
#include <TinkerKit.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
TKLed led(O5); //O0 does not work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "ackv1"; // a string to send back
EthernetUDP Udp;
void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
// check the switch state
delay(1000);
led.off();
delay(3000);
led.on();
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}
EDIT: 编辑:
$ echo "hello" | nc -4u 192.168.1.177 8888
ackv1
From your description it sounds like the Ethernet I/O is interfering with the LED I/O. 根据您的描述,听起来以太网I / O正在干扰LED I / O。
Notice that: 注意:
TKLed led(O0);
This probably defines the led to be at port 0. You need to determine what ports are used by Ethernet. 这可能将led定义为端口0。您需要确定以太网使用哪些端口。 (I would tell you but this is a good lesson.) (我会告诉你,但这是一个很好的教训。)
IF (you need to read documentation) there is a conflict between the led port number and the ethernet port numbers then you will need to move the LED, because the ethernet ports require serial I/O, while the LED just requires a +5V or 0V. 如果(您需要阅读文档)在led端口号和以太网端口号之间存在冲突,那么您将需要移动LED,因为以太网端口需要串行I / O,而LED仅需要+ 5V或0V。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.