NETWORK AND COMMUNICATION


Home About me

ASSIGNMENT


Design and build a wired and/or wireless network connecting at least two processors

BOARDS DESIGNED


BOARD FOR THE WIFI ESP8266-ESP12-F MODULE


I designed a board for the ESP8266-ESP12F following Neil's example.

Board has a voltage regulator, two de-coupling capacitors and connections to RST, ENABLE, VCC, RXD, TXD, GPIO and GND pins of the ESP12-F.

ESP-12E package is the same as the ESP12F package, routed board:

Board is milled with the Roland MDX40a with 0.2mm tool for inner traces and 1mm for the outer traces.

FabModules is used with the following settings:

===============
INNER TRACES
===============
Cut depth = 0mm
Tool diameter = 0.2mm
Number of offsets = 4
Offset overlap = 55%
Path error = 1.1 pixels
Image threshold = 0.5

===============
OUTER CUT
==============
cut depth = 2mm
tool diameter = 1mm
number of offsets = 1
offset overlap = 50
  

Board is ready for soldering:

Final soldered board:

DESIGN OF ATTINY44 BOARD


An attiny44 board is designed to test the SDA/SCL functionality. It has extra pins for ground, vcc and SDA/SCL.

Routed board to save space and material:

Board is milled like the board above, with the same settings.

Board ready for soldering:

Final soldered board:

I2C BETWEEN TWO BOARDS


I2C was originally defined by Philips and is based on a set of specifications to build an universal bus guarateeing ICs compatibility due to its simple hardware and software standards.

I2C only requires two bus lines, the SCL (serial clock line) and the SDA (serial data line).

Each device connects to a bus and has a unique address in a simple master/slave connection. The connection allows masters to operate as master receivers or master transmitters.

The slave can be (1) a transmitter with capability to send or receive data and (2) a receiver-only device.

According to Philips, serial 8-bit oriented bi-directional data transfers can have 3 modes: 100 kbit/s in standard, 400 kbit/s in fast and 3.4 Mbit/s in high-speed mode. There is also fast-mode plus and ultra-fast modes available.

One of the limitations of I2C is the limited speed; however, it offers simple and cost-effective bus.

First, a slave-master configuration is set-up with two ATmega328 boards.

The set-up for a master-reader / slave-sender connection is fairly straight-forward:

The program has one master reader and one slave sender.

The code for the master is:

// Master-receiver code
#include <Wire.h>

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop() {
  Wire.requestFrom(2, 1);    // request 1 byte from slave device #2

  while (Wire.available()) { // slave may send less than requested
    int number = Wire.read(); // receive a byte as int 
    Serial.print(number);         // print the number
    Serial.print("\n");


  }

  delay(500);
} 
  

Code is uploaded using an arduino as a programmer via ICSP:

avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/jc/Program Files/arduino-1.8.2/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/jc/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino_build_298607/master_reader.ino.hex"
avrdude: writing flash (3214 bytes):

Writing | ################################################## | 100% 3.62s

avrdude: 3214 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_298607/master_reader.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_298607/master_reader.ino.hex:
avrdude: input file /tmp/arduino_build_298607/master_reader.ino.hex contains 3214 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.03s

avrdude: verifying ...
avrdude: 3214 bytes of flash verified

avrdude done.  Thank you. 
  

Next, is the code for the slave-sender:

// Slave-sender code

#include <Wire.h>

int number=1;
void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {

  delay(100);
  if (number == 100) {
    number = 1;
  }
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
    //char data[2];
    //itoa(number, data,10);
    Wire.write(number);
    number++;
  } 
  

Code is uploaded to the slave board using arduino-as-isp.

avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/jc/Program Files/arduino-1.8.2/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/jc/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino_build_275844/slave_sender.ino.hex"
avrdude: writing flash (2162 bytes):

Writing | ################################################## | 100% 2.37s

avrdude: 2162 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_275844/slave_sender.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_275844/slave_sender.ino.hex:
avrdude: input file /tmp/arduino_build_275844/slave_sender.ino.hex contains 2162 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.33s

avrdude: verifying ...
avrdude: 2162 bytes of flash verified

avrdude done.  Thank you. 
  

