Go Down

Topic: "pulsein" kills my GPS data (Read 116 times) previous topic - next topic

Pixxel

Jul 19, 2015, 03:30 am Last Edit: Jul 19, 2015, 05:40 pm by Pixxel
Hey Guys,

I'm making a RC project, it involves a GPS unit and reading a PWM signal from a radio receiver.

My problem is, that when I add a PulseIn command into my sketch i'm no longer able to read the data from the GPS. Any ideas where might be the problem?

Code: [Select]

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
Adafruit_GPS GPS(&Serial1);
HardwareSerial mySerial = Serial1;
int dioda = 13;
int THRin;
int THRout = 3;

#define GPSECHO  true

void setup() 
{
      pinMode(13, OUTPUT);
      pinMode(2, INPUT);
      pinMode(3, OUTPUT);
     

  Serial.begin(115200);
  delay(5000);
  //Serial.println("GPS + RC");
  GPS.begin(38400);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);
}


void loop()    {

  {
  if ((GPS.speed) >= 5) {
 digitalWrite (dioda, HIGH);
  }

 if ((GPS.speed) < 5) {
  {digitalWrite (dioda, LOW);
  }
 }
  char c = GPS.read();
   if ((c) && (GPSECHO))
   // Serial.write(c);
   if (GPS.newNMEAreceived()) {
   if (!GPS.parse(GPS.lastNMEA())) 
      return; 
  }
 
     THRin = pulseIn(2, HIGH); // dlugosc impulsu

 // Serial.println(RCin); 
  if (THRin > 1500)
{
  THRout = (THRin - 300);
}

chucktodd

#1
Jul 19, 2015, 07:16 am Last Edit: Jul 19, 2015, 07:37 am by chucktodd Reason: timeout question
Hey Guys,

I'm making a RC project, it involves a GPS unit and reading a PWM signal from a radio receiver.

My problem is, that when I add a PulseIn command into my sketch i'm no longer able to read the data from the GPS. Any ideas where might be the problem?
Code: [Select]

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
Adafruit_GPS GPS(&Serial1);
HardwareSerial mySerial = Serial1;
int dioda = 13;
int THRin;
int THRout = 3;

#define GPSECHO  true

void setup()  
{
      pinMode(13, OUTPUT);
      pinMode(2, INPUT);
      pinMode(3, OUTPUT);
      

  Serial.begin(115200);
  delay(5000);
  //Serial.println("GPS + RC");
  GPS.begin(38400);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);
}

uint32_t timer = millis();
void loop()    {

  {
  if ((GPS.speed) >= 5) {
 digitalWrite (dioda, HIGH);
  }

 if ((GPS.speed) < 5) {
  {digitalWrite (dioda, LOW);
  }
 }
  char c = GPS.read();
   if ((c) && (GPSECHO))
   // Serial.write(c);
   if (GPS.newNMEAreceived()) {
   if (!GPS.parse(GPS.lastNMEA()))  
      return;  
  }
  
     THRin = pulseIn(2, HIGH); // dlugosc impulsu

 // Serial.println(RCin);  
  if (THRin > 1500)
{
  THRout = (THRin - 300);
}

Why are you using mySerial? for both the GPS and your backdoor access to the GPS?

Serial1 already exists, just use it. (you must be using a MEGA or DUE);

Why the #include SoftwareSerial?  you never use it?


Explain what you mean by 'unable to read'

Does the GPS stop sending data? Does the Call to GPS.read() hang forever?

Does the values returned by GPS.read() no longer make sense?

Are you loosing data because the pulsein() takes to long to complete, and the Serial1 buffers are overflowing

Why don't you include the third parameter for pulsein(), the timeout in microseconds? else if there is no pulse, pulsein() will wait for 1 second, before it fails out.

please use the code tags: [ code ] and [ / code ],  (no spaces in the actual tags). it makes your post readable.

Chuck


TomGeorge

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the  </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html


Tom...... :)
Everything runs on smoke, let the smoke out, it stops running....

Nick Gammon

@Pixxel: Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" icon above the posting area. It is the first icon, with the symbol: </>
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Pixxel

hey,

Thanks for the replies. Managed to do it by Chucktodds advice. The problem was the software serial, which was in some kind of conflict with reading pulses.

Go Up