[dorkbotpdx-blabber] Arduino - reading digital pins as a number?

1 view
Skip to first unread message

Hans Lindauer

unread,
Jan 1, 2009, 6:49:33 PM1/1/09
to A discussion list for dorkbot-pdx (portland, or)
A few easy questions for those in the know. I have a DIP (SIP,
actually) switch connected to pins 5-8 of my dorkboard(s) and to +5V,
and want to read in the switches as as number.

1. Can I safely connect +5V to a digital input (or 4), and leave it
high for an extended period without having to worry about overheating or
other issues? Probably a dumb question, I know, but I'm still learning
the ins and out of this stuff.

2. Do I need pull-down resistors to ground on each of the digital
pins? I guess I don't understand the necessity of that. Also, is my
terminology correct?

3. What's an elegant way to read those pins in as a byte? I know I can
multiply the pin value by 2^n and add them all up, but it seems like
there's got to be a smarter way. Maybe I can read a register with the
pin values and mask off those bits?

Thanks in advance,
-Hans
_______________________________________________
dorkbotpdx-blabber mailing list
dorkbotpd...@dorkbot.org
http://music.columbia.edu/mailman/listinfo/dorkbotpdx-blabber

Donald Delmar Davis

unread,
Jan 1, 2009, 7:33:51 PM1/1/09
to A discussion list for dorkbot-pdx (portland, or)
Hans,

The pins are best set up for connecting them to ground and using the internal pull up resistors. When using them to pull things down they will want to draw real current.
 Unfortunately pins 5 to 8 span ports b and c so there is no tidy and elegant way that would be significantly better than reading the pins using the arduino. You can do the multiply by shifting the bits but any reasonable compiler should figure this out for you so even that is kind of mute. 

Don.

Donald Delmar Davis

unread,
Jan 1, 2009, 9:49:38 PM1/1/09
to A discussion list for dorkbot-pdx (portland, or)
I am not sure if my initial response answered your questions directly. 
 
1. No unless there is some compelling reason to connect the switches to vcc go the other way and connect your switches to ground.
2. if you do this then the internal pullups on the port pins will handle this correctly.
3. given that your pin selection actually spans two io ports then digital reading the pins is as good as any.

Don.
On Jan 1, 2009, at 3:49 PM, Hans Lindauer wrote:

Hans Lindauer

unread,
Jan 4, 2009, 7:45:08 PM1/4/09
to A discussion list for dorkbot-pdx (portland, or)
Thanks Don, that worked (once I RTFM and figured out how to enable the
pullups).

Mykle Hansen

unread,
Jan 4, 2009, 9:09:24 PM1/4/09
to A discussion list for dorkbot-pdx (portland, or)

On Jan 1, 2009, at 4:33 PMThursday, Donald Delmar Davis wrote:

> The pins are best set up for connecting them to ground and using the
> internal pull up resistors.


oh goddammit ... nobody told me there were internal pull-up resistors!
on which pins? how do i use them? how did i miss them?

-m-
---
HELP! A Bear is Eating Me!
http://helpabeariseatingme.com

Thomas Lockney

unread,
Jan 4, 2009, 9:19:23 PM1/4/09
to A discussion list for dorkbot-pdx (portland, or)
On Sun, Jan 4, 2009 at 6:09 PM, Mykle Hansen <my...@mykle.com> wrote:
>
> On Jan 1, 2009, at 4:33 PMThursday, Donald Delmar Davis wrote:
>
>> The pins are best set up for connecting them to ground and using the
>> internal pull up resistors.
>
>
> oh goddammit ... nobody told me there were internal pull-up resistors!
> on which pins? how do i use them? how did i miss them?

This is where Don jumps in to remind everyone to read the manual... ;~)

(sorry... I can give a snide response since I don't actually know...
and I don't have time to look it up right now)

snarkily yours,
thomas

Hans Lindauer

unread,
Jan 4, 2009, 9:21:43 PM1/4/09
to A discussion list for dorkbot-pdx (portland, or)
"A pin may also be configured as an INPUT with pinMode, and subsequently made HIGH with digitalWrite, this will set the internal 20K pullup resistors, which will steer the input pin to a HIGH reading unless it is pulled LOW by external circuitry. "

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

Donald Delmar Davis

unread,
Jan 4, 2009, 9:32:06 PM1/4/09
to A discussion list for dorkbot-pdx (portland, or)
Almost all of them.
In the arduino you DigitalWrite to your readmode pins. Its counter intuitive sort of but it works.
Its on page 73 or the datasheet for the mega168.
Its a good read.

Don.
Reply all
Reply to author
Forward
0 new messages