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--;
}
}