send one byte as string

I need to do something like the following…

byte mybyte;
mybyte = 123;
Firmata.sendString("XMIT: " + mybyte);

In case it helps anyone, the function is:

void FirmataClass::sendString(const char* string) 
  sendString(STRING_DATA, string);

Desired output:

XMIT: 123

Is there a relatively easy way to accomplish this? I don’t want to mess with the FirmataClass itself.


You say “send one byte as string”, but you are sending what appears to be ~9 bites. Can you reconcile the seeming difference?

The byte OP wants to send is mybyte, which is declared as a byte variable. It is to be sent following a prefix string, so the question really is misleading.

Also missing is the answer to the question of where is the data being sent from? Typically, users of Firmata are not sending data using sendString, from the Arduino.

The Serial.print() function can send strings and bytes and ints and floats, all as strings, but it can only send one of each in a given call.

Serial.print("XMIT: ");
Serial.print(mybyte, DEC);

will accomplish what the Firmate::sendString function is doing in OPs example call.

To PaulS: Unfortunately it won’t be the same. The receiving end on the PC expects Firmata communication, not raw serial pumped back up. So SYSEX type of STRING_DATA should be sent back.

I certainly could have been more specific.

The variable I have available is a byte. The routine expects a string constant. I would like to know if there is any way around it. I am by no means fluent in ‘C’.

The originating spot is this

argv is a byte array
argc is size of array
data is a byte

      for (byte i = 2; i < argc; i += 2) {
        data = argv[i] + (argv[i + 1] << 7);
      switch(Wire.endTransmission()) {

Ultimately I want to send back a SYSEX message of STRING_DATA with the value of data. I could call this

void FirmataClass::sendSysex(byte command, byte bytec, byte* bytev)

and place

Firmata.sendSysex(STRING_DATA, argc, argv);

before the Wire.BeginTransmission()

It “seems” to be working.

I kind of want to see that the values that I intended actually made it to Wire.send() for debug purpose, by sending it back to my program on the PC.

I have communicated successfully with my EEPROM. But not my I2C LCD. A logic probe on the D7 line shows no changes on the pin. The eighth bit doesn’t seem to be making it through. Because of all bytes to nibbles to 7bit and all back again, I want to see if I am losing the bit or perhaps it is faulty on the LCD.


The variable I have available is a byte. The routine expects a string constant. I would like to know if there is any way around it.

I think if you are using rs232 serial communication, all the data goes down the wire as 8 bit bytes no matter the names ascribed to it. If the bite is 110011 then it will be sent as such. If the receiving pc program expects to see some pecular arrangement that represents the data, then the sending device will have to package the byte so it will be understood by the pc application. So can you describe the construction of a "string constant" that would contain the bite of interest to you?

You could always use sprintf to format the string to send, using the SYSEX format.

char someString[24];
sprintf(someString, "XMIT: %d", mybyte);