ESP8266 Building Hello World Blink LED and Simple Web Server to drive the Relay and check Button status

ESP8266

ESP8266-EVB is small 57×50 mm board with Relay and Button which are connected to Internet via ESP8266 WIFI module.

ESP8266 has inside Xtensa106 processor and RF front end circuit, you do not need separate processor to drive the relay and read the button as ESP8266 can be programmed with custom code.

Here we will explain how to setup your tools and make your first project.

First you need to install your tools. It’s simple, just follow the instructions here: https://github.com/esp8266/esp8266-wiki/wiki/Toolchain

There are just few small mistakes as some commands will require SUDO before them and some paths are not exactly same, but you have to follow the steps and once you get error to read and correct the problem.

Here is what we do on Ubuntu 14.04 LTE 64-bit:

sudo apt-get install git autoconf build-essential gperf bison flex texinfo libtool libncurses5-dev wget gawk libc6-dev-amd64 python-serial libexpat-dev
sudo mkdir /opt/Espressif
sudo chown $username /opt/Espressif/
sudo cd /opt/Espressif
sudo git clone -b lx106 git://github.com/jcmvbkbc/crosstool-NG.git 
cd crosstool-NG
./bootstrap && ./configure --prefix=`pwd` && make && make install
./ct-ng xtensa-lx106-elf
./ct-ng build
PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH
cd /opt/Espressif
mkdir ESP8266_SDK
wget -O esp_iot_sdk_v0.9.3_14_11_21.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21.zip
wget -O esp_iot_sdk_v0.9.3_14_11_21_patch1.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21_patch1.zip
unzip esp_iot_sdk_v0.9.3_14_11_21.zip
unzip esp_iot_sdk_v0.9.3_14_11_21_patch1.zip
mv esp_iot_sdk_v0.9.3 ESP8266_SDK
mv License ESP8266_SDK/esp_iot_sdk_v0.9.3
cd /opt/Espressif/ESP8266_SDK/esp_iot_sdk_v0.9.3
sed -i -e 's/xt-ar/xtensa-lx106-elf-ar/' -e 's/xt-xcc/xtensa-lx106-elf-gcc/' -e 's/xt-objcopy/xtensa-lx106-elf-objcopy/' Makefile
mv examples/IoT_Demo .
cd /opt/Espressif/ESP8266_SDK/esp_iot_sdk_v0.9.3
wget -O lib/libc.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libc.a
wget -O lib/libhal.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a
wget -O include.tgz https://github.com/esp8266/esp8266-wiki/raw/master/include.tgz
tar -xvzf include.tgz
cd /opt/Espressif
wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb
dpkg -i esptool_0.0.2-1_i386.deb
cd /opt/Espressif
git clone https://github.com/themadinventor/esptool esptool-py
ln -s $PWD/esptool-py/esptool.py crosstool-NG/builds/xtensa-lx106-elf/bin/

For less experienced users, we are preparing VirtualBox disk image which to run on Virtual machine on any OS like Linux, MAC OS, Windows, and everything inside is pre-configured and ready to use, hopefully we will upload this image on ESP8266-EVB web page tomorrow as we didn’t manage to complete it today.

Once you have setup the Tools you can download our examples from GitHub:

cd /opt/Espressif
git clone https://github.com/OLIMEX/ESP8266.git
cd ESP8266-EVB-blinkLED
make

the project will be compiled and you will see something like this:

AR build/app_app.a
LD build/app.out
FW firmware/0x00000.bin
FW firmware/0x40000.bin

congratulations you made your first code!

now we hae to load it to ESP8266-EVB

you need: ESP8266-EVB, 5V adapter like SY0605E, USB-Serial-Cable-F
connect the USB-SERIAL-CABLE-F to ESP8266-EVB UEXT connector as follows:

  • blue wire to pin#2
  • green wire to pin#3
  • red wire to pin#4

plug the USB cable to your computer USB connector and check which serial port it connects by typing:

lsusb

your computer should display something like:

...
Bus 004 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
...

if you type:

ls /dev/tty*

you will see:

.... /dev/ttyUSB0 ....

If the USB device is with different name you have to update it in the makefile.

After the code is compiled with no errors you can write it to ESP8266 by following these steps:

  1.  first you have to press button and hold it and to apply power 5V, ESP8266 will enter bootloader mode
  2. type ‘sudo make flash’ and wait until code is loaded:
sudo make flash
/opt/Espressif/esptool-py/esptool.py --port /dev/ttyUSB0 write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
Connecting...
Erasing flash...
Writing at 0x00007300... (100 %)
Erasing flash...
Writing at 0x00061200... (100 %)
Leaving...

now Green LED must start blinking!

So far so good, you just made blinking LED on ESP8266, now let’s make something more complicated – to run Embedded web server on ESP8266, go to esphttpd project directory:

cd /opt/Espressif/ESP8266/esphttpd
make

then upload the code

sudo make flash

then upload web pages with:

sudo make htmlflash

Now ESP8266 firmware is uploaded and ESP8266 create Embedded server.

Scan for WIFI which name starts with ESP_XXXXXXX where XXXXXX is the ESP8266 MAC address and connect to this network then open browser at http://192.168.4.1 you will see this home page:

HOME

if you click on Relay button in the right side you will see new page:

RELAY

On this page you can switch the on-board relay by clicking on ON and OFF button

If you click on the Button button in the right side you will see new page:

BUTTON

If you click on Start scan the web page will start to refresh each second and display the button status if you click on Stop scan the page will not refresh.

This is very basic demo code which can be used as template for your own projects!

PIC-WEB-BOX demo video

Image

 

