마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 아두이노 통신

0 추천

안녕하세요 안드로이드 연습 중인 학생입니다.

인터넷 및 안드로이드 API를 읽으면서 구성을 짜놨는데. 아두이노에서 보내는 신호를 안드로이드가 

원하는대로 읽히지 않습니다

(아두이노) 123 -> 안드로이드(1), (23) 으로 불러옵니다.

(아두이노 코딩)

if(bluetooth.available())
  {
   Serial.print((char)bluetooth.read());
  } 
 f(Serial.available())
{
  bluetooth.write(Serial.read());
  delay(1);
}

(안드로이드 코딩)

public void run() {
    Log.e(TAG, "BEGIN mConnectedThread");
    int bytes ;
    byte[] buffer = new byte[1024];
    // Keep listening to the InputStream while connected
    while (true) {
        try {
            // Read from the InputStream
            bytes = mmInStream.read(buffer);
            Log.e(TAG, "byte 데이터 길이 : => " + bytes);
            mHandler.obtainMessage(MainActivity.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
            Log.e(TAG, "-------------- obtainMessage clear ---------------: ");;
            // Send the obtained bytes to the UI Activity
        } catch (IOException e) {
            Log.e(TAG, "disconnected", e);
            connectionLost();
            // Start the service over to restart listening mode
            BluetoothChatService.this.start();
            break;
        }
    }
}
핸들러 부분 
case MESSAGE_READ:
    byte[] readBuf = (byte[]) msg.obj;
    String readMessage = new String(readBuf);
    Log.e("TAG", "" + readMessage);
    mConversationArrayAdapter.add(mConnectedDeviceName+":  " + readMessage);
    break;

가장 이상적으로 하고 싶은거는 String 형태로 변경된 byte 자료를 인트형으로 변경하여 센서값을 읽어와 안드로이드 내에서 정보를 처리하고 싶은건데 계속 끊어져 들어옵니다.

 

해결방법 부탁드립니다. ㅠㅠ 

익명사용자 님이 2017년 3월 2일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...