0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« on: May 29, 2009, 03:17:22 am » |
Hey is it possible to use the analog pins as digital pins, and if yes, what numbers are they addressable at?
And if not, got any suggestions for how to fake it?
thanks! -steve
|
|
|
|
|
Logged
|
|
|
|
|
North Yorkshire, UK
Offline
Faraday Member
Karma: 104
Posts: 5531
|
 |
« Reply #1 on: May 29, 2009, 04:27:28 am » |
Just out of interest.... What project are you wanting to use more than 54 digital pins on? Everyone..... Steve's building a spaceship from an arduino!!!  But on a more serious note. I presume that like on the other arduino boards, you just number them following on from the last number of the digital pin. for example if the last digital output is numbered 54 then the analog pins would be 55 (analog 0) 56 (analog 1) 57, 58 and so on... Please elaborate on what you are wanting to do with all of these pin s because I'm interested now! Mowcius
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #2 on: May 29, 2009, 04:36:53 am » |
i wont go into too much detail, its way past my bedtime on a work day...  
|
|
|
|
« Last Edit: May 29, 2009, 04:37:44 am by stevecooley »
|
Logged
|
|
|
|
|
North Yorkshire, UK
Offline
Faraday Member
Karma: 104
Posts: 5531
|
 |
« Reply #3 on: May 29, 2009, 04:52:56 am » |
I would recommend shifting the 10 analog pins up 3 and putting the analog(digital) pins at numbers 0,1,2 and then I would have thought that if you number them to the 'next' theoretical digital pin number (is it 45 onwards?) then it should work like on the other arduino boards.
I would recommend trying it with something simple such as an LED blink on analog pin 0 (set as "int ledPin = 45" or similar).
Mowcius
|
|
|
|
|
Logged
|
|
|
|
|
North Yorkshire, UK
Offline
Faraday Member
Karma: 104
Posts: 5531
|
 |
« Reply #4 on: May 29, 2009, 04:54:54 am » |
I am also thinking of getting an arduino mega just to make some coding much simpler and avoid the use of any extra boards so it would be great if you can use those analog pins as digital pins.
btw... interesting project, I would recommend that you post it up when you have finished it - looks great!
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 271
Posts: 25422
Solder is electric glue
|
 |
« Reply #5 on: May 29, 2009, 05:08:20 am » |
You can also do direct port manipulation on these pins as well they map to the F and the K ports. It is one of the few ports that you get a straight run at so if you need to interface any 8 bit wide devices you can do it with these ports.
Port Pin Function PF 0 54 A0 PF 1 55 A1 PF 2 56 A2 PF 3 57 A3 PF 4 58 A4 PF 5 59 A5 PF 6 60 A6 PF 7 61 A7 PK 0 62 A8 PK 1 63 A9 PK 2 64 A10 PK 3 65 A11 PK 4 66 A12 PK 5 67 A13 PK 6 68 A14 PK 7 69 A15
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #6 on: May 29, 2009, 12:49:59 pm » |
Ok, so can I do something like hook V+ to one side of a pushbutton, and the other side to analog 11 on an arduino mega, and then run this type of code: int pinValue;
void setup(){
pinMode(65, INPUT); Serial.begin(9600); }
void loop(){
if(digitalRead(65) == HIGH) { pinValue = 1; } else { pinValue = 0; }
Serial.println(pinValue); }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #7 on: June 11, 2009, 11:41:58 pm » |
Anyone?  Is it possible to use analog pins on the arduino mega as digital pullup pins? I'm using the awesome hardware abstraction library for buttons for the rest of my project, and it would be super nice if it were possible to use analog pins as pullup digital pins, but so far it doesn't appear that arduino mega can do that, or I don't know how to do it. I would Love some input... I do know which pin numbers to address them as, but is there some hardware limitation that prevents the analog pins from working as pullup digital?
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #8 on: June 11, 2009, 11:59:27 pm » |
The Mega analog pins (as digital pins 54-69) do have pull-up resistors. Did you actually try to use them as digitial inputs? You may want to say more about what you tried and the results of your tests
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #9 on: June 12, 2009, 12:41:35 am » |
I did indeed try using them as pullup digital inputs, thank you for asking me to clarify, I will be happy to do so in pursuit of knowledge on how to do this correctly. Perhaps I need a wiring diagram to explain how I did what I did and what the results i was expecting, and then the results I got. This is currently how my circuit is wired up: and I'm only using the diagram as a loose translation of how it's wired. I am actually paying attention to which pin is connected and which pin is addressed in my code. I do realize that the diagram appears to be pointing at analog 0, which would be digital 54. I was expecting to be able to address the analog pin as a digital input and use it like I am successfully addressing 20 other tact inputs on my project using the digital pins. (16+4 as seen in above posts) I was hoping to use the Button HAL http://www.arduino.cc/playground/Code/Button for this implementation, but if I can't no big deal, I'd love to understand how I can do this the regular way if the HAL can't do this for this hardware in this instance. The results I got was that it doesn't appear to be sending current out to let the switch complete the circuit to ground. Am I totally missing the point or misusing the terminology? I'm one of the horde of untrained enthusiasts. When I use the digital pins with the Button library, I have them connected to the digital pin and to ground, and then I address them as PULLUP and they work like a charm.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #10 on: June 12, 2009, 12:52:11 am » |
Try one of the simple button tutorials that directly set the pinMode and pull-ups (changing the pins numbers as needed). There may be something in that library that is not working with the Mega.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15312
Measurement changes behavior
|
 |
« Reply #11 on: June 12, 2009, 01:04:22 am » |
Don't forget to add series resistors when driving LEDs with digital output pins, otherwise pin damage will result.
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #12 on: June 12, 2009, 02:46:40 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15312
Measurement changes behavior
|
 |
« Reply #13 on: June 12, 2009, 02:56:29 am » |
do you think I can expect to start to see some kind of adverse reaction to running my LEDs like this? Yes, very risky with a good chance of burning out the AVR chips output pin. The pin has a max current rating of 40ma and without a current limiting resistor to a LED you have no control of how much current will flow through the LED. From the Arduino playground section: Important Note!
While LEDs will not work when placed backwards, you don't have to worry about whether it will be damaged: as long as there is a series resistor of at least 100 ohms next to it, the LED will survive the experience!
However, using an LED without a series resistor is a sure-fire way to kill it! (You'll see a bright flash and it may turn dark) Always use a resistor! A 1.0K ohm is a good place to start. We'll cover how to figure out the best resistor value later on. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 70
http://sc-fa.com
|
 |
« Reply #14 on: June 12, 2009, 02:58:02 am » |
welp, that's what beatseqr version 2 is for, I guess. I'm glad all I need is 100 ohms, because the brightness on these LEDs is right at the edge of being too hard to see in bright ambient light. Fortunately, I do all of my best work in a cave-like environment, so no problems there.
|
|
|
|
« Last Edit: June 12, 2009, 03:04:29 am by stevecooley »
|
Logged
|
|
|
|
|
|