Can't get 'clean' analogRead from Multiplexer CD4067BE


i'm trying read analog inputs cd4067be chip. though i'm grounding half of inputs ( can ground them don't see point ). 'dirty' signals. clarify that. should getting 0s ( zeros ) every grounded input. instead i'm getting random values 0 ~400. analogread can return 'dirty' results if inputs doesn't have initial value, hence grounding. know why happens , how fix it? thank time.

here's code.

code: [select]

#include <stdio.h>

//mux control pins
int s0 = 2;
int s1 = 3;
int s2 = 4;
int s3 = 5;

//mux in "sig" pin
int sig_pin = 1;

void setup(){
  pinmode(s0, output);
  pinmode(s1, output);
  pinmode(s2, output);
  pinmode(s3, output);

  digitalwrite(s0, low);
  digitalwrite(s1, low);
  digitalwrite(s2, low);
  digitalwrite(s3, low);
 
  serial.begin(9600);
}

void loop(){
 
  /* buffer init: */
  char buffer[50];
 
  serial.print("[");
  for(int = 8; < 16; ++){
    snprintf(buffer, 50, "{ %d : %d }, ", i, readmux(i) );
    serial.print(buffer);
  }
 
  serial.println("]\n");
 
  delay(200);
}

int readmux(int channel){
  int controlpin[] = {s0, s1, s2, s3};

  int muxchannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through 4 sig
  for(int = 0; < 4; ++){
    digitalwrite(controlpin[i], muxchannel[channel][i]);
  }

  //read value @ sig pin
  int val = analogread(sig_pin);

  //return value
  return val;
}



Arduino Forum > Using Arduino > LEDs and Multiplexing > Can't get 'clean' analogRead from Multiplexer CD4067BE


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial