How to define I0 PIN using esp 32 dev board

i'm using esp 32 dev board with a i2c sensor , i am using I021 pin foe SDA PIN and I022 pin for SCL pin.

i wish to define I0 pin during my coding i'm trying

#define SDAPIN = 21;
#define SCLPIN = 22;

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

pinMode(SDAPIN, INPUT); // Sets the SDAPin as an INput
pinMode(SCLPIN, OUTPUT);// Sets the SCLPin as an OUTput

but this does not working pretty well. So how should i define a I0 PIN.

Delta_G:

#define SDAPIN = 21;

You ever see a #define with an = or a semicolon?

#define is a direct text replacement. It's like "find-and-replace" before it goes to the compiler.

So now this line:

pinMode(SDAPIN, INPUT); // Sets the SDAPin as an INput

Becomes:

pinMode(= 21;, INPUT); // Sets the SDAPin as an INput

Hopefully you can see the problem with that.

sorry is const int not #define .

Delta_G:
Yeah, that would make a lot more sense. Glad you go it figured out.

yeah i am sorry i just relised.

/* This example shows how to get single-shot range
 measurements from the VL53L0X. The sensor can optionally be
 configured with different ranging profiles, as described in
 the VL53L0X API user manual, to get better performance for
 a certain application. This code is based on the four
 "SingleRanging" examples in the VL53L0X API.

 The range readings are in units of mm. */

#include <Wire.h>
#include <VL53L0X.h>
const int SDAPIN = 21;
const int SCLPIN = 22;
VL53L0X sensor;


// Uncomment this line to use long range mode. This
// increases the sensitivity of the sensor and extends its
// potential range, but increases the likelihood of getting
// an inaccurate reading because of reflections from objects
// other than the intended target. It works best in dark
// conditions.

#define LONG_RANGE


// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed

//#define HIGH_SPEED
#define HIGH_ACCURACY


void setup()
{
  Serial.begin(9600);
  Wire.begin(21 , 22);
  pinMode(21,INPUT);
  pinMode(22,OUTPUT);
  sensor.init();
  sensor.setTimeout(500);

#if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  sensor.setMeasurementTimingBudget(200000);
#endif
}

void loop()
{
  Serial.print(sensor.readRangeSingleMillimeters());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

This was my example code . i'm put wire.begin(21,22); because that i relised that if i dont put 21,22 inside the () my sensor range only can detected until mostly 700 it was not making sense. but after i putting in 21,22 my sensor was not working at all the range was not printed out.

Delta_G:
If you're using 21 and 22 for wire, then you probably shouldn't be messing with their pinMode after you call wire.begin

/* This example shows how to get single-shot range
 measurements from the VL53L0X. The sensor can optionally be
 configured with different ranging profiles, as described in
 the VL53L0X API user manual, to get better performance for
 a certain application. This code is based on the four
 "SingleRanging" examples in the VL53L0X API.

 The range readings are in units of mm. */

#include <Wire.h>
#include <VL53L0X.h>
const int SDAPIN = 21;
const int SCLPIN = 22;
VL53L0X sensor;


// Uncomment this line to use long range mode. This
// increases the sensitivity of the sensor and extends its
// potential range, but increases the likelihood of getting
// an inaccurate reading because of reflections from objects
// other than the intended target. It works best in dark
// conditions.

#define LONG_RANGE


// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed

//#define HIGH_SPEED
#define HIGH_ACCURACY


void setup()
{
  Serial.begin(9600);
  Wire.begin(21, 22);
  pinMode(SDAPIN,INPUT);
  pinMode(SCLPIN,OUTPUT);
  sensor.init();
  sensor.setTimeout(500);

#if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  sensor.setMeasurementTimingBudget(200000);
#endif
}

void loop()
{
  Serial.print(sensor.readRangeSingleMillimeters());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

is like this ? but the serial monitor is empty never shown the range

Delta_G:
You're still messing with the pinMode of 21 and 22 after you call wire.begin. That's probably still a bad idea.

oh sorry i have been change to 21 to (SDA,INPUT) and 22 to (SCL,OUTPUT) but the result is same never shown anything on serial monitor

Hi,
Have you googled esp32 I2C
or
googled VL53L0X esp32

You will find many examples of using I2C.

Tom... :slight_smile:

TomGeorge:
Hi,
Have you googled esp32 I2C
or
googled VL53L0X esp32

You will find many examples of using I2C.

Tom... :slight_smile:

thanks very much i have setter this problem!

Hi,
How did you solve your problem?
It would be good information for this thread if you told us what you did to fix it?

Thanks.. Tom... :slight_smile:

TomGeorge:
Hi,
How did you solve your problem?
It would be good information for this thread if you told us what you did to fix it?

Thanks.. Tom... :slight_smile:

sorry for late reply. caused cannot searching on any information so i testing on those normal usually used pin ,so i testing out SDA for pin I021, SCL for pin I022 thats working well.

I am stuck in the coding of esp 32
I have 3 sensors those have 3 rx and 3 tx pin
How to i can manage and connect with esp
And how to i use gpio pin as rx or tx pin

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.