symp

Week 14 - Networking & Communications

Individual Assignment: Design, build, and connect wired or wireless node(s) with network or bus addresses

Group assignment: Send a message between two projects

.

I decided to use WIFI modules for this week's assignment. Since we had CC3000 Wifi module chip in our lab i decided to go with the same. The reason to choose the same was since my it would be useful for my final project for controlling equipments wirelessly.

CC3000 - WIFI MODULE

.

Front side

.

symp

.

.

Back side

.

symp

First step was to get a minimum circuit for operation of the wifi module.The circuit available from adafruit library was used as below, for setting up

.

symp

.

The eagle library required for the the module was added. Since the scheme doesn't have an inbuilt antenna, an antenna was used which was obtained from here. The library was added in eagle as below:

.

symp

.

symp

.

Schematic diagram

.

symp

.

Board diagram

.

symp

.

.

3.3 V Logical Level Shifter was used here, which was planned to be used externally

.

symp

.

As we can see from back side view that the pins are in backside, inorder to solder the component we need to use the stencling method to work with the same. Since we didn't have the required paper for making the stencil, I tried to laser cut the design in an available sheet as below.But it was a failure as below

.

Failed Stencil paper

.

symp

.

The PCB was now milled and the component was placed in oven after filling the necessary portions with solder paste.

.

symp

.

.

symp

.

.

symp

.

.

symp

.

After soldering the components, since the chips works in 3.3 V and the arduino board that i am going to connect works at 5 V , an external 3.3V logical level shifter was added as below

.

symp

.

But when i tried to program the bootloader, there was an issue in programming the same.So i decided to use ESP8266 module for the same purpose. So i ordered an ESP8266 chip for the same since it was not available in our lab

.

Later i found out that a connection from to VBAT enable was missing from the circuit, but i had already shifted to ESP 8266

.

symp

.

ESP8266 - WIFI MODULE?

The ESP8266 WiFi Module is a self contained system-on-a-chip (SOC) with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.Each ESP8266 module comes pre-programmed with an AT command set firmware by which we could connect this to any atmega or arduino device

.

symp

.

.

Library for ESP8266 module was downloaded from here

.

symp

.

.

Since there are different modes for the operation and programming of ESP 8266 , the details can be obtained from here

symp

.

.

ESP8266 modes of programming

.

symp

.

.

The pins were configured as per the modes above like GPIO15 to gnd,GPIO2to HIGH, GPIO0 to HIGH or RESET as per programming requirement

.

.

Schematic Diagram

.

symp

.

.

Board Diagram

.

symp

.

.

For checking the board, i uploaded a sample blinking led program as below

.

symp

.

.

After Checking i found out that the issue was with the wrong connection i had done as below. Without changing the board the traces was milled using blade and required connections were done using copper cable

.

.

symp

.

.

symp

.

.

Program was again uploaded and it was a success

.

symp

.

Output of the program

.

Testing two boards which were made using blink command

.

.

Next step was to have the two boards communicate with each other. Here i will try to use the two esp boards communicate through UDP protocol as wireless serial comunication. UDP gives advantage of sending one message to all ESP8266 devices on same network at the same time using broadcast. For the same i connected the two esp boards to my system through ftdi cable.

.

This program was uploaded to one board to make it work as an access point

.

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
 
const char *ssid = "KERALA STARTUP MISSION";
const char *pass = "INNOVATE@KTIZ"; 
 
unsigned int localPort = 2000; // local port to listen for UDP packets
 
IPAddress ServerIP(192,168,10,1);
IPAddress ClientIP(192,168,10,2);
 
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;
 
char packetBuffer[9];   //Where we get the UDP data
//=======================================================================
//                Setup
//=======================================================================
void setup()
{
    Serial.begin(9600);
    Serial.println();
    WiFi.softAP(ssid, pass);    //Create Access point
 
    //Start UDP
    Serial.println("Starting UDP");
    udp.begin(localPort);
    Serial.print("Local port: ");
    Serial.println(udp.localPort());
}
//======================================================================
//                MAIN LOOP
//======================================================================
void loop()
{
    int cb = udp.parsePacket();
    if (!cb) 
    {
      //If serial data is recived send it to UDP
      if(Serial.available()>0)
        {
        udp.beginPacket(ClientIP, 2000);
        //Send UDP requests are to port 2000
        
        char a[1];
        a[0]=char(Serial.read()); //Serial Byte Read
        udp.write(a,1); //Send one byte to ESP8266 
        udp.endPacket();
        }
    }
    else {
      // We've received a UDP packet, send it to serial
      udp.read(packetBuffer, 1); // read the packet into the buffer, we are reading only one byte
      Serial.print(packetBuffer);
      delay(20);
    }}

