1

I am starting to play with the Adafruit Ultimate GPS Breakout v3 with Android Things v1.0.1 on the Raspberry Pi 3. I am using the code here: Github Contrib Drivers to try and get the GPS co-ordinates but I am not having any luck so I'm hoping somebody could point me in the right direction.

The GpsModuleCallBack() isn't showing anything in the log.

Here is my code:

MainActivity.java

public class MainActivity extends Activity {

private static final String UART_DEVICE_NAME = "UART0";

UartDevice mDevice;
NmeaGpsModule mGpsModule;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle("GPS Test");

    PeripheralManager gpiolist = PeripheralManager.getInstance();
    List<String> portList = gpiolist.getGpioList();
    if (portList.isEmpty()) {
        Log.w(TAG, "No GPIO port available on this device.");
    } else {
        Log.i(TAG, "List of available ports: " + portList);
    }

    PeripheralManager uartlist = PeripheralManager.getInstance();
    List<String> deviceList = uartlist.getUartDeviceList();
    if (deviceList.isEmpty()) {
        Log.w(TAG, "No UART port available on this device.");
    } else {
        Log.i(TAG, "List of available devices: " + deviceList);
    }


    // Attempt to access the UART device
    try {
        PeripheralManager gpsmanager = PeripheralManager.getInstance();
        mDevice = gpsmanager.openUartDevice(UART_DEVICE_NAME);
        Log.i(TAG, "Accessed " + UART_DEVICE_NAME );
    } catch (IOException e) {
        Log.w(TAG, "Unable to access UART device", e);
    }

    try {
        mGpsModule = new NmeaGpsModule(
               "UART0", 9600, 1.8f);

        mGpsModule.setGpsModuleCallback(new GpsModuleCallback() {
            @Override
            public void onGpsSatelliteStatus(GnssStatus status) {
                Log.i(TAG, "Status: " + status.getSatelliteCount());
            }

            @Override
            public void onGpsTimeUpdate(long timestamp) {
                Log.i(TAG, "Time: " + timestamp);
            }

            @Override
            public void onGpsLocationUpdate(Location location) {
                Log.i(TAG, "Location: " + location.getLatitude() + location.getLongitude());
            }

            @Override
            public void onNmeaMessage(String nmeaMessage) {
                Log.i(TAG, "NMEA Message: " + nmeaMessage);
            }
        });

    } catch (IOException e) {
        // couldn't configure the gps module...
    }

    // Close the GPS module when finished:

    try {
        mGpsModule.close();
    } catch (IOException e) {
        // error closing gps module
    }

}

@Override
protected void onDestroy() {
    super.onDestroy();

    if (mDevice != null) {
        try {
            mDevice.close();
            mDevice = null;
        } catch (IOException e) {
            Log.w(TAG, "Unable to close UART device", e); }
    }
}
Faz
  • 63
  • 11
  • Raspberry pi 3 has some issue with UART, so: 1) check your wires connection; 2) take a look at [this](https://stackoverflow.com/a/41497138/6950238). – Andrii Omelchenko Jun 06 '18 at 14:42
  • @AndriiOmelchenko Hi Andrii, I have already tried the solutions from the link. It is wired directly to the Pi, so no TTL cable. could this be a factor? – Faz Jun 07 '18 at 21:48

1 Answers1

1

The Android Things drivers open the Peripheral ports for you, so you should not be accessing the UART directly from PeripheralManager AND using the driver. Remove the following block of code:

try {
    PeripheralManager gpsmanager = PeripheralManager.getInstance();
    mDevice = gpsmanager.openUartDevice(UART_DEVICE_NAME);
    Log.i(TAG, "Accessed " + UART_DEVICE_NAME );
} catch (IOException e) {
    Log.w(TAG, "Unable to access UART device", e);
}

Most likely, the next block of code in your example is throwing an exception because it's failing to open the UART (it can't be opened twice) but the empty catch block is swallowing it up:

try {
    mGpsModule = new NmeaGpsModule(
           "UART0", 9600, 1.8f);
    ...

} catch (IOException e) {
    // couldn't configure the gps module...
}

You should probably add a Log statement there as well just to make sure the there's no exception.

devunwired
  • 62,780
  • 12
  • 127
  • 139
  • Hi, I am unable to test until Monday as I'm away but I do like to have a little logged check before things get started. Could I close the connection then re-open for the driver or should I just get rid of the PM check? Also, theres no exception thrown. Nothing happens at all after the PM logs are displayed. – Faz Jun 07 '18 at 21:54
  • Sorry, I've just realised about the empty catch. Now added a log. Will test Monday. – Faz Jun 07 '18 at 22:22
  • Thanks Devunwired, I removed the uartlist and gpsmanager PeripheralManagers then it started showing the NMEA messages. Now all I need to do is get it to display Lat, Long and Address. Looks like I've got loads of reading to do. – Faz Jun 11 '18 at 13:21