ESP8266 Project from Scratch…

This video https://www.youtube.com/watch?v=y9uk-3A1acM will show you how to start with a blank slate in ECLIPSE and make a project – including compile and flash. Within 10 minutes you may well have a working “Hello world”.

Magic. We owe the author a dept of thanks – and thanks to Glenn for bringing this to my attention.  More like this would be great.

On the other hand.. I got very excited, pulled in a couple of items from another library, compiled..

#include <ets_sys.h>
#include <osapi.h>
#include <gpio.h>
#include <os_type.h>
#include "driver/uart.h"

void user_init(void)
{
    uart_init(BIT_RATE_9600,BIT_RATE_9600);
    os_delay_us(1000);
    ets_uart_printf("Hello World – First Project!\r\n");
}

Flashed and…..

nothing. Not a sausage.

Advertisements

10 thoughts on “ESP8266 Project from Scratch…

  1. Hi Peter,

    The event type nature of programming the ESP means that the uart was probably not set up at the point you are trying to write something to it.

    If you look at other examples, they add a timer after initialisation to call a function. Something along the lines of

    LOCAL os_timer_t info_timer;
    #define DELAY 3000

    LOCAL void ICACHE_FLASH_ATTR info_cb(void *arg)
    {
    ets_uart_printf(“Hello World – First Project!\r\n”);
    }

    void user_init(void)
    {
    uart_init(BIT_RATE_9600, BIT_RATE_9600);
    os_timer_disarm(&info_timer);
    os_timer_setfn(&info_timer, (os_timer_func_t *)info_cb, (void *)0);
    os_timer_arm(&info_timer, DELAY, 1);
    }

    This event type programming requires a little rethinking to the standard arduino programming.

    • Good… but no.

      Same result (your code compiles incidentally and flashes – but still the same usual startup gobbldegook then nothing – and yes the terminal is set to 9600 🙂

      #include

      #include

      #include

      #include

      #include “driver/uart.h”

      LOCAL os_timer_t info_timer;

      #define DELAY 3000

      LOCAL void ICACHE_FLASH_ATTR info_cb(void *arg)

      {

      ets_uart_printf(“Hello World – First Project!\r\n”);

      os_printf(“Hmm”);

      }

      void user_init(void)

      {

      uart_init(BIT_RATE_9600, BIT_RATE_9600);

      os_timer_disarm(&info_timer);

      os_timer_setfn(&info_timer, (os_timer_func_t *)info_cb, (void *)0);

      os_timer_arm(&info_timer, DELAY, 1);

      }

  2. Everything really needs to be a callback, otherwise nothing happens. You can’t, for example, have a tight loop waiting for something to happen as none of the events will be processed.

  3. I know and I hate that. So – assuming we find out why that example didn’t work…. that callback routine is effectively your user_main routine – as you can’t do anything until the UART works…??

      • To answer the question – yes I have now compiled Hello world and surprisingly it comes back and says Hello world!!

        I do wish someone could show me how to extract the COM port out of all of these MAKE files (except the LUA one which doesn’t have that) and put it in a common location – we don’t all use Com2…

      • I suppose the way to go forward is to copy and paste the user_main from hello world into your new project and see if that works.

      • Well, not QUITE – see this..

        #include

        #include

        #include

        #include

        #include “driver/uart.h”

        #define DELAY 1000

        LOCAL os_timer_t info_timer;

        //extern int ets_uart_printf(const char *fmt, …);

        LOCAL void ICACHE_FLASH_ATTR info_cb(void *arg)

        {

        ets_uart_printf(“Hello World – First Project!\r\n”);

        }

        void user_init(void)

        {

        uart_init(BIT_RATE_9600, BIT_RATE_9600);

        os_timer_disarm(&info_timer);

        os_timer_setfn(&info_timer, (os_timer_func_t *)info_cb, (void *)0);

        os_timer_arm(&info_timer, DELAY, 1);

        }

        In my original code, the line commented out above was not present. Put it in and it works – leave it out – it does not work. Frighteningly , if it is missed out – there are no errors!!

        And I have to say I cannot make head or tail of that callback setup. But it does work. So that’s a start – it means we have a working setup for new projects.

  4. Also the os_delay_us() function doesn’t appear to release the processor to do other tasks, so whilst the delay is happening, nothing else is. I’m still looking do a windows style do_events() call that will allow for looping whilst still processing the background tasks, but not had much luck.

    The lack of decent documentation doesn’t help, so I’m trying to learn from the examples. I’ve not found the source code for osapi.h to enable me to reverse engineer exactly how the events system and timers work, which doesn’t help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s