What is the proper way to send a single byte with ArduinoOutStream?

I’m using a Teensy 3.0 to talk to a lmx9838 bluetooth module. The communication with which requires bytes that are outside of the relm of ascii characters.

I’ve got most everything working fine, the problem comes when I try to send a 0x0A (linefeed). Everytime I send 0x0A it also sends a carrige return (0x0D) which is not going to work.

Do I need to switch back to using the traditional Serial.print() statements or is there something I’m missing to make this work with the ArduinoOutStream?

Here is the code needed to replicate:

#include <SdFat.h>

ArduinoOutStream cout(Serial1);

void setup(){
  
  Serial1.begin(38400);
  
  //cout << byte(0x0A);
  cout << char(0x0A);

}

void loop(){}

As usually happens once I ask a question, I’ve just figured out at least one way to fix my problem. I’d still like to know if there is a ‘right’ way to do this cause I’m pretty sure this isn’t it :stuck_out_tongue:

#include <SdFat.h>

ArduinoOutStream cout(Serial1);

void setup(){
  
  Serial1.begin(38400);
  
  char myArray[2];
  
  myArray[0]=0x0A;
  myArray[1]=0x00; //end string
  
  //cout << byte(0x0A);
  //cout << char(0x0A);
  cout << myArray;

}

void loop(){}

... but of course this doesn't work with zeros. Still trying to figure this out.

I’m just grasping at straws here, but based on some small experience with Serial.print, if the typdef handed is char it outputs a character. But, if the typedef handed is byte it converts the value to the ASCII digits. I’m wondering if ArduinoOutStream (I’ve never used it) might also be trying to apply some smarts to char variables. Try changing the type to byte and see if that solves things.

Erm… Nevermind. It looks like you have tried that. What happened when you had “cout << byte(0x0A);” uncommented? Same as “cout << char(0x0A);”? What about casting (I hope that’s the correct term) it as an int?

How related is ArduinoOutStream.h to Streaming.h (the syntax looks similar)? I had downloaded Streaming.h today from Mikal Hart’s web page (same dude who wrote NewSoftSerial that was incorporated into IDEv1.x as SoftwareSerial), but haven’t had a chance to play with it. But, I notice in the example for Streaming.h it does casting like this:

Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;