Trouble when SensorVN/SensorVP as GPIO

ntldr2018
Posts: 3
Joined: Mon Dec 24, 2018 4:28 am

Trouble when SensorVN/SensorVP as GPIO

Postby ntldr2018 » Mon Dec 24, 2018 5:08 am

Hi,

I've been working on design to a real PCB using a WROOM32 module (rather than mounting a devkit via female headers on perfboard). I've however run into an odd issue with the GPIOs 36 and 39.

In my application I'm measuring the amount of times a line has been pulled low per second by a hall sensor. As this signal has a bit of noise, which is picked up when using FALLING interrupts, I'm simply reading from each pin as often as possible and detecting falling edges in software.

This works great on most pins. However on GPIO 36 (Sensor_VP) and GPIO 39 (Sensor_VN) this causes very odd behavior.

When connecting the hall sensor to GPIO 39 (Sensor_VN) the signal is picked up correctly. However GPIO 36 also picks up the same signal without being connected to a sensor at all, but only to an external 5k pullup.
If I switch things around and connect my sensor to GPIO 36 neither of the two pins seems to detect anything.

Do I need to do anything special to make these two GPIOs work correctly?

Minimal schematic for reference: https://i.imgur.com/7ArzTU7.png
Also minimal example code:

Code: Select all

#include <Arduino.h>
#include <driver/rtc_io.h>
  
#define SENSOR_VP_GPIO 36
#define SENSOR_VN_GPIO 39

void setup() {
  Serial.begin(9600);

  // Does not change anything
  //rtc_gpio_deinit(GPIO_NUM_36);
  //rtc_gpio_deinit(GPIO_NUM_39);

  pinMode(SENSOR_VP_GPIO, INPUT);
  pinMode(SENSOR_VN_GPIO, INPUT);
}

long time = 0;
int ticksA = 0;
int ticksB = 0;

bool lastA, lastB;

void loop() {
  long now = millis();
  bool newA = digitalRead(SENSOR_VN_GPIO);
  bool newB = digitalRead(SENSOR_VP_GPIO);  

  if(lastA && !newA) // Falling edge?
      ticksA++;
  lastA = newA;
  if(lastB && !newB) // Falling edge?
      ticksB++;
  lastB = newB;


  if(now - time > 1000)
  {
    Serial.println("[");
    Serial.println(ticksA);
    Serial.println(ticksB);
    Serial.println("]");
    time = now;
    ticksA = 0;
    ticksB = 0;
  }

}
Thanks & Merry Christmas
ntldr

[Edit]
After more fiddling around it appears that my initial guess of the pins being wrongly configured wasn't that wrong. Just instead of using rtc_gpio_deinit, I needed to use gpio_config.

raingrid
Posts: 1
Joined: Thu Apr 07, 2022 4:23 pm

Re: Trouble when SensorVN/SensorVP as GPIO

Postby raingrid » Thu Apr 07, 2022 4:25 pm

ntldr2018 wrote:
Mon Dec 24, 2018 5:08 am
Hi,

I've been working on design to a real PCB using a WROOM32 module (rather than mounting a devkit via female headers on perfboard). I've however run into an odd issue with the GPIOs 36 and 39.

In my application I'm measuring the amount of times a line has been pulled low per second by a hall sensor. As this signal has a bit of noise, which is picked up when using FALLING interrupts, I'm simply reading from each pin as often as possible and detecting falling edges in software.

This works great on most pins. However on GPIO 36 (Sensor_VP) and GPIO 39 (Sensor_VN) this causes very odd behavior.

When connecting the hall sensor to GPIO 39 (Sensor_VN) the signal is picked up correctly. However GPIO 36 also picks up the same signal without being connected to a sensor at all, but only to an external 5k pullup.
If I switch things around and connect my sensor to GPIO 36 neither of the two pins seems to detect anything.

Do I need to do anything special to make these two GPIOs work correctly?

Minimal schematic for reference: https://i.imgur.com/7ArzTU7.png
Also minimal example code:

Code: Select all

#include <Arduino.h>
#include <driver/rtc_io.h>
  
#define SENSOR_VP_GPIO 36
#define SENSOR_VN_GPIO 39

void setup() {
  Serial.begin(9600);

  // Does not change anything
  //rtc_gpio_deinit(GPIO_NUM_36);
  //rtc_gpio_deinit(GPIO_NUM_39);

  pinMode(SENSOR_VP_GPIO, INPUT);
  pinMode(SENSOR_VN_GPIO, INPUT);
}

long time = 0;
int ticksA = 0;
int ticksB = 0;

bool lastA, lastB;

void loop() {
  long now = millis();
  bool newA = digitalRead(SENSOR_VN_GPIO);
  bool newB = digitalRead(SENSOR_VP_GPIO);  

  if(lastA && !newA) // Falling edge?
      ticksA++;
  lastA = newA;
  if(lastB && !newB) // Falling edge?
      ticksB++;
  lastB = newB;


  if(now - time > 1000)
  {
    Serial.println("[");
    Serial.println(ticksA);
    Serial.println(ticksB);
    Serial.println("]");
    time = now;
    ticksA = 0;
    ticksB = 0;
  }

}
Thanks & Merry Christmas
ntldr

[Edit]
After more fiddling around it appears that my initial guess of the pins being wrongly configured wasn't that wrong. Just instead of using rtc_gpio_deinit, I needed to use gpio_config.
Hi, can you please share the solution or explain one?

Who is online

Users browsing this forum: No registered users and 113 guests