How to use snprintf ?

Hello,

How do I print the values of a sensor ( float data type), value of a solenoid( either 0 0r 1 ) and the time (millis) using snprintf function?

Can anyone guide me or provide a link/example to do this?

Thank you!

By default on the eight bit Arduinos, floats do not sprintf

So just manipulate your float into its integer constituents.

sprintf(buffer, ā€œ%d.%O2dā€, int(myFloat), int(myFloat * 100) %100);

Kind of thing

The thing on the other end of the Serial line can't tell the difference between 6 print statements or one. The only difference is that snprintf bloats up the size of your code by quite a bit. The same stuff is being put in the serial buffer and it is being sent out just the same.

So the question becomes why would you want to do this?

Ble.print (' , ') ;

I doubt the Arduino has support for three byte character constants.

dpoornima:
Is there any other method to increase the speed of sending data to the module?

What you're doing now isn't going to make it any faster. How could it? Think about it, now you have to wait for snprintf to build a buffer before you print it. All you're doing is making it take longer to get the data into the serial buffer, but you're not doing anything that affects how fast it is sent out from that buffer.

How can you make it faster? I don't know, I haven't seen your code. Really, the baud rate on that serial connection is really the only thing that you can change. The data being sent to the serial buffer is the fast part. It's the interrupt driven act of sending the actual characters out from the serial buffer that is the slow step.