Program a button to begin GPS/GNSS tracking

Can anyone help me program a button to begin GPS tracking? I have a sketch that works with GPS, and another one that pushes a button on WB_IO1, but I can’t figure out how to make the button wake the device and start the GPS.
I’m using a RAK5005-O, RAK4630, 1910 and 1904. Is this possible?
Any advice would be amazing!

Welcome to the forum @cseby2000

How to implement the button to wake up the device depends on which example code you used as a base for the GNSS tracking?
Basic GNSS example => WisBlock/examples/RAK4630/solutions/GPS_Tracker at master · RAKWireless/WisBlock · GitHub
LPWAN Tracker Solution (used on RAK10700) => GitHub - RAKWireless/LPWAN-Tracker-Solution: LPWAN Tracker Solution "Built with RAK's WisBlock"

The way to wake-up the device is slightly different for the two examples.

Bernd,
Thank you for your fast response! Sorry I was unclear. It’s definitely the basic GNSS example I truly appreciate you taking the time.

Hi Scott,

If you just want to poll the button status, you can remove the timer initialization and timer start from the code and call two functions to retrieve the location and send it over LoRaWAN.

void setup()
{
	// ...
	// keep the initialization calls
	// ...
	// Initialize Button
	pinMode(WB_IO1, INPUT_PULLUP);
}

void loop()
{
	// Put your application tasks here, like reading of sensors,
	// Controlling actuators and/or other functions.
	if (digitalRead(WB_IO1) == LOW)
	{
		// Button pushed, try to get location and send the LoRaWAN packet

		// Get location
		tx_lora_periodic_handler();
		// Send the packet
		send_lora_frame();
	}
}

Remove or comment all calls to TimerSetValue, TimerStart and TimerSetValue from the code to disable the automatic sending.

If you want to send the packet independent of the orientation, remove as well if (abs(x - z) < 400) (just the line) from tx_lora_periodic_handler


This requires some fine tuning, but it should give you an idea how to start.
You should add

  • check if sending is still active
  • check if the WisBlock has joined the network already
  • check the time since last packet sent, to avoid sending to often.

I’m not very experienced in programming and don’t know C++, but I added your changes, and tried several different variations, but no matter what I do, it just goes through the loop function on its own over and over. I can’t get the button to do anything when I press it if I have the GPS functions in the sketch.

How is your button connected to WB_IO1?

It is connected to IO1 and GND.

Then it should work if you implemented everything as I showed.

  • Important to set the GPIO as input with a pull-up!
  • (digitalRead(WB_IO1) == LOW) makes no sense, look into my example code. It must be if (digitalRead(WB_IO1) == LOW)
void setup()
{
	// ...
	// keep the initialization calls
	// ...
	// Initialize Button
	pinMode(WB_IO1, INPUT_PULLUP);
}

void loop()
{
	// Put your application tasks here, like reading of sensors,
	// Controlling actuators and/or other functions.
	if (digitalRead(WB_IO1) == LOW)
	{
		// Button pushed, try to get location and send the LoRaWAN packet

		// Get location
		tx_lora_periodic_handler();
		// Send the packet
		send_lora_frame();
	}
}

I tried your loop function, as well as this one:

void loop()
{
// Put your application tasks here, like reading of sensors,
// Controlling actuators and/or other functions.
int stat=digitalRead(WB_IO1);
if(!stat){
// Get location
tx_lora_periodic_handler();
// Send the packet
send_lora_frame();
delay(1000);
}
}
changed timer values you mentioned, adjusted void setup and void loop, tried a few different things on the loop with no success, basically what happens is the gps packets are still constantly triggering regardless of the timers being commented out

Sometimes the simplest things get forgotten.

RAK1910 uses both WB_IO1 and WB_IO2 pins.
WB_IO1 is connected to the 1PPS output of the GNSS chip, WB_IO2 is used to switch on/off the power and control reset.

Your button cannot work on the RAK5005-O on WB_IO1, because the pin is already used.

Only solution: Use RAK13002 to get access to other GPIO’s (WB_IO3 … WB_IO6)

I was afraid of that! Can’t say we didn’t try though, haha! I may have one of those boards, thank you for the tip.

I’m looking at implementing this “panic button” product from SEEED, although they have been “out of stock” for months.

Anyone else tried/used this yet?

I have a Missouri-based application waiting to give to farmers who will soon have a LORA gateway with a good antenna to cover a 5 mile radius or so.

Charlie

Coming soon: RAK2171 TrackIt?
Small, works with LoRa/LoRaWAN, has BLE to connect to phone as well.

I have prototype, it works well. But still not in stock.
image