Go Down

Topic: Boarduino Analog Input problem (Read 1 time) previous topic - next topic


Dear Reader,

I have a Boarduino with the Atmega 168 chip.  I've run the blinky apps and had newbie fun with it, using the Arduino software and serial TTL/USB cable.  I'm running Kubuntu Hardy Heron.

Up until recently, I've solved all the usual problems I initially had with it.  
However, I could not seem to address the analog ports.  I've run several example sketches but no go, including the "AnalogInput" one.  I have selected the Diecimila board and played around with other board choices that also use the 168 chip, but still no go.  

I note that the pin selections from the Diecimila board do not match my Boaruino.  For instance, the example sketch AnalogInput uses pin 2; I've tried that, and I've tried all the analog input pins on the chip, 28, 27, 26, 25, 24, and 23  So I have chosen the pin numbers directly from the chip.

So this is what I found out after struggling for hours:  In one instance, when the Sketch directs the LED output to "pin" 13, it actually does go to pin 13.  However, when it directs the input to pin "2", it is not talking about a "pin" but a port.  Therefore, I should not direct the Sketch to "pin" 24, etc., but to "Analog1" which corresponds to pin 24 on the chip itself.  

In other words, the instructions switch, for no apparent reason, from addressing actual pins on the chip to addressing ports on the chip.  

So I'm writing this for fellow newbies who might have to discover this the hard way like I did.  I'm sure these issues are buried in some FAQ somewhere but I did not catch it and I did quite a bit of searching otherwise.  Besides, one does not look for something one does not suspect!




Jun 28, 2008, 09:28 pm Last Edit: Jun 28, 2008, 09:32 pm by ladyada Reason: 1
yup this is true of all arduinos & clones: digital input '0' is not pin 0 but in fact, pin 1. The analog input #'s are different than pin numbers. while its confusing for people who are used to dealing with pins it does mean that if the Arduino goes to a different chip the numbers can stay the same. note, however, the pin/numbering scheme is the same for the Boarduino as it is for the Arduino

you can use this to see the matching numbers


Thanks LadyAda,

Well, if it's done this way for the benefit of dealing with planned chip revisions then it's worthwhile and make sense, IMHO.  

Perhaps an update of the analog example Sketches might include a caveat in the commented section that outputs go to pins but inputs go to ports?



Someone help me, I'm obsessed with this stuff!   :D


A call to, say, analogRead(0) reads from analog input 0, which is labelled that way on the board (both Diecimila and Boarduino, I think).  A call to digitalRead(0) reads from digital pin 0.  Typically, you should never need to worry about which pin (i.e. 1 to 28) of the ATmega168 you're dealing with.  

Go Up