35
35
* advertising payloads, with fully parsed data displayed in the
36
36
* Serial Monitor.
37
37
*
38
- * ENABLE_TFT
39
- * ----------
40
- * An ILI9341 based TFT can optionally be used to display proximity
41
- * alerts. The Adafruit TFT Feather Wing is recommended and is the only
42
- * device tested with this functionality.
43
- *
44
38
* ARRAY_SIZE
45
39
* ----------
46
40
* The numbers of peripherals tracked and sorted can be set via the
51
45
* This value determines the number of milliseconds before a tracked
52
46
* peripheral has it's last sample 'invalidated', such as when a device
53
47
* is tracked and then goes out of range.
48
+ *
49
+ * ENABLE_TFT
50
+ * ----------
51
+ * An ILI9341 based TFT can optionally be used to display proximity
52
+ * alerts. The Adafruit TFT Feather Wing is recommended and is the only
53
+ * device tested with this functionality.
54
+ *
55
+ * ENABLE_OLED
56
+ * -----------
57
+ * An SSD1306 128x32 based OLED can optionally be used to display
58
+ * proximity alerts. The Adafruit OLED Feather Wing is recommended and
59
+ * is the only device tested with this functionality.
54
60
*/
55
61
56
62
#include < string.h>
57
63
#include < bluefruit.h>
58
64
#include < SPI.h>
59
65
60
66
#define VERBOSE_OUTPUT (0 ) // Set this to 1 for verbose adv packet output to the serial monitor
61
- #define ENABLE_TFT (0 ) // Set this to 1 to enable ILI9341 TFT display support
62
67
#define ARRAY_SIZE (4 ) // The number of RSSI values to store and compare
63
68
#define TIMEOUT_MS (2500 ) // Number of milliseconds before a record is invalidated in the list
69
+ #define ENABLE_TFT (0 ) // Set this to 1 to enable ILI9341 TFT display support
70
+ #define ENABLE_OLED (0 ) // Set this to 1 to enable SSD1306 128x32 OLED display support
64
71
65
72
#if (ARRAY_SIZE <= 0)
66
73
#error "ARRAY_SIZE must be a non-zero value"
67
74
#endif
75
+ #if (ENABLE_TFT) && (ENABLE_OLED)
76
+ #error "ENABLE_TFT and ENABLE_OLED can not both be set at the same time"
77
+ #endif
68
78
69
79
// Custom UUID used to differentiate this device.
70
80
// Use any online UUID generator to generate a valid UUID.
@@ -91,12 +101,30 @@ BLEUuid uuid = BLEUuid(CUSTOM_UUID);
91
101
#define STMPE_CS 30
92
102
#define SD_CS 27
93
103
#else
94
- #error "Unknown target. Please make sure you are using an nRF52 Feather and BSP 0.6.5 or higher!"
104
+ #error "Unknown target. Please make sure you are using an nRF52 Feather and BSP 0.6.5 or higher!"
95
105
#endif
96
106
97
107
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
98
108
#endif
99
109
110
+ /* 128x32 OLED setup if the OLED display is available */
111
+ #if (ENABLE_OLED)
112
+ #include < Wire.h>
113
+ #include < Adafruit_GFX.h>
114
+ #include < Adafruit_SSD1306.h>
115
+
116
+ /* Pin setup for the OLED display */
117
+ #ifdef ARDUINO_NRF52_FEATHER
118
+ #define BUTTON_A 31
119
+ #define BUTTON_B 30
120
+ #define BUTTON_C 27
121
+ #else
122
+ #error "Unknown target. Please make sure you are using an nRF52 Feather and BSP 0.6.5 or higher!"
123
+ #endif
124
+
125
+ Adafruit_SSD1306 oled = Adafruit_SSD1306();
126
+ #endif
127
+
100
128
/* This struct is used to track detected nodes */
101
129
typedef struct node_record_s
102
130
{
@@ -124,6 +152,12 @@ void setup()
124
152
tft.println (" DUNKIN" );
125
153
#endif
126
154
155
+ /* Enable the OLED display if available */
156
+ #if ENABLE_OLED
157
+ oled.begin (SSD1306_SWITCHCAPVCC, 0x3C );
158
+ oled.display ();
159
+ #endif
160
+
127
161
/* Clear the results list */
128
162
memset (records, 0 , sizeof (records));
129
163
for (uint8_t i = 0 ; i<ARRAY_SIZE; i++)
@@ -169,7 +203,7 @@ void setup()
169
203
Bluefruit.Scanner .setRxCallback (scan_callback);
170
204
Bluefruit.Scanner .restartOnDisconnect (true );
171
205
Bluefruit.Scanner .filterRssi (-80 ); // Only invoke callback for devices with RSSI >= -80 dBm
172
- Bluefruit.Scanner .filterUuid (uuid); // Only invoke callback if the target UUID was found
206
+ // Bluefruit.Scanner.filterUuid(uuid); // Only invoke callback if the target UUID was found
173
207
// Bluefruit.Scanner.filterMSD(0xFFFF); // Only invoke callback when MSD is present with the specified Company ID
174
208
Bluefruit.Scanner .setInterval (160 , 80 ); // in units of 0.625 ms
175
209
Bluefruit.Scanner .useActiveScan (true ); // Request scan response data
@@ -180,43 +214,32 @@ void setup()
180
214
/* This callback handler is fired every time a valid advertising packet is detected */
181
215
void scan_callback (ble_gap_evt_adv_report_t * report)
182
216
{
183
- /* Try to insert this packet into the existing record list */
184
217
node_record_t record;
218
+
219
+ /* Prepare the record to try to insert it into the existing record list */
185
220
memcpy (record.addr , report->peer_addr .addr , 6 ); /* Copy the 6-byte device ADDR */
186
221
record.rssi = report->rssi ; /* Copy the RSSI value */
187
222
record.timestamp = millis (); /* Set the timestamp (approximate) */
223
+
224
+ /* Attempt to insert the record into the list */
188
225
if (insertRecord (&record) == 1 ) /* Returns 1 if the list was updated */
189
226
{
190
- /* The list was updated, print the new values */
191
- printRecordList ();
227
+ printRecordList (); /* The list was updated, print the new values */
192
228
Serial.println (" " );
229
+
230
+ /* Display the device list on the TFT if available */
231
+ #if ENABLE_TFT
232
+ renderResultsToTFT ();
233
+ #endif
234
+
235
+ /* Display the device list on the OLED if available */
236
+ #if ENABLE_OLED
237
+ renderResultsToOLED ();
238
+ #endif
193
239
}
194
240
195
- /* Display the device on the TFT if available */
196
- #if ENABLE_TFT
197
- tft.fillRect (0 , 0 , 240 , 30 , ILI9341_BLACK);
198
- tft.setTextSize (1 );
199
- tft.setCursor (0 , 0 );
200
- tft.print (" [" );
201
- tft.print (millis ());
202
- tft.print (" ] " );
203
- tft.print (report->peer_addr .addr [0 ]);
204
- tft.print (" :" );
205
- tft.print (report->peer_addr .addr [1 ]);
206
- tft.print (" :" );
207
- tft.print (report->peer_addr .addr [2 ]);
208
- tft.print (" :" );
209
- tft.print (report->peer_addr .addr [3 ]);
210
- tft.print (" :" );
211
- tft.print (report->peer_addr .addr [4 ]);
212
- tft.print (" :" );
213
- tft.println (report->peer_addr .addr [5 ]);
214
- tft.print (" RSSI: " );
215
- tft.print (report->rssi );
216
- tft.println (" dBm" );
217
- #endif
218
-
219
- /* Fully parse and display the advertising packet if verbose/debug output is requested */
241
+ /* Fully parse and display the advertising packet to the Serial Monitor
242
+ * if verbose/debug output is requested */
220
243
#if VERBOSE_OUTPUT
221
244
uint8_t len = 0 ;
222
245
uint8_t buffer[32 ];
@@ -339,6 +362,73 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
339
362
#endif
340
363
}
341
364
365
+ #if ENABLE_TFT
366
+ void renderResultsToTFT (void )
367
+ {
368
+ tft.fillRect (0 , 0 , 240 , ARRAY_SIZE*8 , ILI9341_BLACK);
369
+ tft.setTextSize (1 );
370
+ tft.setCursor (0 , 0 );
371
+
372
+ for (uint8_t i=0 ; i<ARRAY_SIZE; i++)
373
+ {
374
+ tft.print (records[i].addr [0 ], HEX);
375
+ tft.print (" :" );
376
+ tft.print (records[i].addr [1 ], HEX);
377
+ tft.print (" :" );
378
+ tft.print (records[i].addr [2 ], HEX);
379
+ tft.print (" :" );
380
+ tft.print (records[i].addr [3 ], HEX);
381
+ tft.print (" :" );
382
+ tft.print (records[i].addr [4 ], HEX);
383
+ tft.print (" :" );
384
+ tft.print (records[i].addr [5 ], HEX);
385
+ tft.print (" " );
386
+ tft.print (records[i].rssi );
387
+ tft.print (" [" );
388
+ tft.print (records[i].timestamp );
389
+ tft.println (" ] " );
390
+ }
391
+ }
392
+ #endif
393
+
394
+ #if ENABLE_OLED
395
+ void renderResultsToOLED (void )
396
+ {
397
+ oled.clearDisplay ();
398
+ oled.setTextSize (1 );
399
+ oled.setTextColor (WHITE);
400
+
401
+ for (uint8_t i=0 ; i<ARRAY_SIZE; i++)
402
+ {
403
+ if (i>=4 )
404
+ {
405
+ /* We can only display four records on a 128x32 pixel display */
406
+ oled.display ();
407
+ return ;
408
+ }
409
+ if (records[i].rssi != -128 )
410
+ {
411
+ oled.setCursor (0 , i*8 );
412
+ oled.print (records[i].addr [0 ], HEX);
413
+ oled.print (" :" );
414
+ oled.print (records[i].addr [1 ], HEX);
415
+ oled.print (" :" );
416
+ oled.print (records[i].addr [2 ], HEX);
417
+ oled.print (" :" );
418
+ oled.print (records[i].addr [3 ], HEX);
419
+ oled.print (" :" );
420
+ oled.print (records[i].addr [4 ], HEX);
421
+ oled.print (" :" );
422
+ oled.print (records[i].addr [5 ], HEX);
423
+ oled.print (" " );
424
+ oled.println (records[i].rssi );
425
+ }
426
+ }
427
+
428
+ oled.display ();
429
+ }
430
+ #endif
431
+
342
432
/* Prints a UUID16 list to the Serial Monitor */
343
433
void printUuid16List (uint8_t * buffer, uint8_t len)
344
434
{
0 commit comments