PIC-WEB-BOX is embedded PIC web server using Microchip’s Open Source TCP-IP stack with two buttons, RS232 interface, UEXT connector, two GPIO connectors, Status LED, 2GB Sd card for web storage. The power supply can be in range 9-30VDC and the low consumption makes this board perfect for controlling things over internet or to read sensors etc.

We setup video where you can see how easy is to program it and using the build-in bootloader you can change PIC-WEB-BOX firmware over the net via TFTP.

UART, I2C, SPI interfaces are available and the video demonstrate how you can drive 4.3″ LCD, Relays, measure temperature with thermocouple etc.

SD card with 2GB is build-in for web storage.

PIC-WEB-BOX is with small enclosure.

 

LPC2378-STK Tutorial: Implementation of PPP connection with TCPNet Stack

Image

Ohmohm tip us this tutorial via Twitter. Its in Russian language but you can use Google translate.

LPC2378-STK in this case act as web server and allow other devices to connect to it via PPP.

http://wiki.ru.com/index.php/90-art/16492-realizatsiya-ppp-soedineniya-s-pomoshchyu-steka-tcpnet

Web Server with MOD-IO + MOD-ENC28J60

Image

Doing embedded Web servers with microcontrollers is not new but Andrew Rossignol blogged recently that he made embedded Web Server with MOD-IO and MOD-ENC28J60, the catch is that MOD-IO have ATMega16 microcontrollers with only 16KB Flash and 1K RAM!

You can read more about his implementation on his blog

Good work!

A13-OLinuXino web server with MOD-RGB controlling RGB LED stripe over internet

Image

A13-OLinuXino have enough power to run real apache web server with php5, java script etc like any desktop linux computer.

With MOD-RGB connected to A13-OLinuXino UEXT you can control RGB LED stripe up to 5A per channel over fancy web interface from any device with web browser like your tablet or phone.

For instance you can make cool RGB LED lighting in your home and to control then with your phone, A13-OLinuXino can connect to many different MOD-RGB controllers as they are addressable, so you can connect many LED stripes to A13-OLinuXino web server and to controll them separately.

These are step by step instructions how to duplicate yourself:

Prepare A13-OLinuXino-WIFI for web serving:

Update repository
$apt-get update

Install apache and php
$apt-get install apache2 php5 libapache2-mod-php5

Open browser and type A13 board internal network IP address. For instance http://192.168.0.30 . You should get message “It Works”

Extract demo files into apache dir. For example /var/www/RGB

Compile i2c-tool
$gcc i2c-tool

Make executable
$chmod 777 a.out

Change permitions of i2c-bus
$chmod 777 /dev/i2c*

Now open index.html. You should see color picker. Move mouse. Enjoy :)

WEB-IO control of iMX233-OLinuXino-MAXI GPIOs from web

Image

In the previous post I explained how to setup web server on iMX233-OLinuXino-MAXI now will explain how to control iMX233-OLinuXino resources through the web.

Clone WEB-IO from GitHub:

# mkdir web-io

# cd web-io

# git clone https://github.com/OLIMEX/olinuxino-web-io.git

Copy gpio into /etc/rc.d/

# cp -vf web-io/init/gpio /etc/rc.d/

Start the script

# /etc/rc.c/gpio start

Change the permission of i2c-o

# chmod 666 /dev/i2c-0

Copy web folder into /srv/http/

# cp -rvf web-io/web/io /srv/http/

Go to your browser and enter the IP-address of the board: 192.168.0.1/io/menu_1.html

you will see the GPIOs web page and with mouse click you can change GPIO state

Running Web server with PHP on iMX233-OLinuXino-MAXI

Image

Here are the steps to run your own embedded web server with iMX233-OLinuXino-MAXI.

We assume you use ARCH Linux distribution:

1. Using pacman download the following packages:

lighttpd

# pacman -Sy lighttpd

mod_fastcgi

# pacman -Sy mod_fastcgi

php-cgi

# pacman -Sy php-cgi

2. Edit the lighttpd.conf file

#vi /etc/lighttpd/lighttpd.conf

NOTE: if you can’t find this file reboot the board and try again..

The file should look something like this

# This is a minimal example config
# See /usr/share/doc/lighttpd
# and http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions

server.port = 80
server.username = “http”
server.groupname = “http”
server.document-root = “/srv/http”
server.modules = (
“mod_access”,
“mod_fastcgi”,
“mod_accesslog”)
server.errorlog = “/var/log/lighttpd/error.log”
dir-listing.activate = “enable”

fastcgi.server = ( “.php” => ((
“bin-path” => “/usr/bin/php-cgi”,
“socket” => “/tmp/php.socket”
)))
index-file.names = ( “index.html” )
mimetype.assign = ( “.html” => “text/html”, “.htm” => “text/html”, “.txt” => “text/plain”, “.jpg” => “image/jpeg”, “.png” => “image/png”, “” => “application/octet-stream” )

Save and exit the editor. You can check the syntax with the command:

# lighttpd -t -f /etc/lighttpd/lighttpd.conf

With this configuration you should have working web-server at port 80 and implemented php

3. Reboot the board.

4. After the restart load the configuration file and start the daemon:

# lighhtpd -f /etc/lighttpd/lighttpd.conf

# /etc/rc.d/lighttpd start

You can see which daemons are started with the command:

# rc.d list

If you want to add this to autostart modify /etc/rc.conf and add lighttpd to DAEMONS array:

DAEMONS=(set-olinuxino-mac !hwclock syslog-ng network netfs crond sshd lighttpd)

5. Test the server

Now just open any browser and type the IP of the OlinuXino board and you should see “Hello” message. The folder containing the index.html is /srv/http. Just put your webpages there and your good to go.

Previous Older Entries

Follow

Get every new post delivered to your Inbox.

Join 619 other followers