Trouble with Communication Pins

Hi All

I have tried to research the answer to this question but Im not sure I understand. I have designed a project that uses almost all of the Pins on an Arduino Mega. It worked great when I didn't use all the pins but now I have moved things around so there not crossed wires everywhere, it doesn't work. What I have basically done is move some button inputs to the communication pins 14-21. My question is can I use these as normal digital input pins? My research suggests that you can, but do I have to tell the program code that I am doing that as these don't seem to be working right now.

P.S I have seen some suggestions saying that if you use a certain analogue pin then you can't use a comm pin, but can't find a list that says which pins are replicas.

Hope this makes sense to someone.

Thanks

aside from pin 14, Arduino Mega pin mapping indicates that those pins are digital.

do you have any old code enabling (e.g. begin()) those pins for serial use or configuring them as OUTPUT?

Hi gcjr

No, theres nothing in the code that uses those functions, everything is literally either input, output or analogue input. I wasnt actually using pins 14 -21 for anything. So what I did is went through the code and changed each pin to the number I wanted it to be, all the input, output digitalwrite etc hasn't changed, just the pin numbers.

gface83:
I did is went through the code and changed each pin to the number I wanted it to be, all the input, output digitalwrite etc hasn't changed, just the pin numbers.

hopefully you just needed to change #defines

i actually had a similar problem and eventually discovered that i didn't plug the shield in properly and didn't connect the shield pins to that 8 pin connector. I also found that some pins on the connector were broken and needed to replace it.

you might consider using the following code to check the pins

// pcRead - debugging using serial monitor

const char version [] = "PcRead 200416a";

int debug = 0;

// ---------------------------------------------------------
// toggle output bit
void
pinToggle (
    int pin)
{
    static int  bits = 0;
    int     bit = 1 << pin;

    if (debug)  {
        Serial.print ("pinToggle: ");
        Serial.println (pin);
    }

    if (bits & bit)  {
        digitalWrite (pin, LOW);
        bits &= ~bit;
    }
    else {
        digitalWrite (pin, HIGH);
        bits |= bit;
    }
}

// ---------------------------------------------------------
// toggle output bit
int
readString (
    char *s,
    int   maxChar )
{
    int  n = 0;

    Serial.print ("> ");
    do {
        if (Serial.available()) {
            int c    = Serial.read ();

            if ('\n' == c)
                break;

            s [n++] = c;
            if (maxChar == n)
                break;
        }
    } while (true);

    return n;
}

// -----------------------------------------------------------------------------
// process single character commands from the PC
#define MAX_CHAR  10
char s [MAX_CHAR] = {};

void
pcRead (void)
{
    static int  analogPin = 0;
    static int  val = 13;

    if (Serial.available()) {
        int c = Serial.read ();

        switch (c)  {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            val = c - '0' + (10 * val);
            break;

        case 'A':
            analogPin = val;
            Serial.print   ("analogPin = ");
            Serial.println (val);
            val = 0;
            break;

        case 'D':
            debug ^= 1;
            break;

        case 'I':
            pinMode (val, INPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT");
            val = 0;
            break;

        case 'O':
            pinMode (val, OUTPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" OUTPUT");
            val = 0;
            break;

        case 'P':
            pinMode (val, INPUT_PULLUP);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT_PULLUP");
            val = 0;
            break;


        case 'a':
            Serial.print   ("analogRead: ");
            Serial.println (analogRead (val));
            val = 0;
            break;

        case 'c':
            digitalWrite (val, LOW);
            Serial.print   ("digitalWrite: LOW  ");
            Serial.println (val);
            val = 0;
            break;

        case 'p':
            analogWrite (analogPin, val);
            Serial.print   ("analogWrite: pin ");
            Serial.print   (analogPin);
            Serial.print   (", ");
            Serial.println (val);
            val = 0;
            break;

        case 'r':
            Serial.print   ("digitalRead: pin ");
            Serial.print   (val);
            Serial.print   (", ");
            Serial.println (digitalRead (val));
            val = 0;
            break;

        case 's':
            digitalWrite (val, HIGH);
            Serial.print   ("digitalWrite: HIGH ");
            Serial.println (val);
            val = 0;
            break;

        case 't':
            Serial.print   ("pinToggle ");
            Serial.println (val);
            pinToggle (val);
            val = 0;
            break;

        case 'v':
            Serial.print ("\nversion: ");
            Serial.println (version);
            break;

        case '\n':          // ignore
            break;

        case '"':
            while ('\n' != Serial.read ())     // discard linefeed
                ;

            readString (s, MAX_CHAR-1);
            Serial.println (s);
            break;

        case '?':
            Serial.println ("\npcRead:\n");
            Serial.println ("    [0-9] append to #");
            Serial.println ("    A # - set analog pin #");
            Serial.println ("    D # - set debug to #");
            Serial.println ("    I # - set pin # to INPUT");
            Serial.println ("    O # - set pin # to OUTPUT");
            Serial.println ("    P # - set pin # to INPUT_PULLUP");
            Serial.println ("    a # - analogRead (pin #)");
            Serial.println ("    c # - digitalWrite (pin #, LOW)");
            Serial.println ("    p # -- analogWrite (analogPin, #)");
            Serial.println ("    r # - digitalRead (pin #)");
            Serial.println ("    s   - digitalWrite (pin #, HIGH)");
            Serial.println ("    t   -- toggle pin # output");
            Serial.println ("    v   - print version");
            Serial.println ("    \"   - read string");
            Serial.println ("    ?   - list of commands");
            break;

        default:
            Serial.print ("unknown char ");
            Serial.println (c,HEX);
            break;
        }
    }
}

// -----------------------------------------------------------------------------
void
loop (void)
{
    pcRead ();
}

// -----------------------------------------------------------------------------
void
setup (void)
{
    Serial.begin(115200);

    Serial.println (version);
}

Yes, everything was set up as variables so all I needed to do was change the pin numbers, all the code uses is the variable name. I know the pins I was using before were working fine and most of them still work fine, its just pins 14-21 are not working at all. As I said in the first post, i've come across a post while searching that suggested that you cant use certain analogue pins with other pins as they are duplicates, but I cant find a list of which ones are. if that's even the problem

i know you can use analog pins an digital inputs, i'm not so sure about using them as OUTPUTs

were you using pins 14-21 in the same way (input or ouput) before you made changes?

All my analogue pins are set up as inputs. I wasn't actually using pins 14-21 at all. I wanted to tidy up the project so wires weren't crossing everywhere before I build it properly from breadboard.