Bangle 2. How to set GPS Serial1 baud rate?

Posted on
Page
of 2
Prev
/ 2
  • I think you still have rx,tx pins switched there.

    Maybe you can let the bangle libs turn it on and off as it is and then if you really want change speed you could do it after it is turned on. And then set it back to 9600 before turning it off.

    As for saving power I'd say changing speed has very small impact so it is not worth it. Turning serial off and on based on expected NMEA frequency would save much more than changing speed and yet it is still insignificant when comparing to power draw of gps itself.

    Too bad it is below zero outside where good gps signal is. Otherwise I could charge b5 fully and measure time until it dies (or reaches some low battery voltage) with gps fix and changed nmea frequency (e.g. from 1s to 5s), and then also with turning serial off between those 5s intervals. Without having a fix it is IMO worthless excercise as the gps is probably not sleeping until getting a fix.

  • The pins I've got from here https://hackaday.io/project/175577-hacka­ble-nrf52840-smart-watch

    AT6558 runs in automatic power save mode, I've posted link here http://forum.espruino.com/comments/16320­287/. Although they claim it can be controlled externally.

    set it back to 9600 before turning it off.

    that may not happen if the application fails for some reason.

    As I mentioned, there can be other use cases where the GPS should run "full speed", like 10 fixes/sec, and issuing many NMEA messages per fix (i.e. RMC 10Hz, GSA 1Hz, GSV 0.1Hz). Here I think it would require to increase baud rate.

    I think that Serial1 can be switched from one baud rate to another without need to do anything with the GPS port, or turning off the GPS. Like, first step - we issue CAS01 to change BR of the GPS, second step we reset Serial1 to this BR. I remember I did this way with uBlox and other arduino-like boards. But when I tried it with Bangle2, it did not work. What I've done wrong?

    Serial1.println('$PCAS01,0*1C');
    Serial1.unsetup();
    Serial1.setup(4800,{tx:30, rx:31});
    

    May be after that I need to call
    Serial1.on('data',gpsdata);
    ?
    then I suspect I will need to replace Bangle.GPSpower with my code completely.

  • What I've done wrong?

    Did you try switching rx ,tx pins? (3rd and last reminder ;-)

  • :) OMG! Yes. The pins were switched! Because they are switched here https://hackaday.io/project/175577-hacka­ble-nrf52840-smart-watch

    Now I can set baud rate of NRF UART. But cannot control AT6558.
    For some reason. Looks like I need to drain the battery again.

    Reading about AT6558 http://www.icofchina.com/d/file/xiazai/2­016-12-05/b1be6f481cdf9d773b963ab30a2d11­d8.pdf ...
    ON_OFF does not turn its power off completely, when it is OFF it will close the RF circuit and baseband circuit, then enter the state of low power consumption.
    That is why it remembers settings even after I stop the watch completely and then restart it.
    Also AT6558 may be connected in battery backup mode. If so GPS will remember settings until watch battery drained.

  • :) OMG! Yes. The pins were switched! Because they are switched here https://hackaday.io/project/175577-hacka­ble-nrf52840-smart-watch

    The info there is correct, uart is confusing, you typically connect (gps) TX to (nrf) RX, and vice versa.

  • yes, confusing.
    Anyway. after discharge, it works again with 9600. However once I switch to another frequency, GPS produces output, but does not accept input.

    Bangle.setGPSPower(1,"TST");
    Bangle.on("GPS-raw", function(m){print(m);});
    // I see output
    
    Serial1.println("$PCAS01,2*1E");
    Serial1.setup(19200,{rx:D30, tx:D31});
    // I see output
    
    Serial1.println("$PCAS01,1*1D");
    Serial1.setup(9600,{rx:D30, tx:D31});
    // no output, it looks like CAS01,1 was not accepted
    
    Serial1.setup(19200,{rx:D30, tx:D31});
    // I see only output again.
    

    What am I doing wrong again?
    @fanoush, were you able to switch baud rates back and force?

  • I tried CAS12 and got no response. And $GNGGA continue to be output. I would expect it to stop for 30 seconds using:

    >cas12();
    $PCAS12,30*2D
    =undefined
    $
    

    I'd like to try the CASIC commands @fanoush - do you know if they are supported ?
    I tried these but not sure if I have got the checksum calculation correct, its not a simple XOR.

    function prt() {
      // CFG-PRT       cc       len        id       p  
      //            ---------  --------  ---------  ----
      print([0xBA,0xCE,0x00,0x00,0x06,0x00, 0x00, 0xd4,0x00,0x00,0x00]);
      Serial1.write([0xBA,0xCE,0x00,0x00,0x06,­0x00, 0x00, 0xd4,0x00,0x00,0x00]);
    }
    
    // ck = d4040000
    function rate() {
      // CFG-PRT       cc       len        id       p  
      //            ---------  --------  ---------  ----
      print([0xBA,0xCE,0x00,0x00,0x06,0x04, 0x00, 0xd4,0x04,0x00,0x00]);
      Serial1.write([0xBA,0xCE,0x00,0x00,0x06,­0x04, 0x00, 0xd4,0x04,0x00,0x00]);
    }
    

    So far I am trying simple commands with 0 payload as it means the checksum is easier to calculate.

    I have written this bit of code to do the first part of the calculation.

    
    function ck(id,len,pl) {
      var clas = new Uint32Array(1);
      var i = new Uint32Array(1);
      var sum = new Uint32Array(1);
    
      clas[0] = 0xBACE;
      clas[0] = clas[0] << 24 ;
    
      i[0] = id;
      i[0] = i[0] << 16;
    
      //                       len     pl
      sum[0] = clas[0] + i[0] + len   + 0;
      print(sum[0].toString(16));
    }
    
    
  • I've got it, finally.
    When I switch baud rate manually
    first

    Serial1.println("$PCAS01,2*1E");
    

    then

    Serial1.setup(19200,{rx:D30, tx:D31});
    

    It works.

    But, when I push them both together

    Serial1.println("$PCAS01,2*1E");
    Serial1.setup(19200,{rx:D30, tx:D31});
    

    it makes AT6558 unresponsive, it keeps going, but cannot be controlled. I do not know is it buffer issue in its UART, or whatever. I tried to push \r\n, and \r, and \n, multiple of them, to make its buffer shift or flush. But nothing helped.
    There should be a pause between these commands, that's it.
    Does Bangle or Espruino have a pause command? I cannot find it.

  • Does Bangle or Espruino have a pause command? I cannot find it.

    Have a look at gpssetup.
    https://github.com/espruino/BangleApps/b­lob/master/apps/gpssetup/gpssetup.js

    You need to use promises. There was a discussion thread about this but I cant find it right now.
    the functions at line 107 and 129 demonstrate how to chain them together.

  • it does not work unfortunately. no delay.

    >function delay(ms) {
    :  return new Promise(resolve => setTimeout(resolve, ms));
    :};
    =function (ms) { ... }
    
    >print(new Date()); delay(5000); print(new Date());
    Date: Wed Dec 31 1969 19:05:07 GMT-0500
    Date: Wed Dec 31 1969 19:05:07 GMT-0500
    =undefined
    > 
    
  • You haven't used it correctly.
    It has to be used in conjunction with functions that return a promise. See the functions that demonstrate how to use it on lines 107,129.

  • You haven't used it correctly.
    It has to be used in conjunction with functions that return a promise. See the functions that demonstrate how to use it on lines 107,129.

  • I see. But it is too complicated for me :).
    I've made delayed call of Serial1.setup via simple setTimeout.

    var baudRate = 9600;
    var serialBaudRate = 9600;
    
    function setSerial1BaudRate(){
      print("set Serial1 BaudRate", baudRate);
      Serial1.setup(baudRate,{rx:D30, tx:D31});
      serialBaudRate = baudRate;
    }
    
    function setBaudRate(br){
      var brn = "";
      switch (br) {
        case 4800:  brn = "0"; break;
        case 9600:  brn = "1"; break;
        case 19200: brn = "2"; break;
        case 38400: brn = "3"; break;
        case 57600: brn = "4"; break;
        case 115200:brn = "5"; break;
        default:
          return;
      }
      print("set Baud Rate", br);
      baudRate = br;
      sendCommand("CAS01," + brn);
      const to1 = setTimeout(setSerial1BaudRate,1000);
    }
    
    
    setBaudRate(19200);
    
  • A simple timeout will work for separating two actions, but it starts to get messy if you have a sequence of things that each require delays between them.

  • 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