I have a mega 2560. It has digital pins marked from 22 to 53 which is 32 pins. However I need at least 45 pins. Are there other pins on the board that I can configure to use as digital, if so how do I do that or is there some way of adding more pins?
Running out of pins on a Mega? Amazing.
All pins are capable of digital output, even the "analog in" pins.
Tried that?
I'm not certain how well the "analog in" pins work as digital inputs (viz. the ADC 30k impedance) - or if that only comes into play given an analogRead (vs. a digitalRead.)
The ADC has a much higher impedance than that - it is precise to better than one part in 1024 with a 10k
driving impedance, so clearly its impedance must be > 10M - at DC. The equivalent circuit on the datasheet
shows the equivalent circuit and load capacitance which become important at higher frequencies.
The analog pins are only connected to the ADC when a call to analogRead selects them anyway, so if you
don't call analogRead on a pin, its isolated from the ADC (again by a practically infinite resistance). They
are exactly the same as any other digital pin when used as digital pins.
The typical input resistance of CMOS circuit at room temperature is in the 10^10 to 10^11 ohms range,
at higher temperatures it can drop preciptously to 10^8 ohms or so, in practice you've never notice.
Incidentally some MEGA clones (I know of the Seeeduino one) bring out more pins to headers, the
Seeeduino MEGA has about 90 pins in all.
Thank you for the information.
At the moment I have this.
int switchPins[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56};
int pinCount = 35;
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(switchPins[thisPin], INPUT_PULLUP);
So can I use this
int switchPins[] = {1, 2, 3, 4 ,5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
int pinCount = 45;
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(switchPins[thisPin], INPUT_PULLUP);
Although pin 1 is TX which you might want to reserve for Serial.
int pinCount = sizeof(switchPins)/sizeof(int) ;
Is the normal way to do a count - you can alter the array initializer without having to
remember to update the count correctly that way
Are we allowed to ask how many pins you NEED ?
I think a better question is What are the pins being used for. If driving LEDs, be sure to use current limit resistors, and observe the current limits of the ports and the overall limit of 800mA for a 2560.
You could use a 74HC595 shift register. They can be bought as a pack of 20 from ebay for about $2
http://www.ebay.com/itm/20Pcs-SN74HC595N-74HC595-8-Bit-Shift-Register-DIP-16-IC-/130806676456?hash=item1e74af7be8:g:uycAAOSwgQ9Vgoa2
Thank you every one for the information. I am developing a game that has 45 momentary contact switches each one attached to a small door. Hence 45 pins to act as inputs. When a switch is pressed it will need to activate a sound so I will need some other pins to act as outputs to an Adafruit VS1053
If a pin is configured as INPUT_PULLUP does it automatically use the mega's internal resistor.
45 keys can be done with 14 inputs. Just implement a 7x7 (49 switches) matrix and don't populate 4 of them. Arduino even has a "keypad" library for this. The schematic would look like this:
That was for a 4x4 (16 key) keypad. You can define your own organization for your keypad beyound 4x4. I suggest 7x7. Here for an explanation of how it works, library documentation, and sample code:
Doesn't the VS1053 just need a serial input as a command?
That's what these MP3 modules need,
Serial.write (0x01); // to 45.
Wow! 49 switches with only using 14 inputs! Fantastic but I looked at the library and it is above my level of expertise but I will work towards it. Thanks for the info on using serial input as a command.
A little confused.
Original post.
int switchPins[] = {1, 2, 3, 4 ,5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
int pinCount = 45;
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(switchPins[thisPin], INPUT_PULLUP);
Does this piece of code
int pinCount = sizeof(switchPins)/sizeof(int) ;
replace
int pinCount =45;
or
int thisPin = 0; thisPin < pinCount; thisPin++
My game has 45 doors. Behind the doors are small Simpsons Characters. There are 22 matching pairs of characters. The aim of the game is to match characters so I have been working on (and still working on) developing the logic to play a particular sound when matching doors are opened. I originally posted the concept in another forum (project) so have not posted here.
roadshark:
I have a mega 2560. It has digital pins marked from 22 to 53 which is 32 pins. However I need at least 45 pins. Are there other pins on the board that I can configure to use as digital, if so how do I do that or is there some way of adding more pins?
Please confirm the current before extending the pins or changing anything. It will damage the circuit in case of improper current.
I am planning to use the megas 5v current using the built in resistors via INPUT_PULLUP.
roadshark:
I am planning to use the megas 5v current using the built in resistors via INPUT_PULLUP.
While what you wrote there doesn't make 100% sense, you are right in the sense that if you are using all those pins as inputs, there is no issue with current. The other guy didn't read this thread closely. As outputs, you have to calculate it out and make sure you don't exceed currents on any pin, bank, or for the IC, assuming you want to be professional about things.
Thx. Using 45 pins as inputs. I will be using a few pins to communicate with an adafruit-vs1053.
I'm pretty sure, without even looking (note: not professional!) that the vs1053 isn't going to require much current at all from the Arduino's outputs. You might want to check power supply requirements if it is going to use the Arduino's power supply for it's power pins though.
Thx for taking the time. Will check everything as I do not want fries with the main course!