EDIT: I removed all references to any analog read and my program is just reading channel 0 at the mux and still a lot of deviation.....
EDIT 2: the chip was left unpowered, i'll run another test sorry about this.
Thanks to all for the quick replies!
Ok these values come out when using only one channel:
x: 330 x: 330 | y: 330 | z: 273
x: 91 x: 330 | y: 330 | z: 273
x: 100 x: 330 | y: 330 | z: 272
x: 330 x: 330 | y: 330 | z: 273
x: 143 x: 331 | y: 330 | z: 273
x: 325 x: 330 | y: 330 | z: 273
x: 48 x: 330 | y: 330 | z: 273
x: 119 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 133 x: 330 | y: 330 | z: 273
x: 60 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 133 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 121 x: 331 | y: 330 | z: 273
x: 47 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
still all over the place.
So try to decouple the power source of the multiplexer. I put a capacitator from 0.047 uF from the power pin of the multiplexer to ground.
these are the values i get:
x: 331 x: 331 | y: 330 | z: 273
x: 135 x: 331 | y: 330 | z: 273
x: 68 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 273
x: 163 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 329 | z: 273
x: 121 x: 331 | y: 330 | z: 273
x: 91 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 273
x: 158 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 272
x: 97 x: 331 | y: 330 | z: 273
not much difference.
The wiring is in the attachment, hope it's clear.
Thanks again!
This is the code i'm using:
//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the ADXL335, prints calculated orientation via serial
//////////////////////////////////////////////////////////////////
//mux pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
//Mux in "SIG" pin
int SIG_pin = 0;
//Analog read pins
const int xPin = A8;
const int yPin = A9;
const int zPin = A10;
void setup(){
Serial.begin(57600); //does the speed matter?
}
void loop(){
//read the analog values from the accelerometer
int xRead = readMux(0);
int xReadDirect = analogRead(xPin);
//int yRead = readMux(1);
int yReadDirect = analogRead(yPin);
//int zRead = readMux(2);
int zReadDirect = analogRead(zPin);
//Output the caculations
Serial.print("x: ");
Serial.print(xRead);
Serial.print("\t x: ");
Serial.print(xReadDirect);
Serial.print(" | y: ");
Serial.print(yReadDirect);
Serial.print(" | z: ");
Serial.println(zReadDirect);
delay(10);//just here to slow down the serial output - Easier to read
}
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
};
delay(40);//maybe it helps??
//loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
int val = analogRead(SIG_pin);
//return the value
return val;
}