Arduino + android + jy-mcu = *garbled transmission*

Hey,

I have a Arduino, android, jy-mcu...i am trying to send the status of a bunch of sensors to my android...so as i test i am running the following code on the arduino

void setup()
{
  Serial1.begin(56700);//I have changed the baud already
  Serial1.println("This is a test of the bluetooth to androind system");
}
void loop()
{
}

on the android side, i get bits and pieces of that sentence...sometimes only part...sometimes just mixed up...i am using the Bluetooth Chat example from the android sdk examples...any suggestions

You have to provide a few more details. Which Arduino do you use? Provide a link to the exact hardware you use (datasheet or product page). Have you tried the bluetooth connection first with a notebook? How are the sensors connected to the Arduino?

Arduino Mega 1280 jy-mcu seriale module http://gnosia.anu.edu.au/wiki/CSR_Bluetooth_module I have tested it on 3 different android phone (no pc BT) and i am just writing the Android app first...so i am just sending it a dummy string

.so i am just sending it a dummy string

You're doing that in the setup() routine (which is run once at startup). Does this mean you test the setup by constantly resetting the Arduino to run the setup() again?

I strongly suggest that you test your setup with a notebook first. When it works with the PC you'll get an easier setup with the smartphones because you know that the Arduino part is working.

And for testing: try reducing the baudrate to the default 9600 again.

I have figured out where i am having the issues…i know this is an arduino forum…but it can’t hurt to have a 2nd (and more) set of eyes…it is on the ConnectedThread…here is the code:

        public void run() 
        {
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;
            String mm = "";
            while (true) 
            {
                try 
                {
                    bytes = mmInStream.read(buffer);
                    mm += new String(buffer,0,bytes);
                    if (mm.contains("%"))
                    {
                    	String[] temp = mm.split("%");
                        mHandler.obtainMessage(Main.MESSAGE_READ, bytes, -1, temp[0])
                        .sendToTarget();
                    	if (temp.length > 1)
                        {
                        	mm = "";
                        	for(int i = 1; i < temp.length - 1; i++)
                        	{
                        		mm += temp[i];
                        		if(i + 1 < mm.length() - 1)
                        		{
                        			mm += "+";
                        		}
                        		else
                        		{
                        			
                        		}
                        	}
                        }
                    }
                } 
                catch (IOException e) 
                {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    break;
                } 
                catch (Exception e)
                {
                    Log.e(TAG, "ERROR-RUN", e);
                }
            }
        }

So here is what it is SUPPOSED to do…it is supposed to read in the data from the BlueTooth being sent from my Arduino…the commands are delimited by a +…let say it sends the string “update-1-2-2-1-2-1-1-1-2-2-1-2+”…it will split the string at the +…send the most recent command to the handler…lets say it is being slow and receives 2 commands “update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-2-1-2-1-1-1-2-2-1-2+”…still not a problem…but lets say it hits the end of the buffer half way thur like “update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-”…it is supposed to save the 2nd part and wait for the remainder…but it isn’t saving it…when i use debug mode…it for some reason starts to get to the for loop and then just ends up back at the beginning of the while…truth be told i am NOT good at Java…i am a VB programmer at heart (be my guest to point fingers…lol)…does anyone see any issues with the code???

does anyone see any issues with the code???

Maybe, at least it doesn't do what you think it's doing. The delimiter is not "+" but "%". It reads from the mmInStream into a buffer. As soon as this buffer contains the character "%", it obtains the message contained in the buffer till that character and sends it to some target. Then it reconstructs the split string but using the "+" as the delimiter now (other languages have the join method for this). This is then used for the next run.

you are right…i mixed up my delimiters a bit…it did fix everything…i had to tweek a few other places…but it is all good…here is what i ended up with

         public void run() 
        {
            byte[] buffer = new byte[1024];
            int bytes;
            String mm = "";
            while (true) 
            {
                try 
                {
                    bytes = mmInStream.read(buffer);
                    mm += new String(buffer,0,bytes);
                    if (mm.contains("%"))
                    {
                    	String[] temp = mm.split("%");
                        mHandler.obtainMessage(Main.MESSAGE_READ, bytes, -1, temp[0])
                        .sendToTarget();
                    	if (temp.length > 1)
                        {
                    	    mm = "";
                    	    for(int i = 1; i < temp.length; i++)
                    	    {
                    	        mm += temp[i];
                        		if(i + 1 < temp.length)
                        		{
                        			mm += "%";
                        		}
                        	}
                        }
                    }
                } 
                catch (IOException e) {connectionLost(); break;
                } 
                catch (Exception e) { }
            }
        }