0

Boarduino pins?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Boarduino pins?

by aspro648 on Tue Feb 19, 2008 11:35 pm

OK, feeling really stupid. When I look at the Boarduino and see pin "D8" on the board, is that pin "8" for programming, or is it pin "14" (looking at schematic on http://ladyada.net/images/boarduino/boarduinosch.png)?

Thanks.

aspro648
 
Posts: 40
Joined: Sat Feb 16, 2008 3:06 pm

by adafruit on Wed Feb 20, 2008 12:45 am

its the "arduino digital pin 8" as used in the arduino software, which is pin 14 on the atmega chip

its quite confusing!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by aspro648 on Wed Feb 20, 2008 2:32 am

Thanks for the quick reply. I'm on tutorial 5, so hopefully that will help me understand. My poor old brain has lost some spring since my Sinclair ZX-81 days. I'm surprised I haven't let out any of the magic smoke of your Boarduino yet.

How about a tutorial #6 on analog inputs?

aspro648
 
Posts: 40
Joined: Sat Feb 16, 2008 3:06 pm

by aspro648 on Fri Feb 22, 2008 3:33 pm

Let me see if I've come to the correct understanding of the Boarduino pins.

Digital pins (0-13) are accessed using digitalRead(), digitalWrite(), and analogWrite().

The analog pins (0-5) are accessed only using analogRead().

Clear as mud, eh?

aspro648
 
Posts: 40
Joined: Sat Feb 16, 2008 3:06 pm

by darus67 on Fri Feb 22, 2008 4:20 pm

You're close.
Not all of the Digital I/O pins are capable of PWM (analog output).
Only pins 3, 5, 6, 9, 10, and 11 can provide PWM output.
"He's just this guy. You know?"
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 10:25 pm
Location: Minnesota, USA

by jgotthardt on Sat Feb 23, 2008 8:12 am

Also, analog pins 0 thru 5 can be used as digital pins 14 thru 19.
John

jgotthardt
 
Posts: 33
Joined: Mon Dec 03, 2007 11:58 am
Location: Massachusetts

by mtbf0 on Sat Feb 23, 2008 1:10 pm

... and of course the real fun comes when you ditch the api and start reading the atmega168 datasheet. only then will you know true freedom.

and frustration. paroxysms of joy. unplumbable depths of despair. in short the full rich palate of the human experience.
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by caitsith2 on Sat Feb 23, 2008 8:26 pm

That whole analog pin/digital pins is really not too well documented, I do have to agree with that.


DigitalRead/DigitalWrite applies to 0-19 (20 I/O lines), PinMode is explicitly required for these calls.

AnalogRead applies to 0-5 (Which would be digital 14-19), no PinMode call required.

AnalogWrite applies to 3,5,6,9,10,11, (same mapping as the digital pins.) no PinMode call required. Using analogWrite on any of the other digital pins will digitalWrite a 1 if >127 or a 0 if <= 127, and the PinMode is still done for you.

Finally, if you don't mind diving a little deeper, like the data sheets, you can access more than one pin at the same time, both for reading, and writing.

Code: Select all | TOGGLE FULL SIZE
Example: a code snippet taken from one of my arduino projects, where I needed to read/write 8 pins as fast as possible.  This leaves DigitalRead/DigitalWrite/PinMode out of the question.

unsigned char readdata(unsigned char address)
{
  unsigned char data;

  DDRB = 0x0F;    //Data lines 0-1 from another device, are inputs.
                          // /WR, /RD, A0, A1 are outputs.
  DDRD &= ~0xFC;  //Data lines 2-7 from another device are outputs.
                             //TX/RX are left as they are.
  PORTB &= ~0x03;  //Clear A0/A1 value,
  PORTB |= (address & 0x03);  //And set it to the parameter.
 
  PORTB &= ~0x04;  // Activate /RD
  delayMicroseconds(1);  //Wait for data to be ready
  data=((PINB&0x30)>>4) | (PIND&0xFC);  //Now read the data

  PORTB |= 0x04;  //And deactivate /RD
  return data;
}
caitsith2
 
Posts: 217
Joined: Thu Jan 18, 2007 11:21 pm

Please be positive and constructive with your questions and comments.