【问题标题】:Arduino - how can i make the ethernet + led on off module working? led is not reacting when ethernet module is usedArduino - 我怎样才能使以太网 + led on off 模块工作?使用以太网模块时,led 没有反应
【发布时间】:2013-09-09 21:51:56
【问题描述】:

当我使用 Ethernet.begin(mac,ip) 时,LED 不会打开和关闭。但是当我不使用那条线时它会起作用。但我需要通过使用以太网和 UPP 模块来开启和关闭。我该怎么办?

板卡型号:以太网 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);
}

编辑:

$ echo "hello" | nc -4u 192.168.1.177 8888
ackv1

【问题讨论】:

    标签: c arduino plc arduino-ide


    【解决方案1】:

    从您的描述看来,以太网 I/O 正在干扰 LED I/O。

    注意:

    TKLed led(O0);
    

    这可能将 LED 定义为端口 0。您需要确定以太网使用哪些端口。 (我会告诉你,但这是一个很好的教训。)

    如果(您需要阅读文档)LED 端口号和以太网端口号之间存在冲突,那么您需要移动 LED,因为以太网端口需要串行 I/O,而 LED 只需要一个+5V 或 0V。

    【讨论】:

    • 我仍然无法让它工作。如图所示,我的 tinkerkit 在以太网板的顶部,在 tinkerkit 的顶部我有输出和输入,O0 是我用来打开和关闭 LED 的端口。然后我也将输出切换到 O5 输出,但仍然无法正常工作。但我看到有人使用相同的板,它的工作。请有任何想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多