Do some edits for serial redirect (#605)
* Do some edits for serial redirect * Broken links
This commit is contained in:
@ -27,5 +27,5 @@ serial.readBuffer(64);
|
||||
[writeLine](/reference/serial/write-line), [writeNumber](/reference/serial/write-number), [writeValue](/reference/serial/write-value),
|
||||
[writeString](/reference/serial/write-string), [readUntil](/reference/serial/read-until), [readLine](/reference/serial/read-line),
|
||||
[readString](/reference/serial/read-string), [onDataReceived](/reference/serial/on-data-received),
|
||||
[redirect](/reference/serial/redirect-to), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer),
|
||||
[redirect](/reference/serial/redirect), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer),
|
||||
[redirectToUSB](/reference/serial/redirect-to-usb)
|
||||
|
@ -1,6 +1,8 @@
|
||||
# Serial Redirect To USB
|
||||
# redirect To USB
|
||||
|
||||
Dynamically configure the serial instance to use ``USBTX`` and ``USBRX``.
|
||||
Direct the serial input and output to use the USB connection.
|
||||
|
||||
The @boardname@ is set to use the USB connection for serial data by default. If serial data is currently redirected, using [redirect](/reference/serial/redirect), to the pins, you can set it back to use USB.
|
||||
|
||||
```sig
|
||||
serial.redirectToUSB()
|
||||
@ -9,4 +11,4 @@ serial.redirectToUSB()
|
||||
## See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[redirect](/reference/serial/redirect-to)
|
||||
[redirect](/reference/serial/redirect)
|
||||
|
@ -1,32 +0,0 @@
|
||||
# Serial Redirect To
|
||||
|
||||
Dynamically configure the serial instance to use pins other than
|
||||
``USBTX`` and ``USBRX``.
|
||||
|
||||
```sig
|
||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
* ``tx``: the [serial pin](/device/pins) on which to transmit data
|
||||
* ``rx``: the [serial pin](/device/pins) on which to receive data
|
||||
* ``rate``: the baud rate at which to transmit and receive data (either `9600` or ``115200``)
|
||||
|
||||
## Example
|
||||
|
||||
When button ``A`` is pressed, the following example reconfigures the
|
||||
serial instance. The new configuration uses pin ``P1`` to transmit and
|
||||
``P2`` to receive, at a baud rate of `9600`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
serial.redirect(SerialPin.P1, SerialPin.P2, BaudRate.BaudRate9600);
|
||||
});
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[redirectToUSB](/reference/serial/redirect-to-usb)
|
||||
|
44
docs/reference/serial/redirect.md
Normal file
44
docs/reference/serial/redirect.md
Normal file
@ -0,0 +1,44 @@
|
||||
# redirect
|
||||
|
||||
Configure the serial port to use the pins instead of USB.
|
||||
|
||||
```sig
|
||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||
```
|
||||
The default connection for the serial port is over a USB cable. You can have the serial data go across wires connected to pins on the @boardname@ instead. To set the input and output for the serial connection to be on the pins, you redirect it to the pins. Also, you decide how fast you want to send and receive the data on the pins by choosing a _baud_ rate.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **tx**: the transmit [pin](/device/pins) to send serial data on.
|
||||
* **rx**: the receive [pin](/device/pins) to receive serial data on.
|
||||
* **rate**: the baud rate for transmitting and receiving data. Baud rates you can choose from are:
|
||||
>`300`, `1200`, `2400`, `4800`, `9600`, `14400`, `19200,`, `28800`, `31250`, `38400`, `57600`, or `115200`
|
||||
|
||||
## ~hint
|
||||
**Baud rate**
|
||||
|
||||
Serial communication transmits data by sending one bit of a [digital number](/types/buffer/number-format) (usually a byte sized number), at a time. So, the data bytes are sent as a series of their bits. Serial communication uses just one wire to send these bits so only one bit can travel across the wire at a time.
|
||||
|
||||
When pins on your @boardname@ are configured for serial communication, they make a serial port for data. The port switches the voltage on the pins to represent a new bit to send on the wire. A series of these voltage changes eventually sends a complete byte of data. The speed at which the voltage changes create a signal to communicate the bits is called the _baud_ rate.
|
||||
|
||||
You will typically use `9600` or `115200` for your baud rate. Sometimes the device you connect to can figure out what your baud rate is. Most of the time though, you need to make sure the device you connect to is set to match your baud rate.
|
||||
|
||||
## ~
|
||||
|
||||
## Example
|
||||
|
||||
Change where serial data is sent to and received from. When button **A** is pressed, reconfigure the
|
||||
serial port to use the pins. The new configuration uses pin ``P1`` to transmit and
|
||||
``P2`` to receive. The baud rate is set to `9600`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
serial.redirect(SerialPin.P1, SerialPin.P2, BaudRate.BaudRate9600);
|
||||
});
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[redirectToUSB](/reference/serial/redirect-to-usb)
|
||||
|
Reference in New Issue
Block a user