IS THAT ABLE TO DIGITAL READ A I2C BUS SENSOR

i'm using VL6180X senosr its a I2C BUS Sensor only have SDA AND SCL PIN but i need to digital Read SDA Pin to working on some code. After i tried it , it did not working well. Is that able to read a I2C Sensor on digital Read?

Please read and follow the directions in the "How to use this forum" post. You need to post code, using code tags, and describe the problem clearly.

void telegramButton1Pressed() {
  Serial.println("Telegram Button-1 Pressed");
  int sda = digitalRead(D2);
    
  {
  telegramButton1PressedFlag = true;
  }
  return;
}
void sendTelegramMessage() {
  String message = "11!";              //Full
  if(bot.sendMessage(CHAT_ID, message, "Markdown")){
    Serial.println("TELEGRAM Message  Successfully sent");
  }
    telegramButton1PressedFlag = false;
}

i need a digital pin to read by telegrame code before it can process to send a message

[color=#222222]int sda = digitalRead(D2);

SDA & SCL are on pins A4, A5 on a 328P based board. What you are asking does not make sense.

CrossRoads:

[color=#222222]int sda = digitalRead(D2);

SDA & SCL are on pins A4, A5 on a 328P based board. What you are asking does not make sense.

yeah i am using ESP8266 WEMOS D1PRO BOARD , the SDA is D2 AND SCL IS D1 its fixed

Makes no sense at all to me.

You communicate with an I2C device via messages sent/received using the 'wire' library. You cannot do a simple digitalRead() like for the Arduino's native I/O.

Read about it.

dougp:
You communicate with an I2C device via messages sent/received using the 'wire' library. You cannot do a simple digitalRead() like for the Arduino's native I/O.

Read about it.

oh,i'm using

#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <VL6180X.h>
#include <Wire.h>

this five libraries

Look at the example code that comes with the VL6180X library. It shows you how to read the sensor. You can't use digitalRead() with I2C.

GypsumFantastic:
Look at the example code that comes with the VL6180X library. It shows you how to read the sensor. You can't use digitalRead() with I2C.

yeah i have look it i knew that i cant read I2C sensor but i need a "digital read" for my telegram coding to work that its what i anxious of .

Joshtan:
i knew that i cant read I2C sensor but i need a "digital read" for my telegram coding to work

I don't understand what you mean. Show us your code.

GypsumFantastic:
I don't understand what you mean. Show us your code.

#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <VL6180X.h>
#include <Wire.h>
VL6180X sensor;
#define SCLPIN  D1     //output
#define SDAPIN  D2   //input to recieve and an output to transmit
long Bot_lasttime;
int bulk_messages_mtbs = 36000; // testing to delay 6sec to detecting another distance and which message been sent .
int Range = 0;   //Set  Range to integer
//------- WiFi Settings -------
char ssid[] = "";       // your network SSID (name)
char password[] = "";  // your network key
// ------- Telegram config ----------
#define BOT_TOKEN ""  // your Bot Token (Get from Botfather)
#define CHAT_ID "" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)

// SSL client needed for both libraries
WiFiClientSecure client;

UniversalTelegramBot bot(BOT_TOKEN, client);

String ipAddress = "";

volatile bool telegramButton1PressedFlag = false;
volatile bool telegramButton2PressedFlag = false;

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
sensor.init();
sensor.configureDefault();
// Reduce range max convergence time and ALS integration
// time to 30 ms and 50 ms, respectively, to allow 10 Hz
// operation (as suggested by Table 6 ("Interleaved mode
// limits (10 Hz operation)") in the datasheet).
sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);

sensor.setTimeout(500);

// stop continuous mode if already active
sensor.stopContinuous();
// in case stopContinuous() triggered a single-shot
// measurement, wait for it to complete
delay(300);
// start interleaved continuous mode with period of 100 ms
sensor.startInterleavedContinuous(350);

// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
    delay(500);
 }
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);

 ipAddress = ip.toString();
}
void telegramButton1Pressed() {
  Serial.println("Telegram Button-1 Pressed");
  int SDAPIN = digitalRead(D2);
  {
      telegramButton1PressedFlag = true;
  }
  return;
}

