LibrePilot Forum

Development => Firmware General => Topic started by: jalandub on August 20, 2018, 01:02:21 am

Title: Configure U-blox M8N GPS on a Mac running Crossover with TTL converter
Post by: jalandub on August 20, 2018, 01:02:21 am
I purchased a U-blox GPS (NEO M8N) to use with a racing drone running a CC3D flight controller. I need to configure the GPS before the controller will read it, so I purchased a 3.3V 5V USB to TTL Converter CH340G UART Serial Adapter Module STC. I'm on a Macbook running High Sierra, and I installed U-center through Crossover, which lets me run Windows programs. I cannot get U-center to recognize the GPS though. One light is solid red on my TTL converter and the other flashed red continuously, even after over 15 minutes. Do I need to install some sort of driver for my mac to recognize this through the USB?

GPS: https://us.banggood.com/Wholesale-Warehouse-7M8M-Ublox-M8N-GPS-Module-for-APM-Pixhawk-CC3D-Naze32-F3-Flight-Control-wp-Usa-1078657.html?rmmds=myorder

TTL Converter: https://www.banggood.com/3_3V-5V-USB-to-TTL-Converter-CH340G-UART-Serial-Adapter-Module-STC-p-1232728.html?rmmds=myorder
Title: Re: Configure U-blox M8N GPS on a Mac running Crossover with TTL converter
Post by: TheOtherCliff on August 20, 2018, 03:50:47 am
My experience with uCenter on Windows is that it works well (once you get used to it).

Serial connections need to be set up
TxD <-> RxD
RxD <-> TxD

Does the GPS have a power LED so you know you have power connected right?  There is at least a blue LED that flashes once it starts seeing satellites, but sats aren't needed for uCenter to work, and you may not even get sats indoors.  Are you sure you have 5V power connected to the GPS?

One last thing.  The smallest, cheapest GPSs don't store settings and (if you need non-defaults) must be configured each time you power them up.  In LP, Revo class FC's have auto-config, but CC3D's don't.  If your GPS doesn't store settings then effectively, this means that you must configure the FC to understand the GPS defaults.  I think the GPS defaults to NMEA which CC3D does not support for memory reasons.  I suppose that it is possible to rig it so the GPS stays powered all day (through battery changes) and configure it once at the beginning of the day, but that is a hassle.

Here are some setup instructions I wrote a long time ago.  These are the packet types needed by LP.  Program your GPS, then power it off overnight and see if it still has the same settings a day later.  The day of flying, make sure it still has the same settings too.  If so, you are good to go.
Code: [Select]
< < <   S E T U P   > > >
< < <   S E T U P   > > >
< < <   S E T U P   > > >

You need U-Center app from ublox http://www.u-blox.com/en/evaluation-tools-a-software/u-center/u-center.html
  Note it is a windows app but runs nicely (with some crash from time to time).
  It also runs in Linux Wine.

You also need one of the two following ways of converting USB to serial (TTL level):
  an "FTDI" or similar USB to serial adapter (and adapter cable, from FTDI to GPS)
    FTDI is the brand of the chip on the board, but is used here to mean "FTDI brand USB to serial (TTL level) converter"
    they are less that $3 shipped on eBay
    search this on eBay
      ft232rl usb
    by far the hardest part of starting to use an FTDI is making the cable
      if you can solder, you can make a cable from two standard RC servo cables (with connector)
        six wires side by side, so glue and tape the two servo connectors together to make a single 6x1 connector with wires
      you can use one 5S (6 wire) lipo balance connector in place of the two servo cables
      solder both the 4 wire OP connector, and 4 of the 6 wires of the FTDI connector to the (non-OP) GPS
        use the FTDI connector to program the GPS and the OP connector to fly with the GPS
      another way is to just have all your GPS's have a cable ending in a normal OP connector, the type of connector that plugs in the Revo
        then you need a cable from the 6 pin FTDI but with a female OP connector on the other side
          (the sex that is on the Revo board, not the sex you get with an OP GPS cable)
          so the GPS cable can plug into this end of the adapter cable as if it were a Revo board
          and you can quickly program any GPS that is wired up to be able to plug into a Revo
        you must either truely be a master craftsman solderer or you must find and buy that Revo connector with wires already attached
  a Revo or CC/3D to be (temporarily) used in VCP ComBridge mode
    use the normal GPS port and cable that you will use when flying
    easy cabling, a little more pain when using it, but not as bad as making an FTDI to GPS cable

