0

NRF8001 not working
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NRF8001 not working

by jmac4790 on Wed Jun 12, 2019 10:31 pm

Hi,
I'm currently trying to get an NRF8001 BLE module to send voltage readings from the analog pins of an Arduino Nano to an android device. I am unable to get the NRF8001 to advertise using the code I have written. The code is getting stuck on the blePeripheral.begin(); line. I am having the same issue with the example sketches as well as with sketches found online. I have bought and tested using a second NRF8001 module as well as another Arduino Nano and Arduino Uno with no luck. Previously this code has been working fine but now it is not advertising hence why i suspected i had broken my original NRF8001 module and tested it using a new one. I have included my sketch below. I'm relatively new to this so it is possible I have missed something. Any help would be much appreciated.

Code: Select all | TOGGLE FULL SIZE
#include <MemoryFree.h>
#include <BLEPeripheral.h>
#include <Wire.h>
#include<SPI.h>

#define BLE_REQ 10
#define BLE_RDY 2
#define BLE_RST 9

BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ,BLE_RDY,BLE_RST);
BLEService Service = BLEService("DDD0");
BLECharacteristic Characteristic = BLEFixedLengthCharacteristic("DDD1", BLERead | BLEWrite | BLENotify,12);

unsigned long previousMillis = millis();    //Stores the last time sensor was read
unsigned long interval = 10000;         //Interval between sensor readings

void setup()
{
  Serial.begin(9600);
  Serial.println(Service.uuid());
  Serial.println(Characteristic.uuid());
  Serial.println(F("Bluetooth Low Energy Sensor Reader"));

  blePeripheral.setLocalName("Pressure Reader"); 
  blePeripheral.setDeviceName("Pressure Reader");

  Serial.println(F("Local name and device name set to Pressure Reader"));
 
  blePeripheral.setAdvertisedServiceUuid(Service.uuid());
  blePeripheral.addAttribute(Service);
  blePeripheral.addAttribute(Characteristic);
  Characteristic.setValue(0);
  Serial.print(F("freeMemory()="));
  Serial.println(freeMemory());
  Serial.println(F("1234"));
  blePeripheral.begin();
  Serial.println(F("blePeripheral.begin() worked"));
}
void loop()
{
  blePeripheral.poll();

  if (millis() - previousMillis >= interval)
  {
    pollSensors();
    previousMillis = millis();
  }
}
void pollSensors()
{
  union {
    float f;
    byte bytes[4];
  } floatUnion;

  union {
    float f;
    byte bytes[4];
  } floatUnion2;

  union {
    float f;
    byte bytes[4];
  } floatUnion3;

 
  float voltage1 = analogRead(A0);
  float pressure1 = voltage1*5/1023;      //Change for correct calibration

  floatUnion.f = pressure1;

  float voltage2 = analogRead(A0);
  float pressure2 = voltage2*2*5/1023;    //Change for correct calibration

  floatUnion2.f = pressure2;

  float voltage3 = analogRead(A0);
  float pressure3 = voltage3*3*5/1023;    //Change for correct calibration

  floatUnion3.f = pressure3;

  byte byteArr[12];

  int ii = 0;
  for(ii= 0 ; ii < 12 ; ii ++ ){
    if(ii<4){
      //pressure1
      byteArr[ii] = floatUnion.bytes[ii];
    }else if((ii>=4)&&(ii<8)){
      //pressure2
      byteArr[ii] = floatUnion2.bytes[ii-4];
    }else if((ii>=8)&&(ii<12)){
      //pressure3
      byteArr[ii] = floatUnion3.bytes[ii-8];
    }
  }
 Characteristic.setValue(byteArr,12);
    Serial.print(F("Pressure 1: "));
    Serial.println(pressure1);
    Serial.println(pressure2);
    Serial.println(pressure3);
}

jmac4790
 
Posts: 5
Joined: Mon Jan 07, 2019 4:31 am

Re: NRF8001 not working

by siddacious on Fri Jun 14, 2019 2:29 pm

Hi jmac4790,

Please help us help you by posting pictures that allow us to clearly see your wiring so we can determine how things are connected.

siddacious
 
Posts: 111
Joined: Fri Apr 21, 2017 3:09 pm

Re: NRF8001 not working

by jmac4790 on Mon Jun 17, 2019 9:37 pm

The connections are
Arduino Nano>>NRF8001
Vin>>Vin
GND>>GND
D2>>RDY
D9>>RST
D10>>REQ
D11>>MOSI
D12>>MISO
Attachments
64260280_1026193444251891_2289123891236306944_n.jpg
64260280_1026193444251891_2289123891236306944_n.jpg (104.15 KiB) Viewed 81 times
64468237_691658217951194_8490125509160599552_n.jpg
64468237_691658217951194_8490125509160599552_n.jpg (94.84 KiB) Viewed 81 times
62169390_1382755995198057_4600244917040578560_n.jpg
62169390_1382755995198057_4600244917040578560_n.jpg (140.25 KiB) Viewed 81 times

jmac4790
 
Posts: 5
Joined: Mon Jan 07, 2019 4:31 am

Please be positive and constructive with your questions and comments.