Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

GPS shield odd results. Novice user.


  • Please log in to reply
2 replies to this topic

#1 bytepoet

bytepoet

    New Member

  • Members
  • Pip
  • 2 posts

Posted 13 July 2012 - 12:27 AM

using hardware:
Netduino Plus (SolutionReleaseInfo.solutionVersion: 4.1.0.6)
Adafruit GPS Shield
EM-406A GPS Module

using System;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace GpsLogger
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            SerialPort serialPort = new SerialPort("COM1", 4800, Parity.None, 8, StopBits.One);
            serialPort.Open();

            // pin D2 off = gps module turned on
            Debug.Print("Turning on the GPS");
            Thread.Sleep(1000);
            OutputPort powerPin = new OutputPort(Pins.GPIO_PIN_D2, false);

            while (true)
            {
                int bytesToRead = serialPort.BytesToRead;
                if (bytesToRead > 0)
                {   
                    // get the waiting data
                    byte[] buffer = new byte[bytesToRead];
                    //serialPort.Read(buffer, 0, buffer.Length);
                    serialPort.Read(buffer, 0, buffer.Length);
                    // print out our received data
                    Debug.Print("bytestoread is " + bytesToRead.ToString());
                      Debug.Print(new string(System.Text.Encoding.UTF8.GetChars(buffer)));

                }

                Thread.Sleep(500); // wait a bit so we get a few bytes at a time...
            }
        }
    }
}

As soon as i turn on the Netduino Plus, i get a red light on the actual GPS module itsself, along with a white light near the micro gps unit.


When i read the output of the above code, i get the following:
Turning on the GPS
bytestoread is 24
<null>
bytestoread is 11
<null>
bytestoread is 13
<null>
bytestoread is 7
<null>
bytestoread is 13
<null>
bytestoread is 3
<null>
bytestoread is 7
<null>
etc....

so there's characters in there, and i'm not sure how to get them to display.

I have three wires D0(tx), D1(rx), D2(power-on/off) connected.


questions:
1. Is the code proper for an adafruit GPS shield?
2. Is there a reason i get <null> but i can see there's bytes to read?
3. Is there a 100% complete schematic to show all of the wires that should be soldered in the digital IO area?

#2 JimmyNet

JimmyNet

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 July 2012 - 03:29 PM

Maybe you can try connecting the gps module directry on your netduino without the shield.

#3 Nobby

Nobby

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 17 July 2012 - 06:30 AM

I use the DFRobot GPS shield based on the UBlox GPS unit but interfacing is the same. The first change you'll want to make is how you read the data. The GPS unit will constantly send NMEA and UBX packets to you. It could also send packets of other GPS protocols. With UBX in particular, the packets start with a deterministic pattern.

Sometimes the data can contain characters which are non punctuation, letters, numbers etc because certain bytes are acutally bit-fields of configuration and satelite data. String constructors might return NULL based on these non-alpha numeric characters. Instead, make a string, use a for/foreach loop and append each byte onto the string but cast it as a char.

change this
Debug.Print(new string(Encoding.UTF8.GetChars(buffer)));

to this
string dataString = "";
foreach(byte b in buffer) dataString+=(char)b;
Debug.Print(dataString);

Good luck




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.