3

I am working on a simple app for the android OS. It needs to reliably communicate with the Arduino Uno. I used the USBSerialDriver with AndroidStudio. I'm getting data but there are dropped characters. my code below. I get the same result when i use apps available on Google Play. Except for one app that does work the Arduino-Communicator. The only thing i guess is that in the Arduino-Communicator they set some setup bytes to the driver to configure the Arduino interface. Is this possible using the libraries i currently use below?

        // Get UsbManager
        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

        // Find the first available driver.
        UsbSerialDriver arduinoDrv = UsbSerialProber.acquire(manager);


        // setup serial port
        if (arduinoDrv != null) {
            // establish connection
            try {
                arduinoDrv.open();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                arduinoDrv.setBaudRate(9600);
            } catch (IOException e) {
                e.printStackTrace();
            } 
            try {
                numBytesRead = arduinoDrv.read(rxBuff, 500);
            } catch (IOException e) {
                e.printStackTrace();
            }

            rxBuff[numBytesRead]=0;

this is the code in the Arduino-Communicator. I just don't know if it will help the drop packet and how to implement it using the USBSerialdriver above.

    // Arduino USB serial converter setup
    // Set control line state
    mUsbConnection.controlTransfer(0x21, 0x22, 0, 0, null, 0, 0);
    // Set line encoding.
    mUsbConnection.controlTransfer(0x21, 0x20, 0, 0, getLineEncoding(9600), 7, 0);

thanks!

dsolimano
  • 8,870
  • 3
  • 48
  • 63
CEO Hack
  • 31
  • 2

0 Answers0