Problems with SoftwareSerial and Strings

Hello!

I want to send Strings using SoftwareSerial library, however, it has confused me a bit.

This code compiles:

softSerial.write("hello");

This code doesn't:

String s="hello";
 
softSerial.write(s);

The error it presents is the following:

bluetooth_comm_v3.ino: In function 'void loop()':
bluetooth_comm_v3:22: error: no matching function for call to 'SoftwareSerial::write(String&)'
D:\Program Files\Arduino\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.h:92: note: candidates are: virtual size_t SoftwareSerial::write(uint8_t)
D:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:54: note:                 size_t Print::write(const char*, size_t)
D:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:53: note:                 virtual size_t Print::write(const uint8_t*, size_t)
D:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)

I tried converting the String to both char array or byte array and write that to the Serial instead, but that didn't work, although I maybe didn't do it correctly.

So can anyone tell me how to make the code above work?

I want to send Strings using SoftwareSerial library, however, it has confused me a bit.

Why? There is no excuse for using Strings. And, the SoftwareSerial library is smart enough to know that. Use C strings (NULL terminated arrays of chars), instead.

growqx:
This code doesn't:

String s="hello";

softSerial.write(s);

In line with what @PaulS said, try this

char s[] = "hello";
 
softSerial.write(s);

...R

Along with what Paul and Robin said, check out the code size differences using their suggestions versus using the String class for processing strings.