Serial ports ychwanegol ar Arduino Uno

Arduino Uno with Multiple Software Serial Devices

The Arduino Uno (ATmega328) has a single hardware serial connection.
If more serial connections are needed, you must implement these in software.
Luckily, there is a very easy to use library to implement software serial connections.
It is called SoftwareSerial.h and is included with the latest Arduino IDE.
The following code demonstrates how to use this library to implement more than one software serial channel.
Importantly, no more than one software serial connection can be in use at a time so an open connection must be terminated before another can be started.

#include <SoftwareSerial.h>
// define the digital pins to use as RX and TX for two
 // software serial connections
 const int RX1 = 8;
 const int TX1 = 9;
 const int RX2 = 10;
 const int TX2 = 11;
// create SoftwareSerial objects
 SoftwareSerial SoftSerialOne(RX1,TX1);
 SoftwareSerial SoftSerialTwo(RX2,TX2);
void setup(void)
 {
 // setup the software serial pins
 pinMode(RX1, INPUT);
 pinMode(RX2, INPUT);
 pinMode(TX1, OUTPUT);
 pinMode(TX2, OUTPUT);
 }
void loop(void) 
{
 SoftSerialOne.begin(9600); // begin communication on the first
 // software serial channel
 SoftSerialOne.print("Hello World"); // send something
 SoftSerialOne.end(); // end communication on the first software
 // serial channel
 SoftSerialTwo.begin(9600); // begin communication on the second
 // software serial channel
 SoftSerialTwo.print("Hello World"); // send something
 SoftSerialTwo.end(); // end communication on the second software
 // serial channel
 }

Gadael Ateb

Ni fydd dy gyfeiriad e-bost yn cael ei gyhoeddi. Mae'r meysydd gofynnol yn cael eu marcio *