nebrius / raspi-io

An IO plugin for Johnny-Five that provides support for the Raspberry Pi
MIT License
546 stars 63 forks source link

Pin Mode Error - Pi3, GPS GP-20U7 & Johnny-Five #94

Closed avcohen closed 7 years ago

avcohen commented 7 years ago

I used raspi-config to disable Serial/USB Console and Enabled Serial interface. I've also added enable_uart=1 config.txt.

Running cat /dev/serial0 from the command like outputs a stream of data from the GPS unit and seems to be doing it's job. Nonetheless, I'm having an issue with Pin 10 receiving data from the GPS Unit. When I run my code below it throws the error:

Error: Pin "10" does not support mode "other"

var five = require("johnny-five");
var Raspi = require("raspi-io");
var board = new five.Board({
  io : new Raspi({ enableSerial : true /* apparently required as per raspi-io docs */ })
});

    board.on("ready", function() {
        const gps = new five.GPS({
            pins : {
                    rx : 'P1-10',
                    tx : 'P1-8',
            }
    });

    gps.on("data", () => {
            console.log("position");
            console.log(" latitude  : ", this.latitude);
            console.log(" longitude : ", this.longitude);
            console.log(" altitude  : ", this.altitude);
            console.log("———————————————————————————————————");
    });

});
nebrius commented 7 years ago

Try this:

const five = require("johnny-five");
const Raspi = require("raspi-io");
const board = new five.Board({
    io : new Raspi({ enableSerial: true /* apparently required as per raspi-io docs */ })
});

board.on("ready", () => {
    const gps = new five.GPS({});

    gps.on("data", () => {
        console.log("position");
        console.log(" latitude  : ", gps.latitude);
        console.log(" longitude : ", gps.longitude);
        console.log(" altitude  : ", gps.altitude);
        console.log("———————————————————————————————————");
    });
});

I did a few things here. Most important is that I removed the pins entry from the GPS constructor. The pins entry is really only useful if you need to used software emulated serial, something that isn't supported on the Raspberry Pi. Without pins, it defaults to using port, which itself defaults to an internal value supplied by Raspi IO.

Another thing I did, I changed from using this.latitude et al in the data event, because the arrow function causes the this value to be global instead of gps, which would make this.latitude to equal undefined in your code.

Let me know if you run into any other issues!

avcohen commented 7 years ago

Thanks for the feedback this was a huge help. Big oversight on my part with the fat arrow and this. While this runs, the values returned are all 0.

running either cat /dev/ttyAMA0 or cat /dev/serial0 outputs the following:

$GPGLL,,,,,,V,N*64 $GPRMC,,V,,,,,,,,,,N*53 $GPVTG,,,,,,,,,N*30 $GPGGA,,,,,,0,00,99.99,,,,,,*48 $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

so while I know data is coming through so there is data but it doesn't seem to be found in the latitude longitude and altitude objects of gps.

Thanks again.

nebrius commented 7 years ago

Hmm, at this point, I would guess that there is some sort of issue with parsing data somewhere in the stack.

Which GPS device are you using?

avcohen commented 7 years ago

I'm using GPS Receiver - GP-20U7 (56 Channel).

nebrius commented 7 years ago

I've ordered one of these devices, I'll test it out as soon as it arrives

nebrius commented 7 years ago

ok, I did some testing and I confirmed that Raspi IO is outputting what looks like valid data, but the GPS parser in Johnny-Five isn't able to parse it.

@rwaldron, do you see anything fishy about this output from Raspi IO?

screen shot 2017-06-15 at 4 05 29 pm

console logging the data gives this:

,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,3,1,09,02,,,09,03,,,09,04,,,16,05,,,16*72
$GPGSV,3,2,09,08,,,24,16,,,08,24,,,26,26,,,24*70
$GPGSV,3,3,09,27,,,24*73
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,04,,,21,05,,,14,08,,,24,24,,,25*74
$GPGSV,2,2,06,26,,,24,27,,,24*7E
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,04,,,21,05,,,12,24,,,23,26,,,25*7A
$GPGSV,2,2,05,27,,,25*7E
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,04,,,18,08,,,28,24,,,20,26,,,26*74
$GPGSV,2,2,05,27,,,26*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,04,,,15,08,,,27,10,,,26,24,,,17*74
$GPGSV,2,2,06,26,,,26,27,,,25*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,08,,,26,10,,,26,24,,,13,26,,,26*72
$GPGSV,2,2,05,27,,,26*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,08,,,26,10,,,26,24,,,13,26,,,26*72
$GPGSV,2,2,05,27,,,26*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,08,,,26,10,,,26,11,,,26,24,,,15*73
$GPGSV,2,2,06,26,,,26,27,,,26*7E
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,07,08,,,25,10,,,26,11,,,25,13,,,28*78
$GPGSV,2,2,07,24,,,15,26,,,26,27,,,26*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,08,,,26,10,,,26,11,,,24,24,,,15*71
$GPGSV,2,2,06,26,,,26,27,,,26*7E
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,08,,,26,10,,,26,11,,,23,26,,,26*77
$GPGSV,2,2,05,27,,,26*7D
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,04,08,,,26,10,,,26,11,,,23,27,,,26*74
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,08,,,26,10,,,25,11,,,23,14,,,25*75
$GPGSV,2,2,06,26,,,27,27,,,26*7F
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,07,08,,,26,10,,,25,11,,,23,12,,,07*72
$GPGSV,2,2,07,14,,,24,26,,,26,27,,,26*7C
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,06,08,,,25,10,,,25,11,,,23,14,,,23*70
$GPGSV,2,2,06,26,,,26,27,,,26*7E
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,08,08,,,25,10,,,27,11,,,23,14,,,23*7C
$GPGSV,2,2,08,16,,,26,17,,,30,26,,,28,27,,,26*78
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,08,08,,,26,10,,,26,11,,,23,14,,,23*7E
$GPGSV,2,2,08,16,,,25,17,,,26,26,,,27,27,,,26*73
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,08,08,,,26,10,,,25,11,,,22,14,,,22*7D
$GPGSV,2,2,08,16,,,25,17,,,25,26,,,26,27,,,26*71
$GPGLL,,,,,
nebrius commented 7 years ago

A thought: is each data chunk suppose to be split per line? All of the data above was from a single data chunk

dtex commented 7 years ago

@nebrius It should split the messages on \r\n so that's not it. You don't appear to be acquiring a satellite signal. Can you try it near a window?

nebrius commented 7 years ago

Sorry for the delay, but I finally got around to testing outdoors and the code in https://github.com/nebrius/raspi-io/issues/94#issuecomment-304953213 works for me.

@avcohen can you test with your Raspberry Pi outside?

If you are unsure if your GPS unit has signal or not, check the raw output and look for the GPGLL command, and then check the letter in the second to last comma-separated entry. If it says V, that means void, aka you don't have signal. If it says A, that means active and you do have signal.

Let us know if it works!

nebrius commented 7 years ago

Closing due to inactivity. If this is still an issue, feel free to reopen!