2

I am trying to use an esp32 (NodeMCU-32s) as a ringlight controller for my camera. All it should do is sense when an input pin goes low (the camera's output connects to ground when the shutter goes off) which is easy to detect with a simple digitalRead(). If low, then it raises 6 pins with digitalWrite() which are connected to transistors which let current flow from a 24v power supply and light up 6 banks of white LEDs. This entire setup was working great on an esp32wroom I bought from our school's shop - like I said it is very simple - but after ordering more esp32's online, I was greeted with slightly different looking ones that don't behave the same even when running the exact same code. Yes, I have verified that the pinout is the same on these two boards, although the footprint of the online boards (best datasheet I could find linked above) is one breadboard slot thinner.

Expected behavior:

I power it on, and nothing should happen until I connect pin 14 to ground, then the lights should turn on for a tenth of a second, then back off.

Actual Behavior:

I power it on, 3 banks of lights turn on rather dimmly. The other three stay off. When I connect pin 14 to ground, the three that were off turn on for a tenth of a second, then back off. While they are on, a blue light on the nodemcu-32s dev board turns on as well...

I did some digging:

On this random nerd tutorials website I found code that identifies which pins are your board's default SPI pins and when I ran it, I found that 3 of the 6 pins I was currently using (pins 23, 19, and 5) are SPI-related ones. These were in fact the pins that behaved correctly (they were off until 14 was pulled low.)

I am not sure if this is related to the root cause of my issue or not, but it seems suspicious. Any tips from you wise arduino wizards would be appreciated - this was supposed to be simple!

Code:

Below is the code I am using. You can ignore the rgb LED stuff (LED_PIN, NUM_LEDS, BRIGHTNESS, etc.) All that matters for what I am trying to get working here are the led banks connected to pins 23, 21, 19, 5, 16, and 2. I intentionally avoided pins 6-11 because many sites were saying to avoid them.

#include <Adafruit_NeoPixel.h>

#define LED_PIN 15      // Pin connected to the Data Input of WS2812B
#define NUM_LEDS 24     // Number of WS2812B LEDs in the strip
#define BRIGHTNESS 200  // Set the brightness (0-255)

#define SHUTTER_PIN 14  //Pin connected to the shutter signal of the cameras via 3.5mm jack
Adafruit_NeoPixel strip;

void setup() {
  // setup code here, to run once:
  pinMode(23, OUTPUT); // set each bank of 6 White Leds as outputs
  pinMode(21, OUTPUT);
  pinMode(19, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(2, OUTPUT);     
                                                                                                                                                                                                                                                                            
  // set the shutterPin as a normally-high input
  pinMode(SHUTTER_PIN, INPUT_PULLUP); 

  // To control rgb leds
  strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); 
  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show(); 

 // Initialize all pixels to off
  digitalWrite(23, LOW);
  digitalWrite(21, LOW);
  digitalWrite(19, LOW);
  digitalWrite(5, LOW);
  digitalWrite(16, LOW);
  digitalWrite(2, LOW);
}

void loop() {
  //main code here, to run repeatedly:
  // if the shutter signal drops, flash on and off
  if (digitalRead(SHUTTER_PIN) == 0) { 
    digitalWrite(23, HIGH);
    digitalWrite(21, HIGH);
    digitalWrite(19, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(16, HIGH);
    digitalWrite(2, HIGH);
    delay(500); 
    digitalWrite(23, LOW);
    digitalWrite(21, LOW);
    digitalWrite(19, LOW);
    digitalWrite(5, LOW);
    digitalWrite(16, LOW);
    digitalWrite(2, LOW);
    delay(500);
  }
}
3
  • 2
    Could you provide the code you are using and all of the pin numbers, not just the three that work? From a quick look-up, it doesn't seem like you could actually use IO14 as GPIO14 on ESP32S and you shouldn't use any GPIOs from 6 to 11, unless you really know what you are doing, as those are connected to the internal SPI flash on the chip.
    – Nick S.
    Nov 1, 2023 at 3:37
  • I just added the code that it's running, thanks for your time! Yes, I avoided pins 6-11. Also, why wouldn't I be able to use pin 14 as an input?
    – Zach
    Nov 1, 2023 at 17:21
  • 1
    I was wrong, you are able to use the pin 14 as a GPIO, reading thru this manual a bit more thoroughly.
    – Nick S.
    Nov 1, 2023 at 17:41

2 Answers 2

2

From the schematics, I can see that IO2 is for the board's blue LED. So that's probably your first problem... From this PDF, I see that IO21 is VSPIHD, Hold for Flash chips. No good. IO16 is HS1_DATA4, also used for the Flash chip. Also no good. You'll have to pick other pins.

enter image description here enter image description here

The other issue is SIX pins supposed to deliver 3.3 volts at the same time. On a small ESP board. Not sure that's gonna happen...

5
  • 1
    Thanks for your response dda!
    – Zach
    Nov 1, 2023 at 23:20
  • Why would a pin be labeled as a GPIO if in can't be properly used as a general purpose input or output? As in, shouldn't they just be labeled as just VSPI_HD etc instead to avoid confusion?
    – Zach
    Nov 1, 2023 at 23:22
  • 1
    @Zach I don't think that's an issue, most of the pins on modern MCUs have multiple functions--you decide which ones to utilize. Checking the schematics, I don't see any external quad-SPI peripherals (as dda indicates, most commonly used for flash chips). Another indicator is that it's probably not the pins (aside from GPIO2, we've conclusively established that it's linked to a blue LED...but why is the LED bank dimly lightning up during initialization?) it worked with other ESP32-Wroom modules, which are also the modules used on the NodeMCU-32S board(s).
    – Nick S.
    Nov 2, 2023 at 1:26
  • @Zach okay, I checked on the Espressif docs and yes, pin 16 is indeed not recommended to be used as a GPIO pin (it still can be, of course, but it could lead to unknown behavior as you've experienced)--nothing about pin 21 though.
    – Nick S.
    Nov 2, 2023 at 16:56
  • @Zach it is possible to have different functionalities on the same pin - just don't use them all at once. In the case of the VSPI pins, if there's no Flash chip, and the VSPI bus isn't inited (eg if the code checked whether there's a chip, and didn't deinit afterwards, oops), they can be used.
    – dda
    Nov 3, 2023 at 8:16
0

I'm still not quite sure what's going on, but to troubleshoot this I would do the following:

  • First of all, verify it's not a faulty board and try it with another one of the new ones that you've got. If that doesn't help, then do the following:
    • Move the digitalWrite-s up, above the NeoPixel initialization code. See if that helps with the start-up.
    • If that doesn't help, add pull-down resistors to the LED outputs (try 10kOhm).
    • The blue LED lights up because GPIO 2's output is connected to it, looking at the schematic on the website you've linked. You might want to switch this one to a different GPIO on the board you're using.
    • Check the transistor circuits for the LEDs that are not functioning correctly. You've not posted anything related to it, so I can't help you much there, but if you do link it we might be able to use that info.
2
  • Will do, thanks
    – Zach
    Nov 1, 2023 at 23:23
  • 2
    @Zach do you have an oscilloscope on hand? At least a multi-meter? If you run the main as an empty function, do the 3 LED banks still light up, even though dimly? If you can, check the voltage from the pin to the ground. Take notes. Then, put the main loop back in and measure the voltage on the pins with LED banks that aren't lightning up. What do you see? Of course, you could try just try other pins and if they work alright, just make compilation defines for each board and that'll make it easier to recompile your program as needed.
    – Nick S.
    Nov 2, 2023 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.