wire.h how to write/read on 2scl, 2sda on mega r3

Does the Mega R3 have 2 Ic2 ports.
See the pic, there are the traditional ports 19, and 20 (marked on my board 2SCL and 2SPI) and then, on top left there are another 2 SPI SDA.

I have a situation where I need them both, (meaning 2 SPI streams). So the sketches (examples of Wireh) works fine on the traditional pins 19,20 but how to I move it on the other two (top left)?

I tried instead of Wire.begin();
to put Wire1.begin();

It wont even compile. The wire.h reference does not say anything about second ports…

What to do , Thanks

The Mega has one I2C port on pins 19 and 20. That is, I2C, not SPI. So which one is it? If it's SPI, wire.h is the wrong library.

There are 2 SPI interfaces, one for the USB chip (that you can't use) and one connected to the 2560 that you can use.

Multiple I2C devices can be connected in parallel on the same pins. Not 100% familiar with SPI but as far as I know, multiple SPI devices can be wired in parallel with the exception of the SS line; each device needs it's own SS pin on teh Arduino.

I have made a mistake, refering to this interface as SPI. I do want to know if the Mega R3 has 2 IC2 interfaces. Meanining 2 sets of SCL and SDA pins. If so (2 Sets) how do I write the wire.h code to address the second?

Thanks for bearing with me… Still learning this stuff.


In the pic, see that the top 2 pins are SCL and SDA pins and then again the bottom 2 are SCL and SDA pins.

Screen Shot 2017-04-03 at 2.51.46 PM.png

No, the Mega does not have two I2C interfaces. I2C is a bus and you wire both devices to the same pins.

Mega SCL -------------+-----------------+-----------
                      |                 |
MEGA SDA --------+----|------------+----|-----------
                 |    |            |    |
                 |    |            |    |
                 |    |            |    |
                SDA  SCL          SDA  SCL
                device 1          device 2

Next you can talk to one of the devices by specifying its address in Wire.beginTransmission() or Wire.requestFrom(). Below a combination of the master codes from Master Writer/Slave Receiver and Master Reader/Slave Sender

#include <Wire.h>

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)


byte x = 0;

void loop() {
  send some data to device with address 8
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting


  read some data from device with address 9
  Wire.requestFrom(9, 6);    // request 6 bytes from slave device #9

  while (Wire.available()) { // slave may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character



Note that the addresses need to be adjusted to those of your devices (in the example I used 8 and 9).

PS what are those devices? Libraries often handle what is needed (using the above).

I understand, thanks a lot,