-->
Page 1 of 2

Using Atmega328 as io extender for ESP2866

PostPosted: Mon Nov 14, 2016 5:24 am
by s60sc
I'm new to the ESP2866 and have ordered a board, and was looking at boards to extend the io, e.g add extra ADC. These are available cheaply but so are Atmega328 based boards which provide a lot of io for the price. Is it feasible / has it already been done, to program the atmega to act as a gpio extender connected to the esp8266 via i2c/spi/UART whichever is most appropriate.
Thanks

Re: Using Atmega328 as io extender for ESP2866

PostPosted: Tue Nov 15, 2016 7:04 pm
by eketjall
I'm running a Arduino Pro Mini as a I2C slave with a ESP-01 as master, no problem.
I actually use the slave to power down the master, since the ESP-01 don't have the correct wiring to wake the ESP8266ex from deep sleep.
I then put the slave in sleep mode (draws only about 5uA) and when it wakes up it powers up the ESP-01 which polls the sensor data from the Pro Mini's analog inputs over the I2C bus and finally sends a command for power down. And repeat.

Re: Using Atmega328 as io extender for ESP2866

PostPosted: Wed Nov 16, 2016 6:03 pm
by s60sc
Pleased to hear that its feasible so I've ordered a cheap nano clone. So I've read up on I2C and as I want an interrupt driven rather than polling approach a multi master would be most appropriate but people seem to have problems getting this to work. When I get the boards I'll try a master slave setup but use an extra pin for the slave to alert the master to do a poll.

Re: Using Atmega328 as io extender for ESP2866

PostPosted: Thu Nov 17, 2016 5:26 am
by eketjall
No need for an extra pin. The i2c respons from the slave is of course interrupt driven.
You can even put the Arduino in deep sleep and it will wake on a i2c request on the matching address.

You didn't tell but a guess that you will be using the Arduino IDE for programming both the Arduino and the ESP8266?
In that case just use the "wire" library on both the ESP and the Arduino for the i2c.
I hade som troubles before I fuigered out that my Pro Mini at 8Mhz was a little slow so I had to add this line to the ESP master; Wire.setClockStretchLimit(5000); // in µs
For sleep mode on the Arduino I use Low-Power library from Rocketscream. https://github.com/rocketscream/Low-Power

I haven't used deep sleep on the ESP8266 though so no experience on that.