# Convert gpio values to a binary sequence

**URL:** <https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102>\
**Category:** General\
**Created:** [14 March 2020 14:10 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102 "2020-03-14T14:10:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xhamse2dine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xhamse2dine/32/18346_2.png) [@Xhamse2dine](https://discourse.nodered.org/u/Xhamse2dine)\
**Post date:** [14 March 2020 14:10 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/1 "2020-03-14T14:10:52Z")

</div>

Hi guys,  
i want to reads values from 4 GPIO (1 or 0)  
and convert this 4 values to a binary sequence.  
can i use a "join" node in node-red ? if yes how ?  
Thanks in advance.

---

<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:** [14 March 2020 14:24 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/2 "2020-03-14T14:24:18Z")

</div>

Welcome to the forum.  
If you set a join mode to wait for 4 values and set it to put them into a string it should work. It will get complicated if you need them in any ordered way.

---

<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 March 2020 14:24 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/3 "2020-03-14T14:24:35Z")

</div>

Yes, that is a way to do it. See the post in the node-red cookbook on Joining Streams for how to do it. In addition you will want to select And Every Intermediate Message in the Join node and make sure the four inputs have different topics.

---

<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:** [14 March 2020 14:35 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/4 "2020-03-14T14:35:28Z")

</div>

Key Object pairs works better as it also shows the order:

```auto
[{"id":"f66c52e5.e79f","type":"join","z":"5542a8a0.2ca958","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":460,"y":220,"wires":[["c20ea9e0.d202e8"]]},{"id":"a01e6606.c17d38","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"two","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":160,"wires":[["f66c52e5.e79f"]]},{"id":"a74767e2.c3a8b8","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"four","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":280,"wires":[["f66c52e5.e79f"]]},{"id":"81b4c30e.59ce1","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"three","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":220,"wires":[["f66c52e5.e79f"]]},{"id":"b3f07b2a.53a8b8","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"one","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":100,"wires":[["f66c52e5.e79f"]]},{"id":"c20ea9e0.d202e8","type":"debug","z":"5542a8a0.2ca958","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":220,"wires":[]}]

```

---

<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 March 2020 14:41 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/5 "2020-03-14T14:41:16Z")

</div>

> [@ghayne](#):
>
> Key Object pairs works better

That's what the [example in the cookbook](https://cookbook.nodered.org/basic/join-streams) does. For this case it will also need the Subsequent Messages box checked though, as the GPIO will only send values on change.

---

<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:** [14 March 2020 14:59 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/6 "2020-03-14T14:59:54Z")

</div>

> [@Colin](#):
>
> For this case it will also need the Subsequent Messages box checked though, as the GPIO will only send values on change.

Good point Colin!

---

<div class="post-metadata">

**Author:** ![Xhamse2dine](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xhamse2dine/32/18346_2.png) [@Xhamse2dine](https://discourse.nodered.org/u/Xhamse2dine)\
**Post date:** [14 March 2020 22:35 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/7 "2020-03-14T22:35:51Z")

</div>

yes sir i need them in a certain order( sequence from least significant bit to the most significant bit)  
Do you have any other solution ?

---

<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:** [14 March 2020 22:39 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/8 "2020-03-14T22:39:36Z")

</div>

This might give you an idea how you can do it:

```auto
[{"id":"5542a8a0.2ca958","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"f66c52e5.e79f","type":"join","z":"5542a8a0.2ca958","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":460,"y":220,"wires":[["c20ea9e0.d202e8"]]},{"id":"a01e6606.c17d38","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"two","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":160,"wires":[["f66c52e5.e79f"]]},{"id":"a74767e2.c3a8b8","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"four","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":360,"wires":[["f66c52e5.e79f"]]},{"id":"81b4c30e.59ce1","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"three","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":260,"wires":[["f66c52e5.e79f"]]},{"id":"b3f07b2a.53a8b8","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"one","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":60,"wires":[["f66c52e5.e79f"]]},{"id":"c20ea9e0.d202e8","type":"debug","z":"5542a8a0.2ca958","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":220,"wires":[]},{"id":"75d0a16c.2cad5","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"one","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":100,"wires":[["f66c52e5.e79f"]]},{"id":"b4dd1c38.bae15","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"two","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":200,"wires":[["f66c52e5.e79f"]]},{"id":"7ed05e27.b65e3","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"three","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":300,"wires":[["f66c52e5.e79f"]]},{"id":"24f038fa.41f9e8","type":"inject","z":"5542a8a0.2ca958","name":"","topic":"four","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":400,"wires":[["f66c52e5.e79f"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 May 2020 22:39 UTC](https://discourse.nodered.org/t/convert-gpio-values-to-a-binary-sequence/23102/9 "2020-05-13T22:39:40Z")

</div>

Closed on 13 May 2020 22:39 UTC

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