15
ESP8266 WORKSHOP STI JNVA NDRUNEN( .NL) - HIG HTECHICT

Esp8266 Workshop

Embed Size (px)

Citation preview

Page 1: Esp8266 Workshop

ESP8266 W

ORKSHOP

ST

I JN

VA

ND

RU

NE

N( . N

L ) - H

I GH

TE

CH

I CT

Page 2: Esp8266 Workshop

PROGRAM

• Theoretical• What is the ESP8266• Writing your own code• Cool projects• Considerations

• Practical• Making something with the ESP8266

Page 3: Esp8266 Workshop

ABOUT ME

• Embedded enthusiast• Don’t plug it in, take it apart!

• Personal projects• LightSaga• Ikea lamp• Ambilight

• Blog on www.stijnvandrunen.nl

Page 4: Esp8266 Workshop

WHAT IS A ESP8266

• Wireless SoC

• Has GPIO, I2C, ADC, SPI, PWM and some other nice acronyms

• It’s fast! Running at 80MHz (or 160MHz if you’re brave)

• 64KBytes of instruction RAM, 96KBytes of data RAM and 64KBytes boot ROM

• Has a Winbond W25Q40BVNIG SPI flash for your code

• RISC architecture (in case you care)

• Core is a 106micro Diamond Standard core (LX3) made by Tensilica

• ESP8266 chip is made by Espressif

• It’s cheap enough to be put in everything and anything

Page 5: Esp8266 Workshop

VARIANCES

Page 6: Esp8266 Workshop

NODEMCU

• An open source firmware aimed on the IoT platform. It has the ability to run easy to code LUA scripts, making it easy to program the ESP8266. Based on LUA 5.1.4 (without debug and os module). Build-in json, file, timer, pwm, i2c, spi, 1-wire, net, mqtt, coap, gpio, wifi, adc, uart and system api.

• Example of http server in using NodeMCU:srv=net.createServer(net.TCP) srv:listen(80,function(conn)

conn:on("receive",function(conn,payload)print(payload)conn:send("<h1> Hello, NodeMCU.</h1>”)

end)end)

Page 7: Esp8266 Workshop

ARDUINO

• Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager.

• ESP8266 chip in the Arduino environment. ESP8266WiFi library bundled with this project has the same interface as the WiFi Shield library, making it easy to re-use existing code and libraries.

• Lot’s of libraries to benefit from for interfacing different hardware components.

• More user friendly way of writing code, more examples available.

Page 8: Esp8266 Workshop

COMMUNITY

• Esp8266.com, very active community

• Support from Espressif, regular releases of SDKs (their latest is MIT licensed)

• Google!

• Downsides• Fragmented information.• Chinese documents & quality• Different versions

Page 9: Esp8266 Workshop

WRITING YOUR OWN CODE

• Get a SDK• Linux• ESP-open-sdk

• Windows• Made by some Russian, supports Eclipse

• Look at samples• Blinky• Interrupt examples

• Your own project• Flashing

Page 10: Esp8266 Workshop

BLINKY – INIT FUNCTION

//Init function

void ICACHE_FLASH_ATTR user_init() {

gpio_init(); // Initialize the GPIO subsystem.

PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); // Set GPIO2 to output mode

gpio_output_set(0, BIT2, BIT2, 0); // Set GPIO2 low

os_timer_disarm(&some_timer); // Disarm timer

os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL); // Setup timer

os_timer_arm(&some_timer, 1000, 1); / /Arm the timer, 1000 is the fire time in ms, 0 for once and 1 for repeating

system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); // Start os task

}

Page 11: Esp8266 Workshop

BLINKY – TIMER & OS FUNCTION

// Do blinky stuff

void some_timerfunc(void *arg) {

if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2) { // Check if GPIO2 is HIGH

gpio_output_set(0, BIT2, BIT2, 0); // Set GPIO2 to LOW

} else {

gpio_output_set(BIT2, 0, BIT2, 0); // Set GPIO2 to HIGH

}

}

//Do nothing function

static void ICACHE_FLASH_ATTR user_procTask(os_event_t *events) {

os_delay_us(10);

}

Page 12: Esp8266 Workshop

COOL PROJECTS

• MQTT• Project running MQTT messaging on the ESP8266, very useful for

IoT applications such as reporting temperature and more.

• HTTP deamon• Made by Sprite_TM (Dutch & GoT moderator), running a webserver

on an ESP to serve a site that allows control of GPIO.

• ESP8266 powerstrip• Phoqus is playing with ESP8266s too, SAP wants to focus on IoT and

@jpenninkhof is making awesome things such as a ESP8266 controlled powerstrip. Check it out on his website: http://www.penninkhof.com/2015/05/linking-the-esp8266-a-raspberry-pi-through-mqtt/

• Many more!!! Check esp8266.com or hackaday.com…

Page 13: Esp8266 Workshop

MQTT?

• MQTT (MQ Telemetry Transport) is a very simple, extremely efficient publish/subscribe reliable messaging protocol. A protocol that enabled devices to open a connection, keep it open using very little power and receive events or commands with as little as 2 bytes of overhead. A protocol that has the things built in that you need for reliable behavior in an unreliable or intermittently connected wireless environments. Things such as “last will & testament” so all apps know immediately if a client disconnects ungracefully, “retained message” so any user re-connecting immediately gets the very latest business information, etc.

Page 14: Esp8266 Workshop

CONSIDERATIONS

• ESP8266 is 3.3V, logic level converter needed for 5V hardware

• Antenna yields various results

• Chinese quality

• Pick the right ESP8266 for you

• Put code in flash

• Don’t give up!

Page 15: Esp8266 Workshop

HANDS-ON

• Driving WS2812b LED ring with ESP8266• Connecting all the parts together• Find a way to interface with the LEDs• Control it! (Maybe esphttpd? Or simple UDP listener…)

• Please beware of the following points• Check the polarity on your PSU• Power and ground rails should be connected through in the middle• Ground first, power later• Logic level of WS2812b is 5V, ESP8266 is 3.3V