Raspberry Pi Read GPIO pin at regular intervals

Hello, first time posting, I am on a steep learning curve with Node-Red, so forgive my ignorance.
I am trying to create a flow that reads the state of a GPIO pin on the raspberry pi every minute. I can read the current status using the rpi-gpio in node but it only activates when there is a change of state and I want to read on a defined period.

This is the way event based programming works. If it hasn't changed it is the same value as before so why do you need to read it again ?
If you really do need to you can save it in a flow context variable and then use a repeating inject to read it back out again, but that shouldn't be necessary.

1 Like

I fully agree with @dceejay that it shouldnt be necessary as you can save the state in a flow variable to have access to it any time but just for options you could also use the exec node and wiringpi in combination with an inject node to read it every minute if necessary.
Install wiringpi using sudo apt-get install wiringpiand than use a command like gpio -g read 17 in the exec where 17 is your pin to read.
Johannes

Thank you for your replies. The purpose of the reading the GPIO at regular intervals is so that I can display the status of the GPIO pin over time but connecting the rpi gpio in node straight to the chart node gives me a graph like this instead of a line running at either 1 or 0
2020-04-24-113752_1280x1024_scrot

So I figured that if I set up a time stamp to take a reading every minute then I would get the desired result..I am making my first foray into the world of flow context variables but have hit another brick wall This is what I have so far

With this in my change node

Assuming what I have done is correct how do I get the message to read in the lower flow? As the I example I saw used a get option but I don't seem to have that option in my change node.

There is an even easier way:
Feed the Gpio directly into the chart but go to the settings of the chart node and at the bottom just above the color selection you will see a dropdown labeled interpolate.
Change this from linear to step and I think you will get the desired result.
Johannes

Edit:
the way you set the flow var looks right, you can see that its working if you look on the top of where the debug tab is there is a context browser where you can see the set values of context flow and global vars.(click on the little arrow next to the dashboard settings)

image

And i forgot something in the editing of the previous post :see_no_evil:
To get the flow var in another change node just turn around what you do to set it:
set msg.payload to flow.something
Johannes

If you want to get a regular repeat of the gpio signal to keep the graph updated then insert a Trigger node between the GPIO and the chart. Configure the Trigger node like this
image
Then the original value will be passed on every minute till the pin changes state, then that value will be repeated.

3 Likes

Thank you all for your responses and solutions, I seem to have got the desired solution. Now ll I have got to do is create a pie chart to show the percentage time that the pin has been high or low.... but that is for another day.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.