What is the easiest way to create a 5 to 32 line decoder in node red?

Hello everyone, I am a novice at node red.
I am trying to automate an old MT3000 manual tuner. In my design I have a 32 position binary switch (5 bit output) that I would like to have 32 mutually exclusive outputs to drive relays (one at a time). Can someone help me find the easiest nodes/flows to take a 5 bit binary input from a MCP23008 input and change it to one of 32 (2 x mcp23017) outputs at the other end of an I2C line?
Any help or guidance would be appreciated!
Thanks,
Dave, K5OZ

Ok, I'll start....

This is going to be fun. :wink:

How are you receiving the messages?

So you receive a message who's value is something from 1 to 32 - yes?
And you want to decode that to a single bit that is on the output of 2 x MPC23017 chips...
Or something like that.

I'm not really the right person to be helping you as I don't have the knowledge of what the commands are. I usually stumble around until I find the one I need, or ask for help.

But, let's make a start.

//  May as well assign a variable to the message.
var desired_output = msg.payload;
//   This is the 1 in 32 pointer.
var output_bit = 0;

Sorry.... There is a command
this.m_bits.push(bits[i]);
That may help you.

I don't want to go too much further as I am already out of my depth.

But you get the incoming number and set that bit in the output_bit byte.

Sorry I seemed to drop this.

I am really out of my depth. But what's life without a challenge?

So can you elaborate on what the input range is?
I'm taking it as 1 to 32

What node are you using to send the message?
Basically you need some rudimentary maths to work it out and set the bit.

I just don't know what 2^32 is and if it falls into being an integer.
(Probably not)

But you create a variable that includes the range needed to cover 2^32.
Get the number, raise 2 to that value and then put that number into/onto the I2C bus and you will have 1 of the 32 bits set.

As I said: I'm out of my depth and am drowning in a lot of my own problems.
Sorry I can't help you any better.

There are a few different nodes for both mcp23008 and mcp23017 in the flows library.

Perhaps you could add some more detail about your switch and sketch out how you plan to connect it up ?
eg Is this connecting to a RPi ?

Hello all, thanks for the quick replies!
Here's a little more on the project that may help. As I say I am very much a newbie at this node red. I am a hardware guy. See pictures below for more info on project.

In summary, I am converting a old 3KW manual T-Type antenna tuner (Trans-match would be a better terminology) into an Automatic Antenna Tuner while still keeping manual capability. I will be replacing the manual switch on the tuner with a 24 position switch that has a binary output. I know I said 32 positions, but it is really going to be a 5 to 24 line decoder. I just said 5 to 32 for the binary inclined persons. I will use this binary input to control 1 of 24 relays to short the correct tap on the coil to ground and light associated display LED. Two stepper motors will adjust the two variable capacitors. These Steppers have a continuous rotatable POT that will give me feedback on position. The controls on the front panel will have an Auto/Manual switch with a memorize button. The system will get SWR and FREQ info from a FLEX Bus (my radio is a Flex 6600) and know were to place all the tuner controls from memory as the Flex changes frequencies. The processor is a Raspberry Pi Zero 2W that mounts on the control board.

@Trying_to_learn - I will look into this.
@smcgann99 - Yes I am using a RPi and mcp23017s.






Dave

2 Likes

Oops forgot the schematics:




Dave

2 Likes

Well this looks like an easy first project for NR :wink:

Looks like you are just using MCP23017 chips, there are a number of nodes for those. For simplicity would it not be easier to wire the Leds to come on with the relays, and remove the extra MCP23017 ? Also less coding.

Probably my eyesight but I couldn't see what you are using to read the feedback pots into the Pi, there are nodes for mcp3008.

I don't have anything connected to my Pi so I cannot test the nodes mentioned unfortunately.

What are the 24FC515 chips for - Could you not store any settings information you need on the Pi ?

Where to start -

I would suggest breaking this down into small functional chunks, then setup some beadboard and get each of the chips talking to NR via the appropriate nodes.