When making a cable understand that you connect:
  + to + (red power)
  - to - (black ground)
  TxD to RxD
  RxD to TxD

That means the straight through GPS cable won't work till you change it
  If I recall correctly, OP cables are already correct
  Use a pin and a jeweler's loupe to _carefully_ lift the tiny plastic locking flap
    that holds the female metal pin in the plastic hood of the GPS cable
    only move the locking flap barely far enough to slide the pin out or you will break the plastic locking flap
  swap the orange and blue wires this way so they are crossed but leave the red and black wires straight through

Check your GPS specs, but most GPS's can run from 3.3V to 5V or higher
  Revo CC/3D puts out whatever voltage you power it with, that is usually 5V from the ESC BEC's

FTDI's usually have an LED that blinks when the GPS sends data
  that LED works whether the baud rate setting is correct or not

u-center.exe has a similar "blinking light" (really!) in the middle at the very bottom
  mine looks like "={X}= COM1 57400" and the X is the thing that blinks green when there is data
  this also blinks even if the baud rate is wrong

For either the FTDI light or the u-center light
  if you see it blinking about once a second, you are probably back to default settings and have to start over at 9600 baud
  if you see it blinking about 5 times a second, it is probably using your new settings and is talking at the expected baud rate you last saved in the GPS
  it blinks even if the baud rate is wrong
  it blinks whenever data is sent from either side (PC or GPS)
  it does not blink if the wrong port it used
  it does not blink if the GPS is temporarily configured not to send messages (as does happen at one point in programming)
  it may stay on solid if you are sending a lot of data at a lower baud rate

Using u-center, I have not been able to import or export GPS settings to a file.  I have tried WinXP and Linux-Wine.
  That's OK, I just run through the setup each time instead of loading a config file

You can use CC/3D or Revo as a USB to serial converter,
  but for old versions of OP software, you must save to non-volatile (Save, not just Send)
  and reboot the OP board after each baud rate change
  reboot is no longer necessary with 'next' or release following 14.06.01 (e.g. 14.10, 15.01 ...)
    but save to non-volatile and reboot of OP board is still necessary when enabling or disabling the ComBridge mode

I use Linux, but this should work fine in Windows too.

You must make an educated guess as to what your GPS baud rate is currently set at because you must know or guess the baud rate to connect and proceed
  9600 is the factory default for non-OP GPS's, so that is where you should start for a new, non-OP GPS or if the GPS has stopped working
  I have had two different non-OP GPS's loose settings and revert back to 9600.
  OLD OP GPS's used 38400 if I recall correctly.

Once you are running u-center and have selected a port, if you disconnect the USB to serial converter and plug it back in,
  the OS will (may) use a different port because u-center is using the old port, and you will have to determine and use the new port
  this usually means going from com5 to com6 or com1 to com2 or similar in u-center
  get in the habit of looking at the current list of ports if things go wrong, you may just need a different port
    in Windows that will be in the obvious section in Control Panel -> Device Manager
    in Linux just "ls -lrt /dev" from a console prompt (look at last few entries for ttyUSB* for FTDI or ttyACM* for Revo/CC3D)

