Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I am working on a small project where I have to read data from different hardware and display it on android app. I am using arduino Uno to get the values from a sensor and a motor and I use a bluetooth module to send the data to the android device. I know how to read data from motor only but not from motor AND sensor. The data displayed on the arduino can be assumed as follows:

Motor: 132

Sensor: 258

Motor: 259

Sensor: 992

So first, we will read the value of the motor then the sensor then the motor and so on. Here is part of the code where I used handler and string builder to read data from the motor. How to modify the code in order to read from BOTH the motor and sensor and keep the updating the values?

Code:

Handler mHandler = new Handler()
    {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case 1:                                                 
                    byte[] readBuf = (byte[]) msg.obj;
                    String strIncom = new String(readBuf, 0, msg.arg1);                 
                    sb.append(strIncom);                                                
                    int endOfLineIndex = sb.indexOf("\r\n");                            
                    if (endOfLineIndex > 0) {                                           
                        String sbprint = sb.substring(0, endOfLineIndex);               
                        sb.delete(0, sb.length());                                      
                        motor.setText(sbprint);             // update TextView
                    }

                    break;
            }
        };
    };
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.