Bangle 2. How to set GPS Serial1 baud rate?

Posted on
Page
of 2
/ 2
Next
  • I've set GPS baud rate to 4800
    Serial1.println('$PCAS01,0*1C');

    Then I tried to set Serial1 baud rate
    Serial1.unsetup();
    Serial1.setup(4800,{rx:31, tx:30});

    but I cannot communicate with GPS any more :(

    Please help!

  • Problem fixed by letting the watch to run overnight until battery discharged completely.
    After reconnect to power and restart all works like a charm!

    However I still need to find a way to safely change Serial1 baud rate.

    Target is to set AT6558 GNSS (aka GPS) to lower power consumption mode by:

    • disabling unnecessary NMEA messages,
    • set output frequency to lower rate for required messages
    • lower down serial baud rate
    • turning off receivers for unused constellations like Baidu and GLONASS (I am in Canada)

    Or opposite, to set GNSS to high performance mode, 10Hz fixes, capturing sats stats, etc.

    Further plan is to start using CSIP CASIC binary protocol instead of NMEA.
    That, theoretically, should also help.

  • Why you think lower serial baud rate saves power? I'd guess the opposite as the communication takes longer so less time to sleep for nrf52 chip. Also the serial itself draws some power when enabled so Serial.unsetup() with setTimeout timed to wake up just before next NMEA sequence comes + Serial1.setup() may save some insignificant power (0.5-1mA). GPS draws much more (10-25mA?)

  • Hi fanoush,
    to be honest, I do not know. I always thought that the higher frequency the more power a device needs. If it is not a case, then why by default the AT6558 is set to 9600 baud, though it can be set up to 115200? The wire between AT6558 and NRF52 is very short, so why not to set baud rate to 115200?
    I have not found specs regarding power consumption for different baud rates. Do you have that? Or I will need to try. But it will not be reliable coz I will measure only time of battery discharge.
    Here is interesting idea to disable RX pin at NRF52 https://devzone.nordicsemi.com/f/nordic-­q-a/66914/uart-current-consumption. But I doubt that will work for our application, because AT6558 sends data to RX, am I right?
    Here in https://infocenter.nordicsemi.com/index.­jsp?topic=%2Fps_nrf52840%2Fchapters%2Fcu­rrent_consumption%2Fdoc%2Ffrontpage.html­ in UART electrical specs there is note "1. High baud rates may require GPIOs to be set as High Drive, see GPIO for more details." , high drive is 14mA there.
    Anyway, if 9600 is ok, we can use it. If higher rates will not cause overconsumption, we can also use it.
    But still, I need a reliable way to set baud rates. :)
    Also I did not want to change BR during functioning, only at beginning of app, i.e. the app reads its usage profile where it will be stated the required baud rate. Then it will run with that.

  • I did the work on the gpssetup app on Bangle 1 for putting the GPS into low power mode.

    I experimented with baud rate but its just sends data at a lower speed it does not put the GPS to sleep between fixes.

    Sending 60 bytes at 4800 baud or 9600 baud is not going to make a lot of difference. All the chip has done has throttled its speed - but its still fully alive. I suspect its the receiver part of these chips that use up the power.

    To get the GPS on Bangle 2 to use less power we need to find the configuration commands to tell the GPS to sleep for X seconds after getting a fix. I have not spent much time on this yet as it took me 30+ hours of trial and error last time and that was with a UBLOX chip and a datasheet in English - so to be honest I've been putting it off. But sooner or later I will have to bite the bullet as the GPS on the B2 flattens the battery pretty quickly.

    The only way to do this is to look at the datasheet and understand the config commands. Then look for example code that uses those commands. I managed to find a number of examples on the UBLOX chip in C and then converted them to run in javascript.

  • This doc http://aitendo3.sakura.ne.jp/aitendo_dat­a/product_img/gps/HT2828Z3G5L/AT6558D.pd­f
    tells that AT6558 uses automatic power mode:

    AT6558 can provide two kinds of low power solution those are automatic low power mode and external control low power mode. Automatic low power consumption mode is that in the non continuous positioning scenarios, the chip positioning, internal procedures automatically turn off the power module, enter standby mode; Wake up automatically and carry on the next position by the timer. According to the different application scenarios, the program needs to customize.

    I am not sure what "the program needs to customize." means.

    There other ways, look at chapter 10.6 Low Power Setting

  • The wire between AT6558 and NRF52 is very short, so why not to set baud rate to 115200?

    A GPS device does not need to send that much data. A fix is only 40-60 bytes and you dont need a fix more than once per second. It is fairly standard to default baud rates on serial devices to 9600. This dates back to the times when we connected terminals to mainframes in the dark ages before USB, the Internet etc etc.

  • I am not sure what "the program needs to customize." means.

    It means you have to send configuration commands to the chip to get it to switch into 'automatic low power mode'. However as is often the case with documents like this they never explicitly tell you how to do it. Its a bit like saying 'to win the game put the king into checkmate', then you give a description of how every piece moves on the board 'The datasheet' and its left up to the user to descover the right sequence of moves.

  • may be internally fix is 60 bytes, but each time the chip issues all NMEA messages to UART(in our case). there is much more bytes.
    There were dozens of meters between terminals and mainframes. That is why 9600. Here is barely 5 mm between chips in the watch. So there should be another reasoning for setting a baud rate - mainly related to power consumption.

    Again, could anybody confirm or oppose that I am configuring the Serial1 correctly, are the pins correct? Should I turn GPS power off before the reconfiguration?
    (I did that previously with other boards and uBlox, and did not have these issues. But there I knew what pins I connected GPS to.)

  • However as is often the case with documents like this they never explicitly tell you how to do it.

    It can be the CAS12 , see page 32 of doc attached to http://forum.espruino.com/comments/16291­862/

  • Serial1.setup(4800,{rx:31, tx:30});

    You have pins switched there, see
    https://github.com/espruino/Espruino/blo­b/master/boards/BANGLEJS2.py#L136
    https://github.com/espruino/Espruino/blo­b/master/libs/banglejs/jswrap_bangle.c#L­2295

    also as seen in second link , Serial1 may be reset back to 9600 in some cases

  • I can't help with the pins etc. To truly measure if the watch is running a lower power level I had an avo connected between the battery and the watch. I could then observe if the current consumption was dropping or not. Gordon might have a B2 with a cracked screen but a functioning GPS that he could maybe send out for tests.

  • Thanks @fanoush - I have a copy of that document from when you posted it but so far have not been able to find anything that looks promising to put it into 'automatic low power mode'. There is discussion of the NAV rate in the CFG-CFG commands.

  • Gordon might have a B2 with a cracked screen but a functioning GPS that he could maybe send out for tests.

    I have previously suggested B5 fitness tracker from SMA aliexpress store because the one I got from there has very same AT6558 GPS but later I got another B5 from aliexpress (different store) and just recently found it has UBX-G7020 which is quite old generation (but may be even better if one doesn't need GLONASS and BDS) but is simply different and more similar to Bangle 1. I also got some EVOLVEO branded B5 too and those are UBX-G7020 too. So getting B5 with AT6558 may be hit and miss.

  • yeah I see the inf.baudRate = 9600; is hardcoded.
    Can we make it configurable may be in next versions?
    Can Serial1 baud rate be changed without GPS bounce?

  • CFG-RATE looks promising. The time between 2 positioning.

    The receiver supports different navigation rates (the default rate is one update per second).
    The navigation rate will directly affect the power consumption.

    How easy is it to send commands to this GPS - will the same code that was used for B1 work ?

  • CAS12. it looks like for the new version of firmware. In current one I never saw LPS, DHV, UTC, INS. Does it understands CAS12?

  • How easy is it to send commands to this GPS

    I hope it should just binary writes to Serial1.

  • Does it understands CAS12?

    just tried with B5 and it does nothing, no pause, nmea still repeats as before
    mine shows at startup these TXT messages

    01,01,02,IC=AT6558-5N-32-1C510800
    01,01,02,SW=URANUS5,V5.1.0.0
    01,01,02,TB=2018-04-18,10:28:16
    01,01,02,MO=GR
    

    and BTW switching serial speed via CAS01,x works for me up to x=5=115200

  • For Bangle 1 someone wrote this code - but I think the format is different for this chip.

    function writeGPScmd(cmd) {
      var d = [0xB5,0x62]; // sync chars
      d = d.concat(cmd);
      var a=0,b=0;
      for (var i=2;i<d.length;i++) {
        a += d[i];
        b += a;
      }
      d.push(a&255,b&255);
      console.log(d);
      Serial1.write(d);
    }
    

    Also the DATASHEET has a different checksum method.

    The checksum is the word-by-word of all data from field 2 to field 5 (including field 2 and >field 5) (1 word includes 4(Bytes) cumulative sum, occupying 4 bytes. The calculation of the >check value can follow the following algorithm:

    ckSum = (class << 24) + (id << 16) + len;
    
    for (i = 0; i <(len / 4); i++){
      ckSum = ckSum + payload [i];
    }
    

    Has anyone implemented this function so that you can send the CAS commands without having to work out the checksum by hand all the time.

  • and BTW switching serial speed via CAS01,x works for me up to x=5=115200

    could you share how you've done this?

  • Has anyone implemented this function so that you can send the CAS commands without having to work out the checksum by hand all the time.

    yes, I've done.

    AT6558.prototype.checksum = function(val) {
      var cs = 0;
      for (const c of val) {
        cs = cs ^ c.charCodeAt(0); //XOR
      }
      return cs.toString(16).toUpperCase().padStart(2­, '0');
    };
    
    AT6558.prototype.sendCommand = function(command) {
      cmd = "P" + command;
      cs = this.checksum(cmd);
      cmd = "$" + cmd + "*" + cs;
      print(cmd);
      Serial1.println(cmd);
    };
    
    AT6558.prototype.setBaudRate = function(v) {
      var br = "";
      switch (v) {
        case 4800:
          br = "0";
          break;
        case 9600:
          br = "1";
          break;
        case 19200:
          br = "2";
          break;
        case 38400:
          br = "3";
          break;
        case 57600:
          br = "4";
          break;
        case 115200:
          br = "5";
          break;
        default:
          return;
      }
      this.baudRate = v;
      sendCommand("CAS01," + br);
    };
    
    
    
  • mine shows at startup these TXT messages

    mine shows same, but mode MO varies

  • could you share how you've done this?

    here https://gist.github.com/fanoush/505a6f44­532e4fdaadef4da5777d7777#file-b5-demo-js­-L272
    so e.g. Serial1.write(gpsformat("PCAS01,5"))

    mine shows same, but mode MO varies

    MO is mode switched by PCAS04, mine has bds off, gps+glonass on

  • fanoush tahnks a lot!
    this PCAS01 part I know how to do. My question was what to do with Serial1 baud rate after/before this CAS01 call.

    Should I do following instead of using standard Bangle.GPSPower() ?

    function MineGPSon(baudRate){
      gpsbuff="";
      Serial1.setup(baudRate,{tx:D30,rx:D31});­
      Serial1.on('data',gpsdata);
      D29.write(1); // adjusted to Bangle2 power pin
    }
    

    MO is mode switched by PCAS04, mine has bds off, gps+glonass on

    I see

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Bangle 2. How to set GPS Serial1 baud rate?

Posted by Avatar for Mark_M @Mark_M

Actions