There are some things that that are less confusing with an FTDI style USB to serial converter than with a Revo or CC/3D.
If you use Revo or CC3D as a USB to serial converter
  you must have openpilotgcs running
  in openpilotgcs you go to Configuration -> Hardware and set USB VCP Function to ComBridge
    speed to whatever, 9600 is the factory default for non-OP GPS's, so that is where you should start
    your port where the GPS is connected (Main or Flexi) will need to be set to ComBridge
    Press Save in the lower right corner
    Reboot the Revo / CC3D to be sure
  you must make the baud rate changes in openpilotgcs, the baud rate setting in u-center does nothing in this setup
    best way for OP version 14.10 or higher is in openpilotgcs System -> Settings -> HWSettings -> ComUsbBridgeSpeed
    and press the green up arrow "Send" (not stored in settings, defaults back to previous on Revo/CC3D reset) at the top of the screen
    you do not have to reboot for OP versions 14.10 and higher
    for OP 14.06 or earlier you need to make the change on the Configuration -> Hardware page
      with the Save button there, and power cycle the Revo / CC3D

In Linux, you may need to become a member of the local "dialout" group (just the first time) (that's the correct, permanent fix) or
  sudo chmod a+rw /dev/ttyUSB* /dev/ttyACM*
  _each_time_ after plugging in your usb to serial adapter (that is connected to the GPS) and before running u-center
  you need to set up .wine/dosdevices/com1 to point to /dev/ttywhatever

If you are already running u-center and unplug the USB to serial converter and plug it back in, it will use a different port

In Linux after installing wine run winecfg and test the sound, then enter these 4 commands from a command prompt
  ln -s /dev/ttyACM0 ~/.wine/dosdevices/com1
  ln -s /dev/ttyACM1 ~/.wine/dosdevices/com2
  ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com3
  ln -s /dev/ttyUSB1 ~/.wine/dosdevices/com4

In Linux after plugging in the FTDI or configuring the Revo or CC/3D run
  ls -lrt /dev
  from a console prompt and look at the last few lines for:
  /dev/ttyACM0 etc are Revo/CC3D
  /dev/ttyUSB0 etc are my FTDI USB to serial converters

Install u-center

< < <   P R O G R A M M I N G   T H E   G P S   > > >
< < <   P R O G R A M M I N G   T H E   G P S   > > >
< < <   P R O G R A M M I N G   T H E   G P S   > > >

Run the previously installed u-center.exe application

Set the com port and baud rate in the drop down receiver menu

Open: View->Messages_View

Changing port speed in the GPS
  UBX->CFG->PRT
  select Target to UART1 and Baudrate 57600.
  Press the Send button (lower left)
  Updates will stop because the baud rate is now wrong
Change your USB to serial converter speed to 57600 to be able to reconnect to the new GPS baud rate
  for FTDT use the u-center drop down Receiver menu to change Baud Rate
  for Revo/CC3D ComBridge, use openpilotgcs System -> Settings -> HWSettings -> ComUsbBridgeSpeed and press the green up arrow (Send)
  You should see updates happening again

Changing protocol
  UBX->CFG->PRT
  set Protocol in and Protocol out to 0-UBX (this filters out any non UBX message)
  Press the Send button (lower left)
  Note that at this point you may not see updates because factory default has only NMEA message enabled and you just turned those off

Define messages to be sent
  UBX->NAV
  right click on each of the following Messages and select "Enable Message"

So for uBlox V7+ you need DOP, PVT, SVINFO
  or for uBlox V6- you need DOP, POSLLH, SOL, STATUS, SVINFO, TIMEUTC, VELNED

At this point you start to see updates again because you have messages again

Reducing the rate for some less important, large messages (actually only SVINFO) per the above table
  SVINFO cosumes a considerable amount of serial bandwidth so it is desirable to reduce its frequency:
  UBX->CFG->MSG
  select "01-30 NAV-SVINFO" from combo, in textbox near UART1 change the 1 to a 10
  to have this message sent once every 10 navigation cycles (so once every two seconds instead of once every 0.2 seconds).
  Press the Send button (lower left)

Changing Measurement rate
  UBX->CFG->RATE
  Set measurement period to 200ms and navigation rate to 1 (thus having 5Hz rate).
  Press the Send button (lower left)

Navigation Model
  to have the best performances it is better to change the default navigation dynamic model.
  UBX->CFG->NAV5
  Select "Airborne < 1g" and "3D Only"
    if you are adventurous and have a very powerful aircraft
    and plan to use that power during GPS enhanced flight (why? :))
    you may want experiment with other models such as Airborne < 2g
    or if you have a surface vehicle, you could try a lot more settings here
  Press the Send button (lower left)

