Output pin not reliably going HIGH

Hi All

I’m having some trouble getting an output pin to behave the way I want it to.

The project is a LoRa GPS tracker with some power saving features built into it that should be doing the following:

  • Power up the GPS by setting the module’s ON/OFF pin to HIGH and wait for satellite lock.
  • Once lock is acquired we power down the GPS by setting the ON/OFF pin of the module to LOW.
  • Transmit location data to TTN.
  • Sleep for one minute.
  • Repeat.

The problem I have is that in about one loop in three or four the pin is failing to go high.

Here’s a very simplified version of the code:

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Adafruit_SleepyDog.h>
#define LPP_GPS 136   

static int OnOffPin = 6;


void setup() {
  
pinMode(OnOffPin,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(OnOffPin,HIGH);
//Wait for GPS lock and record position
digitalWrite(OnOffPin,LOW);
//We transmit the GPS data over LoRa here
//Sleep for 60 seconds
int sleepMS1 = Watchdog.sleep(8000); 
int sleepMS2 = Watchdog.sleep(8000);
int sleepMS3 = Watchdog.sleep(8000);
int sleepMS4 = Watchdog.sleep(8000);
int sleepMS5 = Watchdog.sleep(8000);
int sleepMS6 = Watchdog.sleep(8000);
int sleepMS7 = Watchdog.sleep(8000);
int sleepMS8 = Watchdog.sleep(4000);
}

If the pin were always failing to go high or low then I could understand it but the fact mostly works fine but intermittently fails has me stumped.

Any suggestions would be greatly appreciated.

Thanks

one step at a time :

write a sketch with only one : digitalWrite(OnOffPin,HIGH);
using a DMM, measure the voltage.

How much is it? How much do you expect?
Is there any "load" to the pin (possible overload or short circuit)?

How much current does the GPS module draw?

sorry if im not helpful at all but few times I had some issues with reading high/low pins and/or activating something.
Once I used pull up/down resistors.
The other time for activating something since the current wasn't always enough, I added a Power Distribution Switch. I would set high this and it would give power to the device i wanted to wake up directly from source instead of thru a pin which might not have enough current..

There "shouldn't" be any discernible load on that pin, the GPS power pin is connected to VCC, the "on/off" pin is separate to this and powers down the module when it is connected to ground, then back up when it goes high. The GPS module draws 20ma when it's switched on but all except a fraction of this will be from VCC.

I did try adding a pull-up resistor to try to force it high in case it's being left floating but that didn't help, I have also tried a different GPIO pin in case that might be the issue but that hasn't helped either.

I wrote a really simple sketch, basically Blink, to cycle the pin between high and low and that seems to work ok according to the multimeter. One thing I haven't checked is what the LoRa module is doing while all this is going on. It's using LMIC to send a transmission to TTN which would potentially involve a delayed operation. In all honesty I'm not entirely sure what every part of this code is doing so I could be missing something there.

For what it's worth here is the full code. Please excuse how messy it is, I have written a fair few quick hacks into it to try to troubleshoot this issue with a view to tidying it up later. Also, apologies for using pastebin, it put me over my character limit to include it in the post.

Do you have a link to the GPS module?

have you tried a different module? maybe the module has a problem?

wildbill:
Do you have a link to the GPS module?

http://www.icofchina.com/d/file/xiazai/2016-12-05/b5c57074f4b1fcc62ba8c7868548d18a.pdf

I'm afraid it's not brilliantly translated and a bit scant on detail.

The datasheet for the IC that the module uses is quite a bit better though...

http://www.icofchina.com/d/file/xiazai/2016-12-05/b1be6f481cdf9d773b963ab30a2d11d8.pdf

Am I missing something here?

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(OnOffPin,HIGH);
//Wait for GPS lock and record position
digitalWrite(OnOffPin,LOW);

You set the pin HIGH, then IMMEDIATELY set it LOW again. It is high for a matter of only a few micro-seconds.

RayLivingston:
Am I missing something here?

void loop() {

// put your main code here, to run repeatedly:
digitalWrite(OnOffPin,HIGH);
//Wait for GPS lock and record position
digitalWrite(OnOffPin,LOW);




You set the pin HIGH, then IMMEDIATELY set it LOW again. It is high for a matter of only a few micro-seconds.

Sorry, I simplified the code a lot in order to put across what I was doing but probably generated more confusion in the process. There is code between those operations that continually reads the GPS position until satellite lock is achieved.

If you're asking for help on code that does not work, POST THE ACTUAL CODE that you have ACTUALLY RUN! Otherwise, you're just wasting everyone's time.

I have done, see my earlier comment.

take a look at#1 .... perhaps we ALL save time...