user39047: I have two Arduino unos, and I am using I2C to have them communicate with each other. The A4, A5, and GND of each Arduino is connected to the other. These are my functions:
On the sending Arduino:
void playNote(int pitch, int len, int location){
  Serial.println(String(String(location) + ":" + String(pitch) + "," + String(len) + "\n"));
  Wire.beginTransmission(location);
  Wire.write(pitch);
  Wire.write(len);
  Wire.endTransmission();
}

On the receiving Arduino:
void receiveEvent(int howMany){
  int pitch = Wire.read();
  int len = Wire.read();
  Serial.println("Pitch: " + String(pitch) + ", Length: " + String(len));
  playNote(pitch,len);
}

pitch always sends fine. When I send len as 150, it works and is received as 150. However, when len is sent as 300, it is received as 44. I cannot figure out why this is. Any help is appreciated.

user29342: wire.write(n) sends a single byte of value n
150 decimal = 96 Hex
300 decimal = 012C Hex ...so is 2 bytes, and is truncated to one byte of value 2C Hex.
2C Hex = 44 decimal
Send a single byte! Maximum value of a byte is 255 decimal
If you need to send multiple Len bytes, then you need to ascertain the number of bytes and send them individually.
In your code you send multiple bytes concatenated one after the other already ...you send Pitch followed by Len.
All you need to do is split Len into L1, L2 bytes first.
L1 = Len and xFF
Shift Len left or do other logical math to derive high byte, L2
Then send L1 and L2

39047: <p>I have two Arduino unos, and I am using I2C to have them communicate with each other. The A4, A5, and GND of each Arduino is connected to the other. These are my functions:</p>

<p>On the sending Arduino:</p>

<pre><code>void playNote(int pitch, int len, int location){
  Serial.println(String(String(location) + ":" + String(pitch) + "," + String(len) + "\n"));
  Wire.beginTransmission(location);
  Wire.write(pitch);
  Wire.write(len);
  Wire.endTransmission();
}
</code></pre>

<p>On the receiving Arduino:</p>

<pre><code>void receiveEvent(int howMany){
  int pitch = Wire.read();
  int len = Wire.read();
  Serial.println("Pitch: " + String(pitch) + ", Length: " + String(len));
  playNote(pitch,len);
}
</code></pre>

<p><code>pitch</code> always sends fine. When I send <code>len</code> as 150, it works and is received as 150. However, when <code>len</code> is sent as 300, it is received as 44. I cannot figure out why this is. Any help is appreciated.</p>
 29342: <p>wire.write(n) sends a single byte of value n</p>

<p>150 decimal = 96 Hex<br>
300 decimal = 012C Hex ...so is 2 bytes, and is truncated to one byte of value 2C Hex.</p>

<p>2C Hex = 44 decimal</p>

<p>Send a single byte! Maximum value of a byte is 255 decimal</p>

<p>If you need to send multiple Len bytes, then you need to ascertain the number of bytes and send them individually.
In your code you send multiple bytes concatenated one after the other already ...you send Pitch followed by Len.<br>
All you need to do is split Len into L1, L2 bytes first.</p>

<p>L1 = Len and xFF<br>
Shift Len left or do other logical math to derive high byte, L2<br>
Then send L1 and L2</p>
