# Wire.write() Sanity Check

**URL:** <https://forum.arduino.cc/t/wire-write-sanity-check/497672>\
**Category:** Programming\
**Created:** [December 20, 2017, 3:32am UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672 "2017-12-20T03:32:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheMonkeyStink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/themonkeystink/32/1130692_2.png) [@TheMonkeyStink](https://forum.arduino.cc/u/TheMonkeyStink)\
**Post date:** [December 20, 2017, 3:32am UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672/1 "2017-12-20T03:32:46Z")

</div>

Hi All,

I'm trying to send an unsigned long via Wire.write() from a slave to a master and it refuses to work for me. I can send a string and write() nicely sends each byte over the wire. As well, write() deals with unsigned ints just fine. However when I try to send anything larger than 256 (well, 255) it treats it as an unsigned int. I checked the TWI base and it looks like there's a specific overload for unsigned ints, but I can't get it to work. Am I missing something obvious?

Here's a quick example of what I'm talking about:

```cpp
Wire.write((unsigned long) 25512)  //just a random number, and it fails with or without the cast

```

will give me this when I try to pull the number from the slave

```cpp
I2C>[0x4d rrrrrr]
I2C START BIT
WRITE: 0x4D ACK
READ: 0xA8
READ:  ACK 0xFF
READ:  ACK 0xFF
READ:  ACK 0xFF
READ:  ACK 0xFF
READ:  ACK 0xFF
NACK
I2C STOP BIT
I2C>

```

I've also tried sending an unsigned long via a variable an no joy. Thanks for looking!!

---

<div class="post-metadata">

**Author:** ![BulldogLowell](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@BulldogLowell](https://forum.arduino.cc/u/BulldogLowell)\
**Post date:** [December 20, 2017, 3:36am UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672/2 "2017-12-20T03:36:19Z")

</div>

an unsigned long is 4 (count them, four) bytes....

now look at the [reference page for the wire library](https://www.arduino.cc/en/Reference/WireWrite)

---

<div class="post-metadata">

**Author:** ![TheMonkeyStink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/themonkeystink/32/1130692_2.png) [@TheMonkeyStink](https://forum.arduino.cc/u/TheMonkeyStink)\
**Post date:** [December 20, 2017, 3:44am UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672/3 "2017-12-20T03:44:55Z")

</div>

ARGH. My apologies, I was looking at the definitions for LiquidCrystal\_I2C.write.

---

<div class="post-metadata">

**Author:** ![BulldogLowell](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@BulldogLowell](https://forum.arduino.cc/u/BulldogLowell)\
**Post date:** [December 20, 2017, 3:46am UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672/4 "2017-12-20T03:46:22Z")

</div>

> TheMonkeyStink:  
> ARGH. My apologies, I was looking at the definitions for LiquidCrystal\_I2C.write.

it happens...

😉

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 10:54pm UTC](https://forum.arduino.cc/t/wire-write-sanity-check/497672/5 "2021-05-05T22:54:06Z")

</div>

Closed on May 5, 2021, 10:54pm UTC


