How to use Serial.write?

Hello, it’s my first time to use this forum.
I want to send commands to a sensor. I think I can use Serial.write() , but I got an error like this.
"Error: No instance of overloaded function “mbed::Serial::write” matches the argument list in “main.cpp”
I refer to this page, but I can’t solve the error.
My platform is NUCLEO L432-KC , my code is written below.

#include "mbed.h"

Serial jy901(D1,D0);
int main()
    const unsigned char unlockCom[5]={0xFF,0xAA,0x69,0x88,0xB5};
    for(int i=0;i<10;i++){

I thank you for telling about the problem.


usually is good to also share info Mbed Os version. Anyway it is probably a lower than 6.
This error tell you, the write function is not match to overloaded variants (part of Asynch). The variant what you try to use, come from Stream.h and it is probably not accessible (error from Online compiler).

BR, Jan

Thank you for advice!
mbed library varsion is release version 165.
Although I tried to use mbed OS 6.14 , and BufferedSerial class, I can’t use BufferedSerial.getc().
Is there any function instead of getc() in the class ?

Take a look to the BufferedSerial - API references and tutorials | Mbed OS 6 Documentation and its example. The BufferedSerial has no access to the getc or similar methods like were in the old Serial API.
You should use BufferedSerial ::write(const void *buffer, size_t length), which is similar like you tried before.

BR, Jan

I can use write() in mbed OS 6, BufferedSerial class!

Can I use

char buf;,1);

instead of printf("%c\n\r",jy901.getc()); , in the same way I tried?

Yes, but the read function need a pointer to a void buffer and because your buffer is not an array then you need an ampersand sign ( & ).

    char buf;
    if(,sizeof(buf)) > 0){

BR, Jan