How can I TX mutiple arbitrary bytes in SoftwareSerial

How would you transmit a bunch of bytes over SoftwareSerial easily? (non-text bytes)

Here is what I mean in PBASIC (basic stamp):

SEROUT pin, Baud, [$1F, $28, $66, $11,$55]

I can successfully TX single bytes like this:

mySerial.write(byte(0xc0))

I could make an array, but I was just wondering if there was an easier way.

robowarner:
I could make an array, but I was just wondering if there was an easier way.

I'm not sure why you refer to 'making' an array for the purposes of transmitting it. Presumably you expect to already have your data in some form by the time you need to write it to the serial port.

If you've got it stored in an array (or any other contiguous memory) then you can call write once to send the whole lot. If your data is scattered in separate variables then you can write them separately. Which way is easier in a given situation depends on how you have stored the data.

Thanks for your response. :slight_smile:
What I meant about the array was this:...

byte ledPins[] = { 
  2, 3, 4, 5, 6, 7,8,9,10,11 }; 

mySerial.write(ledPins,3);

where I can send an array of data.

Like I showed with the PBASIC code (SEROUT pin, Baud, [$1F, $28, $66, $11,$55] ), I just need to send some bytes. They don't need to be variables, as they aren't changed in the program.
Is there a way to do this?

I'm trying to make a serial VFD display display a graphic, which I can do on the Basic Stamp 2.

for (int i = 0; i < sizeof (ledPins), i++ ) {
   mySerial.write(ledPins[i]);
}

Rob

I could make an array, but I was just wondering if there was an easier way.

Easier than one of code to make and populate an array? No.

robowarner:
Is there a way to do this?

Given that your data is in a byte array, you can call mySerial.write(ledPins, sizeof(ledPins)) to write the whole array in one operation. (Why you would want to write pin numbers to a serial port escapes me, but I assume this was just an arbitrary example.)

I can successfully write an array now, thanks! (and yes, ledPins was just a example)

But do I need an array to do this? Or is there some way of writing a
mySerial.write( with multiple bytes in it.

This doesn’t work, but it shows what I mean:

mySerial.write(0x1F, 0x28, 0x66, 0x11,0x55)

where it sends a string of bytes.

But do I need an array to do this? Or is there some way of writing a...with multiple bytes in it.

Yes and no.

I got it working, thanks all! :grin:

Here is my working code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

byte VFDinitGraphics[] = { 0x1F, 0x28, 0x66, 0x11,112, 0, 02, 0, 1 };   //tell display to expect a graphic
byte candleGraphic1[] = { 0x00, 0x00, 0x05, 0x1f, 0x1f, 0x94, 0x0b, 0xf2, 0x0d, 0x19, 0x02, 0x1f};    //small candle graphic

void setup()
{
  mySerial.begin(38400);

 mySerial.write(byte(12));   //clear display
 mySerial.write(VFDinitGraphics, sizeof(VFDinitGraphics));   //prep display for a graphic
 mySerial.write(candleGraphic1, sizeof(candleGraphic1));    //send candle graphic
}

This is just a piece of my code, but it shows the serial TX working.