So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Nico1980
#70516 Hello,

I have just received my first ESP12 and have started to play around with it. My goal is to rapidly send a byte of data to a number of receivers (4 to 8). Today I have managed to create and send an UDP broadcast message., which I expect to be the fastest way to send the same message to multiple receivers (if there are any better ways I would love to hear about them).

The next step for me is to get the byte of data, this value has to be loaded from the GPIO pins. I did find some examples for manipulating a single pin (mostly switching an LED on), but could not find a clear example for reading multiple pins.
In the Arduino Uno it is possible to load 8 GPIO pins that belong to the same bank at once. In the ESP12 I don't see that kind GPIO clusters, but internally I would expect them to be clustered and that would mean that a similar IO-reading method should also be available.

My question therefor is, what is the most effective way to read 8 GPIO pins? And can I determine which pins will be used (I would prefer to keep the serial monitor available if possible)?

Kind regards, Nico
Last edited by Nico1980 on Mon Oct 02, 2017 4:29 pm, edited 1 time in total.
User avatar
By QuickFix
#70554 As far as I know, the pins of the ESP are actually all independant General Purpose IO-pins, not put up in banks (of 4, 8 or 16) and therefor can not be read all at once (or in banks).
User avatar
By lethe
#70558
QuickFix wrote:As far as I know, the pins of the ESP are actually all independant General Purpose IO-pins, not put up in banks (of 4, 8 or 16) and therefor can not be read all at once (or in banks).

On pretty much any mircocontroller, I/O pins are mapped to bits in special registers, the ESP8266 is no expection. That's why AVRs for example have GPIO ports of 8 pins (or less), since they are using 8-bit registers.

Since it has a 32-bit CPU and only 16 GPIOs, all pins are mapped to a single 32-bit register.
You can either read the input register using the gpio_input_get() function (see gpio.h in NONOS SDK) or access the register directly as described here: https://github.com/esp8266/esp8266-wiki ... -registers

However reading 8 individual pins on an ESP8266 would use up pretty much all available GPIOs and those pins won't be sequential in the input register (so you have to use bitwise operations to re-order the bits).
I would recommend to use a shift register (e.g. 74HC166) or an I2C port expander instead.
User avatar
By Nico1980
#70586 Hello,

Lethe, QuickFix, thank you very much for you replies. I just realize that I did not mention why I want to send the byte of data. My intention is to reproduce the 8 digital signals on the receiver side (meaning the order/value of the bits is not really relevant, for as long as it can be mapped the same way on the other side).

From QuickFix's reply I see it is possible to read the pins one by one, this would mean 8 calls to read a byte. With the speed of the ESP8266 this should be fast. So I wonder, if I read the values one by one, how can I get them in a single variable?

The link that Lethe provided seems very interesting. It seems like I could get the 32-bit register in one call, mask the values that I don't need and send the value (as two or four bytes). Then on the receiving end I could set all outputs to low in a single call and immediately after set the outputs to reproduce the input pattern in a second call.
Is there some more information about how to do this? Specifically:
- in the link it was mentioned that a number of "provide's" were added to a linker script, I have no idea what that is about or how to do it.
- if the variables are defined in the source, how should they be used to for example retrieve the value from the gpio-register and send it to serial?

Kind regards, Nico