Serial

In Maixduino, there are two types of serial devices, UARTHSClass and UARTClass. The Serial corresponds to the UARTHSClass, and the remaining Serial1, Serial2, and Serial3 are UARTClass. Serial uses the default pin as 4 (RX), 5 (TX). So you can use it in the serial monitor on your computer.The default pins for the other three global serial ports are 6(RX), and 7(TX) (they are connected to the WiFi module),To use them correctly, set different pins for them in begin().

1. Functions

The operation of the serial port is exactly the same as that of Arduino. You can find more information on the Arduino website.

if(Serial)

available()

availableForWrite()

begin()

end()

find()

findUntil()

flush()

parseFloat()

parseInt()

peek()

print()

println()

read()

readBytes()

readBytesUntil()

readString()

readStringUntil()

setTimeout()

write()

serialEvent()


2. Serial port settings

Serial.begin(BaudRate, RX , TX )

2.1. Notes

For platform.io change the serial monitor baudrate in platform.ini.

; serial monitor baudrate
monitor_speed = 115200

3. Serial.println()

3.1. Description

Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as Serial.print().

3.2. Syntax

Serial.println(val)

Serial.println(val, format)

3.3. Parameters

Serial: serial port object.

val: the value to print. Allowed data types: any data type.

format: specifies the number base (for integral data types) or number of decimal places (for floating point types).

3.4. Returns

println() returns the number of bytes written, though reading that number is optional. Data type: size_t.

3.5. Example Code

#include <Arduino.h>

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("Hello world");
  delay(2000);
}

4. Serial Monitor in platform.io

-- Available ports:
---  1: /dev/ttyUSB0         'USB Debugger'
---  2: /dev/ttyUSB1         'USB Debugger'
--- Enter port index or full name: 2

results matching ""

    No results matching ""