You can then build up a flow from there. eg reading the output from the binary switch, switching on relay outputs etc.

You will be in a better place to ask for specific help on the NR side of things, once you are able to show a flow with some input / output.

I look forward to see how this progresses. :smiley:

@smcgann99,
I originally thought about wiring directly, however, that would require lots of wiring and logic switching networks to go between auto and manual modes.

The 24F515 chips are for extra memory in case the pi read/writes to the sd card for memory gets into sd card failures.

The pots are wired to a ADS1115 I2C ADC. The stepper’s are wired to an Adafruit I2C Motorhat for the Pi zero.

I will try to get some flows for criticisms and improvements soon.

Thanks,
Dave

I don't think this would be an issue, what do you need to store / how would you write this ?

@smcgann99 and all;
Attached is a flow that I built. Don't laugh at it, I am trying to learn.
I can short the inputs and make the state change from On to Off however, I want to turn these five bits into a binary number that I can use to turn on one of 32 relays.
How do I make the MCP23017 read the inputs so I can join them into a binary number?

Read Binary Switch.json (19.5 KB)

Could you show what you get on debug set to (complete msg object) when you trigger inputs on MCP23017

@K5OZ As I don't have your nodes see if you can adapt this test flow to the output of your mcp nodes -

[{"id":"e958095560ded9c1","type":"debug","z":"43c26ad8e4dbc534","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":920,"wires":[]},{"id":"4163b16597679b1b","type":"inject","z":"43c26ad8e4dbc534","name":"bit 4 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"true","payloadType":"bool","x":160,"y":800,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"d2e94b362f0094b5","type":"inject","z":"43c26ad8e4dbc534","name":"bit 4 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"false","payloadType":"bool","x":160,"y":840,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"418f8dde3d5d0839","type":"inject","z":"43c26ad8e4dbc534","name":"bit 3 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"true","payloadType":"bool","x":160,"y":900,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"caf8fc1fc4b39a34","type":"inject","z":"43c26ad8e4dbc534","name":"bit 3 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"false","payloadType":"bool","x":160,"y":940,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"b8ede8fc3dd8d91d","type":"function","z":"43c26ad8e4dbc534","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0]\n\nbits[msg.topic] = msg.payload == true ? 1 : 0\n\nflow.set(\"bits\", bits)\n\nmsg.payload = parseInt(bits.join(\"\"), 2);\nmsg.topic = \"decimal\"\nnode.warn(bits)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":920,"wires":[["e958095560ded9c1"]]},{"id":"69582f39e1809158","type":"inject","z":"43c26ad8e4dbc534","name":"bit 5 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"0","payload":"true","payloadType":"bool","x":160,"y":700,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"6735164b20388a9b","type":"inject","z":"43c26ad8e4dbc534","name":"bit 5 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"0","payload":"false","payloadType":"bool","x":160,"y":740,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"1a574322b3504a54","type":"inject","z":"43c26ad8e4dbc534","name":"bit 2 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"3","payload":"true","payloadType":"bool","x":160,"y":1000,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"009ee10ece9ea6df","type":"inject","z":"43c26ad8e4dbc534","name":"bit 2 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"3","payload":"false","payloadType":"bool","x":160,"y":1040,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"4ed7a60f6602ce6b","type":"inject","z":"43c26ad8e4dbc534","name":"bit 1 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"4","payload":"true","payloadType":"bool","x":160,"y":1100,"wires":[["b8ede8fc3dd8d91d"]]},{"id":"65ff318191fd992a","type":"inject","z":"43c26ad8e4dbc534","name":"bit 1 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"4","payload":"false","payloadType":"bool","x":160,"y":1140,"wires":[["b8ede8fc3dd8d91d"]]}]

@smcgann99 Thanks for the input flow! I have been working it for a while and have succeeded! Works great and I will be able to improve it later without the MCP23017 node when I learn how to comm with the chip via I2C better.
Thanks
Dave

