Go Down

Topic: Nano OSC Not Responding to Ping / Working (Read 192 times) previous topic - next topic

rohanmcdermott

I've got this code to fire an OSC message when a button is pressed & depressed.
It works fine on my Arduino Uno.

However, it doesn't work when uploaded to my Arduino Nano with an ethernet shield.

I cant ping it & it doesn't respond to button presses.


Quote
#include <OSCMessage.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>


const int button1 = 3;              // the number of the pushbutton pin
long on=0;
long off=0;
int buttonState1 = 0;              // variable for reading the pushbutton1 status

EthernetUDP Udp;

//the Arduino's IP
IPAddress ip(10, 10, 10, 20);
//destination IP
IPAddress outIp(10, 10, 10, 30);
//port
const unsigned int outPort = 8000;

 byte mac[] = { 
  0x82, 0x40, 0x56, 0xF9, 0xD1, 0x21 };

void setup() {

  pinMode(button1, INPUT_PULLUP); // PULLUP add 5v to pin without hardware prevent pin from floating between HIGH and LOW
  Ethernet.begin(mac,ip);
    Udp.begin(8888);

}

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(button1);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is LOW:


  if (digitalRead(button1)==LOW){
  if (on == 1) {     

  OSCMessage msg("/string/1/send");
 
  Udp.beginPacket(outIp, outPort);
    msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet

  msg.empty(); // free space occupied by message
  }
    on++;

  }

  if (digitalRead(button1)==HIGH){
  if (off == 1) {                     

  OSCMessage msg("/string/2/send");
 
  Udp.beginPacket(outIp, outPort);
    msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet

  msg.empty(); // free space occupied by message
  }
    off++;

  }

  if (buttonState1 == HIGH) {   
    delay(20);
    on=0;
  }
   if (buttonState1 == LOW) {   
    delay(20);
    off=0;
  }
}
Any help is very much appreciated!

pert

Which Ethernet controller chip does your Ethernet shield use? The common models in the Arduino world are W5100, W5200, W5500, ENC28J60. It will be written on the largest chip on the shield.

rohanmcdermott

Which Ethernet controller chip does your Ethernet shield use? The common models in the Arduino world are W5100, W5200, W5500, ENC28J60. It will be written on the largest chip on the shield.
It's a ENC28J60

pert

The Ethernet library is not compatible with the ENC28J60. It only works with the W5x00 Ethernet controller. For the ENC28J60, there are two commonly used libraries: UIPethernet, and EtherCard. The advantage of the UIPethernet library is that its API is compatible with the Ethernet library. This means you can use code written for the Ethernet library by only changing the filename in the #include directive.

rohanmcdermott

The Ethernet library is not compatible with the ENC28J60. It only works with the W5x00 Ethernet controller. For the ENC28J60, there are two commonly used libraries: UIPethernet, and EtherCard. The advantage of the UIPethernet library is that its API is compatible with the Ethernet library. This means you can use code written for the Ethernet library by only changing the filename in the #include directive.
I really appreciate the help!

Ive spent a few hours trying to implement my OSC code with UIPethernet but im really struggling.

I cant seem to find a way to integrate OSCMessage with UIPethernet.

I also cant seem to find anyone who has been able to do this before.

Any thoughts?

pert

Change these lines in your sketch:
Code: [Select]
#include <Ethernet.h>
#include <EthernetUdp.h>

to:
Code: [Select]
#include <UIPEthernet.h>
#include <UIPUdp.h>


After those changes, ideally, code that works with the Ethernet library and W5x00 will now work with the UIPEthernet library and ENC28J60. The reality is that the ENC28J60 is kind of a pain to work with. I've spent some time messing around with that chip but it was always a struggle. Once I switched to W5100 (and moving to W5500 now), everything got much easier. The ENC28J60 is cheaper but if you're not going to be using a lot of them it may well be worth spending the little bit extra for the more pleasant experience of using the W5100 or W5500 and the much more actively developed, tested, and supported Ethernet library.

Go Up