Allocate multiple data in separate bytes to send bluetooth apk

#include <Wire.h>                     
#include <SPI.h>                      
#include <Adafruit_GFX.h>             
#include <Adafruit_SSD1306.h>        
#define OLED_RESET 4               
#include <SoftwareSerial.h>
Adafruit_SSD1306 display(OLED_RESET);  
SoftwareSerial BTserial(0,1);
int analogInput = A0;                 
char company[]="ABCDEFG Technologies";
char unit[]="dB";                 

const int sampleWindow = 50;          
unsigned int sample;
const int noise=A1;


void setup(){
  BTserial.begin(9600);
  Serial.begin(9600);
  pinMode(analogInput, INPUT);                              
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);               
  display.clearDisplay();                                 
}

void loop(){
  
  unsigned long startMillis = millis();                    
  unsigned int PeaktoPeak = 0;                           
  unsigned int SignalMax = 0;
  unsigned int SignalMin = 1024;

  while ( millis() - startMillis < sampleWindow ){

    sample = analogRead(analogInput);
    if (sample < 1024) {

      if (sample > SignalMax){

        SignalMax = sample;                                
      }

      else if (sample < SignalMin){

        SignalMin = sample;                                
      }
    }
  }

  PeaktoPeak = SignalMax - SignalMin;                      
  float MeterValue = ( PeaktoPeak * 3.3 /675) * 100;   
  int change = map(MeterValue, 0, 1023, 0, 255);
  analogWrite(noise, change); 

  Serial.println(MeterValue);
  BTserial.println(MeterValue);
BTserial.println(company);
BTserial.println(unit);
    char temp_buff[5]; 
    char temp_disp_buff[11] = "Sound:";
    dtostrf(a,2,1,temp_buff);
    strcat(temp_disp_buff,temp_buff);
   
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println(temp_disp_buff);
    display.display();

delay(2000);
}
                                                           

Hi,
I'm doing project in digtal sound sensor MAX 9814 and sending 32byte data to android apk via bluetooth. I need to more specific in byte allocation because i'm sending three type of data One is Company name( char type), second sensor data (float type) and sound unit dB( char type). So need to allocate separate byte location for three data. Kindly help me to allocate separate byte location data with code.

Total Data to transfer = 0 to 256 bytes
Company name: ABCDEFGH Technologies(24bytes)
Decibel Value: 120.00(5bytes)
Decibel Unit: dB(2bytes)

for example:
0-24bytes : Company name(ABCDEFGH Technologies)
25-30bytes: Decibel Value(Float value-123.23)
31-32bytes : Unit name(dB)

Your code does not compile.

dtostrf(a, 2, 1, temp_buff);
'a' was not declared in this scope

SoftwareSerial BTserial(0, 1);
Why are you using software serial on hardware serial pins?
What platform are you using?

Please explain more about the concern for 255 bytes. Your package is 32 bytes of ascii data.

0-24bytes : Company name(ABCDEFGH Technologies)
25-30bytes: Decibel Value(Float value-123.23)
31-32bytes : Unit name(dB)

Please explain more about the "android apk" at the receiving end.

I'm sorry about 255 byte just for example i've said like that , i need to send 32 byte ascii data to android app via bluetooth as byte .

i need to send 32 byte ascii data to android app via bluetooth as byte .

BTserial.println(MeterValue);
BTserial.println(company);
BTserial.println(unit);

The use of .println will send all the the data in bytes as ascii values.

I would develop your program by starting with a standard, bluetooth terminal app for Android. The you can separate the issues of Arduino code from any custom Android code you write.

I recommend Kai Morich's Serial Bluetooth Terminal.

thank you so much for your suggestion

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.