Go Down

Topic: Problem with getting single bytes from an Android app through Bluesmirf silver (Read 2023 times) previous topic - next topic


I have an Android app that I've written to send individual bytes to my Arduino board.  I have a Bluesmirf silver connected to my Arduino on ports 0 and 1.  The problem I'm having is that the Arduino seems to always be receiving 255.  Currently I'm doing serial.read into an int.  Is there another type of object that I should send the serial.read to?  On the Android side I'm using the outputstream.write(int) method.  Basically the Android app has a touch area that I pull x and y coordinates from and two button press events on the volume buttons.  The x coordinates are between 0 and 90, the y coordinates 91 and 180, the volume up sends 181, and the volume down sends 182.  But no matter what key I press the Arduino seems to be getting 255.  I'm not sure right now which end the problem is on.  It could be that the Android app is not dropping the significant bits like I expect, thus sending all 1s.  It could also be that the Arduino sketch has the wrong type for the byte.  I would post the testing sketch I'm using but I'm not at home right now.  Here is a link though to a post I made about the Android app with that code.  I would appriciate any help.



Try sending and receiving a byte so that you do not get into the negative number issues with integer. (Two's complement!)


I'll try changing the varible type on the Arduino end to a byte.  But the outputstream.write(int) on the Android is the only way apparently to send true bytes.  This is because Java doesn't use true bytes.  Java's bytes are apparently 16 bits and signed.


Ok I figured it out. The problem wasn't with my Android code. Although I did decide to wrap the outputstream with dataoutputstream so I could use the writebyte method. The problem was on the receiving end (the Arduino). The baud rate that the Arduino was listening to the BlueSmirf was 9600. I had read somewhere that Sparkfun set all their BlueSmirfs to 9600 before shipping. At least in my case that wasn't true. I set the baud rate to 115200 and it started working fine.  So I can now send individual bytes from the Android device to my Arduino.

Go Up