Tech Note 063 - ESP32 / ESP8266 How to Connect and Get I2C Devices Working

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น •

  • @santorcuato
    @santorcuato 6 ปีที่แล้ว +6

    OMG! Thanks Dave. It took me ten minutes thanks to your instructions. Good, nice and simple job, but very valuable.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Happy to help, this is why I produced the video.

    • @santorcuato
      @santorcuato 6 ปีที่แล้ว

      If the problem was, as in my case, with Adafruit_SSD1306 library, just look for it in your Arduino Libraries folder, open Adafruit_SSD1306.cpp and search for "// I2C Init" (aprox line 205) and make changes as this:
      // I2C Init
      #if defined(ESP8266) || defined(ESP32)
      //Put your Wire.begin(SDA, SCL, Bus_Speed); in your Sketch just before display.begin(...);
      #else
      Wire.begin();
      #endif
      In this way the library works for Arduino boards without any mod, and for ESP32 you MUST include one line of code just before display.begin(...) with the custom Wire.begin(SDA, SCL, Bus_Speed).
      For me with an 0.96" OLED display and 15 cm wires, Wire.begin(0, 4, 800000) works fine. (choose ports at your convenience)
      Simple and elegant, right?

  • @aakashpatel2428
    @aakashpatel2428 ปีที่แล้ว +1

    Thanks a lot David!
    I did change the wire.begin() in Wire.h library and set sda= 21, scl=22.
    Now my arduino IDE in able to detect the I2C 16x2 LCD display.
    I am using ESP WROOM 32.

    • @aakashpatel2428
      @aakashpatel2428 ปีที่แล้ว

      I also changed the input voltage for I2C from Vin (5V) pin to 3.3V pin. Before it was not detecting the Display.

  • @bonnome2
    @bonnome2 6 ปีที่แล้ว +3

    Great video, one more tip!!
    Avoid using adafruit libraries when using i2c. Usually the other libraries don't have wire.h defined and you can easily add your own.

  • @ericko5430
    @ericko5430 3 ปีที่แล้ว +1

    Thank you, This has helped me today after a pretty long search..

  • @megan5303
    @megan5303 5 ปีที่แล้ว

    Defining the pins solved my issue! I was communicating with an Arduino Uno and ESP32 with the ESP32 being the master. Thank you!

    • @Bisofication
      @Bisofication 5 ปีที่แล้ว

      Hi, I'm doing exactly the same as you are.
      I got a NodeMCU to work with the uno via I2C but not the ESP32 :(
      Which ESP32 pins did you physically use and did you use the pins in your "Wire.begin()" ?
      Thanks in advance!

    • @megan5303
      @megan5303 5 ปีที่แล้ว +1

      @@Bisofication Hi! I used pins 21 and 22 on the ESP32. so I write "Wire.begin(21,22)". Make sure you specify an address. I had to make up an address (0x08) in order to communicate between the two. Sorry for the late response, you caught me on Christmas break.

    • @Bisofication
      @Bisofication 5 ปีที่แล้ว

      @@megan5303 I made another object called wire1 and assigned its pins to my liking and worked. Thanks anyways!

  • @user-ux9rj9hm4z
    @user-ux9rj9hm4z 4 ปีที่แล้ว +1

    Hi - the Wire begin thingy has been long fixed.
    The ESP32 Wire.begin() function will default to the constants SCL and SDA defined for your platform when called with no parameters - but if you want to use non default pins then indeed you have modify the library code.

  • @cmaleixo
    @cmaleixo 5 ปีที่แล้ว

    I have a DS1307 module. It works in my Arduino Mega, Arduino Nano and ESP8266 but not in my ESP32!! Thank God I found your tech note video. Thank you. Now it is ok !!! I will check later if there is an Wire.begin() in the lib DS1307.h

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว +1

      ESP32 normally uses pins 21 and 22 for I2C, but depends on your board, some are 4 and 5. Serial.println(SDA) will help you same for SCL

    • @cmaleixo
      @cmaleixo 5 ปีที่แล้ว

      @@G6EJD Sorry for my english. I wanted to say that watching your video I learned how to make it work in ESP32 too, after 2 days "fighting" to solve this issue. Thank you very much.

  • @learnelectronics
    @learnelectronics 7 ปีที่แล้ว

    Good video. Thank you for that information. I'll be putting it to use for sure.

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว

      It’s a pleasure. Getting I2C devices bugged me for a long time until I got to grips with the problems and I’m sure others have struggled too, so I wanted to share the knowledge so others can learn just like they do with your channel of which I’m an avid watcher too 😊

  • @davidbristoll195
    @davidbristoll195 3 ปีที่แล้ว +2

    Awesome, very helpful, thank you!

  • @madlan
    @madlan 6 ปีที่แล้ว

    An extensive rewrite of the I2C implementation has just been committed to github, it's significantly better now.

  • @MaxGoddur
    @MaxGoddur 7 ปีที่แล้ว +1

    That was simple and to the point, thank you.

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว

      I think many people have difficulty with the I2C bus so I thought I would give my experience to try and help.

    • @randomguy3505
      @randomguy3505 6 ปีที่แล้ว

      Hello G6EJD. I want to use an DS3231 RTC and a MAX17043 with the Wemos Lolin32. Both of them have an SDA and SCL Pin, so they use i2c communication. My question is: How many i2c devices can be used? Just one or two or more? I want to use both devices with my board.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      The I2C bus uses device addresses so all devices are wired in parallel so SDA and SCL fo to each connected device, then you read the devices sequentially so the DS3231 has an address of 0x68 and the MAX17043 an address of 0x36 or 0x32. Adafruit has produced a list of all devices. The maximum on one bus is 128. You should always fit pull-up resistors ideally 4k7 to Vcc 3.3v and don’t use long lines.
      cdn-learn.adafruit.com/downloads/pdf/i2c-addresses.pdf

    • @randomguy3505
      @randomguy3505 6 ปีที่แล้ว

      Thank you for the answer. So as long as I dont use both devices at the same time, I can use many devices, right? Do you know if the Arduino IDE allows the ESP32 to wakeup from an external RTC like DS3231?

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Yes and there is no means of reading more than one at the same time so it all works as expected, for example there is no bus sharing by more than one processor but if there was the processors would need to negotiate who has access to the I2C bus as that is the bus requirement.
      You can set an input pin to wake up the device from sleep if the DS3231 has an interrupt output pin that can be wired to a GPIO pin. e.g. attachInterrupt(GPIO-pin, Clock_wake_up_function, RISING);You can use a FALLING edge, but on power down when the ESP releases its (internal) pull-up resistors it may cause interactions by creating an interrupt as the input pin FALLS, if that makes sense! void Clock_wakeup_function(){ Clear the interrupt source flag and then process the interrupt request, but you can't do much in an interrupt for example can't use the Serial ports and a few other functions.}

  • @CraigFryer
    @CraigFryer 6 ปีที่แล้ว

    Brilliant! As you say, it should be straight forward, but of course it isn't.

  • @sansjunk
    @sansjunk 5 ปีที่แล้ว

    Thanks for this, it surely would save hours of debugging for anyone trying to use I2C on ESP devices. I had one question about I2C logic level voltages. I need to control the PT2314 audio pre-amp IC with an ESP32 over I2C . The datasheet for this device states a Input Low Voltage (VIL) of 1V and Input High Voltage (VIH) of 3V and Output Voltage SDA Ack of 0.4V. From this it appears like the PT2314 uses 5V logic levels on the I2C. So would I need a level shifter to get it work safely with ESP32?

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว +1

      The data sheet says the 2314 is a 3.3v device so perfectly useable with the ESP32 voltage levels.

    • @sansjunk
      @sansjunk 5 ปีที่แล้ว

      @@G6EJD In two versions (15-page and another 20-page) of the datasheets I couldn't find any mention of the logic voltage level. Could you share the datasheet link where this is mentioned?

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว +1

      If you check the detailed sheets you will see it refers to open-collector interfaces and so are defined by the controlling processor. Both data and clock are interfaces and compatible with a standard I2C bus at 3.3v or 5v. The pt2314 is not sourcing any voltage to the sda and scl inputs.

  • @butcher
    @butcher ปีที่แล้ว

    Thank you, I spend days to figure out what the hell is the problem

  • @PeterScargill
    @PeterScargill 7 ปีที่แล้ว +1

    Not done anything with the ESP32 on I2c - but the ESP8266 - NO ESP8266 has I2c - it's just software and as such you can use any port pair you like (well, apart from GPIO16, obviously). In the link here if you look at the LEFT side of the first diagram, these are the devices I have running on the ESP8266, many of which are I2c, done in software. tech.scargill.net/home-control-2016/

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว

      Hi Peter, my aim was to let folks know that most libraries have the wire.begin() statement that is implemented before they try and specify a pair of pins, wire.begin(n,m), so correct me if I’m wrong how are pins to be used determined if the compiler will use those pins assigned by the hardware file for SDA and SCL when the wire.begin() is compiled? I agree that the ESP8266 does not have hardware provision of I2C but this does not stop the libraries from preventing correct operation of the virtual I2C.

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว

      Hi Peter, I have just checked the compiler source code and the default pins for the ESP8266 are 'default to pins 4(SDA) and 5(SCL)' the problem for most people is how do they know that? And that does not mean D4 and D5 on some boards and so-on, indeed some boards don't bring out every pin. The whole subject of I2C/SPI could do with some standardisation as it's so confusing for many starting out. I also note that on the ESP32 redefining SPI MOSI/CLK does not work it's always on 23 and 18 respectively because it's a hardware implementation!

    • @PeterScargill
      @PeterScargill 7 ปีที่แล้ว

      Well we are assuming here the Arduino version of ESP programming. Normally I just program in C using the SDK functions and i2c source is in a folder. You can just change it. However gpio4 and gpio5 are pretty much the standard now though I did see some Wemos stuff using the same pins but the wrong way around....

    • @PeterScargill
      @PeterScargill 7 ปีที่แล้ว

      Hi - just back in my office. In fact GPIO4 and GPIO5 are the correct names when referring to these pins on the ESP8266 - as specified for the chip, by the makers Espressif. For reasons way beyond me, it has become popular to pretend the ESP8266 is an upmarket Arduino and use the Arduino pin designations, which are NOT D4 and D5, but are D2=GPIO4 and D1=GPIO5 - is it any reason folk are confused. To make matters WORSE some early boards based on the ESP12 module brought out GPIO4 and 5 the wrong way around. So when dealing with the ESP8266 and I2c it is fairly safe to assume GPIO4 (D2) and GPIO5 (D1) but be prepared to swap them of nothing happens. The first thing I do when dealing with I2c is to run a scan - various software packages use different scan routines but generally something like i2c scan - this shows the i2c devices on the bus. The OTHER thing to remember is that there should be one set of pullup resistors to +v - on SOME devices these are on the actual master - but on other devices I've seen the I2c master have no pullup resistors - I2c will NOT work without this as basically you're looking at open-collector - i.e. the signal has to strongly float high when nothing is running the bus. It is important to check for this. A shame that these complications occur because other than that, I2c is easy-peasy.

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว

      Hi Pete, yes Arduino IDE. So in the SDK and say your using Adafruit libraries that habitually include a Wire.begin() statement so they work for Arduino's, how do you use an overriding statement like Wire.begin(x,y); when the library has already defined which pins are being used? I could have usefully included the need to undertake an I2C address scan in my video too. The Arduino IDE uses SDA and SCL for the pin names.

  • @mashurshalehin4972
    @mashurshalehin4972 4 ปีที่แล้ว

    Do I need pullup resistors for the i2c pins in an esp32?

    • @G6EJD
      @G6EJD  4 ปีที่แล้ว

      I don’t use pull-ups because I switch on the ESP32 internal versions

  • @SA-oj3bo
    @SA-oj3bo 6 ปีที่แล้ว

    Hi, I am trying to use 3 * UART + 1 * I2C and 1 * SPI in my design. You gave the solution for choosing the pins for I2C, great! Is it also possible with SPI to choose or redirect the pins we like to use at the ESP32? Thanks in advance for any help.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Yes the ESp32 has 3 UART's and see here: www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdfOn Page-28 all 3 UARTS can be assigned to any GPIO pin and the same for I2C and SPI. BUT, if your using a development board then this is going to be difficult. Well I2C is easy, so is SPI, but usually GPIO0 is used for your programming/serial port for diagnostics, so if you take over UART0 then you lose communication with the ESP32 whilst our programme is running, if reset it will revert back to UART0 default pins so it can be programmed again.What is your problem?I did a video for using the serial ports too.

    • @SA-oj3bo
      @SA-oj3bo 6 ปีที่แล้ว

      Thank you so much for your quick reply! I make my own PCB and need to redirect many pins to use all. The UART0 I want to keep to communicate by USB to the PC. I found out that redirecting pins for UART 1 and 2 seems to work. If I can redirect pins for I2C and SPI also than I can solve my problem. I just not understand how I can control with one SPI ( read/write) the SD card and the SPI sensor. How to control the CS for both? Do I need to use 2 normal GPIO's for the 2 CS and not mind the default CS pin? Or do I need to disable the default CS pin? OR the change the default CS pin every time? I use Arduino IDE. Thanks again.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      All SPI devices are wired in parallel so all share MOSI, SCK, but each device needs its own CS. SD.begin(CS) lets you define the sd card and then your other device library should allow you to define the other CS. You may as well use the compiler predefined CS for the sd card. See my TN on spi bus and code examples on how to define pins.

    • @SA-oj3bo
      @SA-oj3bo 6 ปีที่แล้ว

      Thanks again. Finally, would it be possible to use the SENSOR_VN and SENSOR_VP pins as digital inputs and/or outputs? Is it possible to contact you by email for a commercial question about consultancy?

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Partially, GPIO36 and GPIO39 (VP and VN) are GPI pins they are Input only output so not GPIO.0
      GPIO36 - Input only, RTC GPIO0, Sensor VP, ADC CH0
      GPIO39 - Input only, RTC GPIO3, Sensor VP, ADC CH3You can contact me via my web site from the icon on here/channel

  • @salmanrazeen659
    @salmanrazeen659 2 ปีที่แล้ว

    Hi, Can you please share with us on how we could communicate between ESP32 and ESP8266 using wired communication (I dont want to use ESP WiFi or ESPNOW because i am running a time sensitive function on the ESP8266 and WiFi makes it errorneous). Thank you

    • @G6EJD
      @G6EJD  2 ปีที่แล้ว

      You can simply cross connect the two devices using serial communication, so on the ESP32 set up a serial port on two chosen pins, then do the same on the ESP8266, again using softwareserial library and then connect ESp32 TXD pin to the ESp8266 RXD pin and the same for the other two pins, so TX-RX and RX-TX, you can transfer data at a very fast rate by doing this.

  • @Spaceman487
    @Spaceman487 6 ปีที่แล้ว

    So the connection between ESP32 & I2C devices ultimately depends on the program right?

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว +1

      Unless you specify otherwise (for most libraries) yes with wire.begin(sda,scl) BUT many libraries still have a wire.begin(); statement that then uses the defaults as defined by the compiler in ...pins.h as I shoe on other videos.

  • @grizzbeeuno2242
    @grizzbeeuno2242 7 ปีที่แล้ว

    Thanks .... very good helpful hints !!

  • @manuelcastro5711
    @manuelcastro5711 ปีที่แล้ว

    Hello! how can l declare 2 different ic2 pins?

    • @G6EJD
      @G6EJD  ปีที่แล้ว

      You don’t really need to because it’s an bus system, but you can simply do eg
      bme1.begin(sda1, scl1);
      bme2.begin(sda2, scl2);
      Then refer to each as required eg
      temp1 = bme1.readtemperature();
      temp2 = bme2.readtemperature();

  • @DaleDix
    @DaleDix 4 ปีที่แล้ว

    not mine, but FROM Stickbreaker on github:github.com/stickbreaker
    (the ~Wire() means you don't have to touch the library)
    TwoWire I2cOne, I2cTwo; // create variables
    void setup(){
    Serial.begin(115200);
    ~Wire(); // release hardware assignments, but Wire is still taking up RAM, because it was assign as Global
    I2cOne = TwoWire(0); //initialize using the first i2c peripheral
    I2cTwo = TwoWire(1); // initialize using the second i2c peripheral
    I2cOne.begin(SCL1,SDA1,SPEED1); // you have to select which pins and speed
    I2cTwo.begin(SCL2,SDA2,SPEED2);
    }

  • @chisomodimmegwa3479
    @chisomodimmegwa3479 3 ปีที่แล้ว

    Sir how do you connect ESP32 with an arduin through I2C, is dat possible? I want to use the esp32 cam module to send data to my arduino to control my robots motors.

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      It’s not that easy as the Arduino libraries are all written with the idea that the Arduino/ESP is the master and sensors are slaves so you’d need to have an Arduino that is emulating a slave.

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      forum.arduino.cc/t/using-esp8266-01-to-communicate-to-an-arduino-i2c-master-slave/403887

    • @chisomodimmegwa3479
      @chisomodimmegwa3479 3 ปีที่แล้ว

      @@G6EJD how about using an esp32 cam to send digitalWrite commands to another esp32 dev board

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      @@chisomodimmegwa3479 yes that would be easy, you could use serial easily. With those modules the problem is finding a spare exposed pin or two to send the data

    • @chisomodimmegwa3479
      @chisomodimmegwa3479 3 ปีที่แล้ว

      @@G6EJD I appreciate your quick responses Sir what do you mean by using spare exposed pins. My project basically is to create a website using the esp32 cam. The Web page will have video stream and controls for the motors and servos of my robot vehicle. The robot arm servos and motors will be hooked up to an esp32 dev board. I want to use the esp32 cam to control the esp32 dev board bcs I need d video stream. I dnt want to be forced to create two webpages for the esp32 cam video stream and another for esp32 dev board with controls for motors and servos

  • @ManojKumar-ko5uu
    @ManojKumar-ko5uu 3 ปีที่แล้ว

    sir how can i communicate using I2c with CAP1298 sensor in ESP-IDF environment?

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      You would access it just like any other I2C device, what problems are you getting?

  • @MrToy007
    @MrToy007 4 ปีที่แล้ว

    It worked for me!!!! Thanks a lot!!

  • @sssedo1573
    @sssedo1573 3 ปีที่แล้ว

    how do i use 2x i2c on the same esp32 to send some data?

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      Different I2C devices or the same?

    • @sssedo1573
      @sssedo1573 3 ปีที่แล้ว

      @@G6EJD I want to send from the first esp32 two different numbers like 2 and 3 with the two different i2c channels. Like the number 2 from gpio 21 and number 3 from gpio 2 to another esp32

    • @G6EJD
      @G6EJD  3 ปีที่แล้ว

      Why use I2C when you can use Serial?

    • @sssedo1573
      @sssedo1573 3 ปีที่แล้ว

      @@G6EJD cause I don't know how to write it correctly with serial

    • @sssedo1573
      @sssedo1573 3 ปีที่แล้ว

      @@G6EJD I tried with wire.h and serial2.println("1") and serial1.printl("2) the numbers are just examples

  • @adityaazzani
    @adityaazzani 6 ปีที่แล้ว

    i have rtc ds3231 and wemos lolin32 lite, how can i use i2c in wemos lolin32 lite?

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      First select the Lolin Lite board then run a short programme to determine which pins are SDA and SCL with serial.println(sda) and serial.println(scl) then connect the clock as per the pins-to-pins with supply and ground. There are example codes in the library for the 3231.

  • @JosefZvolanek
    @JosefZvolanek 7 ปีที่แล้ว +1

    I also have this ESP32 board ordered! :-)

    • @G6EJD
      @G6EJD  7 ปีที่แล้ว +1

      It's a good board, excellent for low power work, well better than most Dev. Boards for sure. I hope your projects are going well my friend.

    • @JosefZvolanek
      @JosefZvolanek 7 ปีที่แล้ว +1

      Already I am looking forward to it ...

  • @LatinDanceVideos
    @LatinDanceVideos 6 ปีที่แล้ว

    Very nice. Thanks!!!

  • @CiedJacaba
    @CiedJacaba 5 ปีที่แล้ว

    Does it work on esp32-cam?

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว

      Carlo Jay Jacaba, yes of course. The ESP32 cam is an ESP32 with an SPI connected camera, so you can determine the SPI pins used and connect another SPI device in parallel using a spare pin as it’s chip-select (CS)

    • @CiedJacaba
      @CiedJacaba 5 ปีที่แล้ว

      @@G6EJD thanks, very helpful, I'll do some experiments 👍

    • @philipchisholm
      @philipchisholm 5 ปีที่แล้ว

      @@CiedJacaba did you figure this out Carlo?? I am trying to do the same thing...and attache a MCP23017 to add more GPIO pins...

    • @CiedJacaba
      @CiedJacaba 5 ปีที่แล้ว

      @@philipchisholm Unfortunately, it didn't work, whenever I call this function "wire.begin(sda, scl);"
      I got this error "camera init failed"
      I think, since on board camera uses default sda and scl pin, re-declaring them to other GPIO would make them non-I2C pin, then the camera won't simply work... I just use UART instead to talk to Arduino...

    • @philipchisholm
      @philipchisholm 5 ปีที่แล้ว

      @@CiedJacaba Ok thanks...but I think you can have 2 SDA SCL sets on an esp32 >>> I saw this page randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/ .... plus you can run I2C in parallel.... and check this out.... github.com/espressif/arduino-esp32/issues/1438

  • @christiandavetipactipac5207
    @christiandavetipactipac5207 5 ปีที่แล้ว

    Can 2 I2C Device connect on one ESP8266 NodeMcu?

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว

      Christian Dave Tipactipac, yes but only if they are different devices. Each I2C device has a unique address determined by sensor type and manufacture. If you want to use multiple devices of the same type then you need to use an I2C address multiplexer where you would address device 1 at the multiplexer base address plus 1 and device 2 at the base address plus 2 and so on, the multiplexer will handle the device I2C address for you. They are quite easy to use.

    • @christiandavetipactipac5207
      @christiandavetipactipac5207 5 ปีที่แล้ว

      @@G6EJD Thank you.
      I was planning on using a VL53L0X, a Time of Flight Lidar Sensor, for measuring distance in a single axis, and at the same time, to use a HX711 for 24 Bit reading on an ADC Voltage.
      Those are complete 2 different I2C Devices, right? :
      sorry for the dumb question sir.

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว

      See here for addresses: learn.adafruit.com/i2c-addresses/the-list
      Yes they are two different addresses and will work fine. However I would question the need for 24-bit ADC resolution as the default ADC is capable of very good resolution and practically that level of resolution is not required.

    • @christiandavetipactipac5207
      @christiandavetipactipac5207 5 ปีที่แล้ว

      @@G6EJD Thank you sir for the help, I really appreciate it.
      It made sense when you stated the level of 24-Bit resolution, I just thought having a very sensitive sensor could output an effective device, just learned that it was somehow "Overkill".
      Thank you sir, hope you would make more tutorials for everyone.

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว

      Remember if you were measuring a voltage range of 0-5v using the ESP32 ADC which is 12-bits, then that would give you 1mV resolution as good as a DVM. For the ESP8266 where the ADC is 10-bit that’s 5/1024=5mV resolution and that is still very good. In general terms the lower the voltage range being measured the lower the ADC resolution can be and conversely for higher voltages the higher the resolution, for example measuring 0-100v with a 10-bit ADC would give you 0.1mV resolution, but in % terms and most practical applications that is still good enough. You can end up over complicating solutions. The best approach is to use what the device has to offer and then upgrade only if required.

  • @vectorchan5647
    @vectorchan5647 6 ปีที่แล้ว +1

    I have two different kinds of esp32 devices, the program I'm running only uses the wire.h library, the program works on an arduino, the i2c device shows up on both devices when I run the i2c scanner, tried defining the pins and bus speed. Still can't get it to work.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      What are the devices your trying to use? In most cases the driver library sets the I2C pins overriding your own chose, or the library has not been written to support the ESP32.If the I2C scanner can see the devices then you have them wired correctly, that's a good start. The address found should correspond with the devices address.For example if you have a Adafruit BME280 they set their I2C address usually 1 more than normal, let's say 0x77 and their library is designed to address a device at address 0x77. If you buy a 2rd party type the address is usually 0x76 and so the device apparently does not work.Let me know the device type and your detected address.

    • @vectorchan5647
      @vectorchan5647 6 ปีที่แล้ว

      ​@@G6EJD Trying to use an MPU-9255, the ESP devices are Heltec Wifi Kit 32, and Doit ESP32 DEVKITv1. I'm not using a library, only the wire library which sends pure i2c.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      The MPU-9255 is particularly difficult to communicate with, largely because there are 3-devices on the unit and I can tell you the number of setup commands you must send to the 9255 is huge, about 50 or more parameters. There are some libraries around that do all this for you. There are simpler devices on the market you may find easier to use.

    • @vectorchan5647
      @vectorchan5647 6 ปีที่แล้ว

      @@G6EJD I've tried the dedicated libraries, changed the wire.begin command in them as in your video. Still no luck. Which simpler devices would you recommend? I'm making a bike computer that displays what grade I'm riding up or down, so I only need gyro and accel.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      I have some working examples, what is your email address?

  • @gabididilescu9855
    @gabididilescu9855 3 ปีที่แล้ว

    Thank you so much

  • @pomroys
    @pomroys 6 ปีที่แล้ว

    Thank you

  • @JerryEricsson
    @JerryEricsson 6 ปีที่แล้ว

    A person could, perhaps, edit the offending .h file and write in the 22,23.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Not sure what you mean, the pins are defined by the Compiler support files and if you can find them yes they could be edited but most people don’t understand how to do that. There is a lot to be said to using the defaults.

  • @lfmtube
    @lfmtube 4 ปีที่แล้ว

    Utmost helpful. Thank you!

  • @johnwuethrich6505
    @johnwuethrich6505 6 ปีที่แล้ว

    id wager intellectual property plays a role in this bs... if youve played around a bit, uve probably also notice i2c is often also called the two wire interface. because i2c is somebodies brand... Add engineers, managers and ceos that all want to sell their product in the us/international markets in general, might not speak english very well but understand ip violations might get import banned. id guess other factors are at play but i assume this is a big one. my guess is its harder to know what you can and cant say when the rules arnt in a language you have a strong grasp on..half the time legalese is hard to interpret even if you first language happens to be what its written in.

    • @G6EJD
      @G6EJD  6 ปีที่แล้ว

      Most of the problems are determining which controller pin is which and to the beginner it can be a real difference between success or not or huge amounts of frustration by contrast most sensors are well labelled then add in the need to ensure bus speed is correct and the device address is known and the device is not a bus controller (some are by default) but again luckily most are slaves. On balAnce the i2c bus is the best around for multiple devices, SPI is ok but needs a CS per device so not I/o efficient.

  • @roberthousedorfii1743
    @roberthousedorfii1743 5 ปีที่แล้ว

    Wire.begin(19,20) for a WEMOS 8266 ESP-12S D1 mini THANK YOU!!!!

    • @G6EJD
      @G6EJD  5 ปีที่แล้ว

      Robert Housedorf II, the default I2C pubs set by the compiler are 4 and 5, the ESP8266 doesn't have a hardware I2C bus, so I²C is bit-banged in software. This means that you can use any GPIO pins. By default, Wire.begin() initializes pins 4 (SDA) and 5 (SCL), but you can specify other pins using Wire.begin(int sda, int scl). What pins are you using?

  • @JBoek30
    @JBoek30 4 ปีที่แล้ว

    thx ; ]

  • @qzorn4440
    @qzorn4440 2 ปีที่แล้ว

    wow i know this info must be somewhere, however your video is wonderful and a real how to video, for setup the:
    LILYGO® TTGO T-CAN485 ESP32 CAN RS-485 Supports TF Card WIFI Bluetooth Wireless I2C PCB thanks you.