Here is the flow:
Read Binary Switch (2).json (20.7 KB)

:thumbsup: No problem

Have played with it a bit, see if it is something you can use.
bit 0 to bit 4 should come from i2c input.

[{"id":"97e3eafb5e14722d","type":"tab","label":"5=>32 decoder","disabled":false,"info":"","env":[]},{"id":"617b7b6bf48f140d","type":"function","z":"97e3eafb5e14722d","name":"0-7 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\n\nlet bits_o = [0, 0, 0, 0, 0, 0, 0, 0] \n\nlet decode = msg.payload\n\nswitch(decode) {\n    case 0:\n        bits_o[7] = 1\n        break\n    case 1:\n        bits_o[6] = 1\n        break\n    case 2:\n        bits_o[5] = 1\n        break\n    case 3:\n        bits_o[4] = 1\n        break\n    case 4:\n        bits_o[3] = 1\n        break\n    case 5:\n        bits_o[2] = 1\n        break\n    case 6:\n        bits_o[1] = 1\n        break\n    case 7:\n        bits_o[0] = 1\n        break\n}\n\nmsg0.payload = bits_o[7]\nmsg1.payload = bits_o[6]\nmsg2.payload = bits_o[5]\nmsg3.payload = bits_o[4]\nmsg4.payload = bits_o[3]\nmsg5.payload = bits_o[2]\nmsg6.payload = bits_o[1]\nmsg7.payload = bits_o[0]\n\nnode.warn('0-7 udgange  ' + bits_o)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":180,"wires":[["4dc8e7d48bab45fc"],["8d103b8eac08517a"],["0a61260f029e4a95"],["c0ab337cc1eba9c9"],["1a84f6aba9c6b2af"],["64852e0938f031b8"],["4fdcab956296f75b"],["6a62d4fbe33ab69b"]]},{"id":"4dc8e7d48bab45fc","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"6","set":"","level":"0","freq":"","out":"out","bcm":true,"x":700,"y":100,"wires":[]},{"id":"6a62d4fbe33ab69b","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"20","set":"","level":"0","freq":"","out":"out","bcm":true,"x":840,"y":280,"wires":[]},{"id":"64852e0938f031b8","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"16","set":"","level":"0","freq":"","out":"out","bcm":true,"x":840,"y":220,"wires":[]},{"id":"c0ab337cc1eba9c9","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"12","set":"","level":"0","freq":"","out":"out","bcm":true,"x":840,"y":160,"wires":[]},{"id":"8d103b8eac08517a","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"5","set":"","level":"0","freq":"","out":"out","bcm":true,"x":840,"y":100,"wires":[]},{"id":"4fdcab956296f75b","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"26","set":"","level":"0","freq":"","out":"out","bcm":true,"x":700,"y":280,"wires":[]},{"id":"1a84f6aba9c6b2af","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"19","set":"","level":"0","freq":"","out":"out","bcm":true,"x":700,"y":220,"wires":[]},{"id":"0a61260f029e4a95","type":"rpi-gpio out","z":"97e3eafb5e14722d","name":"","pin":"13","set":"","level":"0","freq":"","out":"out","bcm":true,"x":700,"y":160,"wires":[]},{"id":"06e2c56b1910aa15","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[4] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":540,"wires":[["9782c7eec7d057b9"]]},{"id":"dd48178cc5f9cac9","type":"debug","z":"97e3eafb5e14722d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":380,"wires":[]},{"id":"d7c207b02829c9ab","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[3] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":460,"wires":[["9782c7eec7d057b9"]]},{"id":"e3c208a2aa0b684c","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[1] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":300,"wires":[["9782c7eec7d057b9"]]},{"id":"b496c05047d34ba5","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[2] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":380,"wires":[["9782c7eec7d057b9"]]},{"id":"f2bdfb5e40f99834","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[0] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":220,"wires":[["9782c7eec7d057b9"]]},{"id":"c18e61185e181775","type":"inject","z":"97e3eafb5e14722d","name":"0 bit0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":560,"wires":[["06e2c56b1910aa15"]]},{"id":"4bf59cd00c9b6ec9","type":"inject","z":"97e3eafb5e14722d","name":"1 bit0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":520,"wires":[["06e2c56b1910aa15"]]},{"id":"eefebac5d8370d16","type":"inject","z":"97e3eafb5e14722d","name":"0 bit1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":480,"wires":[["d7c207b02829c9ab"]]},{"id":"41894b23bee161e0","type":"inject","z":"97e3eafb5e14722d","name":"1 bit1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":440,"wires":[["d7c207b02829c9ab"]]},{"id":"623c4e80fa8983cd","type":"inject","z":"97e3eafb5e14722d","name":"0 bit2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":400,"wires":[["b496c05047d34ba5"]]},{"id":"7184856fa3f2607b","type":"inject","z":"97e3eafb5e14722d","name":"1 bit2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":360,"wires":[["b496c05047d34ba5"]]},{"id":"e922ccba24a66d92","type":"inject","z":"97e3eafb5e14722d","name":"0 bit3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":320,"wires":[["e3c208a2aa0b684c"]]},{"id":"9deb38bc4bc6af5c","type":"inject","z":"97e3eafb5e14722d","name":"1 bit3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":280,"wires":[["e3c208a2aa0b684c"]]},{"id":"7a7c247e59d0f153","type":"inject","z":"97e3eafb5e14722d","name":"0 bit4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":240,"wires":[["f2bdfb5e40f99834"]]},{"id":"991d31676c164e78","type":"inject","z":"97e3eafb5e14722d","name":"1 bit4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":200,"wires":[["f2bdfb5e40f99834"]]},{"id":"30dae2070375b75b","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = [0, 0, 0, 0, 0] \n\nflow.set(\"bits\", bits)\nmsg.payload = bits\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":140,"wires":[["9782c7eec7d057b9"]]},{"id":"a5d94ddc05a2a765","type":"inject","z":"97e3eafb5e14722d","name":"reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":140,"wires":[["30dae2070375b75b"]]},{"id":"9782c7eec7d057b9","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \nlet vaerdi = 0\n\nvaerdi = Math.pow(2, 4) * bits[0]\nvaerdi = vaerdi + Math.pow(2, 3) * bits[1]\nvaerdi = vaerdi + Math.pow(2, 2) * bits[2]\nvaerdi = vaerdi + Math.pow(2, 1) * bits[3]\nvaerdi = vaerdi + Math.pow(2, 0) * bits[4]\n\n\n//msg.payload = parseInt(bits.join(\"\"), 2);\n\nmsg.payload = vaerdi\n\nnode.warn(bits)\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":380,"wires":[["dd48178cc5f9cac9","c5fe6efb717cc017"]]},{"id":"fe03549976dbcb93","type":"function","z":"97e3eafb5e14722d","name":"8-15 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\n\nlet bits_p = [0, 0, 0, 0, 0, 0, 0, 0] \n\nlet decode = msg.payload - 8\n\nswitch(decode) {\n    case 0:\n        bits_p[7] = 1\n        break\n    case 1:\n        bits_p[6] = 1\n        break\n    case 2:\n        bits_p[5] = 1\n        break\n    case 3:\n        bits_p[4] = 1\n        break\n    case 4:\n        bits_p[3] = 1\n        break\n    case 5:\n        bits_p[2] = 1\n        break\n    case 6:\n        bits_p[1] = 1\n        break\n    case 7:\n        bits_p[0] = 1\n        break\n}\n\nmsg0.payload = bits_p[7]\nmsg1.payload = bits_p[6]\nmsg2.payload = bits_p[5]\nmsg3.payload = bits_p[4]\nmsg4.payload = bits_p[3]\nmsg5.payload = bits_p[2]\nmsg6.payload = bits_p[1]\nmsg7.payload = bits_p[0]\n\nnode.warn('8-15 udgange  ' + bits_p)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":660,"wires":[[],[],[],[],[],[],[],[]]},{"id":"c5fe6efb717cc017","type":"link out","z":"97e3eafb5e14722d","name":"","mode":"link","links":["00d9d73122463b39","8316c248caa91b4f","01a6d6933677b4bb","b288378eed936df2"],"x":635,"y":420,"wires":[]},{"id":"8316c248caa91b4f","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":405,"y":180,"wires":[["617b7b6bf48f140d"]]},{"id":"00d9d73122463b39","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":235,"y":660,"wires":[["fe03549976dbcb93"]]},{"id":"0872be30838a0b66","type":"function","z":"97e3eafb5e14722d","name":"16-23 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\n\nlet bits_q = [0, 0, 0, 0, 0, 0, 0, 0] \n\nlet decode = msg.payload - 16\n\nswitch(decode) {\n    case 0:\n        bits_q[7] = 1\n        break\n    case 1:\n        bits_q[6] = 1\n        break\n    case 2:\n        bits_q[5] = 1\n        break\n    case 3:\n        bits_q[4] = 1\n        break\n    case 4:\n        bits_q[3] = 1\n        break\n    case 5:\n        bits_q[2] = 1\n        break\n    case 6:\n        bits_q[1] = 1\n        break\n    case 7:\n        bits_q[0] = 1\n        break\n}\n\nmsg0.payload = bits_q[7]\nmsg1.payload = bits_q[6]\nmsg2.payload = bits_q[5]\nmsg3.payload = bits_q[4]\nmsg4.payload = bits_q[3]\nmsg5.payload = bits_q[2]\nmsg6.payload = bits_q[1]\nmsg7.payload = bits_q[0]\n\nnode.warn('16-23 udgange  ' + bits_q)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":660,"wires":[[],[],[],[],[],[],[],[]]},{"id":"01a6d6933677b4bb","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":475,"y":660,"wires":[["0872be30838a0b66"]]},{"id":"2e4ab5bbaa95e247","type":"function","z":"97e3eafb5e14722d","name":"24-31 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\n\nlet bits_r = [0, 0, 0, 0, 0, 0, 0, 0] \n\nlet decode = msg.payload - 24\n\nswitch(decode) {\n    case 0:\n        bits_r[7] = 1\n        break\n    case 1:\n        bits_r[6] = 1\n        break\n    case 2:\n        bits_r[5] = 1\n        break\n    case 3:\n        bits_r[4] = 1\n        break\n    case 4:\n        bits_r[3] = 1\n        break\n    case 5:\n        bits_r[2] = 1\n        break\n    case 6:\n        bits_r[1] = 1\n        break\n    case 7:\n        bits_r[0] = 1\n        break\n}\n\nmsg0.payload = bits_r[7]\nmsg1.payload = bits_r[6]\nmsg2.payload = bits_r[5]\nmsg3.payload = bits_r[4]\nmsg4.payload = bits_r[3]\nmsg5.payload = bits_r[2]\nmsg6.payload = bits_r[1]\nmsg7.payload = bits_r[0]\n\nnode.warn('24-31 udgange  ' + bits_r)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":860,"y":660,"wires":[[],[],[],[],[],[],[],[]]},{"id":"b288378eed936df2","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":735,"y":660,"wires":[["2e4ab5bbaa95e247"]]}]

Thanks Frida, I will give this a try tonight.
Dave

Has cleaned up the software a bit.
Use it as you see fit.

[{"id":"97e3eafb5e14722d","type":"tab","label":"5=>32 decoder_b","disabled":false,"info":"","env":[]},{"id":"617b7b6bf48f140d","type":"function","z":"97e3eafb5e14722d","name":"8-15 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\nlet bits = [0, 0, 0, 0, 0, 0, 0, 0] \n\nif(Math.trunc(msg.payload/8)===1) {\n    bits[7-msg.payload%8] = 1\n}\n\nmsg0.payload = bits[7]\nmsg1.payload = bits[6]\nmsg2.payload = bits[5]\nmsg3.payload = bits[4]\nmsg4.payload = bits[3]\nmsg5.payload = bits[2]\nmsg6.payload = bits[1]\nmsg7.payload = bits[0]\n\nnode.warn('8-15 udgange  ' + bits)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":1080,"wires":[["8da97ca7e62b334e"],["b0a32a90616a731b"],["f719ec32c2250e77"],["89b46b7f2bbf6bd2"],["42c18d04c5675448"],["778d95578c3dd088"],["e4e85eba084b2445"],["976cadc729286545"]]},{"id":"06e2c56b1910aa15","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[4] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":540,"wires":[["9782c7eec7d057b9"]]},{"id":"d7c207b02829c9ab","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[3] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":460,"wires":[["9782c7eec7d057b9"]]},{"id":"e3c208a2aa0b684c","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[1] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":300,"wires":[["9782c7eec7d057b9"]]},{"id":"b496c05047d34ba5","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[2] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":380,"wires":[["9782c7eec7d057b9"]]},{"id":"f2bdfb5e40f99834","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \n\nbits[0] = msg.payload\n\nflow.set(\"bits\", bits)\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":220,"wires":[["9782c7eec7d057b9"]]},{"id":"c18e61185e181775","type":"inject","z":"97e3eafb5e14722d","name":"0 bit0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":560,"wires":[["06e2c56b1910aa15"]]},{"id":"4bf59cd00c9b6ec9","type":"inject","z":"97e3eafb5e14722d","name":"1 bit0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":90,"y":520,"wires":[["06e2c56b1910aa15"]]},{"id":"eefebac5d8370d16","type":"inject","z":"97e3eafb5e14722d","name":"0 bit1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":480,"wires":[["d7c207b02829c9ab"]]},{"id":"41894b23bee161e0","type":"inject","z":"97e3eafb5e14722d","name":"1 bit1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":90,"y":440,"wires":[["d7c207b02829c9ab"]]},{"id":"623c4e80fa8983cd","type":"inject","z":"97e3eafb5e14722d","name":"0 bit2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":400,"wires":[["b496c05047d34ba5"]]},{"id":"7184856fa3f2607b","type":"inject","z":"97e3eafb5e14722d","name":"1 bit2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":90,"y":360,"wires":[["b496c05047d34ba5"]]},{"id":"e922ccba24a66d92","type":"inject","z":"97e3eafb5e14722d","name":"0 bit3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":320,"wires":[["e3c208a2aa0b684c"]]},{"id":"9deb38bc4bc6af5c","type":"inject","z":"97e3eafb5e14722d","name":"1 bit3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":90,"y":280,"wires":[["e3c208a2aa0b684c"]]},{"id":"7a7c247e59d0f153","type":"inject","z":"97e3eafb5e14722d","name":"0 bit4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":240,"wires":[["f2bdfb5e40f99834"]]},{"id":"991d31676c164e78","type":"inject","z":"97e3eafb5e14722d","name":"1 bit4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":90,"y":200,"wires":[["f2bdfb5e40f99834"]]},{"id":"30dae2070375b75b","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = [0, 0, 0, 0, 0] \n\nflow.set(\"bits\", bits)\nmsg.payload = bits\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":140,"wires":[["9782c7eec7d057b9"]]},{"id":"a5d94ddc05a2a765","type":"inject","z":"97e3eafb5e14722d","name":"reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":140,"wires":[["30dae2070375b75b"]]},{"id":"9782c7eec7d057b9","type":"function","z":"97e3eafb5e14722d","name":"","func":"let bits = flow.get(\"bits\") || [0, 0, 0, 0, 0] \nlet vaerdi = 0\n\nfor(let x = 0; x < 5; x++) {\n    vaerdi += Math.pow(2, x) * bits[4 - x]    \n}\n\nmsg.payload = vaerdi\n\nnode.warn(msg.payload)\nnode.warn(bits)\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":380,"wires":[["c5fe6efb717cc017"]]},{"id":"fe03549976dbcb93","type":"function","z":"97e3eafb5e14722d","name":"0-7 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\nlet bits = [0, 0, 0, 0, 0, 0, 0, 0] \n\nif(Math.trunc(msg.payload/8)===0) {\n    bits[7-msg.payload%8] = 1\n}\n\nmsg0.payload = bits[7]\nmsg1.payload = bits[6]\nmsg2.payload = bits[5]\nmsg3.payload = bits[4]\nmsg4.payload = bits[3]\nmsg5.payload = bits[2]\nmsg6.payload = bits[1]\nmsg7.payload = bits[0]\n\nnode.warn('0-7 udgange  ' + bits)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":760,"wires":[["9dfe08a047869b0a"],["66893a0d62a17ebe"],["2438fa55f994cdf4"],["38a61d3a9e99b39d"],["0f1b581febe7d546"],["ac672808a7e8c9de"],["c021b750072f3e7b"],["a381599b39a4acee"]]},{"id":"c5fe6efb717cc017","type":"link out","z":"97e3eafb5e14722d","name":"","mode":"link","links":["00d9d73122463b39","8316c248caa91b4f","01a6d6933677b4bb","b288378eed936df2"],"x":635,"y":380,"wires":[]},{"id":"8316c248caa91b4f","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":45,"y":1080,"wires":[["617b7b6bf48f140d"]]},{"id":"00d9d73122463b39","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":45,"y":760,"wires":[["fe03549976dbcb93"]]},{"id":"0872be30838a0b66","type":"function","z":"97e3eafb5e14722d","name":"16-23 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\nlet bits = [0, 0, 0, 0, 0, 0, 0, 0] \n\nif(Math.trunc(msg.payload/8)===2) {\n    bits[7-msg.payload%8] = 1\n}\n\nmsg0.payload = bits[7]\nmsg1.payload = bits[6]\nmsg2.payload = bits[5]\nmsg3.payload = bits[4]\nmsg4.payload = bits[3]\nmsg5.payload = bits[2]\nmsg6.payload = bits[1]\nmsg7.payload = bits[0]\n\nnode.warn('16-23 udgange  ' + bits)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":1400,"wires":[["5aa83f59da0806ea"],["56c293f6fdf5de54"],["563da2fd95131a6c"],["03d24bd0152182bd"],["c1b241fe5e1e7a6b"],["7cac629d07ece575"],["3a284208869613c6"],["8d650e80bfd9ed1f"]]},{"id":"01a6d6933677b4bb","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":45,"y":1400,"wires":[["0872be30838a0b66"]]},{"id":"2e4ab5bbaa95e247","type":"function","z":"97e3eafb5e14722d","name":"24-31 udgang","func":"let msg0 = {}, msg1 = {}, msg2= {}, msg3 = {}\nlet msg4 = {}, msg5 = {}, msg6= {}, msg7 = {}\n\nlet bits = [0, 0, 0, 0, 0, 0, 0, 0] \n\nif(Math.trunc(msg.payload/8)===3) {\n    bits[7-msg.payload%8] = 1\n}\n\nmsg0.payload = bits[7]\nmsg1.payload = bits[6]\nmsg2.payload = bits[5]\nmsg3.payload = bits[4]\nmsg4.payload = bits[3]\nmsg5.payload = bits[2]\nmsg6.payload = bits[1]\nmsg7.payload = bits[0]\n\nnode.warn('24-31 udgange  ' + bits)\n\nreturn [msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7]\n","outputs":8,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":1720,"wires":[["a4902eebbafa1ff6"],["0169cbd96e1fbc94"],["9d25965d311125c1"],["f26659b0bcb6ec9b"],["7ef49743a7a9d854"],["2f3175fa32af6151"],["a82abe19837e4804"],["05537208bdeabcd4"]]},{"id":"b288378eed936df2","type":"link in","z":"97e3eafb5e14722d","name":"","links":["c5fe6efb717cc017"],"x":45,"y":1720,"wires":[["2e4ab5bbaa95e247"]]},{"id":"8de655cb54d66d34","type":"comment","z":"97e3eafb5e14722d","name":"let z = x % y;","info":"","x":550,"y":200,"wires":[]},{"id":"a381599b39a4acee","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":640,"y":900,"wires":[[]]},{"id":"9dfe08a047869b0a","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":360,"y":620,"wires":[[]]},{"id":"38a61d3a9e99b39d","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":480,"y":740,"wires":[[]]},{"id":"ac672808a7e8c9de","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":560,"y":820,"wires":[[]]},{"id":"0f1b581febe7d546","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":520,"y":780,"wires":[[]]},{"id":"66893a0d62a17ebe","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":400,"y":660,"wires":[[]]},{"id":"2438fa55f994cdf4","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":440,"y":700,"wires":[[]]},{"id":"c021b750072f3e7b","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":600,"y":860,"wires":[[]]},{"id":"631be1c0e9ea2936","type":"comment","z":"97e3eafb5e14722d","name":"let z = x / y;","info":"","x":550,"y":240,"wires":[]},{"id":"8b1a0f5b3ed443d4","type":"comment","z":"97e3eafb5e14722d","name":"let x = Math.trunc(8.76);","info":"","x":580,"y":160,"wires":[]},{"id":"8d650e80bfd9ed1f","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":640,"y":1540,"wires":[[]]},{"id":"5aa83f59da0806ea","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":360,"y":1260,"wires":[[]]},{"id":"03d24bd0152182bd","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":480,"y":1380,"wires":[[]]},{"id":"7cac629d07ece575","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":560,"y":1460,"wires":[[]]},{"id":"c1b241fe5e1e7a6b","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":520,"y":1420,"wires":[[]]},{"id":"56c293f6fdf5de54","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":400,"y":1300,"wires":[[]]},{"id":"563da2fd95131a6c","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":440,"y":1340,"wires":[[]]},{"id":"3a284208869613c6","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":600,"y":1500,"wires":[[]]},{"id":"05537208bdeabcd4","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":640,"y":1860,"wires":[[]]},{"id":"a4902eebbafa1ff6","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":360,"y":1580,"wires":[[]]},{"id":"f26659b0bcb6ec9b","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":480,"y":1700,"wires":[[]]},{"id":"2f3175fa32af6151","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":560,"y":1780,"wires":[[]]},{"id":"7ef49743a7a9d854","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":520,"y":1740,"wires":[[]]},{"id":"0169cbd96e1fbc94","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":400,"y":1620,"wires":[[]]},{"id":"9d25965d311125c1","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":440,"y":1660,"wires":[[]]},{"id":"a82abe19837e4804","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":600,"y":1820,"wires":[[]]},{"id":"976cadc729286545","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":640,"y":1220,"wires":[[]]},{"id":"8da97ca7e62b334e","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":360,"y":940,"wires":[[]]},{"id":"89b46b7f2bbf6bd2","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":480,"y":1060,"wires":[[]]},{"id":"778d95578c3dd088","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":560,"y":1140,"wires":[[]]},{"id":"42c18d04c5675448","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":520,"y":1100,"wires":[[]]},{"id":"b0a32a90616a731b","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":400,"y":980,"wires":[[]]},{"id":"f719ec32c2250e77","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":440,"y":1020,"wires":[[]]},{"id":"e4e85eba084b2445","type":"display property","z":"97e3eafb5e14722d","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":600,"y":1180,"wires":[[]]},{"id":"9347a62a4c5e4e69","type":"comment","z":"97e3eafb5e14722d","name":"Math.pow(8, 2);","info":"","x":560,"y":120,"wires":[]}]

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