Can't directly write 0 over serial

Recommended Posts

I'm currently trying to work with a device that expects specific values to be sent to it over serial. When I try to send a value of 0 over serial I get the error "call of overloaded 'write(int)' is ambiguous". An example of this is below:

void setup(){  Serial.begin(9600);}void loop(){  Serial.write(0);}

On the other hand, when I set a variable to 0 and then write that variable out over serial it sends the value out without a problem. An example of the working variant is here:

int number;void setup(){  Serial.begin(9600);  number = 0;}void loop(){  Serial.write(number);}

It's also worth noting that it seems to also do this in the actual Arduino IDE in addition to ZAP.

Is this functioning as intended or is this a bug?

Share this post

Link to post
Share on other sites

The compiler can't guess what data type 0 should be  - char, int, short, signed, unsigned...?


Try casting it:   Serial.Write((int)0));


Or use a char constant:  Serial.Write('0'));


Or a char array: Serial.Write("0"));

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now