how to use serial input as Stream (if at all possible)


I’m trying to send an image from processing to Arduino and then have this thermal printer print the image.
Adafruits thermal printer library expects a Stream:

printBitmap(Stream *stream)

how do you define/construct(?) a Stream.

Can a Stream be data coming from serial??

Or just from files, like on a SD card?

Could I do something like this?


Really confused, please help :frowning:

The Serial objects are derived from the Stream object so you can just pass the Serial object as if it were a Stream object:


Also works with SoftwareSerial objects you create:

SoftwareSerial ss(3,4);

I wonder how the printer decides it is done. You may have problems if the printer library reads until the Stream runs out of data. You may not be able to feed serial data fast enough to keep up with demand. Or you may feed the serial data too fast and run out of buffer space, thus loosing characters. If either of those is a problem you may have to copy the serial stream to a file on an SD card and then print it from there.

Thanks for the answer!

When I use

printer.printBitmap(imageWidth, imageHeight, Serial);

I get error:

no matching function for call to 'Adafruit_Thermal::printBitmap(int&, int&, HardwareSerial&)'

SoftwareSerial doesn't work either. I wonder what the & is about...