# Communicate I/O over I2C

**URL:** <https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021>\
**Category:** General\
**Created:** [9 February 2022 10:48 UTC](https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021 "2022-02-09T10:48:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pa3fbx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pa3fbx/32/49199_2.png) [@pa3fbx](https://discourse.nodered.org/u/pa3fbx)\
**Post date:** [9 February 2022 10:48 UTC](https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021/1 "2022-02-09T10:48:01Z")

</div>

Hi. On my project i started to use I2C to communicate between several devices.  
This was ok with 1 or 2 devices but now starting to get up to 9 devices i need to modify some data flow.  
1 device is an MCP23017 and i send all individual bits i/o..  
Now i want to send I2c combined byte and use 16bit split to split the i/o back into usable input bits.

My problem is only to create output bits from gpio inputs to an output byte over I2c...

So i need a node to send 16 separate switching states to an MCP23017 over I2c with 2 byte.  
Eg. 0000 0000 0000 1111 would be 0E or 15....

who can point me in the right direction..

best regards benno

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 February 2022 11:54 UTC](https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021/2 "2022-02-09T11:54:59Z")

</div>

here is a example of joining incoming i/0 in to a object, then converting to a binary string and outputting a hex string.  
the incoming gpio need topics link in the inject nodes.

```auto
[{"id":"33a4a125.5feda6","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio1","payload":"1","payloadType":"num","x":90,"y":4360,"wires":[["f1206efe.98776"]]},{"id":"f1206efe.98776","type":"join","z":"c791cbc0.84f648","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":310,"y":4580,"wires":[["901640e3.170d88"]]},{"id":"d3409c04.3ffeb","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio1","payload":"0","payloadType":"num","x":100,"y":4400,"wires":[["f1206efe.98776"]]},{"id":"6717ce0b.5720f8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio2","payload":"1","payloadType":"num","x":80,"y":4480,"wires":[["f1206efe.98776"]]},{"id":"b96edc6b.f39de8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio2","payload":"0","payloadType":"num","x":80,"y":4520,"wires":[["f1206efe.98776"]]},{"id":"55548b7e.06c7cc","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio3","payload":"1","payloadType":"num","x":90.33332824707031,"y":4583.66650390625,"wires":[["f1206efe.98776"]]},{"id":"189d1c22.ef16b4","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio3","payload":"0","payloadType":"num","x":100.33332824707031,"y":4623.66650390625,"wires":[["f1206efe.98776"]]},{"id":"4b6d363.10c3c48","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio4","payload":"1","payloadType":"num","x":100,"y":4680,"wires":[["f1206efe.98776"]]},{"id":"dbb44363.c19a5","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpio4","payload":"0","payloadType":"num","x":110,"y":4720,"wires":[["f1206efe.98776"]]},{"id":"901640e3.170d88","type":"function","z":"c791cbc0.84f648","name":"","func":"msg.payload = parseInt(Object.values(msg.payload).reverse().join(\"\"), 2).toString(16);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":4580,"wires":[["5e428022.edd948"]]},{"id":"5e428022.edd948","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":4580,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![pa3fbx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pa3fbx/32/49199_2.png) [@pa3fbx](https://discourse.nodered.org/u/pa3fbx)\
**Post date:** [9 February 2022 16:50 UTC](https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021/3 "2022-02-09T16:50:04Z")

</div>

Marvelous, Will try it tomorrow morning and come back with the results.

Thanks so far.

Benno

---

<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:** [10 April 2022 16:50 UTC](https://discourse.nodered.org/t/communicate-i-o-over-i2c/58021/4 "2022-04-10T16:50:23Z")

</div>

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