What am I doing wrong?

Posted on
  • I am fairly new to Javascript and am trying to understand why I am having an issue displaying gps data on a PCD8544. If I comment out the GPS code the display will characters. When the GPS code is included the LCD screen does not display any characters. I tried converting the lat1 variable from number to string but that did not work. WHat am I doing wrong?

    A2.write(0); // GND
    A4.write(1); // VCC
    SPI1.setup({ baud: 2000000, sck:A5, mosi:A7 });
    var g;
    function onInit() {
      g = require("PCD8544").connect(SPI1,A6,B0,B1­, function() {
    var gps = require("GPS").connect(Serial4, function(data) {
      lat1 = data.lat;
      g.drawString(lat1,0 ,0);
  • It might be that you're sending data to the lcd before it is initialised?

    Maybe try adding if (!inited) return to the gps code, and an inited=true in the connect callback?

  • What happens when you run it interactively? Are you able to get any data out of the GPS? Are you able to control the LCD manually?

    I figure the callback must be running, otherwise it would leave the "LCD OK" on the screen.... My suspicion is that it's not getting data - possibly it's getting no data, but that's being translated into an empty string?

    The GPS module states that it's for interfacing with GPS devices that support the NMEA standard/protocol/whateveryoucallit - Per the NMEA description( http://www.gpsinformation.org/dale/nmea.­htm#hardware ), that means 4800 baud, maybe higher on some units. 57600 is 12 times faster than this. Is there a reason that you picked that?

    Also, are you running this by sending from the IDE, or are you save()ing? If you want that to work after using save(), you need to put the connect() call for the GPS into onInit() as well.

  • I am able to get data out of the GPS by calling variables from the command line. I am unable to control the LCD manually when the GPS is running but am able to do so when I comment out the GPS code.

    So it seems that somehow the GPS code is preventing the LCD code from working. Although the code is similar to the Walking GPS code on the site.

    I am running at 57600 baud as thats how the GPS I am using is configured. I can try another unit that operates at 9600 baud although it has a smaller antenna. Maybe the rapid update on the GPS is preventing the LCD screen from re loading.

  • Update. Tried using the another GPS at 9600 baud and I now the LCD screen works. So it seems that the callbacks were coming to fast for the screen to keep up.

    Thanks for your help.

  • Thanks for letting us know. I've got a bug open to look at speeding up the Serial port handling (here) so hopefully this'll get fixed soon.

  • In case this information helps. I tried changing the speed of the other GPS unit from 57600 to 9600 baud. It still did not work. I believe the reason for this is the period of the updates rather than the baud rate. The two GPS units that I am using are the Adafruit Ultimate GPS and a LS20031. So I think the issue is the 5hz output set from the factory on the LS20031.

  • That's a strange one - have you tried maybe updating the screen on every second GPS update? If the update speed is too high, that may help.

    Otherwise, I've got a new version of the firmware available here which I plan to release soon. The Serial API is slightly re-done (sending strings, not characters), so the GPS receiver part now looks like:

    exports.connect = function(serial, callback) {
      var gps = {line:""};
      serial.on('data', function(data) {
        gps.line += data;
        var idx = gps.line.indexOf("\n");
        while (idx>=0) {
          var line = gps.line.substr(0, idx);
          gps.line = gps.line.substr(idx+1);
          handleGPSLine(line, callback); 
          idx = gps.line.indexOf("\n");     
      return gps;

    That should handle significantly higher data rates. I don't see 57600 being a problem at all.

  • I uploaded the V66 to the espruino. Now I am confused to how to read the data on the gps. When I try to initalize I get


      "line":"\x00\x00\x00\x00\x00\x00\x00\x00­\x00\x00\x00\x00\x00\x00\x00\x00\x00" ... "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0­0\x00\x00\x00\x00\x00\x00\x00"
  • Sorry - it looks like there's some kind of problem with the Serial communications in the new version.

    I tested it before it went out, but it seems some bug has crept in and the data is received but only as zeros. I'll see what I can do to fix it and will update you in an hour or so.

  • Ok, I just did a quick test and setting the port up with bytesize:8 helps:


    There seems to be another big issue with memory leaks though. Sorry about that.

    I'll fix it for the 'real' 1v66 release, and I'll try and get that out soon so nobody else encounters this.

  • Ok, if you install the binary from here:


    Go to the link, copy the address of the '...1r3.bin' file, paste it into the Web IDE flasher page and click 'advanced flash'.

    It should solve your problems.

  • It did very well, I now have no memory leak on my bluetooth comm, which I have with 1V65, so 1V66 did the job.
    Thank You very much Gordon.

  • Thank you. That fixed the issues with reading data at a higher rate. I am now able to read both the Adafruit GPS and the other GPS with the higher update rate and baud rate at the same time. Amazing how much easier this seems to be to learn than an Arduino like platform.

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

What am I doing wrong?

Posted by Avatar for user7143 @user7143