Arduino With RN4870 1
LINK ->->->-> https://urlca.com/2ttXNR
How to Use Arduino With RN4870 1 BLE Module
If you are looking for a way to create your own Bluetooth Low Energy (BLE) services and characteristics with Arduino, you may want to consider the RN4870 1 module from Microchip. This module is a small (only 12mm wide) BLE device that supports full BLE 4.2 functionality, including secure AES128 encryption, keyboard I/O authentication, scripting engine for hostless operation, and more. In this article, we will show you how to get started with Arduino and RN4870 1, and how to use the UART transparent service for serial data over the air.
What You Need
To follow this tutorial, you will need:
An Arduino board (we used a Beetle BLE)
An RN4870 1 module (we used the RN4870-V/RM118 version with antenna and all pins available)
A breakout board for the RN4870 1 module (you can make your own or buy one online)
Some jumper wires and a breadboard
A USB cable to connect the Arduino to your computer
The Arduino IDE installed on your computer
A BLE scanner app on your smartphone (we used nRF Connect)
Wiring Diagram
Here is how to connect the Arduino and the RN4870 1 module:
The RN4870 1 module communicates with the Arduino via UART, so we need to connect the TX and RX pins of both devices. We also need to connect the VCC and GND pins to provide power to the module. Optionally, we can connect a LED to pin 13 of the Arduino to indicate when data is received.
Arduino Code
Here is the code we will upload to the Arduino:
```c
// Include SoftwareSerial library
// Define pins for SoftwareSerial
#define RX_PIN 10
#define TX_PIN 11
// Create SoftwareSerial object
SoftwareSerial rn4870(RX_PIN, TX_PIN);
// Define LED pin
#define LED_PIN 13
// Define buffer size
#define BUFFER_SIZE 32
// Create buffer array
char buffer[BUFFER_SIZE];
// Create index variable
int index = 0;
void setup() {
// Initialize serial monitor at 9600 baud
Serial.begin(9600);
// Initialize SoftwareSerial at 115200 baud
rn4870.begin(115200);
// Initialize LED pin as output
pinMode(LED_PIN, OUTPUT);
// Turn off LED
digitalWrite(LED_PIN, LOW);
}
void loop() {
// Check if data is available from RN4870
if (rn4870.available()) {
// Read a byte from RN4870
char c = rn4870.read();
// Check if byte is end of line character
if (c == '\\n') {
// Add null terminator to buffer
buffer[index] = '\\0';
// Print buffer to serial monitor
Serial.println(buffer);
// Toggle LED state
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
// Reset index
index = 0;
}
else {
// Check if buffer is not full
if (index < BUFFER_SIZE - 1) {
// Add byte to buffer
buffer[index] = c;
// Increment index
index++;
}
}
}
}
```
This code uses the SoftwareSerial library to create a serial communication between the Arduino and the RN4870 1 module. The module operates at a default baud rate of 115200, so we need to match that in our code. The code also uses a buffer array to store the incoming data from the module until an end of line character (\\n) is received. Then, it prints the buffer content to the serial monitor and toggles a LED state. This way, we can see what data is sent from the module and when.
RN4870 Configuration
The 248dff8e21