Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ESP8266-12F cannot discover ADXL345 through I2C

Status
Not open for further replies.

impeham

New Member
I'm trying to connect ADXL345 sensor to ESP8266 12-F:

ADXL345
https://www.ebay.com/itm/GY291-ADXL...156056&hash=item2a261d5260:g:Fr8AAOSwbwJZ7t3F
ESP:
https://www.aliexpress.com/item/new...2f-46bd-ab34-71796a9b83d5&transAbTest=ae803_5

I'm using GPIO14 and GPIO16 as SCL/SDA. See the circuit photo attached.

Using an oscilloscope between GND + SCL and GND + SDA I can see a some binary protocol working, but the I2C scanner software does not find the device. I'm using a scanner sketch from (Made only the required changes for the ESP to use it):


One thing I've noticed with the oscilloscope is that the default value reading is HIGH - I'm not sure if this is ok.

Is something wrong with the connections I'm using? I read something about needing pull ups for the ESP pins - not sure if it is needed.

118949
 
Last edited:
Hi - thx but as i wrote - i'm only testing the I2C scanner which only requires SCL/SDA/GND/VCC. it does work with 4 wires only when i use arduino uno (the device's address is found and printed from serial) - but the same procedure fails with the ESP, so i assumed something should be different specifically when using the ESP with it - i'm not sure.
at this point i want to make just the basic circuit/software to work (i2c scanner).
 
If the CS line not pulled to vdd it will not show up as I2C it's in spi mode
There are no internal pull-up or pull-down resistors for any unused pins; therefore, there is no known state or default state for the CS or ALT ADDRESS pin if left floating or unconnected. It is required that the CS pin be connected to VDD I/O and that the ALT ADDRESS pin be connected to either VDD I/O or GND when using I2C.
 
Hi - thx but as i wrote - i'm only testing the I2C scanner which only requires SCL/SDA/GND/VCC. it does work with 4 wires only when i use arduino uno (the device's address is found and printed from serial) - but the same procedure fails with the ESP, so i assumed something should be different specifically when using the ESP with it - i'm not sure.
at this point i want to make just the basic circuit/software to work (i2c scanner).

Read the link I posted, which explains why you need SIX connections, the other two are to set it to I2C - and the pull-ups of course.
 
ok so i tried the following connections:

GND GND
3V3 VCC
3V3 CS
GND SDO
GPIO16 SDA
GPIO14 SCL


SDA, SCL are pulled up to 3.3v with 10k resistors. still - I2C scanner fails to find it.
i didn't try using a level shifter yet, but according to the spec, ADXL345 supports 3v -5v.tried the uno again (pins A4, A5 as SDA, SCL) and using power input of 3.3v from the arduino pin - the ADXL is discovered immediately with no issues.

any other ideas?

another question - with the arduino, the pins don't need to be pulled up and the I2C protocol is working fine (even with only 4 pins connected GND,VCC,SDA,SCL) - when changing to pulled up mode with the ESP - the ADXL is supposed to work the same?
 
Whos I2C scanner code are you using?
Cause most scanners use GPIO5 SCL
And GPIO4 SDA

2C (Wire library)
Wire library currently supports master mode up to approximately 450KHz. Before using I2C, pins for SDA and SCL need to be set by calling Wire.begin(int sda, int scl), i.e. Wire.begin(0, 2); they default to pins 4(SDA) and 5(SCL).
 
Last edited:
Lol you got use 4 and 5 wire.h dosent work on esp like uno. Has to be hardware pins
There is no software opt
 
take a look at Wire.begin() - it has an overloaded method for ESP - "void begin(int sda, int scl);" this is how you can set the pins.
 
ok so i tried the following connections:


GND GND
3V3 VCC
3V3 CS
GND SDO
GPIO16 SDA
GPIO14 SCL




any other ideas?

Yes, here is another idea. With your setup above, change SCL/SDA to these:

GPIO14 (D5) --> SCL
GPIO12 (D6)--> SDA

Use this scanner https://github.com/jainrk/i2c_port_address_scanner Don't modify it at all. If it scrolls by too quickly or if you want to change pins and test again, just reset the ESP12.

Using a Weemos D1 v3.0 and your setup with my changes above (except I use 4.7k pull ups), I get:
11:12:23.392 -> Scanning (SDA : SCL) - GPIO12 : GPIO14 - I2C device found at address 0x53 !

If I use GPIO16, I get no devices found. I can't remember why exactly, but there may be some ESP8266 peculiarity on the pin pairs. I thought it was all bit-banged, but why fight the results?

Using the scanner that I linked is a convenience as you don't have to mess with the args in wire.begin and you can futz with the pairs you want.

Edited to add: Below is the setup I just used for testing in case you want to compare wiring. I wonder if your ESP8266 board/circuit is using GPIO16 for something?

.
118969


Hope this helps.
 
Last edited:
Yes, all pins on ESP8266 are capable of I2C (and interrupt and PWM) (except gpio16).
Never tried 16
I use the ones shown which are 4 and 5 but GPIO16 will not work with I2c the rest will.
and when I first tried years ago there was no overload for the esp now there many wire.h for it LOL
 
Yes, here is another idea. With your setup above, change SCL/SDA to these:

GPIO14 (D5) --> SCL
GPIO12 (D6)--> SDA

Use this scanner https://github.com/jainrk/i2c_port_address_scanner Don't modify it at all. If it scrolls by too quickly or if you want to change pins and test again, just reset the ESP12.

Using a Weemos D1 v3.0 and your setup with my changes above (except I use 4.7k pull ups), I get:
11:12:23.392 -> Scanning (SDA : SCL) - GPIO12 : GPIO14 - I2C device found at address 0x53 !

If I use GPIO16, I get no devices found. I can't remember why exactly, but there may be some ESP8266 peculiarity on the pin pairs. I thought it was all bit-banged, but why fight the results?

Using the scanner that I linked is a convenience as you don't have to mess with the args in wire.begin and you can futz with the pairs you want.

Edited to add: Below is the setup I just used for testing in case you want to compare wiring. I wonder if your ESP8266 board/circuit is using GPIO16 for something?

.View attachment 118969

Hope this helps.

man - thanks for the detailed answer! it works with my own sketch now - the problem was GPIO16 - i changed to GPIO12 instead and both My sketches work now - I2C scanner and the AXIS reader- Thanks!

so to summarize - there were 2 issues - GPIO16 is not working, and both SCL,SDA needs pull up resistors. this will make the ADXL discoverable for I2c scanner. in order to be able to actually get readings - SDO needs to be connected to GND, and CS to 3.3V..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top