Weird value when Attiny84 and Android communicate with ble

55 Views Asked by At

I have an encoding error between Android and ATtiny84[1mhz]. Whenever I sent to float value through ATtiny84, float value changed to weird value in Android.

Android code which I use is ble chat application in google playstore.

Bluetooth module is JDY-10 and connected to ATtiny84. Also one analog sensor is connected to ATtiny84.

I'm trying to send analog sensor data as float to Android using ble.

Connection between JDY-10 and Android is pretty fine.

When I tested it as Uno instead of ATtiny84. It doesn't have an encoding problem including other character value.

How can I solve the encoding problem?

If I want to transmit data without weird value, Do I have to use Manchester library?

below is my code.

ATtiny84

#include <SoftwareSerial.h>  //Software Serial Port

const int FSR_PIN = A2;
const float VCC = 3.3;
const float R_DIV = 100.0;

SoftwareSerial blueToothSerial(7,8);

void setup(){
  Serial.begin(9600);
  pinMode(FSR_PIN, INPUT);
  blueToothSerial.begin(115200);
  delay(2000);
}

void loop(){
  int fsrADC = analogRead(FSR_PIN);

  if (fsrADC != 0){
    float fsrV = fsrADC * VCC / 1023.0;
    float fsrR = R_DIV * (VCC / fsrV - 1.0);

    float force;
    float fsrG = 1.0 / fsrR;

    if (fsrR <= 600) 
      force = (fsrG - 0.00075) / 0.00000032639;
    else
      force =  fsrG / 0.000000642857;

      blueToothSerial.println(String(force));
      blueToothSerial.println();
      Serial.println("Force: " + String(force) + " g");
      Serial.println();

  blueToothSerial.flush();
  delay(500);
  }
}
1

There are 1 best solutions below

0
On

I solved it. I changed Clock Internal 1MHz to 8MHz when burn bootloader. Float and String value are fine now in Android Chat application.