#include <WiFi.h>
int xyzPins[] = {13, 12, 14}; //x,y,z pins
void setup() {
Serial.begin(115200);
pinMode(xyzPins[2], INPUT_PULLUP); //z axis is a button.
//WiFi.begin();
delay(500);
}
void loop() {
Serial.begin(115200);
int xVal = analogRead(xyzPins[0]);
int yVal = analogRead(xyzPins[1]);
int zVal = digitalRead(xyzPins[2]);
Serial.printf("X,Y,Z: %d,\t%d,\t%d\n", xVal, yVal, zVal);
delay(500);
}
uncommenting WiFi.begin(); will give these outputs
X,Y,Z: 0, 0, 1
commenting //WiFi.begin(); will give these expected outputs
Why is that? What is happening?
What device are you using? ESP32?
yes, I am using an ESP 32 red_car
this is the setup
Should this...
be connected to 5V?
Instead of 3.3v
Could be a power issue when WiFi is running (usually takes a bit of juice for WiFi)...
moved red and black wire to
and this is the new output
rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff
ets Jul 29 2019 12:21:46
The ESP32 is a 3.3v level device... so 5v might not be recommended.
Also... read some stuff about GPIO12 being used for other things internally... can you try another pin?
I still get the same 0 values. but everything goes back to normal after WiFi.begin(); gets removed. this is very strange.
does WiFi.begin(); and pinMode(xyzPins[2], INPUT_PULLUP); got problem with each other?
Try 3 other pins.
What power supply are you using?
no luck, the only one that seems to work is Z ( the button). any suggestions for other pins for X and Y?
power supply is my laptop USB lol
red_car
December 6, 2022, 9:37am
11
Google found...
The ESP32 integrates two 12-bit SAR (Successive Approximation Register) ADCs supporting a total of 18 measurement channels (analog enabled pins).
The ADC driver API supports ADC1 (8 channels, attached to GPIOs 32 - 39), and ADC2 (10 channels, attached to GPIOs 0, 2, 4, 12 - 15 and 25 - 27). However, the usage of ADC2 has some restrictions for the application:
ADC2 is used by the Wi-Fi driver. Therefore the application can only use ADC2 when the Wi-Fi driver has not started .
Some of the ADC2 pins are used as strapping pins (GPIO 0, 2, 15) thus cannot be used freely.
Can you use the ADC1 pins?
Thanks! this info will greatly help me on other projects as well