Ah I understand what you mean now.
I am not able to figure what could be wrong with the code. But checking this SO Q&A got me thinking, parity or stopbits settings may need to be provided at the receiving end to match the sending end.
It's been a long time since I played with serial. But I remember, sometimes I got results almost effortlessly (just modifying example codes). And sometimes I struggled a lot, thanks to some "minor" detail that made all the difference.
I am not able to figure what could be wrong with the code. But checking this SO Q&A got me thinking, parity or stopbits settings may need to be provided at the receiving end to match the sending end.
It's been a long time since I played with serial. But I remember, sometimes I got results almost effortlessly (just modifying example codes). And sometimes I struggled a lot, thanks to some "minor" detail that made all the difference.