Ethernet library does not work with arduino-pico core

I have the W5500 ethernet module that I connected to the default SPI pins of a Raspberry Pi Pico. I tested the ethernet examples and if I use the arduino mbed os rp2040 core then all the examples run without a problem, however if I switch to the arduino-pico core then I always get the message that the ethernet shield was not found.

I saw that there are some fixes/alternate libraries (eg; EthernetWebServer) however I need the Ethernet library specifically as I am using it for Modbus communication with a PLC (modbus-arduino library).

And the reason why I just don't stick with the arduino mbed os rp2040 core is because I want to utilize both cores of the pico where one core is used purely for tracking an encoder and the other core deals with communication and other logic. And for some reason, simply using setup() and setup1() with the arduino mbed os rp2040 core results in setup1() being ignored and the encoder does not get tracked.

I include the code I used for testing as a reference. All libraries and other files are up to date. If the code is run with the arduino mbed os rp2040 core then the encoder does not get tracked. If it is run with the arduino-pico core then the modbus communication vi the W5500 ethernet module does not work. Any advice is greatly appreciated.

#include <ModbusIP.h>
#include <Modbus.h>
#include <Ethernet.h>
#include <SPI.h>

#define encoder_A 8
#define encoder_A2 9
#define encoder_B 4
#define encoder_B2 5

//following variables used for modbus communication
const int statusWord1_add = 0;
const int statusWord2_add = 1;
const int statusWord3_add = 2;

const int controlWord1_add = 4;
const int controlWord2_add = 5;
const int controlWord3_add = 6;

uint32_t currentPosition = 0;

ModbusIP mb;

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(350);

  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  byte ip[] = {192, 168, 0, 100};
  mb.config(mac, ip);

  mb.addIreg(statusWord1_add,3);
  mb.addIreg(statusWord2_add,2);
  mb.addIreg(statusWord3_add,10);

  mb.addHreg(controlWord1_add);
  mb.addHreg(controlWord2_add);
  mb.addHreg(controlWord3_add);
}

void setup1(){//if this setup is included in setup() then it works as intended except everything runs only on one core
  pinMode(encoder_A, INPUT);
  pinMode(encoder_A2, INPUT);
  pinMode(encoder_B, INPUT);
  pinMode(encoder_B2, INPUT);
  attachInterrupt(digitalPinToInterrupt(encoder_A), rising_A, RISING);
  attachInterrupt(digitalPinToInterrupt(encoder_A2), falling_A, FALLING);
  attachInterrupt(digitalPinToInterrupt(encoder_B), rising_B, RISING);
  attachInterrupt(digitalPinToInterrupt(encoder_B2), falling_B, FALLING);
}

void loop(){
  modbus();
  Serial.println(currentPosition);
}

void modbus(){
  mb.task();
  uint16_t controlWord1 = mb.Hreg(controlWord1_add);
  uint16_t controlWord2 = mb.Hreg(controlWord2_add);
  uint16_t controlWord3 = mb.Hreg(controlWord3_add);
  Serial.print(controlWord1);Serial.print(" ");
  Serial.print(controlWord2);Serial.print(" ");
  Serial.print(controlWord3);Serial.print(" ");
  mb.Ireg(statusWord1_add, 0);
  mb.Ireg(statusWord2_add, uint16_t(currentPosition/65535));
  mb.Ireg(statusWord3_add, uint16_t(currentPosition%65535));
}

void rising_A(){
  if(!digitalRead(encoder_B)){
    currentPosition++;
  }
  else{
    currentPosition--;
  }
}

void falling_A(){
  if(digitalRead(encoder_B)){
    currentPosition++;
  }
  else{
    currentPosition--;
  }
}

void rising_B(){
  if(digitalRead(encoder_A)){
    currentPosition++;
  }
  else{
    currentPosition--;
  }
}

void falling_B(){
  if(!digitalRead(encoder_A)){
    currentPosition++;
  }
  else{
    currentPosition--;
  }
}

you have some strange Ethernet library. did you copy the Mbed Ethernet library? that will not work with Nano RP2040. At least not without some setup of a network interface driver for W5500 compatible with Mbed.
Other Mbed boards have Ethernet peripherals in MCU and it is preconfigured for the Mbed core's Ethernet library.
Even the WiFi on Nano RP2040 uses the WiFiNINA library not the WiFi library from the Mbed core.

you have to use the normal Arduino Ethernet library.

Alright, that makes sense. I just download the first library that popped up when I searched for Ethernet in the arduino ide library manager, those usually work. Would you mind posting the link to the library you are talking about please? Just so I can make sure I got the right one and it works

Yeah that's exactly the library I got and still the same problem persists.

the WebClient example works?

No, just still get the same message; "Ethernet shield was not found. Sorry, can't run without hardware."

CS pin is pin 10? try to add Ethernet.init(10);
how do you power the module? is it a module with 5 V or 3.3 V Vin?
if you power it from 5 V pin of the Nano, did you 'activate' the 5 V pin on the bottom side of the board?

Well I am using an rPI pico, CS is connected to GPIO17. I power the module directly with 3.3V. I tried using the Ethernet.init() and interestingly enough it kills the code. I do not get any repsonse on Serial at all. Maybe it is also worth noting that I am technically using an rPi pico W, dont know if that makes a difference

I think RPi Pico W uses GPIO23, 24, 25, & 29 for WIFi so that could cause a conflict.

Right but I am using the default SPI pins, so GPIO 16,17,18,19. I just look at the schematic of the rPi pico W and the pins 16-19 are not used for anything, they go directly to the pin header. But I did order a normal rPi pico, just to see whether that'll make the difference.

do you have Ethernet.init for the CS pin?

Yes, but still won't work. If I include Ethernet.init(), I do not get any response over Serial at all, its as if it kills the code.

do you have the pin number in that init as parameter?

Yes, of course

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.