Microsoft MakeCode

Serial comms with PC

I am using a Micro:bit V2 with MakeCode. Using PuTTY in the PC (terminal emulator) and the Makecode commands “Serial write line ()” and “Serial write number ()” , I am able to send serial communication (for program troubleshooting) and display it on the PC screen. However, it prints out all serial strings, numbers, etc, as one ling line. What is the escape character? How can I send a New Line character or Carriage Return?


Hi @canodot,
I’ve been doing some serial writes after a receiving a radio message recently and I’ve been able to use “\n” as a new line character. I’ve been sending it as a separate serial write afterwards (see picture).
Hope that helps!

Thanks Alasdair. I also wrote to the Microsoft forum, and they replied with the same info, but it took 3 days to come, and by that time, I had come up with another solution. Up till now, I haven’t used the serial write line because I had written a lot of debug statements using my invented method. I had tried serial write string “This is my string \r\n” - but it just sends the \r\n as 4 ASCII characters, and PuTTY displays them verbatim. I have noticed that when I use serial write number, it doesn’t send a CR (Carriage Return), but if I use serial write numbers (plural) with a string of numbers, it sends a CR after that.
Anyway, the solution I found is to send a “#” character every time I want a CR, then I copy everything from PuTTY to my editor (Notepad++), and I do a global replace of # to NL/CR, then I look at my results in Notepad++. It’s not much extra effort, and it does what I wanted.

Hi Alasdair, as I said above, I was already invested in my own method, so it took me a while to get round to playing with serial write line . I tried …
… which yields (in PuTTY) - copied as text because I can only embed one image. How long will I be a “New user”? I had expected that after a technical post, it would be realised that a new user’s interests are technical.

This is my line \r\n and this is the continuation.
This is my second line \r\n
This is my third line \r\n

This is my fourth line

… so unless you can tell me what I’m dong wrong, I’m back to replacing ‘#’ with ‘\r\n’

Is this a weird PuTTY thing? I don’t think I’ve seen this issue using screen or Mu or the Arduino serial monitor…

I don’t know. I wondered about that, but I couldn’t see any setting on PuTTY that would alter it. However, I have learned how to drive it now. I came from the C language, so even though I didn’t expect a printf() substitute, I was expecting that I would be able to send a cr or nl character in a string, like Serial write line “\r\nThis line will start at the margin\r\nand this one will be directly under it.”
That doesn’t work for me, though - PuTTY just prints the whole thing out as it is written above, in one long line, in which \r\n comes out looking like “\r\n”. However, I have found that you can write…

I have found that “Serial Print Line” prints a cr/lf I have tried to include arguments, but they don’t do anything, so …
Serial write Line"\r\n" does exactly the same as

Serial write Line. So to correct the attempt above, you can write …

Serial write line

serial write string " This line will start at the margin"
Serial write line

serial write string “and this one will be directly under it.”

It’s a bit cumbersome, but it displays in PuTTY OK.

The other ruse is to use a character that you won’t use anywhere else to represent a new-line. Below, I use #

serial write string “#This line will start at the margin#and this one will be directly under it.”

PuTTY displays that verbatim, complete with the # signs, but its output can be copied and pasted to an editor (I use Notepad++), where you can do a global replace of “#” with “\r\n”, which makes a nice display for debugging.