An attiny44 board designed below is used to test the SDA/SCL functionality as another slave.

Code for the master is slightly modified:

// Master-receiver code


#include <Wire.h>

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop() {
  Wire.requestFrom(2, 1);    // request 1 byte from slave device #2

  while (Wire.available()) { // slave may send less than requested
    int number = Wire.read(); // receive a byte as character
    Serial.print(number);         // print the number
    Serial.print("\n");

    if (number = 100) {
      Wire.requestFrom(3, 1);
      int attiny_read = Wire.read();
      Serial.print(attiny_read);
      Serial.print("\n");
    }
  }

  delay(500);
} 
  

Similarly, the code for the Attiny44 is written. It uses the TinyWireS library with support for ATtiny44/84 available here.

#define I2C_SLAVE_ADDRESS 0x3   //this slave address (0x1, 0x2, 0x3)
#include <TinyWireS.h>         //the ATTiny Wire library
int i=0;

void setup() {
  TinyWireS.begin(I2C_SLAVE_ADDRESS);
  TinyWireS.onRequest(requestEvent);
}

void loop() {
  TinyWireS_stop_check();
}

void requestEvent()
{
  TinyWireS.send(i);
}
  

However, the library above was very difficult to compile.

The ATtiny44 has USI which can implement I2C, code above to compile successfully, needs tweaking the library settings.

My set-up was one arduino board as ISP programmer, the three boards and an ftdi cable to the master board:

WIFI WITH THE ESP8266


The datasheet is available here.

The ESP8266 is connected with an FTDI cable:

ESP8266 is tested using a serial monitor with NL&CR with 115200 baud rate.

The ESP8266 uses hayes command set to communicate. A series of short text strings produce commands for operations.

A list of commands can be found here

When the command AT is sent, it should return OK.

CONNECTING TO AN ANDROID AP


First, the ESP8266 break-out board is connected to one of the atmega328p boards.

ESP8266 BREAKOUT    jc-watchobot-v1.0
-------------------------------------
gnd                 gnd
vcc                 vcc
tx                  pd3
rx                  pd4
  

Arduino software serial is used to emulate serial and send commands to the ESP8266f.

Following code connects to an AP connection on my phone.

#include "SoftwareSerial.h"
SoftwareSerial mySerial(11, 12);  //pd5, pd6 is 11/12 and pd3, pd4 for watchobot
const char* idpass = "AT+CWJAP=\"jc-android-ap\",\"fabacademy2017\"\r\n";

void setup(){
  Serial.begin(115200);
  mySerial.begin(19200);
  //setup the esp8266
  connectWifi();
}

void loop() {
  
}

void connectWifi(){
  sendData("AT+RST\r\n",1000,false);
  sendData("AT+CWMODE=1\r\n",1000,false);
  sendData(idpass, 3000,false);
  mySerial.println("init ok");
}
String sendData(String command, const int timeout, boolean debug){
     
      String response = "";
     
      Serial.print(command);
      mySerial.print("Command: "+command);
     
      long int time = millis();
     
      while((time+timeout) > millis()){
       
        while(Serial.available()){
         
          char c = Serial.read();
          response+=c;
       
        } 
      }
     
      if(debug){
      
        mySerial.print("response: ");
        mySerial.print(response);
      }
     
      return response;
   
  }
  

Code is uploaded using arduino as isp via icsp:


avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/jc/Program Files/arduino-1.8.2/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/jc/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino_build_497968/test_esp8266f.ino.hex"
avrdude: writing flash (5086 bytes):

Writing | ################################################## | 100% 5.57s

avrdude: 5086 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_497968/test_esp8266f.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_497968/test_esp8266f.ino.hex:
avrdude: input file /tmp/arduino_build_497968/test_esp8266f.ino.hex contains 5086 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.12s

avrdude: verifying ...
avrdude: 5086 bytes of flash verified

avrdude done.  Thank you.
  

LESSONS LEARNED


FILES


I2C codes

ESP8266F eagle files

ATtiny44 board eagle files

RESOURCES


Networking references


The content of this page is licensed under Attribution-NonCommercial 4.0 International CC BY-NC 4.0. Any source code, if otherwise unspecified, is licensed under the MIT License