# How to read GPIO as binary

**URL:** <https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840>\
**Category:** General\
**Created:** [15 January 2019 13:22 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840 "2019-01-15T13:22:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![15green](https://avatars.discourse-cdn.com/v4/letter/1/c6cbf5/32.png) [@15green](https://discourse.nodered.org/u/15green)\
**Post date:** [15 January 2019 13:22 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/1 "2019-01-15T13:22:20Z")

</div>

I am a newcomer to Node-Red but learning all the time and managed to get a few things up and running on the dashboard on my Pi.

However my next goal is to read an 8 bit binary code as input to 8 GPIO pins on my Pi, and then turn it into a decimal code(0-255).

It sounds simple but not sure to start. Any ideas/advice welcomed!

---

<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:** [15 January 2019 14:58 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/2 "2019-01-15T14:58:01Z")

</div>

Method:  
Sum(Gpio1x1, Gpio2x2,Gpio3x4,......Gpio8x128) lowest to highest bit.

---

<div class="post-metadata">

**Author:** ![15green](https://avatars.discourse-cdn.com/v4/letter/1/c6cbf5/32.png) [@15green](https://discourse.nodered.org/u/15green)\
**Post date:** [16 January 2019 10:57 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/3 "2019-01-16T10:57:51Z")

</div>

Thanks @ghayne I get your principle to do the math. But I have problem adding the numbers in a function. How do I read the gpio status (and add) all 8 all at once? .

---

<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:** [16 January 2019 11:02 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/4 "2019-01-16T11:02:07Z")

</div>

No need for a function node, think flow context variables using a change node. Cannot give you an example as I am away from a node-red machine.

---

<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:** [16 January 2019 11:27 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/5 "2019-01-16T11:27:59Z")

</div>

> [@15green](#):
>
> How do I read the gpio status (and add) all 8 all at once? .

Feed all the inputs into a Join node configured something like this

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

The effect is that whenever an input changes, then 0.1 second later (to give any other changed inputs time to arrive) it will send a message with all 8 values in the payload, identified by their pin numbers. You might need to play with the delay.

---

<div class="post-metadata">

**Author:** ![15green](https://avatars.discourse-cdn.com/v4/letter/1/c6cbf5/32.png) [@15green](https://discourse.nodered.org/u/15green)\
**Post date:** [18 January 2019 18:43 UTC](https://discourse.nodered.org/t/how-to-read-gpio-as-binary/6840/6 "2019-01-18T18:43:29Z")

</div>

Thanks @Colin I have this running now.
