universally applicable BLE (cant read Analog signal)

sigrun
Posts: 5
Joined: Sat Oct 05, 2019 1:47 pm

universally applicable BLE (cant read Analog signal)

Postby sigrun » Thu Oct 24, 2019 8:47 am

Dear forum

I am making a universally applicable BLE for students
The program is running, and transmitting hard coded data (out commented in the program)

The problem is:
The program do not read the Analog values from Pot1, Pot2 and Flag. The corresponding values
t,f,H are all written as 4096 both in serial monitor and in nRF Connect.

Relevant code are center adjusted
i hope some one are able to help

Best regards

Code: Select all

/*********
  
  Global -- Bluetooth Low Energy
  Server -- Master 
*********/
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

//BLE server name
#define bleServerName "dhtESP32"

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "91bad492-b950-4226-aa2b-4ede9fa42f59"

  BLECharacteristic Avar("cba1d466-344c-4be3-ab3f-189f80dd7518", BLECharacteristic::PROPERTY_NOTIFY);
  BLEDescriptor LeftRight(BLEUUID((uint16_t)0x2902));

  BLECharacteristic Bvar("f78ebbff-c8b7-4107-93de-889a6a06d408", BLECharacteristic::PROPERTY_NOTIFY);
  BLEDescriptor Hastighed(BLEUUID((uint16_t)0x2901));

  BLECharacteristic Flag("ca73b3ba-39f6-4ab3-91ae-186dc9577d99", BLECharacteristic::PROPERTY_NOTIFY);
  BLEDescriptor FlagReg(BLEUUID((uint16_t)0x2903));

bool deviceConnected = false;
BLEService *bilservice;

//Setup callbacks onConnect and onDisconnect
class MyServerCallbacks: public BLEServerCallbacks {
  void onConnect(BLEServer* pServer) {
    deviceConnected = true;
  };
  void onDisconnect(BLEServer* pServer) {
    deviceConnected = false;
  }};
                                                                            const int Pot1 = 26;
                                                                            const int Pot2 = 27;
                                                                            const int Pot3 = 14;

                                                                            int t = 0;
                                                                            int f = 0;
                                                                            int h = 0;

void setup() {

  // Start serial communication 
  Serial.begin(115200);

  // Create the BLE Device
  BLEDevice::init(bleServerName);

  // Create the BLE Server
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  BLEService *bilService = pServer->createService(SERVICE_UUID);
  // Create BLE Characteristics and Create a BLE Descriptor
  // Descriptor bluetooth.com/specifications/gatt/viewer?
  // attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml       

    bilService->addCharacteristic(&Avar);
    LeftRight.setValue("Højre/Venstre");
    Avar.addDescriptor(new BLE2902());

    bilService->addCharacteristic(&Bvar);
    Hastighed.setValue("Hastighed");
    Bvar.addDescriptor(new BLE2902());

    bilService->addCharacteristic(&Flag);
    FlagReg.setValue("Flag indhold");
    Flag.addDescriptor(new BLE2902());
  
  // Start the service
  bilService->start();

  // Start advertising
  pServer->getAdvertising()->start();
  Serial.println("Waiting a client connection to notify...");
}

void loop() {
  if (deviceConnected) {
    // Read Potentiometer 1
                                                                            t = analogRead(Pot1);
                                                                            delay (5);
    // Read Potentiometer 2
                                                                            f = analogRead(Pot2);
                                                                            delay (5);
    // Read Flag
                                                                            h = analogRead(Flag);
                                                                            delay (5);

    
    //Notify readings from potentiometers
                                                                            //t=240;
                                                                            Avar.setValue(t);
                                                                            Avar.notify();
                                                                            Serial.print("Højre/Venstre");
                                                                            Serial.print(t);
                                                                            Serial.print("   ");

                                                                            //f=3;
                                                                            Bvar.setValue(f);
                                                                            Bvar.notify();
                                                                            Serial.print("Hastighed");
                                                                            Serial.print(f);
                                                                            Serial.print("   ");
    
                                                                            //h=2000;             //  0 - 65536 der sendes 2 bytes lsb før MSB
                                                                            Flag.setValue(h);
                                                                            Flag.notify();   
                                                                            Serial.print("Flag indhold");
                                                                            Serial.print(h);
                                                                            Serial.println("   ");
    
    delay(1000);
  }
}

sigrun
Posts: 5
Joined: Sat Oct 05, 2019 1:47 pm

Re: universally applicable BLE (cant read Analog signal)

Postby sigrun » Sat Oct 26, 2019 6:38 pm

Solved the problem was:
While operating the BLE the entire Analog to Digital Converter number2 is out of duty
you are bound to use the Analog to Digital Converter number1

By replace the ADC1 GPIO 26, 27, 14 by the ADC2 36, 39, 34 The problem was solved

Who is online

Users browsing this forum: No registered users and 67 guests