Arduino Micro pin issues

Hello anyone,

I am working am fairly new to Arduino. I have a Arduino micro and I feel the pin layout is a mess. I have looked around and found that both the offical pin layout and [url=http://www.pighixxx.com/test/pinoutspg/boards/#prettyPhoto[gallery]/8/]this one[/url] are not working for me the way they should.

What happens is when pin A6 is LOW all other pins assigned also read(from serial window) low. Only if pin 6 is low will the other pins read low even if I ground them.

I am not sure which pin layout is correct or if I have a bad board. The code below what I am using to debug.

Any help is much appreciated.

Thanks

boolean calibPin0 = A6; //set the MAX value of the sensor input boolean calibPin1 = A5; //set the MIN value of the sensor input boolean thumbPin = A4; //change the thumb position among three preset values boolean fingerPin = A2; //lock or unlock the position of middle finger, ring finger and pinky const int analogInPin0 = A40; //sensor input

boolean Cal0, Cal1, Thum, Fing;

void setup() { // put your setup code here, to run once:

Serial.begin(9600);

pinMode(calibPin0, INPUT_PULLUP); // setting pin A6 to input high if floating pinMode(calibPin1, INPUT_PULLUP); pinMode(thumbPin, INPUT_PULLUP); pinMode(fingerPin, INPUT_PULLUP);

}

void loop() { // put your main code here, to run repeatedly: Cal0 = analogRead(calibPin0); \ store analog value Cal1 = analogRead(calibPin1); Thum = analogRead(thumbPin); Fing = analogRead(fingerPin);

Serial.print("Cal0 "); Serial.println(Cal0); if( Cal0 == LOW){ \ just a read out of current value of Cal0 \ repeated for other pins Serial.println(" low"); } else if( Cal0 == HIGH){ Serial.println(" high"); } else{ Serial.println(" none"); }

Serial.print("Cal1 "); Serial.println(Cal1); if( Cal1 == LOW){ Serial.println(" low"); } else if( Cal1 == HIGH){ Serial.println(" high"); } else{ Serial.println(" none"); } Serial.print("Thum "); Serial.println(Thum); if( Thum == LOW){ Serial.println(" low"); } else if( Thum == HIGH){ Serial.println(" high"); } else{ Serial.println(" none"); } Serial.print("Fing "); Serial.println(Fing);

if( Fing == LOW){ Serial.println(" low"); } else if( Fing == HIGH){ Serial.println(" high"); } else{ Serial.println(" none"); } Serial.println(millis()); delay(25000);

}

Anyone else have issues with the pin out for the Micro?
I just need some clarification on the correct pin out to follow.

Thanks,

Both pin mappings are consistent with eachother and correct. Your code is wrong.

You are declaring lots of variables as booleans. A boolean can only hold 0 or 1.

This is your problem, I think. The pin defines should be ints or bytes, not booleans.

Likewise, when you're analogRead()ing, if you don't store them in ints (or something else big enough to fit a 10-bit value), the value will be truncated to fit the datatype you're using.

HIGH and LOW are 1 and 0 respectively.

analogRead() returns a value of 0~1023.

So testing if a value from analogRead() == HIGH, it'll be true only if it reads a 1 (ie, just barely above 0), meanwhile it will be equal to LOW only if it's right at ground (and I've seen it occasionally read small numbers higher than 0 or 1 with the pin grounded).

If you want to see if the pin is considered "HIGH" or "LOW", use digitalRead(), not analogRead()

If you want to do analogRead() to get an analog value on the pin, you must store the result in an appropriate datatype.

You must store pin references in bytes or ints - a boolean is not large enough. I think they're getting truncated to the LSB, so they're all either reading ADC channel 0 or ADC channel 1, which are A6 and A5.

Thanks that makes since. My test code was taking parts from another code that I did not understand. I will have to try that out.

Thanks!

That did it. Thank you so much!