Go Down

Topic: using internal pullup resistors (Read 2187 times) previous topic - next topic


Hi All,
I'm trying to write a sketch using the internal pullups in the 168 and getting very confused. The sketch compiles & uploads, but according to my multimeter the input pins I'm using are not being pulled HIGH.

I'm trying to use analog pins 0 to 4 as marked on the freeduino board. Am  I writing the correct pin no.s in the sketch?

Here's the setup.

*flashes a LED at various rates & on/off times depending on which of 5 buttons is pressed
int ledPin = 13;        //output pin for the LED
int inPin1 = 0;         //button 1 pin
int inPin2 = 1;         //button 2 pin
int inPin3 = 2;         //button 3 pin
int inPin4 = 3;         //button 4 pin
int inPin5 = 4;         //button 5 pin

void setup()
 pinMode(ledPin, OUTPUT);    //declare LED as output
 pinMode(inPin1, INPUT);      //declare button as input
 digitalWrite(0, HIGH);  //button 1 pin __turn on pullup resistors
 pinMode(inPin2, INPUT);
 digitalWrite(1, HIGH);
 pinMode(inPin3, INPUT);
 digitalWrite(2, HIGH);
 pinMode(inPin4, INPUT);
 digitalWrite(3, HIGH);
 pinMode(inPin5, INPUT);
 digitalWrite(4, HIGH);
Thought I'd seen my share of confusing hardware, but this has me stumped. :-[


Jan 27, 2009, 09:46 am Last Edit: Jan 27, 2009, 09:48 am by retrolefty Reason: 1
I think if you are going to use analog input pins 0-5 as digital input pins you have to refer to them as pins 14-18 in your sketch. And don't blame the hardware it's a software 'feature' to have two aliases for the same physical hardware pins.  ;)



Thanks, Lefty. I tried those numbers and at last my sketch works!  :P :)

I would like to know if there is a list somewhere of the correct numbers to "call" the arduino pins in a sketch. The chip pin no.s  are obviously not the ones to use. I found this

but it doesn't look like what I'm after.


The information is avalible but somewhat scattered around the Arduino reference manual. Here is a page that mentions the use of analog input pin as digital pins and the name change required.




Lefty: Yes, that info must be very scattered. I think I have the analog pins covered now but haven't found a ref to the digital pin no.s yet. I would have expected to find it here


which is one link beyond the last link you posted. When I get the digital pin nos sorted out I'll try and put them on that page.

Unless some better-informed person does it first. hint, hint. ;)


This is the schematic for LadyAda's Boarduino, but the pin references are the same.



drspectro: That schematic looks a lot like the one I have for my freeduino board, but with different pin numbers. But unless I am missing something here, these  only show how to physically connect to the analog or serial pins, and these are not the pin numbers I have a problem with.

The pin numbers I'm talking about are the "imaginary" ones I need to put into the code of an arduino sketch to address the correct "real" (electrical) connection on the board. I'm surprised that I can't seem to find a cross-reference for this anywhere.

Maybe I'm missing something obvious (wouldn't be the first time) because lots of people have made these things work.

To put the question another way: For example, what pin number do I use in a line of code if I want the result to appear on digital pin 0 of my board?


Jan 30, 2009, 03:17 pm Last Edit: Jan 30, 2009, 03:19 pm by halley Reason: 1
Look at the far right edge of this schematic for the Duemilanove.  You see the jumpers with their silkscreen names there.  And you can trace back to the pin numbers of the ATmega168 package.


The jumper that's not labeled is the six ADC pins, and you see their A0-A5 numbers in the ATMEGA8 [sic] part box.


"The pin numbers I'm talking about are the "imaginary" ones I need to put into the code of an arduino sketch to address the correct "real" (electrical) connection on the board. I'm surprised that I can't seem to find a cross-reference for this anywhere."

The concept of using 'virtual pin numbers' Vs physical package pin numbers is so that the software functions can stay consistent and internal software mapping functions can resolve the hardware differences between many otherwise software compatible AVR microprocessors.

Otherwise one would have to modify or load a completely different version of the Arduino IDE for each different board if it used a different mega chip.

Some people use the term 'leg number' when they are referring to the physical chip's pin numbers and 'pin numbers' when referring to the software virtual pin number. It may be confusing when first learning but in the long run it makes things a lot more easy to use and less to memorize when working with different versions of the AVR mega series. Most designers of Arduino boards label the 'virtual pin names' near the connector pins, so that one doesn't really need to know what physical pin number (leg number') that it routes to. One really only has to deal with this if there are building there own board from scratch.


Go Up