Note: If your board has a micro USB port, you can probably skip this step.
Connect your board to laptop/desktop via a USB to TTL cable/adapter. Here's a pinout showing the different connections.
Connections between the ESP and USB TTL are the following:
- ESP8266 <-> USB TTL
- GND <-> GND
- TX <-> RX
- VCC <-> 3.3V(+)
- CH_PD <-> 3.3V(+)
- GPIO0 <-> GND (Only while flashing the board)
- Install the Arduino IDE. You can download it for Mac OS X, Windows and Linux here
- Start the Arduino application and open
Preferences
- Enter
http://arduino.esp8266.com/stable/package_esp8266com_index.json
into the Additional Board Manager URLs. If you need more than one, they can be separated with commas
Go toTools > Board > Boards Manager
Search for esp8266
. When found, click Install
Select your ESP8266 board type by going to Tools > Board
, then choosing your type. For this example I am using NodeMCU 1.0 (ESP-12E Module)
.
You can get the name of your device's port using one of the following steps:
Linux and Mac OS X- Download and install the FTDI drivers from here. Select the appropriate version for your operating system and architecture
- Open a terminal window and run the Command
ls /dev/tty*
- Look for a device with the name that begins with
/dev/tty
e.g./dev/tty.usbmodemPy343431
on MAC or/dev/ttyUSB0
/dev/ttyACM0
on Linux
Note: For Linux, you may need to run the two Commands below. Once you've completed that, reboot your computer. This will add permissions that will allow you to upload a sketch to the board.
`sudo usermod -a -G tty ${USER}``sudo usermod -a -G dialout ${USER}`
Windows- Download and install the FTDI drivers from here. Select the appropriate version for your operating system and architecture
- Open the Windows start menu and search for
Device Manager
- The COM port for the ESP8266 device will be listed as
USB Serial Device
or something similar
- Keep note of the COM port (e.g. COM4)
In the Arduino IDE, Go to Sketch > Include Libraries > Manage Libraries
Install each of the following libraries by searching for their name in the search bar within the modal. A button will appear in the bottom right of the box that will allow you to install the library.
- ESP8266WiFi
- PubSubClient
- ArduinoJson
If you haven't already, you'll need create a Device and add a Command to your Wia account. Tutorials can be found here to add a Device and here to add a Command.
CREATE THE SKETCHIn the Arduino IDE:
- Click on
File > New
to create a new Sketch
- Copy and paste the example code below labeled
Wia Command
. This code subscribes to a Wia Command
- The callback contains a placeholder section to write code to do something useful when a Command has been triggered
Replace the following values of the following variables:
your-wifi-ssid
- with your WiFi network name
your-wifi-password
- with your WiFi network password
your-device-id
with your Device id from the Wia Dashboard (the one that begins withdev_
)
your-device_secret_key
with your Device secret key from the Wia Dashboard (the one that begins withd_sk
)
- Go to
Sketch > Upload
in the Arduino IDE menu to send it to your ESP8266
- Open your Serial Monitor to view the output from your ESP8266 by going to
Tools > Serial Monitor
Go to the Wia dashboard in the Command section and click run
on the Command associated with the code above.
Comments
Please log in or sign up to comment.