Ethernet and CAN-shield on top of Arduino UNO R3?

Hello,

I am exploring my options to control a model train using my phone. I can control the model train using a CAN-shield, and want a connection to my phone using the Ethernet shield.

Now I wanted to know, is it possible to use this V1.2 CAN-shield on top of a Arduino Ethernet shield or the other way around? The documentation says the CAN-bus uses the SPI pins of the Arduino and the Arduino Ethernet shield uses the pins 10, 11, 12 and 13. Does this the shields are usable on top of each other?

Thanks in advance!

EDIT: Just found out the CAN-shield uses 9, 10, 11, 12 and 13 as SPI pins. Does this mean the shields cannot be used at the same time? Or is this not the way SPI works?

Because of the way the Ethernet shield is desinged, you would like to put it on top of the CAN shield. The CAN shield uses SPI (like the Ethernet shield) and D9 as CS. Due to the use of D10 as CS by the Ethernet shield, it should work.

But there might be a problem about SRAM usage, the UNO has got only 2 KB. A MEGA 2560 looks more suitable with its 8 KB.

I have recently finished a prototype Protocol converter for my company where i take can bus and convert it to mod bus,RTU,TCP,IP,UDP and so on. you can stack the Ethernet shield and the can bus shield on top of the arduino uno just make sure you have set your CS pin correctly at pin 10 for the CAN BUS shield.I have found that the UNO is indeed "to small" when it comes to the memory, when working with can bus and Ethernet together you might end up needing alot of memory, especial if you are going to start addressing your CAN data with large strings. I suggest using the MEGA, if you really want to use the UNO then you should look at the SD card option for increased memory, there is a Ethernet shield available with SD capabilities. Would you like a working code that you can build from that incorparates the CANBUS and Ethernet. I have a base code that you can connect to the Ethernet and then read the canbus data, from that you can build your own function

I'm trying to do the same
can you send me the code?

I'm sending you PM

Thanks ,

Hallo sorry i have been away, here is a short sample on using Canbus while connected to Ethernet. you have to make sure you have the correct libraries, having various canbus libraries on your system causes crashes and malfunction, you must use the MCP canbus libraries, and remove any other canbus/modbus libraries as well they really do clash and then you will think your code is wrong when its actualy the libraries.

#include <mcp_can.h>   //Use only this libriary for canbus and modbus
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

// Change these for your network!
byte mac[] = {0xD8, 0xB0, 0x4C, 0xB5, 0x18, 0xA0}; // use your own mac id for the ethernet module
IPAddress      ip(192, 168, 1, 11);   // make sure your ip settings are correct
IPAddress gateway(255, 255, 255, 0);
IPAddress    dest(192, 168, 17, 10);

unsigned int localPort = 8888;
unsigned int   remPort = 54321;

unsigned long rxId;
byte len = 0;
byte rxBuf[8];   // this buffer is for how many pars there is to your information string with your id
char buffer[728];  // how big the entire string is

MCP_CAN CAN0(10);                                   // Make sure your CS pin is correct, for uno it is 10 and for mega it will be 53

EthernetUDP UDP;
void setup()
{
  Serial.begin(38400);
//  CAN0.begin(CAN_250KBPS);                         // init CAN Bus with 250kb/s baudrate
  CAN0.begin(MCP_ANY, CAN_250KBPS, MCP_16MHZ);     // init CAN Bus with 250kb/s baudrate at 16MHz with Mask & Filters Disabled
  CAN0.setMode(MCP_NORMAL);                        // Set operation mode to normal so the MCP2515 sends acks to received data.
  pinMode(2, INPUT);                               // Setting pin 2, MCP2515 /INT, to input mode  NB!!!!
  Ethernet.begin(mac,ip);                          // Initialize Ethernet
  UDP.begin(localPort);                            // Initialize the UDP listen port that is currently unused!

  Serial.println("CAN to Ethernet...");
}

void loop()
{
    if(!digitalRead(2))                            // If pin 2 is low, read receive buffer
    {
      CAN0.readMsgBuf(&rxId, &len, rxBuf);         // Read Data: rxID = Message ID, len = Data Length, buf = Data Byte(s)
//      CAN0.readMsgBuf(&len, rxBuf);                // Read Data: len = Data Length, buf = Data Byte(s)
//      rxId = CAN0.getCanId();                      // Function will be depreciated soon due to readMsgBuf now returning ID

      sprintf(buffer, "ID: %.8lX  Data: %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X\n\r",
              rxId, rxBuf[0], rxBuf[1], rxBuf[2], rxBuf[3], rxBuf[4], rxBuf[5], rxBuf[6], rxBuf[7]);

      UDP.beginPacket(dest, remPort);
      UDP.write(buffer);
      Serial.print(buffer);
      UDP.endPacket();
    }
}

sprintf(buffer, "ID: %.8lX Data: %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X\n\r",
rxId, rxBuf[0], rxBuf[1], rxBuf[2], rxBuf[3], rxBuf[4], rxBuf[5], rxBuf[6], rxBuf[7]);

this sprintf buffer is the important part along with this part
CAN0.readMsgBuf(&rxId, &len, rxBuf);

you have to receive your can messages with your canbus module and then place all the data into the buffr in order to send it over Ethernet.,
Canbus to Ethernet is still easy, if you want to convert it to Modbus RTU or TCP then you will have to categorize every part of canbus input along with canbus ID individual so that you can post it onto a Http web server, i can send you an example on how to do this as well if you want it.

I hope this helps, it worked very well for me when i needed to write my software for my BMS controller