# GPIO processing speed

**URL:** https://discourse.nodered.org/t/gpio-processing-speed/12191
**Category:** General
**Created:** [13 June 2019 17:20 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191 "2019-06-13T17:20:52Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [13 June 2019 17:20 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/1 "2019-06-13T17:20:52Z")

</div>

HI,

Im trying to count the amount of signals of a stamping machine. Every 200miliseconds there is a signal. Is this possible to count within node-red and a Raspberry PI 3b+? or is the processing time to count a signal more then 200 miliseconds?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [13 June 2019 18:01 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/2 "2019-06-13T18:01:50Z")

</div>

Sounds well within the capabilities of a Pi and Node-RED

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [13 June 2019 18:10 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/3 "2019-06-13T18:10:21Z")

</div>

Any recommendation how to count it?

---

<div class="post-metadata">

### Author: ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)
#### Post date: [13 June 2019 18:32 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/4 "2019-06-13T18:32:14Z")

</div>

That's a very open ended question. Are you looking for a daily count? An hourly count? A total lifetime count? A rolling average? Different use cases will require slightly, or possibly even very different approaches.

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [13 June 2019 19:26 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/5 "2019-06-13T19:26:25Z")

</div>

A daily count would be the best if possible

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [13 June 2019 20:01 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/6 "2019-06-13T20:01:58Z")

</div>

The node-red-contrib-counter would be the place to start

> **[node-red-contrib-counter](https://flows.nodered.org/node/node-red-contrib-counter)**
>
> A Node-RED node to create a counter with messages.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/af5a1fb123466c2eea97dc7aab3017a5441bb378.png)

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [13 June 2019 20:37 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/7 "2019-06-13T20:37:59Z")

</div>

> [@Carloj](#):
>
> Every 200miliseconds there is a signal.

If there is a signal every 200 milliseconds then the signal count per day is 432000, or do the signals themselves contain more information?

Or are you trying to count how long the machine is working per day?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 June 2019 20:59 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/8 "2019-06-13T20:59:22Z")

</div>

While 200 mS should be fine - for something that is happening like that all day I would probably use something more dedicated like an arduino or esp8266 chip to be a dedicated counter - then feed the result to Node-RED. That way you won't miss anything if you have to restart the Pi for whatever reason - like upgrade, re-deploy, etc

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 05:49 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/9 "2019-06-14T05:49:24Z")

</div>

It is the amount of products the machine makes. Every 200ms +/- there is a product

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 05:53 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/10 "2019-06-14T05:53:41Z")

</div>

Well, i understand it. But it's only for 1 shift, so 8 hours a day. Any updates or upgrades i can do before or after that time.

About the esp8266 or esp32. Could i use Mqtt to communicate? It's just a signal 1 or 0.

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 06:02 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/11 "2019-06-14T06:02:01Z")

</div>

I tried the counter node but when the manual counter on the machine counts 50 the counter node counts 3? And when i look into the raspberry pi pin node it flashes (1,0) way to slow like every second it changes. Or could this be a framerate issue?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [14 June 2019 06:26 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/12 "2019-06-14T06:26:08Z")

</div>

I don't think its a framerate issue - I can count pulses every 200ms very reliably  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b558e17b8983c4ca65821ac56d1c959f683401a8.png)

Do you know the specification of the pulse width coming out of the machine?

Try adjusting the Debounce time parameter to a value of 1 ms and see if reliability improves  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/323990ffb2e30ea3193f5b12ccbb4a9d578d0e81.png)

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [14 June 2019 06:37 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/13 "2019-06-14T06:37:32Z")

</div>

Hi,  
As mentioned in this thread... you could use the ESP8266 to count the pulses.  
The Wemos D1 Mini (running ESP Easy firmware) is a great board/module and very inexpensive.  
It has loads of plugins including a 'count' facility and MQTT (so you could send the 'count' value to Node-RED via MQTT).

I prefer to use an inexpensive board for sensing switches and transducers rather than using the RPi's GPIO pins because if you have a problem (with wiring or voltage levels) you have only destroyed a 'cheap' unit rather than an expensive Raspberry Pi.

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 07:46 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/14 "2019-06-14T07:46:26Z")

</div>

Im trying it now. Im not sure of the pulse width but i can see that with 1mS it's a bit optimistic and 50mS is no result (stays on 0). So it should be between those i think?

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 07:51 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/15 "2019-06-14T07:51:32Z")

</div>

I understand your comment. The raspberry is galvanic isolated from the machine, so it should not be a problem.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 June 2019 08:05 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/16 "2019-06-14T08:05:38Z")

</div>

> [@Carloj](#):
>
> Im trying it now. Im not sure of the pulse width but i can see that with 1mS it's a bit optimistic

What to you mean by a bit optimistic?

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 08:15 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/17 "2019-06-14T08:15:32Z")

</div>

It was counting more then the machine. But i noticed it counts the signals 0 and 1 so it doubles it.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 June 2019 08:21 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/18 "2019-06-14T08:21:33Z")

</div>

So does that mean that with 1ms it is working correctly, once you divide by 2?

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [14 June 2019 09:36 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/19 "2019-06-14T09:36:42Z")

</div>

Yeh, it works. Im gonne test if i can use mqtt to get them on my server. 🤞

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [14 June 2019 12:22 UTC](https://discourse.nodered.org/t/gpio-processing-speed/12191/20 "2019-06-14T12:22:30Z")

</div>

Even if you can get it to work, I'd still follow Dave's advice and use an ESP8266 to do the counting and then reduce the updates to MQTT to a more manageable level - every few minutes unless you really need it more often (what would you do with information moving that fast though?).

An ESP8266 is WiFi connected and there are MQTT libraries that allow you to write direct.

While a 200ms signal may process just fine most of the time, You cannot be sure that something happening on your Pi won't pause processing because Linux is not a real-time OS. The ESP8266 however IS a real-time system.

[Next page](https://discourse.nodered.org/t/gpio-processing-speed/12191.md?page=2)