Note that you need to save the settings to non-volatile storage before powering down the GPS.
  This is done with the u-center drop down menu Receiver -> Action -> Save Config
  or in the messages view with UBX->CFG->CFG->Save_current_configuration (select all devices?)
    and press the Send button in the lower left of screen

Before putting everything away, make sure it it is stored permanently
  disconnect in u-center first, drop down menu, Receiver -> Port -> Disconnect
  unplug the GPS (or FTDI or Revo / CC3D)
  plug the GPS back in (or FTDI or Revo / CC3D)
  if using a Revo / CC3D wait for Revo / CC3D to boot up
    and then make sure the baud rate is set right
    see the setup section for how to set the OP board ComBridge baud rate in openpilotgcs
  in u-center, look for updates coming from the GPS
  both FTDI and u-center (!) have a light that blinks when the GPS sends data
    as described in the setup section
    that light blinks even if the baud rate is wrong, as long as you are using the right port and the GPS is sending data
    if you see it blinking about once a second, you are back to default settings and probably have to start over at 9600 baud
    if you see it blinking about 5 times a second, it is probably using your new settings

Configure GPS correctly in openpilotgcs
  you will have your GPS connected to either the Main Port or the Flexi Port on the Revo or CC3D
  under the appropriate port in openpilotgcs -> Configuration -> Hardware set to
    (*) Port = GPS
    Speed    = 57600
    Protocol = UBX
  press Save in the lower right corner 

Further reading if interested

In addition to DOP and SVINFO, if you have a GPS Generation 7 or higher (e.g. Ublox NEO-7M) you can use the single PVT message
  for generation 6 or lower you must have POSLLH, SOL, STATUS, TIMEUTC, and VELNED messages instead of the single PVT message
  You must use those 5 additional messages for Gen 6 or lower as Gen 6 and lower don't have the PVT message

Here are the message rates
  Note the following numbers are updates per second, but that is not the way you configure it in u-center
  in u-center it is a cycle skip number, so 5 means do it every 5th cycle
  so the 5s are entered as 1 and the 1s are entered as 5
  you only need to change one, SVINFO (and VER when that becomes available)
    the rest are already correct by default

Msg     old    V8&V9.old   V9.new
---     ---    ---------   ------
DOP     10?        5         5
POSLLH  10?        5         5     or these old 5 messages
PVT      .         .         5     this new 1 message
SOL     10?        5         5     or these old 5 messages
STATUS   .         5         5     or these old 5 messages
SVINFO  10         1         1
TIMEUTC 10         5         5     or these old 5 messages
VELNED  10?        5         5     or these old 5 messages
VER      .         .         1

Reading ubx.c
Looks like these are OpenPilot defined
op_sys, op_mag

You need all of these (some more important than others):
nav_dop
nav_svinfo
mon_ver

You can use this one (not available on e.g. Neo 6M? and earlier)
nav_pvt

Or these four (per the code, note the nav_sol)
nav_posllh
nav_velned
ubx_nav_sol
nav_timeutc


Here are the messages that OP uses with NMEA GPS's
NMEA strings that we parse
Skip first two character, allow GL, GN, GP...
THEN
        .prefix  = "GGA",
        .prefix  = "VTG",
        .prefix  = "GSA",
        .prefix  = "RMC",
#if !defined(PIOS_GPS_MINIMAL)
        .prefix  = "ZDA",
        .prefix  = "GSV",
#endif // PIOS_GPS_MINIMAL

Go into UBX -> CFG -> MSG and set the cycle multiplier to zero for all the unused NMEA messages
Set the cycle multiplier for GSV to 10 because it is the same as the UBX SVINFO message
Set the cycle multiplier for the other messages in the above list to 1

Note that the code doesn't work well with NMEA right now.
You will get a large oscillation in the EKF if you use NMEA.