Serial.write instead of serial.print

Hi,

I want to replace my serial.print() with serial.write() in my code to achieve faster communication. But I am unable to see the data in the serial monitor, please help me in achieving the same.

For example, consider below program

int X=1; void setup() { Serial.begin(9600); }

void loop() { Serial.print(X); delay(1000); }

I see the value of X that is one in the serial monitor, however if I remove serial.print() with serial.write()... I dont get the values in the monitor.

I need to know the additional codes to be included to get the same result.

Please help with the same.

Why do you think it will be faster...? And why do you think it’s equivalent? (there is a reason write and print exist, they don’t do the same thing and you should read the doc....)

Explain what you have in mind... (binary communication for data outside strings is indeed usually using less bytes, so will be faster, but it’s binary so not in a human friendly text representation...)

Getting your prints faster could be as simple as changing the baud rate in yourSerial.begin(9600); // USE 115200 OR MORE!!

You need to understand what Serial.write() does. Serial.write(1) is sending ASCII character code 1. That character is not visible. It is "Start of heading": http://www.asciitable.com/ If you wanted to output the character 1 you could do this:

Serial.write('1');

or this:

Serial.write(49);

(the ASCII code for the character 1 is 49)

This tutorial will be helpful: https://www.arduino.cc/en/Tutorial.ASCIITable

Why do you think you need faster communication? And if you do, why don’t you increase the baudrate?

J-M-L: Why do you think it will be faster...? And why do you think it’s equivalent? (there is a reason write and print exist, they don’t do the same thing and you should read the doc....)

Explain what you have in mind... (binary communication for data outside strings is indeed usually using less bytes, so will be faster, but it’s binary so not in a human friendly text representation...)

Getting your prints faster could be as simple as changing the baud rate in your

Serial.begin(9600); // USE 115200 OR MORE!!

what I have in mind is to transmit information from the arduino faster than I can with serial.print() @ the highest baud rate (say instead of 9600, I'm using "115200 or more").

In this case, would the serial.write() function be helpful in transmitting information faster?

I previously assumed there must have been some way to obtain and translate the information sent by serial.write().Please let me know if we can do that.

In this case, would the serial.write() function be helpful in transmitting information faster?

Yes, since an integer is two bytes, while the ASCII representation of that value is up to 6 bytes.

The drawback is that all values in a byte are legal values in an int, so you have no way of knowing if one byte of the pair got lost. So, staying in sync is a real problem.

It's trivial with ASCII data.

Oh, and the receiving application has to KNOW that you are sending binary data. The Serial Monitor app does not know that, and can not know that.

PaulS: Oh, and the receiving application has to KNOW that you are sending binary data. The Serial Monitor app does not know that, and can not know that.

Yes, that is the thing, is there any additional codes or circuitry using which we can retrieve that information.

Neha2778: Yes, that is the thing, is there any additional codes or circuitry using which we can retrieve that information.

I can't imagine how you would attach a circuit to the Serial Monitor application. Adding additional circuitry to the Arduino would not make the Serial Monitor application behave differently.

You don't control the Serial Monitor application's code, so you can't add code to that application.

PaulS: I can't imagine how you would attach a circuit to the Serial Monitor application. Adding additional circuitry to the Arduino would not make the Serial Monitor application behave differently.

You don't control the Serial Monitor application's code, so you can't add code to that application.

Can we add some code to retrieve the transmitted information from serial monitor..

Neha2778: Can we add some code to retrieve the transmitted information from serial monitor..

Yes, you have our permission to do that.

You can use a different serial monitor application that is more capable and which will display binary information received

J-M-L:
You can use a different serial monitor application that is more capable and which will display binary information received

Could you please suggest one ,if you know

But why?

PieterP: But why?

As I mentioned earlier that I am trying to use Serial.Write(). and I need to retrieve that information which is being sent, so I need to see the output on serial monitor,,, which is not there.

In the last comment ,it was mentioned to use any other serial monitor application, so please suggest if you know any other serial monitor application

No, why do you require such high speeds that you cannot use the ASCII representation. For the 10-bit analog input of the Arduino, going from ASCII (4 characters+CR LF) to binary (2 bytes) is 3 times faster (at best). On the other hand, going from a rate of 9,600 baud to 2,000,000 baud is 200 times faster.

I use coolTerm

|500x423

or Serial on my Mac