Hi Guys,
I am pretty new to this stuff still but can usually make stuff work with a certain amount of google and cut/ paste but I am stuck on this one.
I am interfacing with a parallax GPS sensor (PMB-648 NMEA). Everything is working great except it will not transmit speed if it is below aprox 3.0 MPH. This is a problem for what I am trying to do. Turns out this is something called "static navigation", and it can be disabled by sending a command to the unit (after commanding the unit to switch to binary mode).
This is where I need some help, I am obviously not knowledgeable on binary and sending data via serial!
Here is a quote from the parallax forum for arduino code to turn static navigation off. There were reply's to indicate that it was successful.
"The following will turn it off:
Using 4800 baud send/Serial.print
this string:
("$PSRF100,0,4800,8,1,0*0F",\r,\n)
followed by this series of Hex bytes
0xA0,0xA2,0x00,0x02,0x8F,0x00,0x00,0x8F,0xB0,0xB3
0xA0,0xA2,0x00,0x18,0x81,0x02,0x01,001,0x00,0x01
0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x01,0x00,0x01
0x00,0x01,0x00,0x01,0x00,0x01,0x12,0xC0,0x01,0x61
0xB0,0xB3
To clarify:
re. the bytes --
Serial.print(0xA0, BYTE);
Serial.print(0xA2, BYTE);
and so on
I can't seem to make this work. The Sensor is connected to pins A3 (Rx), and A2 (TX) on software serial. I could not get it to compile like the above mentioned (says "BYTE is no longer valid) so I tried this in the setup of my code.:
SoftwareSerial nss(A3, A2);
nss.begin(4800);
nss.println("$PSRF100,0,4800,8,1,0*0F");
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x02);
nss.write((byte)0x8F);
nss.write((byte)0x00);
nss.write((byte)0x00);
nss.write((byte)0x8F);
nss.write((byte)0xB0);
nss.write((byte)0xB3);
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x18);
nss.write((byte)0x81);
nss.write((byte)0x02);
nss.write((byte)0x01);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x18);
nss.write((byte)0x81);
nss.write((byte)0x02);
nss.write((byte)0x01);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x12);
nss.write((byte)0xC0);
nss.write((byte)0x01);
nss.write((byte)0x61);
nss.write((byte)0xB0);
nss.write((byte)0xB3);
This will compile but does not change anything.
Here is the complete code:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <Servo.h>
Servo myservo1;
Servo myservo2;
TinyGPS gps;
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
SoftwareSerial nss(A3, A2);
int leftposition;
int rightposition;
int lastleftposition;
int lastrightposition;
float leftright;
float foraft;
unsigned long lastmillis;
int incriment;
int buttondelay;
int leftservomicros;
int rightservomicros;
float rawMPH;
int ALT;
const int numReadings = 5;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
float total = 0; // the running total
float smoothMPH = 0; // the average
void setup(){
myservo1.attach(3);
myservo2.attach(10);
leftposition = 45; //set intial servo position to 45 degrees, neutral.
rightposition = 45; //same for the right.
lastmillis = millis();
incriment = 1;
buttondelay = 0;
Serial.begin(9600);
lcd.begin(16, 2);
nss.begin(4800);
for (int thisReading = 0; thisReading < numReadings; thisReading++) //for smothing speed
readings[thisReading] = 0; //smothing speed
delay(1000);
nss.println("$PSRF100,0,4800,8,1,0*0F");
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x02);
nss.write((byte)0x8F);
nss.write((byte)0x00);
nss.write((byte)0x00);
nss.write((byte)0x8F);
nss.write((byte)0xB0);
nss.write((byte)0xB3);
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x18);
nss.write((byte)0x81);
nss.write((byte)0x02);
nss.write((byte)0x01);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0xA0);
nss.write((byte)0xA2);
nss.write((byte)0x00);
nss.write((byte)0x18);
nss.write((byte)0x81);
nss.write((byte)0x02);
nss.write((byte)0x01);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x00);
nss.write((byte)0x01);
nss.write((byte)0x12);
nss.write((byte)0xC0);
nss.write((byte)0x01);
nss.write((byte)0x61);
nss.write((byte)0xB0);
nss.write((byte)0xB3);
}
void loop(){
// FLIGHT CONTROLS:
leftright = map(analogRead(A2), 0, 1023, 0.0, 5.0); // map to volts 0 - 5 (2.5 is neutral!)
foraft = map(analogRead(A3), 0, 1023, 0.0, 5.0); // same as above
if((leftright < 2.0) && (millis() > lastmillis + (buttondelay))){
leftposition -= (incriment);
rightposition += (incriment);
lastmillis = millis();
}
if((leftright > 2.9 ) && (millis() > lastmillis + (buttondelay))){
leftposition += (incriment);
rightposition -= (incriment);
lastmillis = millis();
}
if((foraft < 2.0) && (millis() > lastmillis + (buttondelay))){
leftposition -= (incriment);
rightposition -= (incriment);
lastmillis = millis();
}
if((foraft > 2.9 ) && (millis() > lastmillis + (buttondelay))){
leftposition += (incriment);
rightposition += (incriment);
lastmillis = millis();
}
leftposition = constrain(leftposition, 0, 90);
rightposition = constrain(rightposition, 0, 90);
leftservomicros = map(leftposition, 0, 90, 1050, 1950); //limits for servo in microseconds
rightservomicros = map(rightposition, 0, 90, 1950, 1050);// limits for servo
myservo1.writeMicroseconds(leftservomicros);
myservo2.writeMicroseconds(rightservomicros);
/*if(lastleftposition != leftposition){
lcd.setCursor(0,1);
lcd.print("L: ");
lcd.setCursor(2, 1);
lcd.print(leftposition);
lastleftposition = leftposition;
}
if(lastrightposition != rightposition){
lcd.setCursor(4,1);
lcd.print("R: ");
lcd.setCursor(6, 1);
lcd.print(rightposition);
lastrightposition = rightposition;
}
*/
// GPS INTERFACE:
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (nss.available())
{
char c = nss.read();
// Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flat, flon;
unsigned long age;
//GPS SMOOTHING SPEED
rawMPH = (gps.f_speed_mph() == TinyGPS::GPS_INVALID_F_SPEED ? 0 : gps.f_speed_mph());
total= total - readings[index]; // subtract the last reading:
readings[index] = rawMPH; // read from the sensor:
total= total + readings[index]; // add the reading to the total:
index = index + 1; // advance to the next position in the array:
if (index >= numReadings) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning:
smoothMPH = total / numReadings; // calculate the average (smoothMPH):
Serial.println(smoothMPH); // send it to the computer as ASCII digits
lcd.setCursor(0, 0);
lcd.print("MPH:");
lcd.setCursor(4,0);
lcd.print(rawMPH);
Serial.print(rawMPH);
lcd.setCursor(0,1);
lcd.print("sm:");
lcd.setCursor(3, 1);
lcd.print(smoothMPH, 1);
lcd.setCursor(8,1);
lcd.print("ALT:");
lcd.setCursor(12 ,1);
lcd.print((gps.altitude() == TinyGPS::GPS_INVALID_ALTITUDE ? 0 : gps.altitude()) * .0328, 0); // ZERO DECIMALS!
Serial.print((gps.altitude() == TinyGPS::GPS_INVALID_ALTITUDE ? 0 : gps.altitude()) * .0328);
lcd.setCursor(10,0);
lcd.print("SAT:");
lcd.setCursor(14,0);
lcd.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites(), 2);
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites(), 2);
}
}
I really hope someone can help me figure this out! I will post the actual SIRF NMEA guide for setting the GPS unit to binary mode and sending the proper command tomorrow (which is what the quote at the beginning is). Thanks for your time in reading this post!
Roto.