How to send float over serial

前端 未结 9 1925
Happy的楠姐
Happy的楠姐 2021-01-02 09:15

What\'s the best way to send float, double, and int16 over serial on Arduino?

The Serial.print() only sends val

9条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 09:58

    Structures and unions solve that issue. Use a packed structure with a byte sized union matching the structure. Overlap the pointers to the structure and union (or add the union in the structure). Use Serial.write to send the stream. Have a matching structure/union on receiving end. As long as byte order matches no issue otherwise you can unpack using the "C" hto(s..l) functions. Add "header" info to decode different structures/unions.

提交回复
热议问题