Cd4051 Multiplexer Tutorial Is Here!

Has anyone got this working with the Patch SM? I see the comments above and tried to follow by editing the daisy_patch_sm.cpp but I’m having no luck at all. Example code for the Patch SM would be greatly appreciated!

Ahhh, good catch! Yes, I think it’ll be good to use the 3V3 Analog for the pots even if the 3V3 Digital was working.
Sorry about that!

1 Like

Hi otem_rellik!
I’m sorry for the delay in my response. We definitely need an example code for using mux with the Patch SM! I would love to do a video version of this tutorial in the near future and I should include how to do it with the SM as well.

In the meantime, please feel free to start a thread and let us know what code you have tried so far and we would be happy to have a closer look. It could be good to include a photo of the circuit too since that could be a factor.

What about multiplexers for switches and leds along with this potentiometer multiplexer and with using pd2dsy?
Thank you

1 Like

For switches, you can still use the "CD4051AnalogControl" like the potentiometer example since you can treat the switch as like an analog sensor that either outputs 0.0 or 1.0 where potentiometer outputs 0.0 to 1.0.

Alright, here comes a short guide on how to use the multiplexer for LEDs (pd2dsy edition)!
I HIGHLY recommend that you read the main Cd4051 multiplexer tutorial on this thread to understand how multiplexer work.

Ok, so what we need to do is send either a 0 (LOW) or 1 (HIGH) to the three selector pins, right? Well, we can use the GateOut in the json file! Now in Pure Data, we can output a digital LOW or HIGH using [send] object like this:

Screenshot 2023-08-31 at 5.37.44 PM

In addition to having three separate GateOuts for each of the three selector pins, we would need one GateOut for the COM OUT/IN pin on the multiplexer. This is the pin that is connected to the Daisy’s pin D15 in the potentiometer example. Unlike that example where we used that pin as ADC0, this pin is now used for sending out digital LOW/HIGH for the LED (similar to how we are sending digital outputs to the selector pins).

With all that in mind, here’s the json file:

{
  "name": "mux",
  "som": "seed",
  "components": {
    "select0": {
      "component": "GateOut",
      "pin": 2
    },
    "select1": {
      "component": "GateOut",
      "pin": 1
    },
    "select2": {
      "component": "GateOut",
      "pin": 0
    },
    "led_out": {
      "component": "GateOut",
      "pin": 15
    }
  }
}

You may have noticed that you can hook up the components like in the potentiometer example, except we now have LEDs instead of the potentiometer! By the way, the digital out (which you can also think of as either 0 volt or 3.3 volt) should be connected to the long leg of the LED, and the short leg to ground.

Now let’s move on to Pure Data!
Here’s a quick patch that I put together:

Every 500 milliseconds, one of the four LEDs is going to be lit up randomly! All from a single digital output pin!! And yes, you could have up to 8 LEDs :slight_smile:

pd2dsy_mux_led_1

Ok, can we light up more than one LED at a time? Yes! Check out this patch:

We are sending out an alternating LOW/HIGH to select pin 1 super fast (5 milliseconds)!!

pd2dsy_mux_led_2

And it actually works! No flickering!

OK, this all should get you started! If you understand how multiplexer work, you’ll be able to put together patches like these from scratch. Good luck, take your time, and have fun!!

3 Likes

Hi @Takumi_Ogata,

I was wondering if it would be possible to use CD4021B for switches. The schematic I found is trivial to implement, but I am not sure how to control CP, PL and DS.

Thanks

For C++ use, there is a reference about 4021 in the libDaisy document: libDaisy: SHIFTREGISTER

Because the Daisy Field uses it, you can reference the json files for pd2dsy and Oopsy usages too.

If you have any specific questions about 4021, I suggest starting a new thread as we want to focus on one component at a time here :slight_smile:

1 Like

I found some CD74HC4067 16-Channel multiplexer modules $1.60 plus tax recently. DAOKI? brand well-fabbed, marked pinouts IIRC yay 24-pin DIP form factor, too, 2.54mm headers included

2 Likes

Hi,I need your help.
I try to use your josn file for cd4051,but doesn’t work with oopsy,Error message:“node.script: undefined component kind: CD4051AnalogControl”,please check,But When I use your json to open in oopy, the same doesn’t work.

