# Concatenate Serial.print() values

**URL:** <https://forum.arduino.cc/t/concatenate-serial-print-values/49009>\
**Category:** Troubleshooting\
**Created:** [June 16, 2010, 1:30pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009 "2010-06-16T13:30:59Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 28, 2010, 5:18pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/21 "2010-06-28T17:18:05Z")

</div>

Yes, you do.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 28, 2010, 11:33pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/22 "2010-06-28T23:33:21Z")

</div>

Thanks! For once the compiler didn't come up with an error. Now I can finally begin the real programming. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 4, 2010, 3:34pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/23 "2010-07-04T15:34:08Z")

</div>

As my mom might have said, "Don't count your chickens before they hatch." I tried out the code and, even though there was no error detected by the compiler, nothing appeared on the screen of the LCD. Any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 4, 2010, 7:08pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/24 "2010-07-04T19:08:52Z")

</div>

```cpp
char xValHex[4];
char yValHex[4];

```

Make those 5 bytes long, so they'll have room for the terminating zero-byte.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 4, 2010, 10:10pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/25 "2010-07-04T22:10:00Z")

</div>

Did your mom ever tell you that it's useful if you post your code, 'cos very few of us are psychic?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 7, 2010, 2:45pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/26 "2010-07-07T14:45:24Z")

</div>

Here's my code: (After I took drhex's advice)

```cpp
#define TO_HEX(x)  (((x) > 10) ? (x) - 10 + 'A' : (x) + '0')
byte xVal = 64;
byte yVal = 32;
char xValHex[5];
char yValHex[5];

void setup(){
sprintf(yValHex,"0x%c%c", TO_HEX (yVal >> 4), TO_HEX (yVal & 15));
sprintf(xValHex,"0x%c%c", TO_HEX (xVal >> 4), TO_HEX (xVal & 15));
Serial.begin(9600);
Serial.print(0x7C,BYTE);//cmd
Serial.print(0x02,BYTE);//backlight
Serial.print(0x19,BYTE);//set to 25
}
void loop(){
Serial.print(0x7C,BYTE);//cmd
Serial.print(0x03,BYTE);//circle
Serial.print(xValHex);//x-coord
Serial.print(yValHex);//y-coord
Serial.print(0x0A,BYTE);//radius ten
Serial.print(0x01,BYTE);//draw
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 11, 2010, 2:21pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/27 "2010-07-11T14:21:50Z")

</div>

Hello? Anybody got some advice? I posted my code.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 11, 2010, 3:02pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/28 "2010-07-11T15:02:23Z")

</div>

You're the one with the hardware - what steps have you taken to debug?

I'd be inclined to use the serial monitor rather than unproven LCD hardware, at least until you've proven that the messages you need are ebing sent and received, at the correct rate and in the expected format.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 11, 2010, 3:48pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/29 "2010-07-11T15:48:40Z")

</div>

I tried the serial monitor and I think I've found the problem. When It sends the information that sets the backlight value, it comes up on the serial monitor as funky symbols, but when It sends the hex information, it comes up as readable letters. If I am correct (which I'm probably not) it's the result of the "BYTE" format being removed from the Serial.print() command. Any suggestions? (Honestly, I haven't done much to debug. I only checked the connections and ran it through the compiler a couple times.) In case you're wondering, my code is still the same.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 17, 2010, 2:28pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/30 "2010-07-17T14:28:02Z")

</div>

Does anyone have some advice? I'm still confused!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 17, 2010, 8:40pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/31 "2010-07-17T20:40:25Z")

</div>

Your "funky" symbols are unprintable ASCII codes below 0x20 (space character), like 0x02 and 0x19. If you want to see their actual values:

```arduino
Serial.print(0x7C,HEX);//cmd
Serial.print(0x02,HEX);//backlight
Serial.print(0x19,HEX);//set to 25

```

> , but when It sends the hex information, it comes up as readable letters

What "hex information"?  
I'm still confused as to what the problem is.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 26, 2010, 2:13am UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/32 "2010-07-26T02:13:19Z")

</div>

Sorry I didn't get back to you until now. Anyway, I suppose it's all technically hex information. what I meant was when it sends the coordinates of the circle's center, it comes up as readable characters. And, even though I like to know what its sending, it should be the weird symbols and _not_ the readable ones.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 8:19pm UTC](https://forum.arduino.cc/t/concatenate-serial-print-values/49009/33 "2021-05-06T20:19:17Z")

</div>



[Previous page](https://forum.arduino.cc/t/concatenate-serial-print-values/49009.md?page=1)
