Use an arduino as i2c expander

i use a esp8266. i would like more digital pins. could i talk to an arduino over i2c to control outputs of arduino from esp8266.

How can i communicate with arduino over i2c from esp8266 vice versa?

I ask because i dont know if i should use a level shifter because of the voltage differences or of it will matter that the arduino is 5v.

Bidirectional level shifters for SCL/SDA exist.

Check that the Arduino can act as an I2C slave, some can only act as masters.

from what i understand as long as i specify an address for Wire(addr) the device will be a slave. the master would be undefined. i suppose software serial may be an option. more importantly here is stability. i dont want a device to freeze if the i2c gets some noise

That's correct but some Arduinos can not behave as slaves, can not have an I2C address and thus can not receive data.

SPI is faster yet simpler and thus more stable than I2C, can span larger distances, at the expense of a dedicated select (and MISO?) line for each slave.

Ive looked into SPI it seems reasonable. i could use an arduino to take some of the load from my esp cpu too. Now im worried about endian"ness with between arduino and esp.

Why do you need an Arduino instead of a port expander?

1 Like

i could use a port expander. i just dont have one. i do have arduinos. I think the arduino could be more useful. i could probably flash the arduino over spi if i needed to. but i could just simple make it change output state like expander too

Which arduino cannout be used as i2c slave. i didnt find any information regarding that

Two ATmega328p equipped Arduinos can act as I2C master and slave.

e.g. Nano BLE

touche

for me the i2c expander cost more than the arduino nano and the nano has analog and digital pins. i have arduino and esp setup on i2c now and it works pretty good.

i have dozens of nanos and other arduino but no io expanders except for reading analog

I think it can happen. All you have to do is set a free address in the software and work as a slave device. The datasheet shows that the ATmega328 can work below 3 volts if it is 8 MHz. In this way, it will be possible to connect directly to the ESP and possibly be powered by it.

Page 260, Speed Grades.

1 Like

so the 328p is factory 8mhz so should work good at 3.3v. 16 mhz would be faster but require higher voltage to get the most out of it?

the atmega328p is really automotive grade? or did i miss understand that?

this dont mean i need to set the esp8266 to run at 8mhz does it?

if you just need more digital IO-pins use something like this

best regards Stefan

1 Like

I might if the arduino dont work well. i have so many nanos and 0 i/o expanders. i dont see why it should be an issue. except for making sure the slave arduino received the message from the master and the master can request the pin states right after to make sure my request to change pin state was successful

Need to program ATmega328 as standalone without external XTAL - 8MHz is possible with internal RC generator. Need test of what speed is possible on I2C in that case because internal oscilator is not very precisly. I2C work on 100kHz, 400kHz, 1MHz or 3.4MHz. Work on internal oscilator is possible with program of fuse bits. In ESP8266 is no needed to change nothing. I use similar (ATmega88) work on internal RC oscilator for different purpose.

1 Like

since an EXP8266 can measure and control scores of sensors and devices. it seems that what is needed is just an I/O expander.

1 Like

as a note, there is another version, search for :
Arduino LCD serial
cheap board on e-bay and other places.

But not that one, which is the 8-pin (that is, eight available I/O pins) version.

This one is the sixteen: