Go Down

Topic: 8 channels mux problem (Read 96 times) previous topic - next topic

DanaGuen

Nov 20, 2018, 02:57 pm Last Edit: Nov 20, 2018, 03:01 pm by DanaGuen
Hello!

I've decided to make my own MIDI controller, so for more fun I've been buying some muxs (8 and 16 channels).

I'm using:

-arduino uno

-mux 8 channels (https://www.amazon.fr/Ils-74HC4051-multiplexeur-analogique-CJMCU-4051/dp/B07F3T3B61/ref=sr_1_13?ie=UTF8&qid=1542714760&sr=8-13&keywords=multiplexeur)

-2 pots 10k (first tested on analog inputs A0 and A1)

Here you can find my circuit and the code I'm using:

https://imgur.com/guzNVkT

https://imgur.com/dboHWwl

https://imgur.com/zNY4r0m

https://imgur.com/s4HT7kV

-VEE and GND pins are connected to ground

-VCC is connected to +5V

-Z out is connected to A0 (red jumper wire)

-ENABLE pin is connected to digital input 2 (green jumper wire)

-S0, S1 et S2 are respectively connected to digital inputs 3, 4 and 5 (yellow jumper wires)

The values from the serial monitor are autonomous and jumping all by themselves. I should also have a value near to 0 for the third value Y2 which I connected to ground.

I don't know what i've been doing wrong :(
I've checked with my voltmeter that pin E was at LOW (i tried to connect it directly to ground too, but the problem remains), I've checked that VCC had 5V, that GND had 0V, verified again the tension at my pots. I've even tried to change my mux for another one...I'm desperate :D

Any idea/help would be truely appreciated :)

Thanks,

D.

GolamMostafa

#1
Nov 20, 2018, 04:02 pm Last Edit: Nov 20, 2018, 04:23 pm by GolamMostafa
Are you expecting something like the following in the Serial Monitor? I have tested your sketch (unchanged) with 3.3V at y0-pin, 3.3/2V at y1-pin, and 0V at y2-pin of the 4051. The z-pin (output) of 4051 has been connected to A0-pin. The response looks OK to me. Please, check wiring of of your 4051 or try with a stand-alone 4051 chip.



Copy of your sketch (along with my few comments for myself):
Code: [Select]
//8-channel mux test with 2 10k potentiometers, third input connected to ground

// adress pins
const byte PIN_ENABLE = 2; //Enable pin
const byte PIN_ADDR_A = 3; //S0
const byte PIN_ADDR_B = 4; //S1
const byte PIN_ADDR_C = 5; //S2
 
// signal pin
const byte PIN_SIG = A0;
 
void setup()
{
  
  // adress pins out and LOW
  pinMode(PIN_ADDR_A, OUTPUT);
  pinMode(PIN_ADDR_B, OUTPUT);
  pinMode(PIN_ADDR_C, OUTPUT);
  digitalWrite(PIN_ADDR_A, LOW);
  digitalWrite(PIN_ADDR_B, LOW);
  digitalWrite(PIN_ADDR_C, LOW);
  
  // Activation of the CD4051B mux
  pinMode(PIN_ENABLE, OUTPUT);
  digitalWrite(PIN_ENABLE, LOW);
 
  // initialization of monitor
  Serial.begin(9600);
  Serial.println("Demonstration CD4051B");
}
 
void loop()
{
 
  // For each channel the value is printed on the serial monitor. We only need 3 channels for this example.
  for(byte i = 0; i < 3; i++)
  {
    Serial.print("Channel ");
    Serial.print(i);
    Serial.print(" : ");           //Channel 0 :
  //  int x = readAnalogMux(i);
    Serial.println(readAnalogMux(i));
  }
  Serial.println("-------------");
  
  // 1 sec delay between prints
  delay(1000);
}
 
// reading function for the CD4051B
int readAnalogMux(byte channel) //0
{
  
  // Channel selection
  digitalWrite(PIN_ADDR_A, bitRead(channel, 0));  //3, 0
  digitalWrite(PIN_ADDR_B, bitRead(channel, 1));  //4, 0
  digitalWrite(PIN_ADDR_C, bitRead(channel, 2));  //5, 0
 
  // Reads the value
  return analogRead(PIN_SIG);
}



BTW:
(1) What are the sources of signals at the inputs of 4051 analog multiplexer?
(2) What is the range (0 to ? ) of the signal that arrives at the input of 4051?

DanaGuen

#2
Nov 20, 2018, 05:06 pm Last Edit: Nov 20, 2018, 05:29 pm by DanaGuen
Hi,

Thank you for your answer :)
Yes it's exactly the kind of result i'm looking for :O At least i'm relieved about the code...but I still don't know what could be wrong with my wiring...did you see anything on the pictures that looked weird? :/ (are the pictures clear enough? :x)

(1)My two first inputs are rot pots, the third is ground.
(2)I didn't divide the value so it should be [0-1023]...I'll divide it to [0-127] later for the MIDI connexion, but I leave it for later.

By curiosity I've measured the tension between ground and S0, S1, S2 and with my analog inputs.
I think something's wrong: I always obtain 0V for S0, 5V for S1 and 0V for S2...I don't understand how it's possible.
The tension for my pots are good when I measure them on the mux.

Thanks again, I'll keep looking!

D.

GolamMostafa

#3
Nov 20, 2018, 06:32 pm Last Edit: Nov 20, 2018, 06:35 pm by GolamMostafa
Remove all wirings and make a fresh wiring as per following diagram. Avoid breadboard as it, for most of the times, gives trouble. Make direct jumpers from the 4051 break-out board to the UNO. If necessary, make 5V and GND buses on the breadboard. Use a DVM or AVM-sound to check continuity of every terminal pin with the IC-pin and the UNO pin. When something is not working, it gives a good chance of learning things in your own way. Place the voltage divider circuit on breadboard and measure the mid-point voltage by DVM.


Go Up