Pages: [1]   Go Down
Author Topic: SoftwareSerial - Can not send 0x00  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, sorry if it's a stupid question but I try to send a synchronisation pattern (0x55 0x55 0x00 0x00 0xFF) to one of my board via the SoftwareSerial library (arduino v1.0.3).

I use these lines:
mySerial.write(0x55);
mySerial.write(0x55);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0xFF);

At the first "mySerial.write(0x00);" I got this error: call of overloaded 'write(int)' is ambiguous

Can somebody help?

Thx
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
mySerial.write( (uint8_t) 0x00 );

...or...

Code:
mySerial.write( (byte) 0x00 );

If you're feeling especially verbose...

Code:
const uint8_t ZeroByte = 0x00;
mySerial.write( ZeroByte );
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2037
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is this only a problem for the 0x00 ,  and not a problem for the 0x55  ?

And wouldn't it be easier to put this sequence into some kind of string or array or even a loop,  rather
than waste code space with 5 calls to the same function ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thx Coding Badly, it's working perfectly now.
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23753
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, why do 0x55 & 0xFF get interpreted as bytes, while 0x00 gets interpreted as an int?

creating a variable:
const byte ZeroByte = 0;

and then using that seems simple enough:

mySerial.write(0x55);
mySerial.write(0x55);
mySerial.write(ZeroByte);
mySerial.write(ZeroByte);
mySerial.write(ZeroByte);
mySerial.write(0xFF);


 
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is this only a problem for the 0x00 ,  and not a problem for the 0x55  ?

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

Quote
And wouldn't it be easier to put this sequence into some kind of string or array or even a loop,  rather than waste code space with 5 calls to the same function ?

It's only a "waste" if the amount of Flash available is approaching or has surpassed zero.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, why do 0x55 & 0xFF get interpreted as bytes, while 0x00 gets interpreted as an int?

See the link above.

Quote
creating a variable ... const byte ZeroByte = 0; ... and then using that seems simple enough:

I like it more than the typecast.
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23753
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can somebody help?

It would IMO be cleaner, as well as resolving your problem, to put the byte sequence into a const byte array and make one call to Serial.write() to send the array.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: