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"Automaticdata transfer rate in bits per second
"DataBits"Automaticnumber of data bits to use per frame
"Parity"Automaticsetting for the parity bit
"StopBits"Automaticnumber of stop bits to use

Basic serial specifications.

Load the package.
Click for copyable input
Set the baud rate.
Click for copyable input

There is only one RX and one TX pin on the Uno, so specification can just be "Serial".

The input and output pins are unique and need not be explicitly given.
Click for copyable input

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"Automaticthe number of digits in the fractional part

Serial data specifications.

The "DelimiterByte" is relevant only if there are more than one input or output channels.

Set the delimiter byte as an empty space.
Click for copyable input

The parameters in the deployed code can be retrieved from the MicrocontrollerCodeData object.

The values of the serial properties.
Click for copyable input

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.

The baud rate value.
Click for copyable input

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.

Set the start byte to .
Click for copyable input
Retrieve the value of the start byte.
Click for copyable input

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.

Set up the microcontroller to send and receive numerical data.
Click for copyable input

The microcontroller is now a serial device. Open a serial connection to it using the device framework.

Open a connection.
Click for copyable input
Start a task to send and receive data.
Click for copyable input
Plot the data.
Click for copyable input
Stop the task and close the connection to the device.
Click for copyable input