Hello,
I have my nRF52840 hooked up, was successful at sending 1’s and 0’s over Rx from the nRF Connect app for IOS. However, under the “UART TX characteristic” > “Properties,” it says “Write and Write without response.” So I am unable to see the status of the light from the app.
I am also able to read accelerometer data from the on the SparkFun MMA8452Q on the serial monitor. I would like to be able to read the accelerometer data remotely. Can anyone help with this?
Here is the code I am using:
/* BLE Example for SparkFun Pro nRF52840 Mini
*
* This example demonstrates how to use the Bluefruit
* library to both send and receive data to the
* nRF52840 via BLE.
*
* Using a BLE development app like Nordic's nRF Connect
* https://www.nordicsemi.com/eng/Products/Nordic-mobile-Apps/nRF-Connect-for-Mobile
* The BLE UART service can be written to to turn the
* on-board LED on/off, or read from to monitor the
* status of the button.
*
* See the tutorial for more information:
* https://learn.sparkfun.com/tutorials/nrf52840-development-with-arduino-and-circuitpython#arduino-examples
*/
#include <bluefruit.h>
#include <Wire.h> // Must include Wire library for I2C
#include "SparkFun_MMA8452Q.h" // Click here to get the library: http://librarymanager/All#SparkFun_MMA8452Q
MMA8452Q accel; // create instance of the MMA8452 class
BLEUart bleuart; // uart over ble
// Define hardware: LED and Button pins and states
const int LED_PIN = 7;
#define LED_OFF LOW
#define LED_ON HIGH
const int BUTTON_PIN = 13;
#define BUTTON_ACTIVE LOW
int lastButtonState = -1;
void setup() {
// Initialize hardware:
Serial.begin(9600); // Serial is the USB serial port
Serial.println("MMA8452Q Basic Reading Code!");
Wire.begin();
if (accel.begin() == false) {
Serial.println("Not Connected. Please check connections and read the hookup guide.");
while (1);
}
pinMode(LED_PIN, OUTPUT); // Turn on-board blue LED off
digitalWrite(LED_PIN, LED_OFF);
pinMode(BUTTON_PIN, INPUT);
Serial.println("Adafruit MPU6050 test!");
// Uncomment the code below to disable sharing
// the connection LED on pin 7.
//Bluefruit.autoConnLed(false);
// Initialize Bluetooth:
Bluefruit.begin();
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
Bluefruit.setName("SparkFun_nRF52840");
bleuart.begin();
// Start advertising device and bleuart services
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addService(bleuart);
Bluefruit.ScanResponse.addName();
Bluefruit.Advertising.restartOnDisconnect(true);
// Set advertising interval (in unit of 0.625ms):
Bluefruit.Advertising.setInterval(32, 244);
// number of seconds in fast mode:
Bluefruit.Advertising.setFastTimeout(30);
Bluefruit.Advertising.start(0);
}
void loop() {
// If data has come in via BLE:
if (bleuart.available()) {
uint8_t c;
// use bleuart.read() to read a character sent over BLE
c = (uint8_t) bleuart.read();
// Print out the character for debug purposes:
Serial.write(c);
// If the character is one of our expected values,
// do something:
switch (c) {
// 0 number or character, turn the LED off:
case 0:
case '0':
digitalWrite(LED_PIN, LED_OFF);
break;
// 1 number or character, turn the LED on:
case 1:
case '1':
digitalWrite(LED_PIN, LED_ON);
break;
default:
break;
}
}
if (accel.available()) { // Wait for new data from accelerometer
// Acceleration of x, y, and z directions in g units
Serial.print(accel.getCalculatedX(), 3);
Serial.print("\t");
Serial.print(accel.getCalculatedY(), 3);
Serial.print("\t");
Serial.print(accel.getCalculatedZ(), 3);
Serial.println();
}
// If our button state has changed:
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastButtonState = buttonState;
// Write the new button state to the bleuart TX char
bleuart.write(!buttonState);
}
}