Pages: [1]   Go Down
Author Topic: using internal pullup resistors  (Read 918 times)
0 Members and 1 Guest are viewing this topic.
Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

/*
*fivebutton
 *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. :-[
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink

Lefty

« Last Edit: January 27, 2009, 03:48:04 am by retrolefty » Logged

Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, Lefty. I tried those numbers and at last my sketch works!  smiley-razz smiley

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
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229849197

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

http://arduino.cc/en/Reference/PinMode

Lefty
Logged

Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.arduino.cc/playground/Learning/Pins

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. smiley-wink
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
he's not a real doctor
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.ladyada.net/media/boarduino/usbboarduinosch.png
Logged

Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf

The jumper that's not labeled is the six ADC pins, and you see their A0-A5 numbers in the ATMEGA8 [sic] part box.
« Last Edit: January 30, 2009, 09:19:45 am by halley » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.

Lefty

Logged

Pages: [1]   Go Up
Jump to: