Go Down

Topic: 74HC4051 Not showing right data (Read 815 times) previous topic - next topic

wvmarle

4.4V only? That should be 5V (assuming resistance goes all the way to zero).

How about the pins of the 4051 IC? Same voltage?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Ard2016

4.4V only? That should be 5V (assuming resistance goes all the way to zero).

How about the pins of the 4051 IC? Same voltage?
Yes 4.4V
Which pins? Pins that are connected with Pots? If so these pins have the same value as the pots. If the pot moves the value increase or decrease depend on situation.

I disconnect all pots and measure volts in Input pins and these are all 0.


Ps. With the same code i try different channel on mux and some channel respond to Pot and display data in serial. Maybe is wrong configuration for mux.

Thanks for help.



wvmarle

Sounds like your hardware is working as it should - so indeed configuration/software error is the most likely culprit.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

TomGeorge

#18
Feb 04, 2018, 09:04 pm Last Edit: Feb 04, 2018, 09:05 pm by TomGeorge
Hi,
Can you leave the pots disconnected and just wire input 1 and 3 of the 4051 to 5v and 2 and 4 inputs to 0V.
So you should see 1023, 0 , 1023, 0 as your outputs.

Did you try @Delta_G coding suggestion? In post #8?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

allanhurst

#19
Feb 05, 2018, 04:38 am Last Edit: Feb 05, 2018, 04:43 am by allanhurst
Code: [Select]
    for (int i=0; i<3; i++){
      digitalWrite(selectPins[i], muxChannel[channel][i]);
    }



I'm not sure exactly what this does....

I'd write

Code: [Select]

    for (int i=0; i<3; i++){
      digitalWrite (selectPins[i];

    }
    for (int i=0; i<3; i++){
      digitalWrite (channel[muxChanne][i]);
    }

etc




  You have to set up all the chip select pins before you can read the data....




Allan

Delta_G

@Allan,

That just won't compile at all.  digitalWrite takes two arguments.  The pin number first and then the state. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

allanhurst

Sorry - brainstorm. You're right. It was very late.

Allan

TomGeorge

#22
Feb 05, 2018, 09:05 am Last Edit: Feb 05, 2018, 09:07 am by TomGeorge
Hi,
I built your circuit and found your problem was caused by;
Code: [Select]
const int selectPins[] = {7, 8, 9};
It should be;
Code: [Select]
const int selectPins[] = {9, 8, 7};
Your MSB and LSB were the wrong way around, so you weren't looking at the assumed inputs.

Also you are displaying ch1 to 4, instead of 0 to 3.

I have cleaned your code up to make it easier to read, including getting rid of;
Code: [Select]
int selectPins[] = {9, 8, 7};
That you had in your function.
I also shifted the array out to be global.
Code: [Select]

const int selectPins[] = {9, 8, 7};
const int Z = A0;

int ch0;
int ch1;
int ch2;
int ch3;
int ch4;

int muxChannel[8][3] = {
  {0, 0, 0},
  {0, 0, 1},
  {0, 1, 0},
  {0, 1, 1},
  {1, 0, 0},
  {1, 0, 1},
  {1, 1, 0},
  {1, 1, 1}
};


void setup()
{
  Serial.begin(9600); // Initialize the serial port
  // Set up the select pins as outputs:
  for (int i = 0; i < 3; i++)
  {
    pinMode(selectPins[i], OUTPUT);
    digitalWrite(selectPins[i], HIGH);
  }
  pinMode(Z, INPUT); // Set up Z as an input
}


void loop() {
  ch0 = readMux(0);
  ch1 = readMux(1);
  ch2 = readMux(2);
  ch3 = readMux(3);
  //  ch4 = readMux(4);
  Serial.print(ch0);
  Serial.print("\t");
  Serial.print(ch1);
  Serial.print("\t");
  Serial.print(ch2);
  Serial.print("\t");
  Serial.print(ch3);

  Serial.println();
  delay(100);

}

int readMux(int channel) {
  for (int i = 0; i < 3; i++) {
    digitalWrite(selectPins[i], muxChannel[channel][i]);
  }
  int val = analogRead(A0);
  val = analogRead(A0);
  return val;
}


Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up