Announcement

Collapse
No announcement yet.

Compass with a GPS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compass with a GPS

    Hi, i'm trying to make a compass using the coordinates of a GPS. I have a uLCD- 28PTU display. This is the code i'm using to get the coordinates. I'm showing them in diferents strings.

    Code:
    #include <SoftwareSerial.h>
    #include <genieArduino.h>
     
    SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
    const int sentenceSize = 80;
     
    char sentence[sentenceSize];
     
    void setup()
    {
      genieBegin (GENIE_SERIAL, 9600);  //Serial0
      
     
      //Serial.begin(9600);
      gpsSerial.begin(9600);
    }
     
    void loop()
    {
      static int i = 0;
      if (gpsSerial.available())
      {
        char ch = gpsSerial.read();
        if (ch != '\n' && i < sentenceSize)
        {
          sentence[i] = ch;
          i++;
        }
        else
        {
         sentence[i] = '\0';
         i = 0;
         displayGPS();
        }
      }
    }
     
    void displayGPS()
    {
      char field[20];
        
      getField(field, 0);
      if (strcmp(field, "$GPRMC") == 0)
      {
        //Serial.print("Lat: ");
        getField(field, 3);  // number
        //Serial.print(field);
        genieWriteStr(0,field);
        getField(field, 4); // N/S
        //Serial.print(field);
        genieWriteStr(1,field);
     
        //Serial.print(" Long: ");
        getField(field, 5);  // number
        //Serial.print(field);
        genieWriteStr(2,field);
     
        getField(field, 6);  // E/W
        //Serial.println(field);
        genieWriteStr(3,field);
     
      }
     
    }
     
     
    void getField(char* buffer, int index)
    {
      int sentencePos = 0;
      int fieldPos = 0;
      int commaCount = 0;
      while (sentencePos < sentenceSize)
      {
        if (sentence[sentencePos] == ',')
        {
          commaCount ++;
          sentencePos ++;
        }
        if (commaCount == index)
        {
          buffer[fieldPos] = sentence[sentencePos];
          fieldPos ++;
        }
        sentencePos ++;
      }
      buffer[fieldPos] = '\0';
     
    }
    How can I make the compass using these data (latitude N/S, longitude E/W)?
    Is it possible to show it on the 4D display using ViSi-Genie?
    This is the kind of compass i want to get:


    Thank you!!

  • #2


    The compass would simply take the heading and truncate it to 0-359 (round it if you like)

    You could then use Orbit command to generate a simple needle display in serial.

    Or, if you've created a 'user images' (of 360 frames) in ViSi, you could use the Serial equivalent of the commands used in AppNote P3005 to select the frame to show. http://www.4dsystems.com.au/appnotes/
    Mark

    Comment


    • #3


      Thank you for your answer. I'm a beginner and i'm pretty lost with the ViSi module, so i prefer to use ViSi Genie if possible.

      Could i save a compass image in a uSD in order to use it in the ViSi-Genie module to show the data from the GPS?
      I just found this example:

      Comment


      • #4


        Sure, you just create each of the 360 images required and add them into a user images object.

        The video you found was created in a similar way.
        Mark

        Comment


        • #5


          Once i have created the 360 images, how do i compress them into one file in order to save it in the uSD and load it to the display?

          Comment


          • #6


            You add all 360 images to the User images object. It will take care of the rest
            Mark

            Comment


            • #7


              Sorry for the silly question but where is the user images object in ViSi genie? I don't find it and i can't go on with my project.
              Once I had uploaded all the images to the uSD, how do I write the data receipt from the GPS in that images? For example, when I use a temperature sensor I write the data in the thermometeR with genieWriteObject(GEN_OBJ_THERMOMETER). How can i do the same with the compass?
              Thank you for your patience

              Comment


              • #8


                UserImages were new in Workshop 4.1.0.11, so you will need 'at least' that version to use them.

                Similarly the library will need updating to include the new constants, then you will be able to use genieWriteObject for them, same as always.

                UserImages are on the System/Media tab, fourth from the left.
                Mark

                Comment


                • #9
                  That was the problem, I was using an older version.

                  I have created the 360 images and they have been already uploaded to the display through the uSD card.
                  This is how they look at the starting position:


                  The GPS is working right and it gives coordenates like these, for example:
                  Lat: 2400.0000N
                  Long: 12100.0000E

                  I have to write these coordenates into the User Images Object using the command genieWriteObject(GENIE_OBJ_USERIMAGES), but how do I write both two (lat and long)??
                  This is the code:

                  Code:
                  #include <genieArduino.h>  
                  #include <SoftwareSerial.h>  
                  
                  
                  SoftwareSerial gpsSerial(10, 11); 
                  const int sentenceSize = 80;
                  char sentence[sentenceSize];
                  
                  
                  void setup() 
                  { 
                    genieBegin (GENIE_SERIAL, 9600);  con la pantalla
                    gpsSerial.begin(9600);  
                  
                  }
                  
                  
                  
                  void loop() 
                  { 
                  
                    static int i = 0;
                    if (gpsSerial.available())
                    {
                      char ch = gpsSerial.read();
                      if (ch != '\n' &amp;&amp; i < sentenceSize)
                      {
                        sentence[i] = ch;
                        i++;
                      }
                      else
                      {
                       sentence[i] = '\0';
                       i = 0;
                       displayGPS();
                      }
                    }    
                  }
                  
                  
                  void displayGPS()
                  {
                    char field[20];
                    
                    getField(field, 0);
                    if (strcmp(field, "$GPRMC") == 0)
                    {
                  
                      
                      getField(field, 3);  // Latitude
                      I guess here goes the genieWriteObject(GENIE_OBJ_USERIMAGES)
                      getField(field, 4); // N/S
                      genieWriteObject(GENIE_OBJ_USERIMAGES)
                  
                      
                      getField(field, 5);  // Longitude
                      genieWriteObject(GENIE_OBJ_USERIMAGES)
                      getField(field, 6);  // E/W
                      genieWriteObject(GENIE_OBJ_USERIMAGES)
                  
                    }
                  }
                  
                  
                  void getField(char* buffer, int index)
                  {
                    int sentencePos = 0;
                    int fieldPos = 0;
                    int commaCount = 0;
                    while (sentencePos < sentenceSize)
                    {
                      if (sentence[sentencePos] == ',')
                      {
                        commaCount ++;
                        sentencePos ++;
                      }
                      if (commaCount == index)
                      {
                        buffer[fieldPos] = sentence[sentencePos];
                        fieldPos ++;
                      }
                      sentencePos ++;
                    }
                    buffer[fieldPos] = '\0';
                   
                  }

                  Comment


                  • #10
                    Probably using something like the method covered here

                    http://forum.4dsystems.com.au/forum/forum-aa/4d-systems-software/workshop-4-visi-genie-environment-picaso/4392-freezes-at-geniewritestr
                    Mark

                    Comment


                    • #11


                      Hi JarcorI would also like to build a compass with GPS. Can you tell me how you got the 360 images generated. For every degree a new image. that is, for each course over ground an User Object Images. From the GPS string "$ GPRMC" I can readout the course over ground in degree and connect with the corresponding User Object Images from the uSD card. I would be delighted to hear from you to learn from your experiences.Willy

                      Comment


                      • #12


                        Hi Willy
                        It can be done in a number of graphics applications such as Photoshop.
                        A quick google search reported this discussion which suggests a command line tool which might help you.
                        http://stackoverflow.com/questions/2704840/tool-to-generate-rotated-versions-of-an-image

                        Regards
                        James

                        Comment


                        • #13
                          Confirmed that ImageMagick works well.
                          I downloaded ftp://mirror.aarnet.edu.au/pub/image...x64-static.exe

                          Made the first image I wanted (Compass1.png attached) using Photoshop. Made it round with transparent 'corners'
                          Ran the script I made to loop the command to generate all the images at 1 degree increments.

                          Run the script from cmd prompt or simply double click it from windows.

                          *EDIT* Added simple ViSi-Genie application with all images included as an example. Too big to attach, please download here:
                          http://www.4dsystems.com.au/download...UserImages.zip



                          Enjoy.
                          Attached Files
                          James

                          Comment


                          • #14


                            Hi James
                            Thank you for your help. I will now try your good suggestions to execute.
                            Greetings from Switzerland
                            Willy

                            Comment


                            • #15


                              Hi hkwmon

                              now that you have all the images you can use photoshop and work with all of them at the same time. That's how I did it.

                              Comment

                              Working...
                              X