ESP8266 GPIO

Has anyone had a go at making a set of macros or defines in C to make the programming of the GPIO pins easier?

For people used to:

setMode(1,OUTPUT);

a cold sweat appears when confronted with

PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);

And if you’re only dealing with GPIO0 and GPIO2 then that’s not too hard, but we have commands to pull up pins, disable pull up, pull down, disable pull down, set as outputs etc…

Personally I’ve no idea which commands can be used on which pins and outside of GPIO0 and 2 I’m not even sure what commands CAN be used on which pins.

Is anyone aware of a simple concise set of documentation with examples for all the pins? Or has anyone done their own thing which would make life easier for others?

The nearest I’ve been able to find is this

http://g-lab.ca/esp8266ex-gpio-application-programming-interface/

and there are also some snippets of useful info here..

http://www.esp8266.com/viewtopic.php?f=13&t=273

However I’m still not clear in my head what can and cannot be done with each pin.

Facebooktwittergoogle_pluspinterestlinkedin

8 thoughts on “ESP8266 GPIO

  1. Yes, there are a few of those projects providing Arduino style interface to the ESP8266. I have been doing something a bit different at https://github.com/riban-bw/ribanESP8266. I am trying to provide simple to understand interfaces to each bit of hardware, packaged as a single library. It is partly providing wrapper functions but also removing some of the complexity and cascading (of defines) which confuses me and some IDEs (e.g. Code::Blocks). It is very much a work in progress and I have only just (yesterday) fixed a bug that now allows the UART to work so gives me debug - pretty difficult coding in the dark! The links provided by Krzysztof will prove useful in further enhancing my libs. I am currently struggling with some memory paging issues which took up all of last night - grrrr! I am doing this to make my projects simpler to make and it is on github for my benefit (as a version control repository and backup) but free for anyone else to use as they see fit.

  2. Might be relevant ... I have added 12 and 13 as pwm (15 is grounded so no pwm available there), 14 as out, 5 as input and Tout as an adc input. I use fine ecw wire, dip in solder paste and touch onto pads. ( 3 pairs of glasses though! .. old eyes).
    Being a C thicko it took some time with understanding the pwm, pwm.h and pwm.c.(copied form iot) Help from
    http://www.esp8266.com/viewtopic.php?f=6&t=545 and http://www.esp8266.com/viewtopic.php?f=11&t=450 (chris). I used the pwm at freq 500, which works fine.
    adc turned out to be simple ....
    uint8_t buffer[16];
    uint16 adc = system_adc_read();
    ets_sprintf( buffer, "%d", adc );
    This is all within the MQTT code so it is easy to write and read the various ports via topics.
    ( I use Tasker + Mqttsend as an app, overlayed on MyMqtt dashboard, which is quite handy for testing on android)
    Since getting a new AP/router I went back to trying the RPi + mosquitto. Hardwired in and headless, I must say it's not buckled once, even with the 50mS sends from mqtt-spy.
    The PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12) etc jargon is a necessary evil to me (coming from 8 bit assembler world), It seems to me that everything nowadays requires three pages of text (ok ... a slight overstatement) just to get hold of one variable data. Mother's daughter's aunt of sons sibling evaluates as 1 maybe good for some, but I'd rather do a bit test.
    Hey Ho, getting old here:) I am enjoying it really!
    Wouldn't have got anywhere without your weblog though!

    Dave

  3. In the include / driver directory resides the uart.h file.
    #ifndef UART_APP_H
    #define UART_APP_H

    #include "uart_register.h"
    #include "eagle_soc.h"
    #include "c_types.h"

    #define RX_BUFF_SIZE 256
    #define TX_BUFF_SIZE 100
    #define UART0 0
    #define UART1 0 /* 1 */ Making this 0 disables the following in the driver directory uart.c file.
    ...........................................................
    LOCAL void ICACHE_FLASH_ATTR
    uart_config(uint8 uart_no)
    {
    if (uart_no == UART1)
    {
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
    }

    or so it would appear when I run it! 🙂

  4. Morning Pete, I'm back on the ESP-12 project and although this post is old, I found this resource that makes dealing with the pins somewhat easier so I'll add it for completeness.

Comments are closed.