Trouble with ADXL335 and Multiplexing

Hello,

I am working with two ADXL335 accelerometers and a CD4051 multiplexer. I am having trouble getting correct readings. When I connect the accelerometers directly to the analog inputs, they work fine. When they are connected through the multiplexer, they give random readings. I know my connections are correct, is my code incorrect? Thanks for the help!

 const int select[] = {8,9,10}; // pins connected to the 4051 input select lines
 const int analogPin = 0;      // the analog pin connected to multiplexer output
 float zero_G = 512.0; //uncalibrated zero G reading
 float scale = 102.3;


void setup()
{
  Serial.begin(9600);
  for(int bit = 0; bit < 3; bit++)
  pinMode(select[bit], OUTPUT);  // set the three select pins to output
  Serial.begin(9600);
}


void loop()
{
    for(int channel = 0; channel < 6; channel++)
  {
     float value = (getValue(channel) - zero_G) / scale;
     Serial.print(value);
     Serial.print(",  ");   
  }  
  Serial.print("\n");
}

 // this function returns the analog value for the given channel
int getValue( int channel)
{
   // set the selector pins HIGH and LOW to match the binary value of channel
   for(int bit = 0; bit < 3; bit++)
   {
      int pin = select[bit]; // the pin wired to the multiplexer select bit
      int isBitSet =  bitRead(channel, bit); // true if given bit set in channel
      digitalWrite(pin, isBitSet);
   }
   return analogRead(analogPin);
}

You could try two reads per channel, chucking away the first one.

That really doesn't seem to make a difference. Any other suggestions?

Your code looks OK. Can you show your exact wiring please? Photo maybe or a schematic.