RAK5801 LoraWan Pressure Sketch

I have a 4360 on a 5005-0 V1.0 and a 5801 analog sensor.

I can use the example 4-20ma pressure sketch in Arduino IDE and I can successfully read mA’s from a signal generator connected to ground pin 6 and analog input pin 8.

With this same setup, I can load the 4361 sketch for LoraWan OTAA-ABP and I can successfully connect and transmit to my network server (with all sensors still connected).

However, running the Hydraulic_Pressure_Monitoring.ino sketch, the device hangs sometime while trying to read the analog data. The only modification I made to the sketch was the US915 frequency and my OTAA data. My gateway gets the join request, and following is output in the serial monitor, and then it hangs.

Welcome to RAK4630 LoRaWan!!!
Type: OTAA
Region: US915
OTAA Mode, Network Joined!
Sending frame now...
-------average_raw------ = 523 
-------voltage_ain------ = 1.838672 

I also noticed that disconnecting the ground pin allows the operation to continue, but that breaks the circuit and then get zeroes for the analog data.

In another sketch I did add more logging to debug, but I’ve not tracked it down to any specific line or area. It actually seemed more like a timing issue, but I’m lost on that also.
I’m so close to getting this into the field for testing, any help appreciated!

Without seeing the code, it is not easy to help.

My guess, the problem might be related to the fact that the LoRaWAN-OTAA-ABP example is sending the packet from a timer interrupt, which is ok for an example, but not very good if you are doing lengthy operations before sending the packet.

It might help if do the reading of the 4-20mA sensor outside of the timer interrupt.

E.g. Use FreeRTOS seamphores.
In setup() initialize a semaphore and take it
In loop() wait for the semaphore
In tx_lora_periodic_handler() instead of calling send_lora_frame(), give the semphore, which will run the loop(), then from there read the 4-20mA sensor and send the packet.

Code snippets:

/** Semaphore used by events to wake up loop task */
SemaphoreHandle_t g_task_sem = NULL;

void setup(void)
	// .... usual initialization stuff
	// Create the task event semaphore
	g_task_sem = xSemaphoreCreateBinary();
	// Initialize semaphore
	// Take the semaphore, this stops the loop() from being executed
	// .... other initialization stuff

void loop(void)
	// Wait forever until semaphore is released, FreeRTOS will put the loop task into sleep
	xSemaphoreTake(g_task_sem, portMAX_DELAY);
	Serial.println("Loop wake up");

	// .... Read the 4-20mA sensor
	// .... Prepare your payload
	// Send the payload
	if (lmh_join_status_get() != LMH_SET)
		//Not joined, try again later

	lmh_error_status error = lmh_send(&m_lora_app_data, g_CurrentConfirm);
	if (error == LMH_SUCCESS)
		Serial.printf("lmh_send ok count %d\n", count);
		Serial.printf("lmh_send fail count %d\n", count_fail);

/**@brief Function for handling user timerout event.
void tx_lora_periodic_handler(void)
	TimerSetValue(&appTimer, LORAWAN_APP_INTERVAL);
	Serial.println("Timer wake up");

Thank you @beegee for looking at this, I’ll start implementing this to see if I can make some progress.

Sorry for the confusion, I was talking about example code that comes with the 4630 library, specifically this sketch

@beegee, thanks again, that was an easy implementation and it fixed the issue of hanging right away.

Unfortunately, I’m not getting the same current readings on the input port as I do when I run this sketch, which uses the same calculation, and gives the expected results. The only difference from high level is no radio functions in the second sketch. Seems like something is affecting the current.

I’m using a 4-20ma current generator with ground connected to pin 6 and signal connected to pin 8, again, which works as expected until I try to use a sketch that talks to lora.

Any help appreciated!

UInfortunately I have no equipment to run tests with the 4-20mA module.
I am not sure if the LoRa has an influence, because while you are reading the values, the LoRa transceiver is not active. You start the sending/reading sequence after that.

I see that both sketches are basically using the same formulas, only difference, but from math-rules it should not make a difference, one sketch is using

current_sensor = voltage_ain / 149.9*1000;

while the other one is using

current_sensor = (voltage_ain / 149.9) * 1000;

Again, thanks for looking. Unfortunately like you said the math calc doesn’t affect the outcome.

I have several of these, including the updated 19007 base board, but same results. The same thing in the field when I hooked up an actual 4-20ma source and used the pin 5 for power source and again pin 8 for signal.

I’ve exhausted my electronic engineering just getting the signal generator working lol

Just a little extra info, when I run the lorawan sketch, the analog read gets a semi constant value between 30-50, is what I have observed. This happens with and without a connection on the input pins.

Is there anyone that can help me stay sane and validate they have a working setup?

I’ve ordered a RAK7432 which is a preconfigured 4-20mA reader. The specs don’t say what components it uses, crossing my fingers.

Inside RAK7432 are WisBlock modules, but a different Core module. Not sure which one. I am guessing RAk4270 (old model) or RAK3172 (new model).