Arduino - how can i make the ethernet + led on off module working? led is not reacting when ethernet module is used

StackOverflow https://stackoverflow.com/questions/18646884

  •  27-06-2022
  •  | 
  •  

Question

When i use Ethernet.begin(mac,ip) then the led is not turning on and off. 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. How can i ?

Board model: Ethernet 08 Twinker kit, Twinker relay

enter image description here

#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
Was it helpful?

Solution

From your description it sounds like the Ethernet I/O is interfering with the 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. (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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top