Help with ESP8266 and number of GPIOs

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mgenin
 
Posts: 4
Joined: Mon Sep 11, 2017 8:39 pm

Help with ESP8266 and number of GPIOs

Post by mgenin »

Hi,

I just bought the ADAFRUIT FEATHER HUZZAH WITH ESP8266 WIFI, its my first ever Arduino! I think i've maxed out my GPIO's and wondering if there is any way around it.

My project needs the following:
2x type k temp probes - I've got 2x MAX31855's for those
1x OLED screen
1x Rotary encoder with push button
1x output for PWM for a fan motor

The 2x MAX31855's use software SPI. They each need CLK, DO, CS. They can share CLK and DO, but need a unique CS
So that makes 4 GPIO's to read those 2 probes.

Then I have a rotary encoder with a CLK, DATA, SW - So I need 3x GPIO's for those

I use 1x GPIO to output the signal for the fan.

That's a total of 8 GPIO's, leaving 1 left. But I still need the screen! I2C needs 2 pins is my understanding. I know the screen can do SPI but I don't know how that could work as they seem to need 4 SPI pins + RESET (5 pins?)

Any help would be appreciated.

Mike.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Help with ESP8266 and number of GPIOs

Post by zener »

Well I will throw out some ideas but others might have better ideas. First of all you could get a standard Arduino and put a wifi module on it and I think you would end up with more IO pins. However, assuming you don't want to do that here are some ideas:

If the encoder is being used for user input, replace that with a pot and read it with the analog input pin. You save 2 IO pins.
You could put an inverter on a SPI enable pin and use one pin to enable both MAX parts. When the pin is low one would be enabled and when high the other would be enabled. You save 1 IO pin.
You could have your PWM pin do double duty by also using it to read the PB position. Only problem is pushing the PB would momentarily start (or stop) the fan. You would have to decide if that is acceptable. You save 1 IO pin.
Or... You could PWM the fan with your SPI enable pin. The two temp sensors don't need to be enabled evenly. Your fan might have a noticeable speed change depending on the toggle speed. Again you would have to decide if that is acceptable.

Good luck!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with ESP8266 and number of GPIOs

Post by adafruit_support_mike »

On the Feather HUZZAH, the SPI pins MOSI, MISO, and SCK are also GPIO pins 12, 13, and 14. The pins at the edge of the board are wired straight across.

The I2C pins SDA and SCL are also GPIO pins 4 and 5.

The remaining GPIO pins are 0, 2, 15, and 16. Of those, pins 0, 2, and 15 control the boot mode. 0 and 2 have to be high, and 15 has to be low at power up for the ESP8266 to boot to the firmware you've uploaded. 0 is connected to the red LED, and 2 is connected to the blue LED.

You can use an I2C GPIO expander like the MCP23008 or MCP23017 for simple IO, and can export SPI CS signals to those to increase the number of devices you can connect to MOSI, MISO, and SCK:

https://www.adafruit.com/product/593
https://www.adafruit.com/product/732

Running as a combined I2C/SPI device is about the only way to connect more than a couple of external devices to the ESP8266 though. Bottom line, that chip just doesn't give you many pins to work with.

User avatar
mgenin
 
Posts: 4
Joined: Mon Sep 11, 2017 8:39 pm

Re: Help with ESP8266 and number of GPIOs

Post by mgenin »

All great ideas. I think I'm going to try the potentiometer with the unused analog input. I was so obsessed with trying to find something with more i/o that I forgot about something as simple as that. I suppose I will need something like a 10k pot and a 22k resistor to voltage divide the 3.3v down to 1.0 ish volts to the Analog input?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with ESP8266 and number of GPIOs

Post by adafruit_support_mike »

Yep. The ESP8266's ADC only accepts signals up to 1v.

User avatar
mgenin
 
Posts: 4
Joined: Mon Sep 11, 2017 8:39 pm

Re: Help with ESP8266 and number of GPIOs

Post by mgenin »

Wondering if another idea can work.

Can the analog input be used as a digital input, ie: to read a button? I guess you could feed 1.0v thru the button and do an IF statement to check if we are reading voltage above a certain level indicating the button is pressed. But can it be used as a regular digital input with interrupts and pullup resistors etc...?

For a regular arduino it says:

The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
Pullup resistors

The analog pins also have pullup resistors, which work identically to pullup resistors on the digital pins. They are enabled by issuing a command such as

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with ESP8266 and number of GPIOs

Post by adafruit_support_mike »

You'd have to do it as an analog reading, like you described.

The ESP8266's insides are wired differently than the Uno's ATmega328. The '328 has a set of internal switches connected to each pin, and you set the switches to make the pins do different things.. the pinMode() function is a wrapper for that.

The ESP8266's ADC pin is just an ADC, so the same rules always apply.

Having said that, using an ADC to read buttons can be a great idea.. instead of giving each button its own pull-up/down resistor, make a multi-tap voltage divider like so:
adc-buttons.jpg
adc-buttons.jpg (14.6 KiB) Viewed 502 times
The 100k pull-down will keep the ADC pin at 0v when all the buttons are open, but will pull up to about the same voltage as the tap for the button that closed. Then in code, you can map regions of ADC output to specific buttons.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”