主要内容

Serial Transmit

Transmit data over Arduino SAM D21 core serial port

Since R2026a

  • Arduino SAMD Serial Transmit

Libraries:
Simulink Support Package for Arduino Hardware / Advanced / SAMD

Description

Use the Serial Transmit block to transmit a variable-length array of data on the Arduino® SAMD21 core serial port and configure a serial communication interface on hardware using a SERCOM channel.

To use the SERCOM interrupts for serial transmission, configure the Hardware Interrupt block for SAMD boards. This block allows you to enable and manage SERCOM interrupts, such as transmit complete interrupt.

During simulations without hardware, the Serial Transmit block transmits zeros.

If you use this block in a model that has the Standard Servo Read, Standard Servo Write, or Continuous Servo Write block, specify longer sample times to avoid overruns.

Note

The Serial Transmit block supports C/C++ code generation using Embedded Coder®.

Warning

Do not connect the serial port pins to an RS-232 serial interface, such as the DE-9M connector on a computer, without limiting the input voltage. The RS-232 standard allows higher voltages that can damage your hardware. For more information, read the documentation for your Arduino hardware.

Supported Arduino Boards

  • Arduino MKR 1000

  • Arduino MKR Wi-Fi® 1010

  • Arduino MKR Zero

  • Arduino Nano 33 IoT

Examples

Ports

Input

expand all

Data to transmit over the Arduino serial port to the serial device.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Parameters

expand all

Enter the serial communication channel number for serial transmission. The following table lists the SERCOM channel and their associated pins on each board. Choose a SERCOM channel on your board and connect your serial device to the corresponding transmit pin.

Arduino BoardsSERCOM ChannelPin
Arduino MKR 1000, Arduino MKR Wi-Fi 1010, Arduino MKR ZeroSERCOM 2Pin 2
SERCOM 3Pin 6
Arduino Nano 33 IoTSERCOM 0Pin 6
SERCOM 4Pin 2

To open the Arduino pin mapping table, click View pin map. For more information on the fixed ports and the allocated pins for the block, see Pin Mapping for Arduino Timer-Independent Blocks.

Select the mode to transmit data over the Arduino serial port.

  • write — Write raw binary data to the Arduino serial port.

  • print — Print data to the Arduino serial port as ASCII text.

  • println — Print data to the Arduino serial port as ASCII text followed by a carriage return character '\r' and a newline character '\n'.

Use the print and println options to print messages for debugging and logging purposes.

Specify a header that indicates the beginning of your data block.

Provide the header using the uint8 representation of the corresponding ASCII characters. This table shows some examples of ASCII characters, the corresponding array to use for Header, and a MATLAB® command to generate that array.

Example ASCII CharacterMATLAB CommandParameter Value
"#"uint8('#')[35]
"81"uint8('81')[56 49]
"Start"uint8('Start')[83 116 97 114 116]

You can also specify this parameter using the hexadecimal representation of the ASCII characters.

Dependencies

  • To enable this parameter, set Send mode to write.

Specify a terminator that indicates the end of your data block.

Provide the terminator using the uint8 representation of the corresponding ASCII characters. This table shows some examples of ASCII characters, the corresponding array to use for Terminator, and a MATLAB command to generate that array.

Example ASCII CharacterMATLAB CommandParameter Value
"#"uint8('#')[35]
"81"uint8('81')[56 49]
"End"uint8('End')[69 110 100]

Dependencies

  • To enable this parameter, set Send mode to write.

Specify a title for the data to print over the Arduino serial port.

Dependencies

  • To enable this parameter, set Send mode to print or println.

Select the format in which to print data over the Arduino serial port.

Dependencies

  • To enable this parameter, set Send mode to print or println.

Specify the precision of decimal data that the Arduino hardware transmits.

Dependencies

  • To enable this parameter, set Send mode to print or println and Format to Decimal.

Select this option to generate an interrupt when the data transmission from the Arduino serial port is complete.

When you enable this parameter in the Hardware Interrupt for SAMD block, specify the appropriate Interrupt group, Interrupt name, and Events to serve parameter values.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2026a