Android (Studio) + Dragino LA66 USB

Summary

Issue: Android app fails to transmit LoRa signals to an Arduino board via Dragino LA66 USB device.
Key Symptoms:

  • App recognizes USB device but no data appears on Arduino.
  • Serial communication code (sendComm) does not reliably transmit data.
    Root Cause: Incorrect serial port configuration and missing flow control for LoRa communication.

Root Cause

  • Baud Rate Mismatch: The Arduino and Dragino LA66 may not be configured to the same baud rate.
  • Flow Control Ignored: LoRa communication requires precise timing and flow control, which is missing in the current implementation.
  • AT Command Handling: AT commands are sent without verifying the device’s readiness or response.

Why This Happens in Real Systems

  • Hardware-Software Disconnect: USB-to-serial communication requires strict adherence to hardware specifications.
  • Asynchronous Communication: LoRa devices often require acknowledgment or delay between commands, which is not implemented.
  • Driver Limitations: The USB serial driver may not fully support the Dragino LA66’s specific requirements.

Real-World Impact

  • Drone Control Failure: Inability to transmit commands results in loss of drone control.
  • Debugging Overhead: Time spent troubleshooting hardware-software integration delays development.
  • Safety Risks: Unreliable communication can lead to drone malfunctions or crashes.

Example or Code

private void openSerialPort(UsbDevice device) {
    UsbDeviceConnection connection = usbManager.openDevice(device);
    UsbSerialDriver driver = UsbSerialProber.getDefaultProber().probeDevice(device);
    if (driver == null) return;

    UsbSerialPort port = driver.getPorts().get(0);
    try {
        port.open(connection);
        port.setParameters(
            57600, // Correct baud rate for Dragino LA66
            8,
            UsbSerialPort.STOPBITS_1,
            UsbSerialPort.PARITY_NONE
        );
        port.setDTR(true); // Enable hardware flow control
        port.setRTS(true);
        serialPort = port;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public static void sendComm(String msg) {
    if (serialPort == null || !serialPort.isOpen()) return;
    byte[] msgBuff = (msg + "\r\n").getBytes(); // Add newline for AT commands
    try {
        serialPort.write(msgBuff, 1000); // Timeout for write operation
        Thread.sleep(500); // Wait for device response
    } catch (Exception e) {
        e.printStackTrace();
    }
}

How Senior Engineers Fix It

  • Verify Hardware Settings: Ensure baud rate, parity, and stop bits match the device specifications.
  • Implement Flow Control: Use hardware (RTS/CTS) or software flow control for reliable communication.
  • Command Acknowledgment: Add logic to wait for device responses after sending AT commands.
  • Error Handling: Check for null ports and handle exceptions gracefully.

Why Juniors Miss It

  • Lack of Hardware Knowledge: Juniors often overlook hardware-specific requirements like baud rate and flow control.
  • Assumptions Over Verification: Assuming default settings work without checking device documentation.
  • Incomplete Testing: Not verifying device responses or debugging at the hardware level.

Leave a Comment