Notifications
Clear all

ARDUINO TO ESP12S I2C COMMUNICATION

16 Posts
4 Users
1 Likes
953 Views
(@droggitiszak)
Member
Joined: 1 year ago
Posts: 6
Topic starter  

Hello everyone! Nice to meeting you all.

So here I am seeking solution to my problem. I have an I2C bus involving an Arduino , one  5V LCD I2C 2X16 screen , one 5V PCF8574 I2C module , a 3v3/5v bidirectional level converter and an 3V3 ESP12E module. here is how they are connected :

I2C CONNECTION

When i run the Scanner code with arduino as Master , it only finds the LCD and PCF8574 module.

When I run the Scanner code from ESP12E, it finds all three SLAVE devices ,  the LCD , PCF8574 and the ARDUINO.

 Using ESP12E as master , I can control the LCD (which is at 5v) through the level shifter. Same with pcf 8574. So I guess  the level shifter works fine. I also can pass bytes from the arduino to ESP12E , if I have the ESP12E as Master and Arduino as Slave.

Arduino does not communicate if set as Master. Any ideas?


   
Quote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Just curious... willing to share why you want to connect an Arduino to an ESP8266?  I always ask as I've never heard of a reason to connect the two except, "That's how the Internet tells people to program an ESP8266."  You don't sound like a beginner, so I have to ask... 😉 

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@droggitiszak It would appear the level shifter gets in the way in one direction but not the other. You might need to swap one of the boards.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

@inq >> as an aside, I have in a box a Mega256 with an on board ESP8266. So someone thought to join the two using 8 DIP switches to choose which one was being programmed and I bought one about 5 years ago. I did use it but what a pain juggling all those DIP switches. History is repeating itself with more than one Pico mated to an on board WiFi chip. I have one in the Pi box but felt the need to try it yet.

I'm with you, I'd ditch the Uno and use the raw power and WiFi of the ESP32. This carries a risk but I have a test rig with 4 line lcd, PCF keyboard, running on 5v and connected to an ESP32. I am guessing that the I2C data cannot draw enough current to damage the ESP. Naturally this would be foolish if it was something mission critical.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

@hilldweller - I think you are beyond my experiences with i2c, but I once had three sensors on the same bus and had troubles.  It ended up being that too many of the devices had pull-up resistors built-in and it was too much for the protocol.  Fortunately, one had ability to solder a junction and it would disable the resistor.  All worked.  Doubt that applies to you since you can detect one way versus the other.  Also... I want say I recall some article saying that i2c on the Expressif chips is not a full implementation.  Maybe, it was being a slave that was "defective" but I've never wanted to use it that way... so far.  

Let us know when/if you find a solution... I have a few things that I'd like to use i2c, spi, serial, omnipotence... to talk between more than one ESP8266/ESP32 independent to the radios.

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@inq @hilldweller Is there not an I2C multiplexor?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Posted by: @zander

@inq @hilldweller Is there not an I2C multiplexor?

Not sure you need one... at least on Espressif boards.  i2c is like a network... has addresses.  It can have many, many devices on one bus.  Espressif boards also allow multiple busses, so even if you have multiple devices using the same address, you simply put them on another bus.

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Ron reacted
ReplyQuote
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

Posted by: @zander

@inq @hilldweller Is there not an I2C multiplexor?

 

Almost certainly, it's a very mature system. I've never needed to use one though. Early on there was a very neat i2c RTC clock chip I used and bit banged the time in/out using an intel 186.

 

The PCF8574 is brilliant for HEX keypads, 1 cheap module, 4 x 100k resistors and you have a keyboard port using two IO pins. You can have 8 of them on line at once. The LCD shown above probably has one.

 

 


   
ReplyQuote
(@droggitiszak)
Member
Joined: 1 year ago
Posts: 6
Topic starter  

@inq Hello , Thank you for your reply ! Well I am working on a project that has the ATMEGA328 managing a keyboard on PCF8574 , an LCD screen and 8 inputs of hi-low status for an alarm system. The reason for connecting with ESP12e is that when an alarm appears I would like to "tell" the ESP to send me a text with the values of the I/Os so I know remotely an alarm appeared and in which I/O-zone. There are ways around this , but the best way is if I can make  Arduino as Master.


   
ReplyQuote
(@droggitiszak)
Member
Joined: 1 year ago
Posts: 6
Topic starter  

Posted by: @zander

@inq @hilldweller Is there not an I2C multiplexor?

 

Hi Ron , thank you for your answer! I do not use a multiplexer  , it is straight as shown on the diagram.

 


   
ReplyQuote
(@droggitiszak)
Member
Joined: 1 year ago
Posts: 6
Topic starter  

Thank you all  for taking the time looking into this matter!

