MySensors Library & Examples  2.3.2-62-ge298769
ReceiveTest.ino
1 // AltSoftSerial Receive Test
2 //
3 // Transmit data with Serial1 and try to receive
4 // it with AltSoftSerial. You must connect a wire
5 // from Serial1 TX to AltSoftSerial RX.
6 
7 #include <AltSoftSerial.h>
8 
9 AltSoftSerial altser;
10 const int mybaud = 9600;
11 
12 // Board Serial1 TX AltSoftSerial RX
13 // ----- ---------- ----------------
14 // Teensy 3.x 1 20
15 // Teensy 2.0 8 (D3) 10 (C7)
16 // Teensy++ 2.0 3 (D3) 4 (D4)
17 // Arduino Leonardo 1 13
18 // Arduino Mega 18 48
19 
20 // Serial1 on AVR @ 16 MHz minimum baud is 245
21 // Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733
22 
23 // This example code is in the public domain.
24 
25 byte sentbyte;
26 unsigned long prevmillis;
27 byte testbyte=0xF0;
28 
29 void setup()
30 {
31  delay(200);
32  Serial.begin(9600);
33  while (!Serial) ; // wait for Arduino Serial Monitor
34  Serial1.begin(mybaud); // connect a wire from TX1
35  altser.begin(mybaud); // to AltSoftSerial RX
36  Serial.println("AltSoftSerial Receive Test");
37  prevmillis = millis();
38 }
39 
40 void loop()
41 {
42  // transmit a test byte on Serial 1
43  if (millis() - prevmillis > 250) {
44  sentbyte = testbyte++;
45  Serial1.write(sentbyte);
46  prevmillis = millis();
47  }
48  // attempt to receive it by AltSoftSerial
49  if (altser.available() > 0) {
50  byte b = altser.read();
51  Serial.println(b);
52  if (b != sentbyte) {
53  Serial.println("***** ERROR *****");
54  }
55  }
56 }
AltSoftSerial::read
int read()
read
loop
void loop()
Main loop.
Definition: ReceiveTest.ino:40
AltSoftSerial
Definition: AltSoftSerial.h:43
AltSoftSerial::available
int available()
available
setup
void setup()
Called after node initialises but before main loop.
Definition: ReceiveTest.ino:29
AltSoftSerial::begin
static void begin(uint32_t baud)
Definition: AltSoftSerial.h:51