使用SoftwareSerial Library,可以在digital pin上进行串行通讯。可同时定义多个软件串口,多个串口的话最高速度115200bps。
要使用这个库,需要包含头文件:
#include <SoftwareSerial.h>
这个库的局限:
1,不能同时收发数据
2,定义了多个串口的话,同一时间只能一个串口接收数据。
3,On Arduino or Genuino 101 boards the current maximum RX speed is 57600bps.
定义多个串口对象实例,同一时间只能激活一个。
可用方法
1,创建对象
SoftwareSerial(rxPin, txPin, inverse_logic);
Parameters
rxPin: the pin on which to receive serial data.
txPin: the pin on which to transmit serial data.
inverse_logic: used to invert the sense of incoming bits (the default is normal logic). If set, SoftwareSerial treats a LOW (0v on the pin, normally) on the RX pin as a 1-bit (the idle state) and a HIGH (5V on the pin, normally) as a 0-bit. It also affects the way that it writes to the TX pi