Just to give some more information on what has been done so far, I have used an oscilloscope with one channel  on the 5v side of the level shifter and the other on the 3v3 side of it. . When i have a communication sequence of bits at 5V , I get the exact same on the 3V3 side and vice versa. So I am guessing its not about the level shifter.

 What strikes me strange is that if you dig into the libraries , the Wire Libraries that are being used you find out these things:

 In both codes-programs  , Arduino code and ESP12E code , there is a line stating

#include<Wire.h>

Yes. But! It is not the same library for the Arduino and the ESP12E. They are two different (versions maybe?) of Wire Library , one in arduino boards library and one in esp12e boards library, both called "Wire Library"  using #include<Wire.h> . On top of that , Arduino Wire Library involves files : Wire.h, Wire.cpp, utility/twi.h and utility/twi.cpp .

On the other hand ESP12E Library involves a different Wire.h, Wire.cpp and only twi.h , located in ESP package/ board folder. If you edit the twi.* files ,and wire.* files you see that there is different code on them but the one for ESP12E comes as a modification / new verison of the original twi.* and wire.* files to add support for the ESP boards.

Yeaaaaah ! Eurika !!!! .... i wish. So , I tried to be smart and trick the beast. I though I'd take the modified , new , "updated" version of wire.* and twi.* files of the Wire Library that "belong" to ESP12E boards and replace the original Wire Library files in the Arduino boards , in order to "inject" updated ESP12E support into the arduino code... NO LUCK Kosta , it does not work. Of course it wouldn't . Their C++ code is not the same.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@droggitiszak You have seen a bit of how the library system works. YES, the libraries lke Wire that are close to the metal must have different code since it's different hardware. When you select the board to operate on in the IDE>Tools menu you are selecting which hardware branch of the arduino library structure to use. If you mess with them you will create a bigger mess. I keep telling people to NOT use root/admin ids, use a standard user so those directories are invisible to you meaning you can't mess with them but the compiler can as it has owner access.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@droggitiszak)
Member
Joined: 1 year ago
Posts: 6
Topic starter  

Posted by: @zander

@droggitiszak You have seen a bit of how the library system works. YES, the libraries lke Wire that are close to the metal must have different code since it's different hardware. When you select the board to operate on in the IDE>Tools menu you are selecting which hardware branch of the arduino library structure to use. If you mess with them you will create a bigger mess. I keep telling people to NOT use root/admin ids, use a standard user so those directories are invisible to you meaning you can't mess with them but the compiler can as it has owner access.

Hey Ron , thank you for your reply. I do agree with you that mixing the libraries can cause mayhem and chaos... but not when you can put everything back in place. My problem is not that the libraries malfunction after "tampering" their files. I can fix that and bring everything back to normal ( obviously "dont try this at home" applies with those who are very novice users ). Still the problem remains: Original Arduino Wire Library does not locate ESP12E as a slave device. My best guess is that Arduino Wire Library Code needs some additional code to do that, and i am looking for suggestions / solutions on that. Of course I may be wrong  . Just trying to find out.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@droggitiszak You have it backwards. Choosing the hardware selects the libraries used.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@droggitiszak I scanned my arduino libraries and found 8 wire libraries. This is a list of the hardware branch each is contained in/

1. avr

2. mbed_nano

3. mbed_rp2040

4. megaavr

5. samd

6. esp32

7. esp8266

8. rp2040

You may not have as many, I have a lot of boards installed. If you look at the screen snap of my Boards Manager you will see 8 entries and they match the 8 Wire files I found. So what this means is that the sketch you load into the arduino uses the arduino version of wire so you can use the I2C bus on the arduino, and when you load a sketch into the esp12e it will use the wire library that matches it's hardware so you can use the I2C bus on the esp12e.

This is exactly how libraries work. At the API level the code is identical, but at the hardware implementation level each library has the specific code it needs to work with it's hardware, it won't work with some other hardware.

In addition to having the 'magic' of library code, you are also taking advantage of a 'standard' interface, namely I2C which is described at HERE. To use a different protocols terminology, perhaps you are trying to set up a situation where one board is talking and the other is listening. Perhaps they then swap roles? In any case, I2C was specifically invented for this kind of board to board communications. It sounds like your challenge is to discover what address the esp12e is communicating on but first, are you spec ifying the NODEMCU 1.0 or NODEMCU 0.9 for the esp12e?

If you look at the documentation here for the nodemcu you might learn something, I am not sure.

I am still suspicious the level shifter is getting in the way.

Try the following I2C scanner, it is likely different than the one you have, it may show more. IIRC credit for this goes to @Inq

The bottom line is you don't 'fix' this problem by doing anything to the files and structure that are part of the IDE and boards structure. In fact, create a standard user on your PC and you might see that you not only can't write in those locations, you might not even be able to read (that is how a Mac works but it has real security)

 

Screenshot 2022 12 10 at 07.10.29

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 1 / 2