Hi all,
I'm working with a pressure sensor (LPS22HBTR) and the nRF52-DK and I have some issues when sending data through BLE (nRF52832). When I run the program without BLE it works, but when I connect the nRF52 to a device (I don't even send data) the program crushes. The app (LightBlue) doesn't even tell me that the device is disconnected or something like that.
I have attached the code related to this part of the program.
#include <Arduino.h> #include <BLEPeripheral.h> #include <Wire.h> #include <WireCrc.h> #include <WireSlave.h> #include <MPU6050.h> #include "HX711.h" #include <Adafruit_LPS2X.h> #include <Adafruit_Sensor.h> #include <WireSlaveRequest.h> BLEPeripheral blePeripheral = BLEPeripheral(); //AIRFLOW SERVICE 0000FFC0-0000-1000-8000-00805F9B34FB BLEService AirflowService("ffc0"); BLEIntCharacteristic rightLung_Char("ffc1", BLERead | BLENotify); BLEDescriptor RLDescriptor("2901", "RIGHT LUNG"); BLEIntCharacteristic leftLung_Char("ffc2", BLERead | BLENotify); BLEDescriptor LLDescriptor("2901", "LEFT LUNG"); BLEIntCharacteristic stomach_Char("ffc3", BLERead | BLENotify); BLEDescriptor StomachDescriptor("2901", "STOMACH"); //AIRFLOW VARIABLES Adafruit_LPS22 lps1; Adafruit_LPS22 lps2; Adafruit_LPS22 lps3; // For SPI mode, we need a CS pin #define LPS_CS1 10 #define LPS_CS2 9 #define LPS_CS3 8 // For software-SPI mode we need SCK/MOSI/MISO pins I HAVE ISSUES WITH THIS #define LPS_SCK 13 #define LPS_MISO 12 #define LPS_MOSI 11 float origin1 = 0; float origin2 = 0; float origin3 = 0; int rightLung = 0; int leftLung = 0; int stomach = 0; int count = 0; void setup() { Serial.begin(115200); Wire.begin(); // AIRFLOW SETUP if (!lps1.begin_SPI(LPS_CS1)) { Serial.println("Failed to find LPS22 chip 1"); while (1) { delay(10); } } if (!lps2.begin_SPI(LPS_CS2)) { Serial.println("Failed to find LPS22 chip 2"); while (1) { delay(10); } } if (!lps2.begin_SPI(LPS_CS2)) { Serial.println("Failed to find LPS22 chip 2"); while (1) { delay(10); } } //BLE SETUP blePeripheral.setAdvertisedServiceUuid(AirflowService.uuid()); blePeripheral.addAttribute(AirflowService); blePeripheral.addAttribute(rightLung_Char); blePeripheral.addAttribute(RLDescriptor); blePeripheral.addAttribute(leftLung_Char); blePeripheral.addAttribute(LLDescriptor); blePeripheral.addAttribute(stomach_Char); blePeripheral.addAttribute(StomachDescriptor); blePeripheral.begin(); } void loop() { //Airflow(); //WORKS //blePeripheral.poll(); BLECentral central = blePeripheral.central(); if (central) { // central connected to peripheral Serial.print(F("Connected to central: ")); Serial.println(central.address()); while (central.connected()) { Airflow(); //CRASH delay(100); } Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } } void Airflow() { sensors_event_t temp1; sensors_event_t pressure1; lps1.getEvent(&pressure1, &temp1); sensors_event_t temp2; sensors_event_t pressure2; lps2.getEvent(&pressure2, &temp2); sensors_event_t temp3; sensors_event_t pressure3; lps3.getEvent(&pressure3, &temp3); while (count == 0){ origin1 = ((pressure1.pressure)* 1000); origin2 = ((pressure2.pressure)* 1000); origin3 = ((pressure3.pressure)* 1000); count = 1; } rightLung = ((pressure1.pressure) * 1000) - origin1; stomach = ((pressure2.pressure) * 1000) - origin2; leftLung = ((pressure3.pressure) * 1000) - origin3; if (rightLung < 0) rightLung = 0; if (leftLung < 0) leftLung = 0; if (stomach < 0) stomach = 0; Serial.print(leftLung); Serial.print(" . "); Serial.print(stomach); Serial.print(" . "); Serial.println(rightLung); Serial.println(); // rightLung_Char.setValueLE(rightLung); // leftLung_Char.setValueLE(leftLung); //stomach_Char.setValueLE(stomach); //delay(100); }
I'm not sure what's the problem, I need help with this. Any other idea or another way of doing this?