Skip to content

Commit 701db5f

Browse files
bxparksdeadprogram
authored andcommitted
tutorial/serialmonitor.md: baudrate to 9600 on AVR
Address review comments: * Add COM1 and COM31 for Windows * Add `tinygo monitor -baudrate=9600` for AVR processors * Fix couple of grammar typos. * Add explanation of "baud rate". * Add instructions to use `flash -x` flag to see the port of the microcontroller.
1 parent 2091039 commit 701db5f

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

content/docs/tutorials/serialmonitor.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,24 @@ In this example, the serial monitor missed the first 4 lines of "Hello, World"
132132
(0 to 3) because the program started to print those lines immediately after
133133
flashing, but before the serial monitor was connected.
134134

135+
On some AVR microcontrollers, the speed of the serial port is set to 9600
136+
instead of the default 115200. So you need to override the baud rate of `tinygo
137+
monitor` like this:
138+
```
139+
$ tinygo monitor -baudrate=9600
140+
```
141+
142+
See [Alternative Serial Monitors](#alternative-serial-monitors) for an
143+
explanation of the "baud rate".
144+
135145
## Serial Input
136146

137147
Occasionally it is useful to send characters from the host computer to the
138148
microcontroller. The following program reads a single byte from the
139149
`machine.Serial` object and prints the character back to the host computer.
140150

141151
The caveat is that the `Serial.ReadByte()` feature is *not* currently
142-
implemented on every microcontrollers supported by TinyGo. For example, the
152+
implemented on every microcontroller supported by TinyGo. For example, the
143153
following program does not work on the ESP32 or the ESP8266.
144154

145155
```go
@@ -204,23 +214,26 @@ characters](https://en.wikipedia.org/wiki/C0_and_C1_control_codes), these are
204214
echoed back as 2 characters: the caret character `^` and a letter representing
205215
the control character. For example, typing Control-P prints `^P`.
206216

207-
A number of control characters are intercepted by the `tinygo monitor` itself
208-
instead of being sent to the microcontroller:
217+
Of the 32 possible control characters, some of them are intercepted by the
218+
`tinygo monitor` itself instead of being sent to the microcontroller:
209219

210220
* Control-C: terminates the `tinygo monitor`
211221
* Control-Z: suspends the `tinygo monitor` and drops back into shell
212222
* Control-\\: terminates the `tinygo monitor` with a stack trace
213-
* Control-S: flow-control, suspends output to the console
214-
* Control-Q: flow-control, resumes output to the console
223+
* Control-S: flow control, suspends output to the console
224+
* Control-Q: flow control, resumes output to the console
215225
* Control-@: thrown away by `tinygo monitor`
216226

217227
## Alternative Serial Monitors
218228

219229
There are many alternative serial monitor programs that can be used instead of
220230
`tinygo monitor`. The setup is slightly more complicated because you need to
221231
know the serial port on the host computer that the microcontroller is mapped to.
232+
One way to discover the serial port is to use the `-x` flag on the `flash`
233+
command like this: `tinygo flash -x -target=xxx`. This will print diagnostic
234+
messages which will contain the serial port of the microcontroller.
222235

223-
On Linux machines, the microcontrollers will be assigned a serial port that has
236+
On Linux machines, the microcontroller will be assigned a serial port that has
224237
a `USB` prefix or an `ACM` prefix like this:
225238

226239
* `/dev/ttyUSB0`
@@ -231,19 +244,31 @@ On MacOS machines, the serial port will look like this:
231244
* `/dev/cu.usbserial-1420`
232245
* `/dev/cu.usbmodem6D8733AC53571`
233246

234-
[TODO: No idea on Windows.]
247+
On Windows machines, the serial port looks something like:
248+
249+
* `COM1`
250+
* `COM31`
251+
252+
You also need to know the [baud
253+
rate](https://en.wikipedia.org/wiki/Serial_port#Speed) of the serial port. The
254+
default for almost all microcontrollers supported by TinyGo is 115200. The
255+
current exceptions are boards using the AVR processors ([Arduino Nano]({{<ref
256+
"../reference/microcontrollers/arduino-nano">}}), [Arduino Mega 1280]({{<ref
257+
"../reference/microcontrollers/arduino-mega1280">}}), [Arduino Mega 2560]({{<ref
258+
"../reference/microcontrollers/arduino-mega2560">}})). On these, the serial port
259+
is set to 9600.
235260

236261
### Arduino IDE
237262

238263
The [Arduino IDE](https://www.arduino.cc/en/software) contains its own serial
239264
monitor. You may choose to use that instead. You need to set the serial port
240265
(something like `/dev/ttyUSB0` on Linux, or `/dev/cu.usbserial-1420` on MacOS),
241-
and set the baud rate to 115200.
266+
and set the baud rate to 115200 (or 9600 on AVR processors).
242267

243268
### pyserial
244269

245270
The [pyserial](https://pyserial.readthedocs.io/en/latest/pyserial.html) is a
246-
Python library that comes with its own serial monitor. Setting up python3
271+
Python library that comes with its own serial monitor. Setting up a python3
247272
environment is a complex topic that is beyond the scope of this document. But if
248273
you are able to install `python3` and `pip3`, you can install `pyserial` and use
249274
its built-in `miniterm` tool roughly like this:

0 commit comments

Comments
 (0)