GPS overlay issues

Store Forums Video Experimenter General Discussion GPS overlay issues

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #690
    cyberteque
    Member

    I sorta, kinda got it to work, but only for a few seconds!

    I thought there might be issues with the data rate from the EM-406, so this is what I tried

    #include 
    #include
    #include
    #include
    #include "bitmaps.h"

    #define W 128
    #define H 96
    #define HOMELAT -34.9035
    #define HOMELNG 138.9980
    #define HOMEALT 56

    TVout tv;
    pollserial pserial;
    TinyGPS gps;
    unsigned long lastDisplayTime = 0;
    PROGMEM prog_int8_t ticks[] = {3,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0};
    float theta;

    byte x, y;

    void setup() {
    tv.begin(PAL, W, H);
    tv.set_hbi_hook(pserial.begin(4800));
    initOverlay();
    tv.select_font(font4x6);
    tv.fill(0);
    // enable RMC, output 1Hz:
    pserial.println('$PSFR103,04,00,01,01*21');
    // enable GGA, output 1Hz:
    pserial.println('$PSFR103,00,00,01,01*25');
    // disable GLL
    pserial.println('$PSFR103,01,00,00,01*25');
    // disable GSA
    pserial.println('$PSFR103,02,00,00,01*26');
    // disable GSV
    pserial.println('$PSFR103,03,00,01,01*27');
    // desiable VTG
    pserial.println('$PSFR103,05,00,00,01*21');
    }

    // Initialize ATMega registers for video overlay capability.
    // Must be called after tv.begin().
    void initOverlay() {
    TCCR1A = 0;
    // Enable timer1. ICES0 is set to 0 for falling edge detection on input capture pin.
    TCCR1B = _BV(CS10);

    // Enable input capture interrupt
    TIMSK1 |= _BV(ICIE1);

    // Enable external interrupt INT0 on pin 2 with falling edge.
    EIMSK = _BV(INT0);
    EICRA = _BV(ISC11);
    }



    // Required to reset the scan line when the vertical sync occurs
    ISR(INT0_vect) {
    display.scanLine = 0;
    }

    void debug(int n) {
    tv.print(0, 90, n);
    }

    int getMemory() {
    int size = 512;
    byte *buf;
    while ((buf = (byte *) malloc(--size)) == NULL);
    free(buf);
    return size;
    }

    void displayData() {
    float lat, lng;
    unsigned long fix_age;

    lat = 0.0;
    lng = 0.0;
    gps.f_get_position(&lat, &lng, &fix_age);

    tv.delay_frame(1);

    tv.print(0, 0, lat, 4);
    printRightJustified(W-36, 0, lng, 4);

    displayCourse();
    displaySpeed();
    displayAltitude();

    // display distance from home
    printRightJustified(118, 90, gps.distance_between(HOMELAT, HOMELNG, lat, lng));
    tv.bitmap(122, 89, bitmaps+28, 0, 0, 0);

    // erase home arrow
    byte x1 = 64 + (20 * cos(theta));
    byte x2 = 64 + (25 * cos(theta));
    byte y1 = 50 - (20 * sin(theta));
    byte y2 = 50 - (25 * sin(theta));
    tv.draw_line(x1, y1, x2, y2, 0);

    // compute direction home expressed as radians relative to x axis. Range [-pi,pi]
    theta = atan2(HOMELAT-lat, HOMELNG-lng);
    x1 = 64 + (20 * cos(theta));
    x2 = 64 + (25 * cos(theta));
    y1 = 50 - (20 * sin(theta));
    y2 = 50 - (25 * sin(theta));
    tv.draw_line(x1, y1, x2, y2, 1);

    /*
    // convert to degrees relative to x axis. Range [-180,180]
    directionHome = degrees(directionHome);

    // convert to range [0,360]
    if (directionHome < 0) {
    directionHome += 360;
    }

    // convert to degrees clockwise relative to 0 degree heading (north)
    directionHome = 360 - (directionHome - 90);
    */
    }

    void displayCourse2() {
    int course = (int)(gps.f_course() + 0.5);
    x = 66;
    y = 18;
    printRightJustified(x, y, course);
    }

    void displayCourse() {
    byte index;
    int course = (int)(gps.f_course() + 0.5);

    // clear
    for(y=8;y<23;y++) {
    for(x=4;x<12;x++) {
    display.screen[(y*(W/8))+x] = 0;
    }
    }

    x = 66;
    y = 18;
    tv.draw_line(x-4, 5, x-1, 5, 1);
    tv.set_pixel(x-3, 6, 1);

    printRightJustified(x, y, course);

    x = 48;
    y = y-2;
    course -= 90;
    if (course < 0) {
    course += 360;
    }
    index = (byte)(((float)course / 5.625) + 0.5);
    for(byte t=0;t<=32;t++) {
    byte len = pgm_read_byte(ticks+index);
    switch (len) {
    case 3:
    tv.set_pixel(x, y-2, 1);
    tv.bitmap(x-2, y-8, bitmaps+(7*(index/16)), 0, 0, 0);
    case 2:
    tv.set_pixel(x, y-1, 1);
    case 1:
    tv.set_pixel(x, y, 1);
    }
    index++;
    if (index >= 64) {
    index = 0;
    }
    x++;
    }
    }


    void displaySpeed() {
    int speed = (int)(gps.f_speed_knots() + 0.5);
    //int speed = analogRead(5);
    byte middle = 50;

    for(y=(middle-22);y<=(middle+22);y++) {
    for(x=0;x<4;x++) {
    display.screen[(y*(W/8))+x] = 0;
    }
    }

    x = 17;
    for(int s=(speed+40);s>=(speed-40);s--) {
    y = middle-((s-speed)/2);
    if ((s % 4) == 0) {
    tv.set_pixel(x, y, 1);
    }
    if ((s % 20) == 0) {
    tv.set_pixel(x-1, y, 1);
    if (s > 0) {
    printRightJustified(8, y-2, s);
    }
    }
    }


    y = middle-4;
    x = 12;
    tv.draw_line(0, y-1, x, y-1, 0);
    tv.draw_line(0, y, x, y, 1);
    y++;
    tv.draw_line(0, y, x, y, 0);
    tv.set_pixel(x++, y++, 1);
    printRightJustified(8, y, speed);
    tv.set_pixel(x++, y++, 1);
    tv.set_pixel(x++, y++, 1);
    tv.set_pixel(x--, y++, 1);
    tv.set_pixel(x--, y++, 1);
    tv.set_pixel(x--, y++, 1);
    tv.set_pixel(x, y++, 1);
    tv.draw_line(0, y-1, x, y-1, 0);
    tv.draw_line(0, y, x, y, 1);
    tv.draw_line(0, y+1, x, y+1, 0);
    }

    void displayAltitude() {
    int altitude = (int)(gps.f_altitude() + 0.5) - HOMEALT;
    //int altitude = analogRead(5);
    byte middle = 50;

    for(y=middle-22;y<=(middle+22);y++) {
    for(x=((W/8)-4);x<(W/8);x++) {
    display.screen[(y*(W/8))+x] = 0;
    }
    }

    x = 108;
    for(int a=(altitude+40);a>=(altitude-40);a--) {
    y = middle-((a-altitude)/2);
    if ((a % 4) == 0) {
    tv.set_pixel(x, y, 1);
    }
    if ((a % 20) == 0) {
    tv.set_pixel(x+1, y, 1);
    printRightJustified(123, y-2, a);
    }
    }



    y = middle-4;
    x = 114;
    tv.draw_line(x, y-1, x+12, y-1, 0);
    tv.draw_line(x, y, x+12, y, 1);
    y++;
    tv.draw_line(x, y, x+12, y, 0);
    x--;
    tv.set_pixel(x--, y++, 1);
    printRightJustified(x+11, y, altitude);
    tv.set_pixel(x--, y++, 1);
    tv.set_pixel(x--, y++, 1);
    tv.set_pixel(x++, y++, 1);
    tv.set_pixel(x++, y++, 1);
    tv.set_pixel(x++, y++, 1);
    tv.set_pixel(x++, y++, 1);
    tv.draw_line(x, y-1, x+12, y-1, 0);
    tv.draw_line(x, y, x+12, y, 1);
    tv.draw_line(x, y+1, x+12, y+1, 0);
    }

    void printRightJustified(byte x, byte y, int n) {
    if (n < 0) {
    x -= 4;
    }
    int posN = abs(n);
    if (posN >= 10) {
    x -= 4;
    }
    if (posN >= 100) {
    x -= 4;
    }
    if (posN >= 1000) {
    x -= 4;
    }
    tv.print(x, y, n);
    }

    void printRightJustified(byte x, byte y, float f, int nDecimal) {
    if (f >= 10) {
    x -= 4;
    }
    if (f >= 100) {
    x -= 4;
    }
    if (f >= 1000) {
    x -= 4;
    }
    tv.print(x, y, f, nDecimal);
    }


    void loop() {

    if (readGPS() && ((millis() - lastDisplayTime) > 500)) {
    lastDisplayTime = millis();
    displayData();
    //debug(getMemory());
    }

    }

    bool readGPS() {
    char c;
    while (pserial.available()) {
    if (gps.encode(pserial.read())) {
    return true;
    }
    }
    return false;
    }

    adding

    // enable RMC, output 1Hz:
    pserial.println('$PSFR103,04,00,01,01*21');
    // enable GGA, output 1Hz:
    pserial.println('$PSFR103,00,00,01,01*25');
    // disable GLL
    pserial.println('$PSFR103,01,00,00,01*25');
    // disable GSA
    pserial.println('$PSFR103,02,00,00,01*26');
    // disable GSV
    pserial.println('$PSFR103,03,00,01,01*27');
    // desiable VTG
    pserial.println('$PSFR103,05,00,00,01*21');

    got it to work for a few seconds then the display goes blank until I hit reset

    Any ideas?

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.