c++unicodearduinomojibake

i can't find what is problem. mojibake, unicode


we're making keyboard with five sensor and we have problem with mojibake

if we click sensor 'a' five time, there should be five 'ㄱ'

but there are mojibake like attached picture.

we think this problem is related with unicode but can't find what the exact probelm is

please answer what is problem. thank you

#include <SoftwareSerial.h>
#include<Wire.h>

#define BT_RXD 8
#define BT_TXD 7

SoftwareSerial bluetooth(BT_RXD, BT_TXD);

int SensorPin1 = A0;
int SensorPin2 = A1;
int SensorPin3 = A2;
int SensorPin4 = A3;
int SensorPin5 = A4;

const int MPU_addr=0x68;  
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup()
{
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  
  Wire.write(0);     
  Wire.endTransmission(true);
  Serial.begin(9600);
  bluetooth.begin(9600);
}

void loop()
{
  int SensorReading1 = analogRead(SensorPin1);
  int SensorReading2 = analogRead(SensorPin2);
  int SensorReading3 = analogRead(SensorPin3);
  int SensorReading4 = analogRead(SensorPin4);
  int SensorReading5 = analogRead(SensorPin5);

  int FSR1 = map(SensorReading1, 0, 1024, 0, 255);
  int FSR2 = map(SensorReading2, 0, 1024, 0, 255);
  int FSR3 = map(SensorReading3, 0, 1024, 0, 255);
  int FSR4 = map(SensorReading4, 0, 1024, 0, 255);
  int FSR5 = map(SensorReading5, 0, 1024, 0, 255);

  Wire.beginTransmission(MPU_addr);   //-32768~32767
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers

  AcX=Wire.read() <<  8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read() <<  8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read() <<  8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read() <<  8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read() <<  8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read() <<  8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read() <<  8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.println(AcZ);
  //Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  //Serial.print(" | GyX = "); Serial.print(GyX);
  //Serial.print(" | GyY = "); Serial.print(GyY);
  //Serial.print(" | GyZ = "); Serial.println(GyZ);

  if(FSR1 > 100)
  {
    //Serial.println("ㄱ");
    bluetooth.write("ㄱ");
  }

  if(FSR2 > 100)
  {
    //Serial.println("ㄱ");
    bluetooth.write(FSR2);
  }

  if(FSR3 > 100)
  {
    //Serial.println("ㄱ");
  }

  if(FSR4 > 100)
  {
    //Serial.println("2");
  }

  if(FSR5 > 100)
  {
    //Serial.println("ㄱ");
    bluetooth.write("ㄱ");
  }
  if (bluetooth.available()) 
  {
    //Serial.write(bluetooth.read());
  }

  if (Serial.available()) 
  {
    //bluetooth.write(FSR);
  }

  delay(333);
}

enter image description here


Solution

  • What you are sending is bytes, and the exact bytes you are sending depends on the encoding of your editor. When your capston application receives those bytes, it tries to interpret them according to the encoding of capston. No idea what it might be. In any case, what you need to do is to send utf-8 data from the arduino, and ensure that the capston application decodes utf-8 data.