정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

진동센서를 통해 블루투스로 값을 받는데 ?? 와같은 쓰레기 값이 출력됩니다.
이동우 | 2019-10-16

아두이노 우노 자체에서는 시리얼모니터에 카운터가 되는데 이걸 앱인벤터에서 블루투스를 이용하여 최종적으로는 앱으로 카운터를 나타내려고 합니다. 그런데 블루투스 연결되서 앱을보면 ? 이라고 쓰레기값이 입력됩니다. 쓰레기값말고 카운터가 되어야하는데 어떻게하면 좋을까요..?

 

#include <SoftwareSerial.h>
int LED_Pin = 13;
int LED_Pin1 = 12;
int LED_Pin2 = 11;

int vibr_Pin = 5;
int vibr_Pin1 = 6;
int vibr_Pin2 = 7;
byte measurement;

int RxPin=2;
int TxPin=3;

int key=0, cnt=0;

SoftwareSerial BTSerial(RxPin,TxPin);

void setup(){
  Serial.begin(9600);
  BTSerial.begin(9600);
  pinMode(LED_Pin, OUTPUT);
  pinMode(vibr_Pin, INPUT);  
  pinMode(LED_Pin1, OUTPUT);
  pinMode(vibr_Pin1, INPUT); 
  pinMode(LED_Pin2, OUTPUT);
  pinMode(vibr_Pin2, INPUT);//set vibr_Pin input for measurment
   //init serial 9600
 // Serial.println("----------------------Vibration demo------------------------");
  DDRB =0xFF;//출력모드
  PORTB = 0x00; //LED OFF
 
  DDRD  = 0x00; //D포트 입력모드
  PORTD = 0xFF; //PULL UP

 


 
}
void loop(){

  measurement = TP_init();
 


   // Serial.println(key);
    //delay(1);
   if(measurement == 0) key=0;
   //Serial.println(key);
   
  if (measurement == 32){  //비교 2개 ==
    digitalWrite(LED_Pin, HIGH);
    //sprintf(measurement,"d",measurement);
    key = 1;
    //BTSerial.print(key);
    //Serial.println(key);
  
  }
   else{
       digitalWrite(LED_Pin,LOW);
   }
  if (measurement == 64){
    digitalWrite(LED_Pin1, HIGH);
    //sprintf(measurement,"d",measurement);
     key = 2;
    //BTSerial.print(key);
    //Serial.println(key);

  }
   else{
     digitalWrite(LED_Pin1,LOW);
  }
  if (measurement == 128){
    digitalWrite(LED_Pin2, HIGH);
   // sprintf(measurement,"d",measurement);
    key = 3;
    //BTSerial.print(key);
    //Serial.println(key);

  }
   else{
     digitalWrite(LED_Pin2,LOW);
  }

  Serial.println(cnt);
  if(key !=0) cnt=cnt+1;
}


long TP_init(){
  int i=0;
    byte sensor = 0xff; //진동없음
   for (i=0;i<200;i++){
   sensor &= PIND;  //5,6,7
  }
 
  measurement = ~(sensor + 2);
  return measurement;
}

 

< 앱인벤터>

 


첨부 이미지 

프로필사진

판다마니아 2019-10-17 10:38:33

앱인벤터에서 receiveText numberOfByte 의 수를 고정값 4로 하지 마시고 블루투스 클라이언트 받을 수 있는 크기 변수로 넣어보세요.

 

4로 고정되어 있어 받는 데이터가 잘리거나 부족해서 제대로 인식 못하는거일수도 있습니다.

이전글   |    Blynk 잘 아시는분 있나요?? 2019-10-14
다음글   |    아두이노 오류 해결 ㅠㅠ 2019-10-16