How to send two integer (16 bit) in the i2c

Hi, I want to send two integer (16 bit) from arduino mega (master) to due (slave). i2c can send just one byte evrey time.
i know that if i want to send just one integar i can split it to two byte, but what i need to do if i want to send from the master two integer to the slave? Someone can write the code that needs to be in the master and the slave?
thanks

I2C is a complicated protocol because you have to do a lot of trial and error to make the code successful. SPI is also hard if you new to Arduino. So I prefer you that to use Serial Communication to send the 16 bit int to the slave device. Serial is easy and has simple function. If you use I2C or SPI, you have to deal with the binary, hex and character stuff which requires a lot of time. I prefer you to use Serial between the two devices. If you are using the Serial port for any other work, then you can use any two IO pins of the board instead of RX and TX with the SoftwareSerial library. So you can send the 16 bit int to the device over Serial.

ArnavPawarAA:
I2C is a complicated protocol because you have to do a lot of trial and error to make the code successful. SPI is also hard if you new to Arduino. So I prefer you that to use Serial Communication

Interesting. I had been advocating Serial for quite some time and only explored I2C for communication between Arduinos recently. To my mind I2C is considerably simpler because it works with packets of information. With Serial you have to provide the start- and end-markers for the packets, which is simple with text but not so easy with binary data.

I wrote this I2C Tutorial which shows how to send multi-byte messages.

Whether using Serial or I2C between a Mega and a Due the OP will need to ensure that the Mega's 5v signals are converted to 3.3v for the Due.

...R

I'm worried about connecting a Arduino Mega 2560 with a Arduino Due.

The Due board has troubles, especially with the I2C bus, both in hardware and software. Some time ago it called the onReceive handler two times for a single data packet, and one packet was empty. I don't know if that is fixed. There are pullup resistors of 1k5 or 1k to 3.3V for SDA and SCL. That value is too low. It is a 3.3V I2C bus.

The Arduino Mega 2560 is the only board with onboard 10k pullup resistors to 5V for SDA and SCL. It has a 5V I2C bus.

I suggest to use remove the pullup resistors of 1k5 or 1k from the Arduino Due and put a level shifter between the Mega and the Due.

Why do you have two boards ? A single board is a lot easier to maintain.
Sometimes a sketch has many delays and becomes so slow that an other Arduino board is used for other tasks. However, the solution should be to remove the delays.

Koepel:
I'm worried about connecting a Arduino Mega 2560 with a Arduino Due.

The Due board has troubles, especially with the I2C bus, both in hardware and software. Some time ago it called the onReceive handler two times for a single data packet, and one packet was empty. I don't know if that is fixed. There are pullup resistors of 1k5 or 1k to 3.3V for SDA and SCL. That value is too low. It is a 3.3V I2C bus.

Interesting. I have no experience with the Due

...R

Koepel:
I'm worried about connecting a Arduino Mega 2560 with a Arduino Due.

The Due board has troubles, especially with the I2C bus, both in hardware and software. Some time ago it called the onReceive handler two times for a single data packet, and one packet was empty. I don't know if that is fixed. There are pullup resistors of 1k5 or 1k to 3.3V for SDA and SCL. That value is too low. It is a 3.3V I2C bus.

The Arduino Mega 2560 is the only board with onboard 10k pullup resistors to 5V for SDA and SCL. It has a 5V I2C bus.

I suggest to use remove the pullup resistors of 1k5 or 1k from the Arduino Due and put a level shifter between the Mega and the Due.

Why do you have two boards ? A single board is a lot easier to maintain.
Sometimes a sketch has many delays and becomes so slow that an other Arduino board is used for other tasks. However, the solution should be to remove the delays.

How can I remove the pullup resistors ?

With a blob of solder.


That picture comes from this thread: I2C (Wire) pull up resistors, Arduino Due, 20 (SDA0-3), 21 (SCL0-3) - Arduino Due - Arduino Forum