Flurieu Peninsula, South Aust.
Offline
Jr. Member
Karma: 0
Posts: 61
Arduino rocks
|
 |
« on: January 27, 2009, 02:48:07 am » |
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
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #1 on: January 27, 2009, 03:46:13 am » |
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.  Lefty
|
|
|
|
« Last Edit: January 27, 2009, 03:48:04 am by retrolefty »
|
Logged
|
|
|
|
|
Flurieu Peninsula, South Aust.
Offline
Jr. Member
Karma: 0
Posts: 61
Arduino rocks
|
 |
« Reply #2 on: January 27, 2009, 07:44:52 am » |
Thanks, Lefty. I tried those numbers and at last my sketch works!  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=1229849197but it doesn't look like what I'm after.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #3 on: January 27, 2009, 12:52:23 pm » |
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/PinModeLefty
|
|
|
|
|
Logged
|
|
|
|
|
Flurieu Peninsula, South Aust.
Offline
Jr. Member
Karma: 0
Posts: 61
Arduino rocks
|
 |
« Reply #4 on: January 28, 2009, 02:45:47 am » |
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/Pinswhich 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.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Flurieu Peninsula, South Aust.
Offline
Jr. Member
Karma: 0
Posts: 61
Arduino rocks
|
 |
« Reply #6 on: January 30, 2009, 09:03:45 am » |
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
Edison Member
Karma: 1
Posts: 1036
Whatduino
|
 |
« Reply #7 on: January 30, 2009, 09:17:35 am » |
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.pdfThe 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
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #8 on: January 30, 2009, 01:10:38 pm » |
"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
|
|
|
|
|
|