[Solved]Arduino Micro Not Establishing Serial COM with Android Device

Hi all,

I'm having a troubling problem that other users here have experienced as well: my arduino Micro fails to successfully send data to my android device despite running the same, working, tested code as my arduino Uno.

My android application reads data over a serial communication (via a USB On The Go connection) sent by the microcontroller. When I test the application using an Uno, it works perfectly; the cord is plugged in and immediately the power and TX LEDs light up and stay lit for the entire duration it is connected. When I try testing the same application with my arduino Micro (running the same code as the Uno) the power LED remains on and the Android device recognizes that the Micro is connected, but no data is received on the Android and the Micro's TX pin never lights.

Below I will post the microcontroller code and the relevant Android code, written of course in Java.

Relevant arduino code:

void setup(){ Serial.begin(9600); while (!Serial); //wait for Serial Port to initialize } void loop() { Serial.print(80); }

Relevant Android application code:

port.open(connection); port.setParameters(9600, 8, UsbSerialPort.STOPBITS_1,UsbSerialPort.PARITY_NONE); // sets baud rate,databits, stopbits, & parity byte buffer[] = new byte[100]; while (true){ //continuous loop to read serial port numBytesRead = port.read(buffer, 1000); arduinoData = new String(buffer, "US-ASCII"); String raw = arduinoData.substring(0, numBytesRead); Toast.makeText(MainActivity.this, "arduino sent: "+ raw ,Toast.LENGTH_SHORT).show(); }

As mentioned previously, a constant stream of data is read when the arduino Uno is connected, no data is read when the arduino Micro is connected. The TX pin is constantly high on the Uno once plugged in to the Android device, but the TX pin never goes high on the Micro when tested with the exact same code.

Apparently this is a common problem, as seen with posts such as these: http://forum.arduino.cc/index.php?topic=179061.0 http://forum.arduino.cc/index.php?topic=119557.0 (talks about DTR/RTS needing to be set) http://forum.arduino.cc/index.php?topic=243081.30 (talks about Java libraries)

What is causing the Serial.print() from the Micro to never reach my Android device?

while (!Serial); maybe stalled until your application accesses the serial port.

Could be that your program tries to open the serial port and fails, before the Micro is ready.

Solved. The problem is the DTR circuit must be set to high in your processing (host) application. Most programs don't do this by default, hence why the TX light never turns on when initially connected to your computer. Notice once you open a serial monitor, the TX light will turn on and data will begin transferring over serial usb to your computer.

In your processing program you must manually set the DTR circuit to high voltage. The syntax of this will vary depending on your host language and library choice. For me, I conveniently used the method port.setDTR(true);

so my code became: port.open(connection); port.setParameters(9600, 8, UsbSerialPort.STOPBITS_1,UsbSerialPort.PARITY_NONE); port.setDTR(true); byte buffer[] = new byte[100]

I give thanks to the posters in this topic: http://forum.arduino.cc/index.php?topic=143028.0 for helping with the solution.

Can you add [Solved] to the tile of your first post as well, so that others know this thread contains a solution? Also well done for fixing it.