{
	"name":"podwu",
    "som": "seed",
	"defines": {
        "OOPSY_TARGET_FIELD": 1,
		"OOPSY_TARGET_HAS_MIDI_INPUT": 1
	},
    "max_apps": 8,
	"display": {
		"driver": "daisy::SSD130xI2c128x64Driver", 
		"dim": [128, 64]
	},
    "audio": {
		"channels": 2
	},
    "parents": {
    "pot_mux": {
     "component": "CD4051",
      "mux_count": 8,
      "pin": {
        "adc": 17,
        "sel0": 20,
        "sel1": 19,
        "sel2": 18
        }
      }
    },
	"components": {
		"sw1": {
			"component": "Switch",
			"pin": 7
		},
		"sw2": {
			"component": "Switch",
			"pin": 8
		},
        "sw3": {
			"component": "Switch",
			"pin": 9
		},
		"sw4": {
			"component": "Switch",
			"pin": 10
		},
        "sw5": {
			"component": "Switch",
			"pin": 22
		},
		"sw6": {
			"component": "Switch",
			"pin": 16
		},
        "sw7": {
			"component": "Switch",
			"pin": 27
		},
		"sw8": {
			"component": "Switch",
			"pin": 28
		},
        "knob1": {
			"component": "CD4051AnalogControl",
			"index": 0,
            "parent": "pot_mux"
		},
        "knob2": {
			"component": "CD4051AnalogControl",
			"index": 1,
            "parent": "pot_mux"
		},
        "knob3": {
			"component": "CD4051AnalogControl",
			"index": 2,
            "parent": "pot_mux"
		},
        "knob4": {
			"component": "CD4051AnalogControl",
			"index": 3,
            "parent": "pot_mux"
		},
        "knob5": {
			"component": "CD4051AnalogControl",
			"index": 4,
            "parent": "pot_mux"
		},
        "knob6": {
			"component": "CD4051AnalogControl",
			"index": 5,
            "parent": "pot_mux"
		},
        "knob7": {
			"component": "CD4051AnalogControl",
			"index": 6,
            "parent": "pot_mux"
		},
        "knob8": {
			"component": "CD4051AnalogControl",
			"index": 7,
            "parent": "pot_mux"
		},
		"knob11": {
			"component": "AnalogControl",
			"pin": 21
		},
		"knob12": {
			"component": "AnalogControl",
			"pin": 15
		},
		"encoder": {
			"component": "Encoder",
			"pin": {"a":26, "b":25, "click":13 },
			"meta": [
				"menu_hold = ${name}.TimeHeldMs();",
				"menu_click = ${name}.FallingEdge();",
				"menu_rotate = ${name}.Increment();"
			]
		},
        "led1": {
            "component": "Led",
            "pin": 20
        },
        "led2": {
            "component": "Led",
            "pin": 19
        },
        "led3": {
            "component": "Led",
            "pin": 18
        },
        "led4": {
            "component": "Led",
            "pin": 17
        },
        "led5": {
            "component": "Led",
            "pin": 24
        },
        "led6": {
            "component": "Led",
            "pin": 23
        }
	},
	"aliases": {
		"switch": "sw1",
		"button": "sw1",
		"switch1": "sw1",
		"button1": "sw1",
		"switch2": "sw2",
		"button2": "sw2",
        "switch3": "sw3",
        "switch4": "sw4",
		"knob": "knob1",
		"ctrl": "knob1",
		"ctrl1": "knob1",
		"ctrl2": "knob2",
        "ctrl3": "knob3",
		"ctrl4": "knob4",
        "ctrl5": "knob5",
		"ctrl6": "knob6",
        "ctrl7": "knob7",
		"ctrl8": "knob8",
		"led": "led1"
	}
}

Hi Shawn! Good to have you here in the forum.

Which json file are you referring to?

I recommend adding these lines from this post to the Pod json file: Cd4051 Multiplexer Tutorial Is Here! - #5 by shensley

I unfortunately haven’t seen that error, and I can’t really see what’s wrong with your json file at first glance.

Hi takumi thanks for your reply
I have solved the problem, and it will be fine after osspy is updated, but now there is a new problem, my seed seems to be damaged somewhere, and there may be a short circuit when I test my project. Currently, seed cannot enter dfu mode with usb, so I try to buy a new data cable and try again. There was a successful connection in the middle and flash seemed to be successful, but it didn’t work properly, and it couldn’t connect after that. Other seeds I ordered didn’t arrive late (usps was very slow to enter China).

I’m sorry to hear about that. You can email our customer support and we can continue this conversation over there. Thank you.

Hi Takumi Fortunately, the new seed has been received. When I retested it, I found that the new version of osspy could not light the oled and encoder could not be used (I tested it on pod), and I found that the encoder had serious voltage instability. When I switched back to the old version, everything was normal again, except that 4051 could not be used. Is there any new progress on the repair.

Hi Shawn,

So the new prerelease version of Oopsy is not working with OLED and encoder? Since Pod doesn’t have an OLED, did you add it?

This week, I remembered that the encoder did not work with the new prerelease version of Oopsy. It does on the current version. Is this along the line of what you’re encountering?

I checked the post of oopsy upgrade and followed your steps, yes, there was a problem after the upgrade (oled and encoder) I used pod test and added oled, running my project on old oopsy was stable and work fine.I checked the posts and knew that others seemed to have similar problems.At present, I have not tested the operation of cd4051, it seems that flash can be successful, I use external power supply 5v test, the new osspy will eat electricity when operating encoder, the voltage will be unstable, the test power is 5v/200mA.I’m not sure if there is an updated version of oopsy I didn’t notice?

The GND and VDD on the pots are the opposite way from other references I’ve looked at.

On this link below the VDD is left and GND on the right.

I don’t want to go back to plugdata to work on my project for a while,:) because plugdata often crashes on daisy, but gen is stable. Hope it works out.

Yes, there’s an issue using components like an encoder with the prerelease of the new Oopsy. It works fine on the current version, so I recommend trying to get the Cd4051 working with the current Oopsy.

As for your other post (please post one at a time by the way, thanks!), plugdata has been constantly improving :slightly_smiling_face:
There’s even a new progress being made for adding OLED support right now. I highly recommend trying out the Cd4051 patch and json file I shared above to confirm that things are working fine on hardware side of things on your project!

Good luck!

From the angle in that photo (so the side of pins is facing us), the read analog value will decrease when you turn clockwise if you connect the left to VCC and right pin to ground.
There won’t be any issue with the hardware (like the Daisy frying or anything), but it’s more intuitive for the read value to increase when you turn clockwise.
For that reason most likely, many of the references that I personally have seen have the left pin connected to ground and the right pin is connected to VCC.

Hi, I was interested in trying this out for patchSM, was there any working code confirmed for C++? Also I have some CD74HC4067 multiplexer - would this work with this example code if initialised for 16 channels?