This example shows how to create a wireless cubicle doorbell for an office setting using a capacitive touch button, two Bluetooth® modules and a NeoPixel® LED strip.
- PIC16F18075 Data Sheet
- PIC16F18075 Family Product Page
- Wireless Cubicle Doorbell Application Note
- RNBD451 User Guide
- MPLAB® X IDE 6.10 or newer
- MPLAB XC8 2.41 or a newer compiler
- MPLAB Code Configurator (MCC) 5.7.7 or newer
- MPLAB Melody Library 2.5.0 or newer
- Microchip PIC16F1xxxx Series Device Support pack 1.18.352 or newer Device Pack
- PIC16F18075 Microcontroller (x2)
- Curiosity High Pin Count (HPC) Development Board (x2)
- RNBD451 Bluetooth Low Energy (BLE) Module x2
- MikroElektronika Cap Touch Click Board™
- Adafruit® NeoPixel 8 x 5050 RGB LED Stick
- Jumper wires
The hardware for this code examples consists of two separate components connected wirelessly through their respective Bluetooth modules. These components include the door module, which functions as the conventional doorbell in the demonstration, and the desk module, which serves as the traditional door chime in the demonstration.
Note: This demo was initially created using Bluetooth classic technology with the RN4876 module, but was later adapted for BLE using the RNBD451 module. The two modules are interchangeable, except for one line of code. However, the configuration is expected to function for both modules.
The door module uses a Cap Touch Click as the button, and a RNBD451 Bluetooth module to send the signal wirelessly to the desk module.
The Cap Touch Click connects to the PIC16F18075 by linking the OUT pin on the Click board to an input pin (RB0) of the microcontroller. The MOD pin on the Click board determines the mode of operation (Fast/Low Power mode) and is on RD1 of the PIC16F18075.
The RNBD451 Bluetooth module connects to the PIC16F18075 through the RTS, CTS, RXD, TXD, RST and SW_RST pins. The CTS and TXD pins are configured as input pins on the PIC16F18075, while the RTS, RXD, RST and SW_RST pins are configured as output pins.
Figure 1 shows the connections made between the Cap Touch Click, the RNBD451 Bluetooth module and the PIC16F18075 for the door module.
Figure 1 - Door Module Circuit Diagram
The desk module includes the Adafruit NeoPixel Stick and one RN4678 Bluetooth Click. The RN4678 Bluetooth Click is used to receive the signal from the door module when somebody presses the capacitive touch button, then the Adafruit NeoPixel Stick flashes to get the attention of the person inside the cubicle.
The Adafruit NeoPixel Stick connects to the PIC16F18075 by linking the DIN pin to any output pin of the microcontroller. In this example, RA0 was selected as the output pin. A 4-pin header will need to be soldered onto the back of the Adafruit NeoPixel before connecting to the PIC16F18075. Figure 2 shows where to connect the 4-pin header (see the red box).
Figure 2 - Adafruit NeoPixel - Back Side
The RNBD451 Bluetooth module connects to the PIC16F18075 the same way as on the door module.
Figure 3 shows the connections made between the Adafruit NeoPixel Stick, RNBD451 Bluetooth module and the PIC16F18075 for the desk module.
Figure 3 - Desk Module Circuit Diagram
-
Download, install and open MPLABX IDE version 6.00 (or newer)
-
Download and install the XC8 C-Compiler version 2.36 (or newer)
-
Open the
pic16f18075-cubicle-doorbell-mplab-mcc.X
project as shown in Figure 4
Figure 4 - Open Project Menu in MPLABX
The project file above includes all the needed code and configurations for both the door and desk modules. There are two main.c
files that contain the driving code for each of the modules (Figure 5 below). By selecting the configuration that matches the module and free/pro status (see Table 1 and Figure 6 below), one of the main.c
files will be excluded from being programmed (gray Desk_Module_main.c
file in Figure 5). This exclusion results in the correct main.c
file being programmed to the device for the selected module, so that the same MPLABX project can be used for the door and desk modules.
Figure 5 - Main.c File Organization Using the pro_door Configuration Setting
Figure 6 - Configuration List for MPLABX
Table 1 - Configuration List Selection by Module and Free/Pro Setting
Module | Free/Pro | Configuration |
---|---|---|
Door | Pro | pro_door |
Door | Free | free_door |
Desk | Pro | pro_desk |
Desk | Free | free_desk |
Each of the main.c
files will use a series of functions that are built utilizing the existing APIs generated from the Melody configuration. Tables 2 and 3 below each give an overview of the functions used for either the NeoPixel or RNBD451 Bluetooth module.
There are seven custom-written functions used to control the NeoPixel in this example. Table 2 provides a list of each function along with its description. These functions can be found within the Desk_Module_main.c
file.
Table 2 - NeoPixel Functions and Descriptions
Function | Description |
---|---|
onePulse() |
Sends a 1-code (HIGH) to the NeoPixel using the correct timing |
zeroPulse() |
Sends a 0-code (LOW) to the NeoPixel using the correct timing |
LED_send_byte(K) |
Checks the K byte to see if a 1-code or 0-code needs to be sent |
LED_Array(R, G, B) |
Inputs the R/G/B values (max of 255) to set the brightness of each color for an individual LED and sends in the correct order for the NeoPixel to interpret them accurately |
RED() |
Makes all eight LEDs display the highest intensity red |
OFF() |
Turns all eight LEDs off |
RED_BLINK_500ms() |
All eight LEDs blink red and then turn off at a 500 ms interval |
There are five custom-written functions used to control the RNBD451 in this example. Table 3 provides a list of each function along with its description. These functions can be found within both the Desk_Module_main.c
file and the Door_Module_main.c
file.
Table 3 - RNBD451 Functions and Descriptions
Function | Description |
---|---|
BT_initialConditions() |
Sets the initial conditions for the RNBD451 Bluetooth module |
BT_initialize() |
Puts the RNBD451 Bluetooth module into a state where it is able to receive EUSART data |
BT_enterCommandMode() |
Sends the $$$ command over EUSART which shifts the RNBD451 Bluetooth module into Command mode |
BT_connect() |
Connects to the device which matches the specificed MAC address (stored within the function) |
There are four #defines
that need to be changed depending on your configuration in Desk_Module_main.c
, lines 23-27:
#define NUM_FLASHES 3 // number of times LED array flashes
#define NUM_LEDS 8 // number of LEDs used
#define MAC_ADDR "9C956E40667B" // MAC address of device
#define RNBD451 // this module makes code run BLE commands
//#define RN4678 // this module makes code run BT classic commands
This webpage details how to find the MAC address for the RNBD451 module, and this one provides the instructions for the RN4678 module.
The Curiosity HPC board includes a programmer that can program the PIC16F18075. Connect it to your computer via USB and click the Make and Program Device button for the device to program. Check that the correct configuration is selected from the configuration list drop-down menu for the programmed device, either desk or door side.
Figure 8 - Make and Program Device Button
Figure 9 - Device Programming Successful
After programming the desk and door modules, you can now touch the capacitive touch click to "ring" the doorbell.
Functional Doorbell
The RNBD451 Bluetooth Click has many different settings that are not described within this example. For any additional setting changes, follow these steps:
-
Make sure that all the RNBD451 Bluetooth Click pins are connected to the PIC16F18075 (see Figure 1 or 3 above).
-
Disconnect the TXD and RXD connections between the PIC16F18075 and the RN4678 Bluetooth Click.
-
Using a USB-to-UART device, connect the TXD and RXD pins from the RNBD451 Bluetooth module to that device.
-
Now follow the instructions used with the command guide to change any of the settings. The command guide can be found in the RNBD451 User Guide.
This example has shown how to use a Cap Touch Click, an AdaFruit NeoPixel and two RNBD451 Bluetooth modules to create a cubicle doorbell system that uses the PIC16F18075 microcontroller.