forked from jherland/arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnexa_decoder.ino
78 lines (74 loc) · 1.71 KB
/
nexa_decoder.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Decoder sketch for 433 MHz receiver module receiving Nexa commands.
*
* Objective:
*
* Read the digital output from a RWS-371 or similar 433 MHz receiver, and
* output the Nexa-style commands to the serial port.
*
* Connections:
*
* -----------------------
* | 433 MHz RF Receiver |
* -----------------------
* | | | | | | | |
* 1 2 3 4 5 6 7 8
*
* 1: GND
* 2: Digital output (connect to PC0 (Arduino pin A0))
* 3. Linear output (maybe: pull-down resistor to remove noise from pin 2)
* 4: VCC (5V)
* 5: VCC
* 6: GND
* 7: GND
* 8: Optional Antenna (10-15 cm wire, or 35 cm wire)
*
* Or:
*
* -------------------
* | 433 MHz RF Recv |
* -------------------
* | | | |
* 1 2 3 4
*
* 1: VCC (5V)
* 2 & 3: Digital output (connect to PC0 (Arduino pin A0))
* 4: GND
*
* Author: Johan Herland <johan@herland.net>
* License: GNU GPL v2 or later
*/
#include <Macros.h>
#include <RF433Transceiver.h>
#include <RingBuffer.h>
#include <PulseParser.h>
#include <NexaCommand.h>
// Adjust the following to match where the RF receiver is connected.
RF433Transceiver rf_port(1);
RingBuffer<char> rx_bits(1000);
PulseParser pulse_parser(rx_bits);
NexaCommand cmd;
void setup()
{
Serial.begin(115200);
Serial.println(F("nexa_decoder ready:"));
}
void loop()
{
pulse_parser(rf_port.rx_get_pulse());
if (!rx_bits.r_empty()) {
#if DEBUG
Serial.write((const byte *) rx_bits.r_buf(),
rx_bits.r_buf_len());
Serial.write((const byte *) rx_bits.r_wrapped_buf(),
rx_bits.r_wrapped_buf_len());
#endif
if (NexaCommand::from_bit_buffer(cmd, rx_bits)) {
#if DEBUG
Serial.println();
#endif
Serial.print("RX <- ");
cmd.print(Serial);
}
}
}