wire.write(0) doesnt work??

Why does Wire.write(0); not compile but int zero = 0; Wire.write(zero); will compile? is this one of those 1.0 things?

the write() method is overloaded. Complier can’t tell what you mean by “0”. If you cast the 0 as a byte (or is it int?), it’ll work fine .

The other option, which is best is to use:
wire.write(0, 1)

The 2nd argument is the number of bytes to send.

Actually that won’t work, or not in the way you expect.

That is interpreted as “send one byte from address 0”.

As an example:

#include <Wire.h>

void setup ()
{
  Serial.begin (115200);
  char * p = NULL;

  Wire.begin ();
  Wire.beginTransmission (42); 
  Wire.write (0, 1);
  byte c = *p;
  Wire.endTransmission ();
  
  Serial.print ("address 0 contains: ");
  Serial.println (c, HEX);
  
}

void loop () {}

In my test it printed:

address 0 contains: 47

The logic analyzer confirmed that 0x47 was transmitted.

I raised this issue here:

http://arduino.cc/forum/index.php?topic=89033

The change to Wire just seems to cause a lot of problems for no real benefit IMHO.

The Arduino team could have done what Paul did for the Teensy to ensure that pre 1.0 stuff just continued to work.
Its not rocket science and it makes many things “just work”, which is what Arduino should
be about.

Since write() only takes a unsigned char argument, you can overload the other types
and re-cast them to an unsigned char to catch the ambiguous constants like 0.

This is what he adds to wire.h when you install teensyduino:

#ifdef CORE_TEENSY
    // added by Teensyduino installer, for compatibility
    // with pre-1.0 sketches and libraries
    void send(uint8_t b)               { write(b); }
    void send(uint8_t *s, uint8_t n)   { write(s, n); }
    void send(int n)                   { write((uint8_t)n); }
    void send(char *s)                 { write(s); }
    uint8_t receive(void) {
        int c = read();
        if (c < 0) return 0;
        return c;
    }
    inline size_t write(unsigned long n) { return write((uint8_t)n); }
    inline size_t write(long n) { return write((uint8_t)n); }
    inline size_t write(unsigned int n) { return write((uint8_t)n); }
    inline size_t write(int n) { return write((uint8_t)n); }
#endif

It goes in the public section just above the:

    using Print::write;

If you like, you can uncomment the CORE_TEENSY and enjoy all the benefits
for the other boards/processors.

— bill

Thank you for the explanation, and the solution its a little more elegant than mine lol, I think I will implement that so all id need to do is remove the #ifdef and #endif?

yep. Just drop it into wire.h without the #ifdef/#endif

It is unfortunate that the Arduino team seems to be so closed about accepting input from outside their small little group. They took a very hardline stance on intentionally not wanting to add in anything to attempt to transparently provide as much backward compatibility as possible with the pre 1.0 releases. It is very frustrating.

Because of this, there are several things that "break" on standard Arduino that "just work" or work better on Teensy boards.

This write()/send() 1.0 issue just one of several items that could be handled differently to make things easier on the Arduino users.

There are also items that could make things better/faster/smaller that are unrelated to 1.0

BTW, Paul also has a great collection of libraries on his Teensy web site that have been updated for 1.0 and his Teensy boards. (They work on non Teensy boards as well)

--- bill

Yeah I guess they leave all the fun patches to us! Lol