.

The below program was uploaded to the second ESP board to make it work as a client to connect to the other accesspoint

.

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
 
const char *ssid = "KERALA STARTUP MISSION";
const char *pass = "INNOVATE@KTIZ"; 
 
unsigned int localPort = 2000; // local port to listen for UDP packets
 
IPAddress ServerIP(192,168,5,1);
IPAddress ClientIP(192,168,5,2);
 
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;
 
char packetBuffer[9];   //Where we get the UDP data
//======================================================================
//                Setup
//======================================================================
void setup()
{
    Serial.begin(9600);
    Serial.println();
 
    WiFi.begin(ssid, pass);   //Connect to access point
  
    Serial.println("");
 
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
    
    //Start UDP
    Serial.println("Starting UDP");
    udp.begin(localPort);
    Serial.print("Local port: ");
    Serial.println(udp.localPort());
}
//======================================================================
//                MAIN LOOP
//======================================================================
void loop()
{
    int cb = udp.parsePacket();
    if (!cb) 
    {
      //If serial data is recived send it to UDP
      if(Serial.available()>0)
        {
        udp.beginPacket(ServerIP, 2000);  //Send Data to Master unit
        //Send UDP requests are to port 2000
        
        char a[1];
        a[0]=char(Serial.read()); //Serial Byte Read
        udp.write(a,1); //Send one byte to ESP8266 
        udp.endPacket();
        }
    }
    else {
      // We've received a UDP packet, send it to serial
      udp.read(packetBuffer, 1); // read the packet into the buffer, we are reading only one byte
      Serial.print(packetBuffer);
      delay(20);
    }
}

Serial monitor in arduino was used for sending data from one ESP. 'Putty' was being used to get data from the other other board. I send a data 'hello' as serial input and was received in the second device which was monitored through putty. The screenshots are as below

.

one ESP configured as access point, starting UDP services

.

symp

.

.

Second ESP configured as client, which is connected to access point and data 'hello' was sent from access point to client as below:

.

symp

.

.

.

Out of curiosity my academy friend Akhil joseph decided to test it with Alexa and along with that i was able to check whether the wifi module was working. Here is the output
Arduino program

.

#include <ESP8266WiFi.h>

#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"

// prototypes
boolean connectWifi();

//on/off callbacks
void lightOn();
void lightOff();
void secondOn();
void secondOff();

//------- Replace the following! ------
char ssid[] = "xxx";       // your network SSID (name)
char password[] = "yyyy";  // your network key

WemoManager wemoManager;
WemoSwitch *light = NULL;
WemoSwitch *second = NULL;

const int ledPin = 13;

void setup()
{
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  // Attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

  wemoManager.begin();
  // Format: Alexa invocation name, local port no, on callback, off callback
  light = new WemoSwitch("test lights", 80, lightOn, lightOff);
  second = new WemoSwitch("second lights", 81, secondOn, secondOff);
  wemoManager.addDevice(*light);
  wemoManager.addDevice(*second);

  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, HIGH); // Wemos BUILTIN_LED is active Low, so high is off
}

void loop()
{
  wemoManager.serverLoop();
}

void lightOn() {
    Serial.print("Switch 1 turn on ...");
    digitalWrite(ledPin, LOW);
}

void lightOff() {
    Serial.print("Switch 1 turn off ...");
    digitalWrite(ledPin, HIGH);
}

void secondOn() {
    Serial.print("Switch 2 turn on ...");
    digitalWrite(ledPin, LOW);
}

void secondOff() {
    Serial.print("Switch 2 turn off ...");
    digitalWrite(ledPin, HIGH);
}

.

Week 6

Week 7

Week 8

09

Week 9