3

I have an Adafruit Feather RP2040 (pinouts) connected via pin 6 to a relay. The code (below) triggers the relay when a separate color sensor returns "enough" red values.

The color sensor works (confirmed by the serial print statements); the on-board LED (connected internally to pin 13) lights up when it should; but I don't get any voltage on pin 6 when I should. I'm testing the voltage with a standard multimeter. If I move my connecting wire from pin 6 to pin 13, I get voltage (and the relay activates). Why doesn't pin 6 get voltage? What else can I do to diagnose the issue?

Software versions:

Code:

// copied & modified from the source at: 
// https://github.com/adafruit/Adafruit_APDS9960/blob/master/examples/color_sensor/color_sensor.ino

#include "Adafruit_APDS9960.h" Adafruit_APDS9960 apds;

// the pin on the feather that we're using to talk to the relay #define PIN_TO_RELAY 6

#define BUCKET_FULL_RED 50

void setup() { // enable Serial communication Serial.begin(115200);

// try to start the color sensor if(!apds.begin()) { Serial.println("failed to initialize device! Please check your wiring."); } else { // Assume success // Serial.println("Device initialized!");

// we want color readings
apds.enableColor(true);

}

// define the relay pin as an OUTPUT pin pinMode(PIN_TO_RELAY, OUTPUT); // start with the relay "open" AKA not running the pump digitalWrite(PIN_TO_RELAY, LOW);

// use the built-in LED as an external signal for "pumping" pinMode(LED_BUILTIN, OUTPUT); }

void loop() { // create some variables to store the color data in; unused, except for 'red' uint16_t red, green, blue, clear;

// for checking the relay pin state int relay_pin_state = 0;

// for extra printing int debug = 1;

// wait for color data to be ready while (!apds.colorDataReady()) { delay(5); } // get fresh data; we only care about the red, but we have to read them all apds.getColorData(&red, &green, &blue, &clear);

if (debug) { Serial.print("current red value is:"); Serial.println(red); }

if (debug > 2) { relay_pin_state = digitalRead(PIN_TO_RELAY); if (relay_pin_state == HIGH) { Serial.println("steadystate: Relay pin is HIGH / enabled"); } else { Serial.println("steadystate: Relay pin is LOW / disabled"); } }

if (red > BUCKET_FULL_RED) { if (debug) { Serial.println("start the pump (for 5 sec)"); }

// light up the built-in LED
digitalWrite(LED_BUILTIN, HIGH);
// "close" the relay to turn on the pump
digitalWrite(PIN_TO_RELAY, HIGH);

if (debug > 2) {
  relay_pin_state = digitalRead(PIN_TO_RELAY);
  if (relay_pin_state == HIGH) {
    Serial.println("pumping: Relay pin is HIGH / enabled");
  } else {
    Serial.println("pumping: Relay pin is LOW / disabled");
  }
}

// wait for a while for the pump to do its work
// 5 sec in ms; TODO: eventually circa 4 min 
delay(5 * 1000);

if (debug) {
  Serial.println("stop the pump");
}

// turn off the built-in LED
digitalWrite(LED_BUILTIN, LOW);
// "open" the relay to turn off the pump
digitalWrite(PIN_TO_RELAY, LOW);

} // no need to cycle quickly; wait 1 sec in ms delay(1 * 1000); }

I just looked more closely at the pinouts page again, and was surprised to see the hole labeled "6" on the front is labeled "GP08" on the back, which corresponds to "GPIO8" in https://learn.adafruit.com/assets/107203. I wonder if I'm sending the "D4" pin HIGH ("GPIO6") instead of the one I'm expecting.

Jeff Schaller
  • 169
  • 11

2 Answers2

3

Turns out I misled you with my ignorance. I took for granted that the thing labeled "6" on the front was in fact Pin 6, but it's not:

feather with pin "6" circled

Indeed, if I turn it over, that's "GP08":

reverse face of feather with the same location labeled "GP08"

... and so my code needs to use pin 8, not pin 6.

User timemage pointed out similar confusion on a recent post: D1 mini ESP8266 no sound on speaker where the silk-screened label on the front of the board did not match the actual pin number. They additionally point out a file that I would have never stumbled upon, but demonstrates this mapping: https://github.com/adafruit/circuitpython/blob/16c8c9a739cfe0db2c712696eb340de2d7944d41/ports/raspberrypi/boards/adafruit_feather_rp2040/pins.c#L24, namely:

    { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) },
    { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) },
    { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO7) },
    { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO8) },  /* right here */
    { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) },
    { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },

The description of the pinout still contains some misleading information, in my opinion:

D6/GP08 - Digital I/O pin 6. It is also SPI1 MISO, UART1 TX, I2C0 SDA and PWM4 A.

Here, it seems to me that this spot is still being called "pin 6".

Jeff Schaller
  • 169
  • 11
2

The pin labeled as GP06 on the bottom side of the PCB is labeled as D4 on the top side of the PCB. It is pin 4.

from https://learn.adafruit.com/adafruit-feather-rp2040-pico/pinouts

D4/GP06 - Digital I/O pin 4. It is also SPI0 SCK, I2C1 SDA and PWM3 A.

Juraj
  • 18,264
  • 4
  • 31
  • 49