void sendTelegramMessage() {
  String message = "Toilet_Roll Paper is Replaced!";              //Full
  if(bot.sendMessage(CHAT_ID, message, "Markdown")){
    Serial.println("TELEGRAM Message  Successfully sent");
  }
    telegramButton1PressedFlag = false;
}  
void telegramButton2Pressed() {
  Serial.println("Telegram Button-2 Pressed");
  int SDAPIN = digitalRead(D2);
  {
      telegramButton2PressedFlag = true;
  }
  return;
}

void sendTelegramMessage2(){
  String message2 = "Toilet_Roll Paper need to be Replace!";               //Empty
  if(bot.sendMessage(CHAT_ID, message2, "Markdown")){
    Serial.println("TELEGRAM Message 2 Successfully sent");
  }
    telegramButton2PressedFlag = false;
}
void loop() {
  Serial.print("\tRange: ");
  Serial.println(sensor.readRangeContinuousMillimeters());
  static bool Range_reach = false;
  if(sensor.readRangeContinuousMillimeters()<15) {
       delay(1000);
       Serial.println("Checking Full Condition again");
       delay(10000);       //delay 10 second for checking propose.
       if(!Range_reach)
{
          
            Serial.print("\tRange: ");
            Serial.println(sensor.readRangeContinuousMillimeters());
            if(sensor.readRangeContinuousMillimeters()<15){
                Serial.println("sent notifcation1 to Telegram");
                sendTelegramMessage();
                delay(bulk_messages_mtbs);
                Bot_lasttime = 0;
                if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                Range_reach = true;            
           
                Serial.println();
}  
  
}
}
        
      else if (sensor.readRangeContinuousMillimeters()>80) {
                 delay(1000);
                 Serial.println("Checking Empty Condition again");
                 delay(5000);     //delay 3 minutes for checking propose.
          if(Range_reach) {
      
                   Serial.print("\tRange: ");
                   Serial.println(sensor.readRangeContinuousMillimeters());
                   if(sensor.readRangeContinuousMillimeters()>80){
                       Serial.println("sent notifcation2 to Telegram");
                       sendTelegramMessage2();
                       delay(bulk_messages_mtbs);
                       Bot_lasttime = 0;
                       if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                       Serial.println();
          Range_reach = false;


}
}
}
}

Are you trying to trigger a Telegram message when the VL6180X sensor gives a certain value?

i need a digital pin to read by telegrame code before it can process to send a message

No, you do not.

Please tell us what you are actually trying to do. Write out a clear description in your native language, and have Google Translate turn it into "English".

GypsumFantastic:
Are you trying to trigger a Telegram message when the VL6180X sensor gives a certain value?

yes,sir.Sorry about late reply.

jremington:
No, you do not.

Please tell us what you are actually trying to do. Write out a clear description in your native language, and have Google Translate turn it into "English".

sorry for late reply,i'm trying to trigger a Telegram message when the VL6180X sensor gives a certain value?

Are you trying to trigger a Telegram message when the VL6180X sensor gives a certain value?

yes,sir.Sorry about late reply.

Then, rather than reading a "digital pin", you will read values from the VL6180X sensor, using the I2C bus and the Wire library.

Send a Telegram message when the proper value is received.

But first, write a program that just receives values from the VL6180X sensor, and get it working properly, before adding anything else.

jremington:
Then, rather than reading a "digital pin", you will read values from the VL6180X sensor, using the I2C bus and the Wire library.

Send a Telegram message when the proper value is received.

But first, write a program that just receives values from the VL6180X sensor, and get it working properly, before adding anything else.

you mean i just use

 Serial.print("\tRange: ");
 Serial.println(sensor.readRangeContinuousMillimeters());
          if(sensor.readRangeContinuousMillimeters()>80){
              Serial.println("sent notifcation2 to Telegram");
              sendTelegramMessage2();

example like this ?

Adafruit has library code for the VL6180. Have you tried it?

dougp:
Adafruit has library code for the VL6180. Have you tried it?

yeah,tried before