General Bluno

Help Request for Bluno Mega's BLE connection

userHead Fatih Batuhan.ŞENGÖZ 2023-11-21 19:31:51 151 Views0 Replies

Hello Everyone,

I am a curious mechanical engineer works in aquaculture sector, who has nothing more than wiring in automation/programming.

I bought following items:

Bluno Mega 2560 - Arduino Mega 2560 Compatible - Bluetooth 4.0
Gravity: Analog Dissolved Oxygen Sensor / Meter Kit for Arduino
Waterproof DS18B20 Digital Temperature Sensor for Arduino

and Nextion HMI from somewhere else and in the attached files i created a box to follow up the temp and DO situation in the fish transportation tanks.

I successfully be able to monitor DO and temperature data and send it to HMI with following code: 


I can monitor serial monitor data with USB connection but i need to read serial monitor data by a mobile phone connection.

When I connect with a program generally i get a UUID configuratiob is not correct error.

I would like to connect to a phone and log the incoming data on it. Could someone can assist me for me to overcome this situation.

If there are any alternatives, I am open to suggestions. 

Kind Regards,

Thanks In Advance.


CODE: 

#include <Arduino.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#include <Nextion.h>

#include "NexNumber.h" // Include the library for Nextion's NexNumber component


 

#define DO_PIN A1


 

#define VREF 5000    // VREF (mV)

#define ADC_RES 1024 // ADC Resolution


 

#define TWO_POINT_CALIBRATION 1


 

// Create objects for the DS18B20 temperature sensor

OneWire oneWire(2); // Use digital pin 2 for the DS18B20 sensor

DallasTemperature sensors(&oneWire);


 

// Constants for calibration

#define CAL1_V 131   // mV

#define CAL1_T 25    // °C

#define CAL2_V 1300  // mV

#define CAL2_T 15    // °C


 

const uint16_t DO_Table[41] = {

    14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530,

    11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270,

    9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690,

    7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410};


 

NexNumber n0 = NexNumber(0, 4, "n0"); // Define NexNumber object for DO on page 0, ID 1, and object name "n0"

NexNumber n1 = NexNumber(0, 5, "n1"); // Define NexNumber object for temperature on page 0, ID 2, and object name "n1"


 

uint8_t Temperaturet;

uint16_t ADC_Raw;

uint16_t ADC_Voltage;

uint16_t DO;


 

int16_t readDO(uint32_t voltage_mv, uint8_t temperature_c) {

    #if TWO_POINT_CALIBRATION == 0

        uint16_t V_saturation = (uint32_t)CAL1_V + (uint32_t)35 * temperature_c - (uint32_t)CAL1_T * 35;

        return (voltage_mv * DO_Table[temperature_c] / V_saturation);

    #else

        uint16_t V_saturation = (int16_t)((int8_t)temperature_c - CAL2_T) * ((uint16_t)CAL1_V - CAL2_V) / ((uint8_t)CAL1_T - CAL2_T) + CAL2_V;

        return (voltage_mv * DO_Table[temperature_c] / V_saturation);

    #endif

}


 

void updateDO(void *ptr) {

    uint32_t DO;

    n0.getValue(&DO); // Get the value from the NexNumber object n0

    DO /= 100; // Divide DO value by 100

    // Process the received DO value (if needed)

    // Update DO value in your Arduino code

}


 

void updateTemperature(void *ptr) {

    uint32_t Temperaturet;

    n1.getValue(&Temperaturet); // Get the value from the NexNumber object n1

    // Process the received temperature value (if needed)

    // Update temperature value in your Arduino code

}


 

void setup() {

    Serial.begin(9600);   // Serial monitor

    Serial2.begin(9600);  // Serial communication with the HMI display


 

    n0.attachPop(updateDO); // Attach a callback function for updating DO value

    n1.attachPop(updateTemperature); // Attach a callback function for updating temperature value


 

    // Initialize the DS18B20 temperature sensor

    sensors.begin();

}


 

void loop() {

    // Request temperature data from the DS18B20 sensor

    sensors.requestTemperatures();


 

    // Read the temperature in Celsius from the sensor

    float temperatureC = sensors.getTempCByIndex(0);


 

    // Ensure the temperature reading is valid (not an error value)

    if (temperatureC != DEVICE_DISCONNECTED_C) {

        // Use the temperature reading for DO measurements

        Temperaturet = (uint8_t)temperatureC;


 

        // Read the analog value from the DO sensor on A1

        ADC_Raw = analogRead(DO_PIN);

        ADC_Voltage = (uint32_t)VREF * ADC_Raw / ADC_RES;

        DO = readDO(ADC_Voltage, Temperaturet);

        DO /= 100; // Divide DO value by 100


 

        // Send data to the HMI display to update temperature and DO values as numeric values

        Serial2.print("n1.val=");

        Serial2.print(DO);

        Serial2.write(0xff);

        Serial2.write(0xff);

        Serial2.write(0xff);


 

        Serial2.print("n0.val=");

        Serial2.print(Temperaturet);

        Serial2.write(0xff);

        Serial2.write(0xff);

        Serial2.write(0xff);

       

        // Print the results to the serial monitor

        Serial.print("Temperaturet:\t" + String(Temperaturet) + "\t");

        Serial.print("ADC RAW:\t" + String(ADC_Raw) + "\t");

        Serial.print("ADC Voltage:\t" + String(ADC_Voltage) + "\t");

        Serial.println("DO:\t" + String(DO) + "\t");

    } else {

        // Handle the case where the temperature reading is invalid

        Serial.println("Error: Temperature reading from DS18B20 is invalid.");

        // You can decide how to handle the error, e.g., use a default value.


 

        Temperaturet = 25; // Default temperature in °C

    }


 

    delay(2000); // Update the display every second

}