Send and receive objects easily over a stream

stream, pb, protocol buffers, serial, communication
platformio lib install 1003


Protocol Buffers Stream

This library makes easy to send and receive protocol buffers objects through an arduino stream. Serialize and deserialize is a complex task and it gets harder when you have to do it in a very limited hradware like Arduino.

Simple interface

My intention is just send and receive objects.

First create the messenger (the thing that encapsulates all the complexity)

    ProtocolBuffersStream messenger(&Serial);

You only need a stream, in this case I used Serial but it is fully compatible with SD, ethernet and any stuff that implements the Stream class (

For this example is used this proto definition:

message Sensor {
  required int32 id = 1;
  required value float = 2;

Once you have defined your data model (in this case just a class that contains sensor data) you may want to send it.

Sensor sensor = Sensor_init_zero; = 0xabc
sensor.value = 56.43

bool success = messenger.send(Sensor_fields, &sensor);

Thats all, everything is serialized and sent. You also know if everything went fine.

Receiving objects is pretty easy too:

Sensor sensor = Sensor_init_zero;

bool success =, &sensor);
if (success) { = 0xabc
   sensor.value = 56.43

Building your model

This library depends on nanopb ( This means that you have to install nanopb library before use Protocol Buffers Stream.

Installing nanopb

If you are using platformio, just execute:

platformio lib install 431

If you prefer a manual install, you should copy those files into your project from


Google Protocol Buffers Documentation

Check the official documentation ( if you dont know how protocol buffers work