-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc1101-uno-lcd.ino
180 lines (146 loc) · 3.94 KB
/
cc1101-uno-lcd.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "EEPROM.h"
#include "cc1101.h" // minimal-cc1101 Where did this come from?
#include <Wire.h> // I2C arduino library ( comes with arduino )
#include <LiquidCrystal_I2C.h> // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
CC1101 cc1101;
// LED & Button
uint8_t buttonPin = 3;
uint8_t ledPin = 7;
// button states
uint8_t state = HIGH;
uint8_t reading;
uint8_t previous = LOW;
// the follow variables are uintmax_t because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
uintmax_t time = 0;
uintmax_t debounce = 300;
// counter to get increment in each loop
uint8_t counter;
uint8_t b;
// SETUP HERE
void setup()
{
// Assign Button and LED pins
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
// SyncWord
//uint32_t syncWord = 61166; // 0xEEEE
uint8_t syncH = 0xEE; //
uint8_t syncL = 0xEE;
Serial.begin(115200);
lcd.begin(20, 4); // initialize the lcd for 20 chars 4 lines, turn on backlight
// reset the counter
counter = 0;
// initialize the RF Chip
/*
lcd.print("SyncH: 0x");
lcd.print(syncH, HEX);
lcd.setCursor(0, 1);
lcd.print("SyncL: 0x");
lcd.print(syncL, HEX);
*/
lcd.setCursor(0, 1);
lcd.print(syncH, HEX);
lcd.print(' ');
lcd.print(syncL, HEX);
delay(2000);
cc1101.init();
//cc1101.setSyncWord(syncH, syncL, false);
cc1101.setSyncWord(syncH, syncL, false);
cc1101.setCarrierFreq(CFREQ_433);
cc1101.disableAddressCheck();
//cc1101.setTxPowerAmp(PA_LongDistance); // if you want HIGH POWER
cc1101.setTxPowerAmp(PA_LowPower);
delay(500);
lcd.clear();
}
/// end void setup
// send_data() becomes a function to be used in void loop()
void send_data()
{
cc1101.flushTxFifo ();
CCPACKET data;
data.length = 5;
cc1101.writeReg(CC1101_MDMCFG3, 0x22); // Register 0x11 set to 115200 Baud
uint8_t count = counter++;
data.data[0] = 0xaa;
data.data[1] = 0xaa;
data.data[2] = 0xaa;
data.data[3] = 0xaa;
data.data[4] = 0xaa;
/*
for (uint8_t i = 0; i < data.length; i++){
data.data[i] = i * thing[i];
}
*/
if (cc1101.sendData(data)) {
delay(100);
// LED ON
digitalWrite(ledPin, HIGH);
/*
lcd.setCursor(0, 0);
lcd.print("Binary :");
lcd.setCursor(9, 0);
lcd.print(count, BIN);
lcd.setCursor(0, 1);
lcd.print("Decimal:");
lcd.setCursor(9, 1);
lcd.print(count, DEC);
*/
lcd.setCursor(0,0);
lcd.print("PKTLEN:");
lcd.print(' ');
lcd.print(cc1101.readReg(0x06, CC1101_CONFIG_REGISTER), DEC);
lcd.setCursor(0, 2);
lcd.print("DR:");
lcd.setCursor(3, 2);
lcd.print(cc1101.readReg(0x11, CC1101_STATUS_REGISTER), HEX);
lcd.print(' ');
lcd.print("PL:");
lcd.print(data.length, HEX);
lcd.print(' ');
lcd.print("0x08:");
lcd.print(cc1101.readReg(0x08, CC1101_STATUS_REGISTER), HEX);
lcd.setCursor(0, 3);
lcd.print(data.data[0], HEX);
lcd.print(' ');
lcd.print(data.data[1], HEX);
lcd.print(' ');
lcd.print(data.data[2], HEX);
lcd.print(' ');
lcd.print(data.data[3], HEX);
lcd.print(' ');
lcd.print(data.data[4], HEX);
/*
for (uint8_t i = 0; i < data.length; i++){
lcd.print(data.data[i], HEX);
}*/
lcd.blink();
//lcd.scrollDisplayRight();
// LED OFF
digitalWrite(ledPin, LOW);
} else {
lcd.setCursor(0, 3);
lcd.print(" send failed :(");
delay(200);
}
}
// send data ( does this send all the data in state machine?? )
void loop()
{
reading = digitalRead(buttonPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
if (state)
send_data();
delay(1000);
}