Pages: [1]   Go Down
Author Topic: problem reading a specific analog output  (Read 1231 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
I love YaBB 1G - SP1!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I wrote this little app to read from specific inputs on a multiplexor and I have 8 small potentiometers.

The problem is that when I ativate one input and read it's value it still reads all the other 7 values so it doesn't matter which input I activate I can still change the value with any of the potentiometers.

I'm using a: 74HCT4051N multiplexer
and regular analog potentiometers.

My code:
Code:
int analog1 = 0;
int value = 0;

void setup() {
 beginSerial(9600);        // connect to the serial port
}

void changeMpu(char val1, char val2, char val3) {
 digitalWrite(1, val1);
 digitalWrite(2, val2);
 digitalWrite(3, val3);
}

void loop() {
 changeMpu(LOW, LOW, LOW);  
 delay(1000);
 printString("A");
 value = analogRead(analog1);
 printInteger(value);
 serialWrite(10); // <-- end of line
 serialWrite(13); // <-- carriage return
 
 changeMpu(HIGH, LOW, LOW);
 delay(1000);
 printString("B");
 value = analogRead(analog1);
 printInteger(value);
 serialWrite(10); // <-- end of line
 serialWrite(13); // <-- carriage return
}


Thanks in advance!
/sebb0
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Hardware Hates Me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems you haven't configured digital pins 1,2 and 3 as outputs, so function digitalWrite may don't work properly. But there is another problem:
when using serial comunication pins 1 and 2 cannot be used because they are mapped to Rx and Tx pins in the serial socket as you can see in the schematics.
So try to assign another set of pins as outputs and good luck. smiley-wink
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
I love YaBB 1G - SP1!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick answer and it works a bit better now.

Another problem I have is that when I change one of potentiometers that I haven't configured it to read the output to the computer just stops with a strange and always different letters.

Also, if I set one of the potetiometers to a specific position and then set to other to a different one, I get two different values which is good. But they aren't very stable and can change without me even touching the potentiometer.
Logged

Forum Administrator
MMX
Offline Offline
Edison Member
*****
Karma: 37
Posts: 1139
hallo kompis
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hej,

these problems you are reporting about the board-to-computer communication stopping, and the readings not being stable sound to me as typical wiring problems. I think you have to take a careful look to the circuit.

/David
Logged

Pages: [1]   Go Up
Jump to: