【问题标题】:Weird value when Attiny84 and Android communicate with bleAttiny84 和 Android 与 ble 通信时的奇怪值
【发布时间】:2017-11-29 00:03:38
【问题描述】:

我在 Android 和 ATtiny84[1mhz] 之间存在编码错误。每当我通过 ATtiny84 发送到浮点值时,浮点值在 Android 中变为奇怪的值。

我使用的 Android 代码是 google playstore 中的 ble 聊天应用程序。

蓝牙模块为 JDY-10,连接 ATtiny84。 一个模拟传感器也连接到 ATtiny84。

我正在尝试使用 ble 将模拟传感器数据作为浮点数发送到 Android。

JDY-10 和 Android 之间的连接非常好。

当我将它作为 Uno 而不是 ATtiny84 进行测试时。它没有编码问题,包括其他字符值。

如何解决编码问题?

如果我想传输没有奇怪值的数据,我必须使用曼彻斯特库吗?

下面是我的代码。

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);
  }
}

【问题讨论】:

    标签: android encoding arduino bluetooth-lowenergy attiny


    【解决方案1】:

    我解决了。 刻录引导加载程序时,我将时钟内部 1MHz 更改为 8MHz。 浮点数和字符串值现在在 Android 聊天应用程序中很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多