![esp32 – Can I exploit SPI-related pins as a Digital Output? esp32 – Can I exploit SPI-related pins as a Digital Output?](https://techtoguide.com/wp-content/uploads/2023/10/Why-wont-my-servo-and-ultrasonic-sensor-work-together.png)
[ad_1]
I’m making an attempt to make use of an esp32 (NodeMCU-32s) as a ringlight controller for my digital camera. All it ought to do is sense when an enter pin goes low (the digital camera’s output connects to floor when the shutter goes off) which is simple to detect with a easy digitalRead(). If low, then it raises 6 pins with digitalWrite() that are linked to transistors which let present movement from a 24v energy provide and light-weight up 6 banks of white LEDs. This complete setup was working nice on an esp32wroom I purchased from our college’s store – like I stated it is extremely easy – however after ordering extra esp32’s on-line, I used to be greeted with barely completely different wanting ones that do not behave the identical even when working the very same code. Yes, I’ve verified that the pinout is similar on these two boards, though the footprint of the net boards (greatest datasheet I might discover linked above) is one breadboard slot thinner.
Anticipated conduct:
I energy it on, and nothing ought to occur till I join pin 14 to floor, then the lights ought to activate for a tenth of a second, then again off.
Precise Conduct:
I energy it on, 3 banks of lights activate fairly dimmly. The opposite three keep off. After I join pin 14 to floor, the three that had been off activate for a tenth of a second, then again off. Whereas they’re on, a blue mild on the nodemcu-32s dev board activates as effectively…
I did some digging:
On this random nerd tutorials web site I discovered code that identifies which pins are your board’s default SPI pins and after I ran it, I discovered that 3 of the 6 pins I used to be at present utilizing (pins 23, 19, and 5) are SPI-related ones. These had been in reality the pins that behaved appropriately (they had been off till 14 was pulled low.)
I’m not positive if that is associated to the basis explanation for my concern or not, but it surely appears suspicious. Any suggestions from you smart arduino wizards could be appreciated – this was imagined to be easy!
Code:
Under is the code I’m utilizing. You may ignore the rgb LED stuff (LED_PIN, NUM_LEDS, BRIGHTNESS, and so on.) All that issues for what I’m making an attempt to get working listed here are the led banks linked to pins 23, 21, 19, 5, 16, and a couple of. I deliberately prevented pins 6-11 as a result of many websites had been saying to keep away from them.
#embody <Adafruit_NeoPixel.h>
#outline LED_PIN 15 // Pin linked to the Knowledge Enter of WS2812B
#outline NUM_LEDS 24 // Variety of WS2812B LEDs within the strip
#outline BRIGHTNESS 200 // Set the brightness (0-255)
#outline SHUTTER_PIN 14 //Pin linked to the shutter sign of the cameras through 3.5mm jack
Adafruit_NeoPixel strip;
void setup() {
// setup code right here, to run as soon as:
pinMode(23, OUTPUT); // set every financial institution 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 enter
pinMode(SHUTTER_PIN, INPUT_PULLUP);
// To manage rgb leds
strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
strip.start();
strip.setBrightness(BRIGHTNESS);
strip.present();
// 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() {
//foremost code right here, to run repeatedly:
// if the shutter sign 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);
}
}
[ad_2]