Serial Communication
Basic Operation
Serial communication uses RX and TX pins to receive and transmit data.
As there is no common clock signal, both devices must agree on a number of parameters. If necessary, these parameters can be given to the microcontroller's "Serial" specification.
"BaudRate" | Automatic | data transfer rate in bits per second |
"DataBits" | Automatic | number of data bits to use per frame |
"Parity" | Automatic | setting for the parity bit |
"StopBits" | Automatic | number of stop bits to use |
There is only one RX and one TX pin on the Uno, so specification can just be "Serial".
In addition, there are other specifications that configure the actual data that is being transferred.
"StartByte" | 19 (XOff) | the first byte transmitted or to be received |
"DelimiterByte" | 44 (,) | the byte inbetween data |
"EndByte" | 17(XOn) | the last byte transmitted or to be received |
"FractionalPartDigits" | Automatic | the number of digits in the fractional part |
The "DelimiterByte" is relevant only if there are more than one input or output channels.
The parameters in the deployed code can be retrieved from the MicrocontrollerCodeData object.
The "BaudRateError" gives the percentage error in the baud rate. Properties like "TransmissionSpeedMode" are microcontroller specific. All the properties, except for "BaudRateError" can be set in the "Serial" option.
Specific property values can also be extracted.
Virtual COM Port
On some microcontrollers the serial functionality can be set up over USB. In these cases, the RX and TX pins are not used but rather the USB pins D- and D+.
The communication happens over a virtual port and the parameters are set using "SerialOverUSB" . Other than that, the workflow is similar to the regular case.
Device Framework
While on some boards such as the Arduino Micro the serial functionality is implemented in software, other boards such as the Arduino Uno have a USB-to-serial converter. Both kinds of boards can communicate with a personal computer through the USB port using the serial interface. Through this serial interface the Wolfram Device Framework can communicate with these boards.
First, the microcontroller needs to be set up to send or receive data.
The microcontroller is now a serial device. Open a serial connection to it using the device framework.