This week we had to work with networking devices in order to communicate over a network. I decided to use WiFi and bluetooth as they are the two simplest and most commonly used in the prototyping and making world. I made a board for each of them and using an FTDI to USB module to program the WIFI board.
Making the WiFi board
For this week's assignment I am using the ESP 8266-12e WiFi module. It contains the chip required for Wifi communication and an antenna. However, some components and connections are required to allow programming and usage of the chip. I initially referred to the , to learn more about these connections. I was kinda lost, it being the first time using such a module, so I found this , which provided me with all the information I needed to design my board.
The schematic shown on the right is the one described in the tutorial. I broke down the circuit schematics to make it easier for me to connect the pins in my schematic. I also added a 3.3V voltage regulator.
The final board contained two buttons for resetting and flashing the module, as well as an LED connected to an output pin in order to indicate when the chip is working. A connection to an FTDI connection was included to allow direct communication to the chip which is required for programming. All other connections were done according to the table on the right, from the datasheet.
The board design was designed to look like a face and include the WiFi logo. It was important to have the antenna sticking out for better connection and to prevent interference. The board design can be seen on the right alongside the milled product board looked like. It was a bit rough in terms of finish since the endmill had chipped halfway through, but I used it after checking all the connections were fine using a multimeter.
Programming the WiFi board
To program the board I downloaded the ESP8266 library by adding http://arduino.esp8266.com/stable/package_esp8266com_index.json to the additional board managers field in the arduino ide preferences.
Once the library is downloaded, open board manager, search for esp8266 and make sure its installed. Then pick the Node 1.0 12E board with the following settings from the board menu in the toolbar.
To check the board and burn the first sketch, I decided to upload an empty sketch. The analog button on the right connected to IO0 has to be pressed during programming. The other button is reserved for flashing the chip, but wont be required right now. There is an automatic reset circuit that I later discovered (shown on the right), but this works fine for the time being. The following was the output in the console terminal, indicating a successful upload.
I then wanted to use the board by uploading a simple program that allows it to communicate using cayenne. I included the special key assigned to my WiFi board, as well as my cayenne username and password. this is required in order to gain access to the personal server.
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
unsigned long lastMillis = 0;//this is required for the Cayenne.loop function
// since it is within the library its use won't be clear in this sketch but its
use is for specifying the timout for loops, especially those for connection
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
void loop() {
Cayenne.loop();
//Cayenne input function from channel 7 on dashboard
CAYENNE_IN(7)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
//turn light on when you turn on the button on cayenne dashboard
digitalWrite(D6, HIGH);
}
else
{
//turn light off you turn off the button on cayenne dashboard
digitalWrite(D6, LOW);
}
}
}
Communicating using the WiFi board
Cayenne is an MQTT service, that communicates with your IOT device over Wifi. I will go into more details during interface and week, so for this week I set up a simple program to blink an LED once a button is pressed on the Cayenne dashboard. The first video is the trial on a breadboard, and the second is for an on-board led that I installed on my custom WiFi board.
Making the bluetooth board
After reading about the bluetooth board, I thought that it would be better to provide a 3.3 V source to the HC-05 by applying a voltage resistor. However, I later realized this was not needed but it was still good practice in making electronics.
Communicating using bluetooth
To communicate over bluetooth I used a software serial sketch on my main board and my phones bluetooth terminal. The HC-05 automatically apears on the bluetooth pairing screen, if a pairing code is requested use 1234. Then access the serial terminal on the Arduino IDE and the HC-05 through the bluetooth terminal on the phone. Messages sent from one side should apear on the other.
The software serial sketch communicates with the bluetooth module using the software serial pins, in order to keep the serial pins free for use over the IDE terminal. It's a simple message relaying sketch which checks for serial data, and if available, writes it to the serial monitor and vice versa; if data was sent through the serial monitor it sends it over software serial to the bluetooth. Below are both terminal windows showing messages exchanged between each other .
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
Laptop Arduino IDE terminal connected via FTDI USB module to Board
Phone bluetooth terminal accessing HC-05 bluetooth module
Files to download
Please find all the files required, if you feel like making your own: