I have purchased Arduino mega 2560 from local supplier. To start with I tested LED blink code from IDE. Then I started interfacing LCD on to digital pins from 22-28 but it didn't work. Then I switched to pins 7-12. The LCD showed the characters I sent i.e. "TEST".
Now I am checking simple LED blink on digital pins(22-53), it is not working. It has worked on pins upto 13.
I am confused and started to think that there could be any settings for using these pins
Please guide me.
P.S. Not posting my code as I am using those available with IDE (blink or button for example)
I have used key to pin 40 and using on board LED. (pin 13).
Hardware connections are : key is with pull up resistor 10K (resistor's one terminal goes to +5V) and one terminal of key is connected to ground. In code I am checking if port pin goes low then turn OFF LED.
I've tested voltage at key when key is pressed and when key is open. Voltages measured are OK. (i.e. 0V when key is pressed and +5V when key is open).
const int buttonPin = 40; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin,HIGH);
digitalWrite(ledPin,HIGH);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW)
{
// turn LED on:
digitalWrite(ledPin, LOW);
} else {
// turn LED off:
digitalWrite(ledPin, HIGH);
}
}
As an experiment try this. Remove the external resistor from the switch circuit and arrange the switch so that it takes the input pin to GND when the switch is pressed. Then load and run this.
Very true! It can be a real pain in the neck, in that the board says pin 50, 51, and 52...... and only reading through the manual (or local knowledge passed on) will reveal that these pins are electrically connected to those bare "SPI" pins poking out from the arduino board.
But that's the way it is. So, as usual..... best to know in advance which pins are general purpose (or not) and understand enough things about the device before plugging things in to the arduino (or any device in general).
On the other hand....... it is true that some manuals don't convey things clearly.
Eg...... for a beginner's arduino tute..... should just say ... USE pins XX to YY for general input or output. DO NOT USE pins PP to QQ for general inputs or outputs, as these are reserved for such and such, and in particular - pins PP to QQ are electrically connected to the SPI pins (which are pins marked in in diagram ZZ).
But..... if it turns out that pins PP to QQ can truly be used as general purpose pins, then the manual should have big bold writing that says something like ---- you may use pins PP to QQ as general purpose pins, PROVIDED that ....... etc etc etc.
You are aware that you CANNOT use pins 50 through 53. They are dedicated to the functions listed below.
Surely you can use them as general purpose digital pins as long as you don't need them to be used for their special functions. There are similar dual purpose pins on the Uno for instance.
No those pins are reserved for the SPI interface PERIOD. Actually, I kind of like it as it gives you two (2) places to interface with the SPI com port which by the way is a hardware SPI not software as in the UNO (much faster).
Besides, you have 48 other digital i/o pins to work with and that does not include the 16 analog input pins that can be used for digital i/o if so desired. That is a lot of I/O. You also have four functional hardware uarts to work with.
No those pins are reserved for the SPI interface PERIOD. Actually, I kind of like it as it gives you two (2) places to interface with the SPI com port which by the way is a hardware SPI not software as in the UNO (much faster).
Besides, you have 48 other digital i/o pins to work with and that does not include the 16 analog input pins that can be used for digital i/o if so desired. That is a lot of I/O. You also have four functional hardware uarts to work with.
pert:
I have Blink running fine on pins 50-53. Where are you getting this information?
It's more like.... the lack of well written documentation. The official documentation doesn't always tell simple important things the way it is..... or makes people assume or guess. But the nice thing is.... at least people are asking so we can establish some things once and for all.
It's great to have the docs..... and the people do put in the hard yards to write it. But some updates would be beneficial.
Digital I/O Pins 54 (of which 15 provide PWM output)
Each of the 54 digital pins on the Mega can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions.
In addition, some pins have specialized functions:
...
SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication
In this case the documentation seems crystal clear to me. That's not to say there aren't other areas where the documentation could be improved. I've found that Arduino is remarkably receptive to suggestions for improvements to the documentation. When I provide a well though out full text of the suggested change it's almost always incorporated within a few days. More vague suggestions may not always get such a good response.
It doesn't say anywhere there that 50-53 can't be normal IO. Can you quote the part that led you to that? @pert just quoted most of it and it seems pretty clear to me.