particle-iot / electron

Creative Commons Attribution Share Alike 4.0 International
90 stars 56 forks source link

Test all pins as GPIO to ensure proper connection #14

Closed technobly closed 9 years ago

technobly commented 9 years ago

I ran through the pins associated with the Photon on the Electron with the attached test app (D0-D7 and A0-A7), and all of them work except for:

These may have some kind of solder issue. This was v004 Dev Electron, will re-test on v009. Update: D4/D5 had some soldering or measurement issue because they work fine on v009 hardware.

#include "application.h"

bool s = false;
String command = "";

SYSTEM_MODE(MANUAL);

char lookup[38][16] = {
    "D0  = PB7",
    "D1  = PB6",
    "D2  = PB5",
    "D3  = PB4",
    "D4  = PB3",
    "D5  = PA15",
    "D6  = PA14",
    "D7  = PA13",
    "ID8 = NULL",
    "ID9 = NULL",
    "A0  = PC5",
    "A1  = PC3",
    "A2  = PC2",
    "A3  = PA5",
    "A4  = PA6",
    "A5  = PA7",
    "A6  = DAC = PA4",
    "A7  = WKP = PA0",
    "RX  = PA10",
    "TX  = PA9",
    "SETUP",
    "RGBR",
    "RGBG",
    "RGBB",
    "B0  = PC8",
    "B1  = PC6",
    "B2  = PB0",
    "B3  = PB1",
    "B4  = PC0",
    "B5  = PC1",
    "C0  = PD2",
    "C1  = PC12",
    "C2  = PC11",
    "C3  = PC10",
    "C4  = PB9",
    "C5  = PB8"
};

#if 0
/* TXD_UC        - 36 */ { GPIOB, GPIO_Pin_10, GPIO_PinSource10, NONE, NONE, TIM2, TIM_Channel_3, PIN_MODE_NONE, 0, 0 },
/* RXD_UC        - 37 */ { GPIOB, GPIO_Pin_11, GPIO_PinSource11, NONE, NONE, TIM2, TIM_Channel_4, PIN_MODE_NONE, 0, 0 },
/* RI_UC         - 38 */ { GPIOB, GPIO_Pin_12, GPIO_PinSource12, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* CTS_UC        - 39 */ { GPIOB, GPIO_Pin_13, GPIO_PinSource13, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* RTS_UC        - 40 */ { GPIOB, GPIO_Pin_14, GPIO_PinSource14, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* PWR_UC        - 41 */ { GPIOB, GPIO_Pin_2, GPIO_PinSource2, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* RESET_UC      - 42 */ { GPIOC, GPIO_Pin_4, GPIO_PinSource4, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* LVLOE_UC      - 43 */ { GPIOB, GPIO_Pin_15, GPIO_PinSource15, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* PM_SDA_UC     - 44 */ { GPIOC, GPIO_Pin_9, GPIO_PinSource9, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* PM_SCL_UC     - 45 */ { GPIOA, GPIO_Pin_8, GPIO_PinSource8, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
/* LOW_BAT_UC    - 46 */ { GPIOC, GPIO_Pin_13, GPIO_PinSource13, NONE, NONE, NULL, NONE, PIN_MODE_NONE, 0, 0 },
#endif

int updatePin(String);

void setup()
{
    Serial.begin(9600);
    //while(!Serial.available()) Spark.process();
    while(Serial.available()>0) Serial.read();
    Serial.print("Enter your desired pin and level (h/l) (e.g. d0h, a3l, t0h, t0l): ");
}

void loop()
{
    s = !s;
    RGB.control(true);
    RGB.color(0,0,0);

    if(Serial.available()) {
        char c = Serial.read();
        if (c != '\r') {
            command += c;
            Serial.print(c); // echo
        }

        if(c == '\r' && command.length() == 3) {
            RGB.color(255,255,255);
            Serial.println(String("\n\rRunning Command: ") + command); // echo

            int pin = updatePin(command);
            if(pin >= 0) {
                Serial.println();
                Serial.println(lookup[pin]);
            }

            command = ""; // clear command

            delay(1000);
            RGB.color(0,0,0);
        }
        else if (c == '\r' && command.length() > 3) {
            command = ""; // clear command
            Serial.println(" <- Bad command bruh");
        }
    }

    RGB.control(false);
}

int updatePin(String command) {
    bool value = 0;
    int pinNumber = command.charAt(1) - '0';
    if (pinNumber < 0 || pinNumber > 7) return - 1;

    if(command.charAt(2) == 'h') value = 1;
    else if(command.charAt(2) == 'l') value = 0;
    else return -2;

    if(command.startsWith("d")) {
        Serial.print(String("d")+String(pinNumber)+String(value));
        pinMode(pinNumber, OUTPUT);
        digitalWrite(pinNumber, value);
        return pinNumber;
    }
    else if(command.startsWith("a")) {
        Serial.print(String("a")+String(pinNumber+10)+String(value));
        pinMode(pinNumber + 10, OUTPUT);
        digitalWrite(pinNumber + 10, value);
        return pinNumber + 10;
    }
    else if(command.startsWith("b")) {
        Serial.print(String("b")+String(pinNumber+24)+String(value));
        pinMode(pinNumber + 24, OUTPUT);
        digitalWrite(pinNumber + 24, value);
        return pinNumber + 24;
    }
    else if(command.startsWith("c")) {
        Serial.print(String("a")+String(pinNumber+30)+String(value));
        pinMode(pinNumber + 30, OUTPUT);
        digitalWrite(pinNumber + 30, value);
        return pinNumber + 30;
    }
    else if(command.startsWith("w")) {
        Serial.print(String("w")+String(17)+String(value));
        pinMode(17, OUTPUT);
        digitalWrite(17, value);
        return 17;
    }
    else if(command.startsWith("r")) {
        Serial.print(String("r")+String(RX)+String(value));
        pinMode(RX, OUTPUT);
        digitalWrite(RX, value);
        return RX;
    }
    else if(command.startsWith("t")) {
        Serial.print(String("t")+String(TX)+String(value));
        pinMode(TX, OUTPUT);
        digitalWrite(TX, value);
        return TX;
    }
    else return -3;
}
technobly commented 9 years ago

Updated above test app and comments... all external pins tested as GPIO outputs... working 0/3.3V.