We are the MAKERS

Fab Academy 2017






Networking and Communications




Tasks:





Networking and Communication was the week which I was waiting for the most! And the most amazing part is to learn how the world is communicating not only between humans, but also electronics

For this assigment I will be using the two boards which I made during the Output Devices week, and the Input Devices week, both PCBs are modified satshakit from Daniele Ingrassia.


satshakit is a 100% Arduino IDE and libraries compatible, fabbable and open source board, and also an improved version of Fabkit.


Here they are the BEASTS





Serial Communication:


To have a starting point, I decided to use the serial communication to send messages from one board to another.

Both boards are driven by the ATmega328P microprocessor, and the problem with this chip is that it has only one hardware serial. Because I want to use the serial communication between two boards, I would also like to debug the information on my computer screen, to have a visual representation if the communication is actually taking place. But printing the information on my screen is also serial communication. So to make my two boards communicate, and debug the information on my screen, I need two serials, which I do not have.

As a solution to this, I discovered for myself SoftwareSerial

The SoftwareSerial library has been developed to allow serial communication on other digital pins, using software to replicate the functionality (hence the name "SoftwareSerial").

So basically using this library I can have two serials, one hardware, and one software!

I decided to use the hardware serial to communicate between the boards, and the softwre serial for debuging


Here is the Arduino sketch which I used:

        
#include <SoftwareSerial.h>  //include library

SoftwareSerial mySerial(10,11);  //RX and TX pins

void setup() {
  
  Serial.begin(9600);  //start the hardware serial at 9600 baud rate
  
  mySerial.begin(9600);  //start the software serial at 9600 baud rate
  
}

void loop() {
 
  Serial.println("Board_1 - Hello");  //send the message to the board#2
  
  delay(1000);
  
  if (Serial.available() > 0) {  //if there is any message received (binary 1 > 0)
    
     mySerial.write(Serial.read());  //print the message received
    
   } 
}


I upload the same code to both PCBs, the only thing which I change is Serial.println("Board_1 - Hello") I change to Serial.println("Board_2 - Hello") in order to differentiate which board is talking

The wiring is also pretty easy, this is how it looks:



I followed this connection schematics:


After I double check all the connections, I plug the FTDI cable into the USB, and open the Serial Monitor:



I was not receiving the full message because the delay(1000) was too short, I know that because before I set the delay(100) and I was receiving only one letter.

But anyway, because I am debuging from the board#2, and I receive the message from the board#1 means that the communication is taking place!




ESP8266 WiFi Module


I always wanted to learn how to connect to the internet, and control my board remotely from anywhere in the world. And I am lucky enough to have such an opportunity)

The module available in our FabLab Kamp-Lintfort is ESP8266-12F (DataSheet)



In short, the ESP8266 module is a TTL "Serial to Wireless Internet" device. It can act as a CLIENT, as well as a HOST. The module is powered ONLY at 3V, and operated using AT Commands

To start using the WiFi module, I first downloaded and replicated the FabAcademy board:


This is how it looks after I soldered everything:



Maybe it looks a little bit ugly because I could not find the predesigned 3.3V voltage regulator, so I used another package. It works fine)

To test the wifi module, I connect it to my computer using the 3.3V FTDI cable using the following connections:



I am not sure why this is the case, usually the RX and TX should be crossed, but in my case this is the only way the module was responding

I was using the ArduinoIDE and the serial monitor in order to program the module. The default baud rate is 115200

To progam the board I used the AT commands. I found a great source which was very useful ESP8266 - AT Command Reference


Here is the LOG of the commands that I used:

        
AT


OK
AT+CWLAP

+CWLAP:(3,"iPhone",-29,"fa:96:95:41:4e:2d",1,18,0)
+CWLAP:(5,"eduroam",-88,"ac:4b:c8:32:b4:44",1,-7,0)
+CWLAP:(0,"hsrw-guests",-90,"ac:4b:c8:32:b4:42",1,-7,0)
+CWLAP:(4,"FabLab",-76,"e8:94:f6:cd:42:5f",2,-16,0)
+CWLAP:(0,"hsrw-students",-91,"ac:4b:c8:32:b4:46",1,-7,0)
+CWLAP:(0,"Chromecast FabLab",-46,"fa:8f:ca:86:42:e8",6,-4,0)
+CWLAP:(0,"hsrw-students",-66,"4c:96:14:23:f8:86",6,-11,0)
+CWLAP:(3,"FabLab2",-52,"04:18:d6:e2:79:44",6,-16,0)
+CWLAP:(5,"hsrw-staff",-65,"4c:96:14:23:f8:80",6,32767,0)
+CWLAP:(0,"hsrw-guests",-68,"4c:96:14:23:f8:82",6,-11,0)
+CWLAP:(5,"eduroam",-64,"4c:96:14:23:f8:84",6,-11,0)
+CWLAP:(5,"hsrw-staff",-79,"3c:94:d5:76:d9:c0",6,32767,0)
+CWLAP:(0,"hsrw-guests",-78,"3c:94:d5:76:d9:c2",6,-7,0)
+CWLAP:(5,"eduroam",-79,"3c:94:d5:76:d9:c4",6,-7,0)
+CWLAP:(0,"hsrw-students",-83,"3c:94:d5:76:d9:c6",6,-6,0)
+CWLAP:(3,"ami.hsrw.eu/legacy",-88,"ea:94:f6:cd:50:31",1,-12,0)
+CWLAP:(0,"hsrw-guests",-88,"78:19:f7:7f:3b:82",8,-9,0)
+CWLAP:(5,"hsrw-staff",-49,"4c:96:14:20:c8:00",11,32767,0)
+CWLAP:(5,"eduroam",-46,"4c:96:14:20:c8:04",11,-11,0)
+CWLAP:(0,"hsrw-students",-52,"4c:96:14:20:c8:06",11,-11,0)
+CWLAP:(0,"hsrw-guests",-93,"4c:96:14:25:3c:c2",11,-2,0)
+CWLAP:(0,"hsrw-students",-91,"4c:96:14:25:3c:c6",11,-2,0)
+CWLAP:(0,"hsrw-guests",-48,"4c:96:14:20:c8:02",11,-11,0)
+CWLAP:(3,"staff.ami.hsrw.eu/legacy",-93,"e8:94:f6:cd:50:31",1,-12,0)

OK
AT+CWJAP="iPhone","12345678"

WIFI CONNECTED
WIFI GOT IP







After I see this message, it means that the WiFi module is connected to the network, in my case it is called iPhone

In order to make something really interesting with the WiFi module, I was doing some research, and found a great platform called Cayenne

Cayenne is an IoT Platform which, as they say, is the first drag-and-drop IoT project builder that provides access to Arduino’s features when choosing an IoT board including WiFi, BLE, IR, NFC, Ethernet, and more.

I decided to give it a try! The platform is very user friendly, and has step by step explanations what should I do in order to connect my Arduino to internet.



More detailed instructions about how to set up the Arduino, also all the libraries and download files can be found HERE

On the next step, I choose Arduino UNO, and the communication type, in my case Serial USB Connection



And then a ready arduino sketch will show up, which I have to copy and upload on my board. The sketch looks like this:

      

#include <CayenneSerial.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "bvsljgb440";

void setup()
{
	//Baud rate can be specified by calling Cayenne.begin(token, 9600);
	Cayenne.begin(token);
}

void loop()
{
	Cayenne.run();
}


The problem here is that I have to have the ESP8266 module connected to my board using Serial Communication, also the module should be connected to the WiFi, and the board should use serial to communicate with the PC. In order to fulfill all the requirements, I used SoftwareSerial again.


This is the modified sketch:

      

#include "SoftwareSerial.h"

#include <CayenneSerial.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "7xw3jozy13";

SoftwareSerial mySerial(2, 3);

void setup()
{

  Cayenne.begin(token,9600);
  mySerial.begin(9600);
}

void loop()
{
   Cayenne.run();
}


After I upload this sketch to my board, there is one more thing which I have to do. In order for this to work I must run the connection script on the machine the Arduino is connected to. The scripts are located under the extras\scripts folder in the main library folder. This redirects the traffic from the Arduino to the Cayenne server.


Windows:


And now the fun part begins:

After the connection is successful, I can create some widgets on my Dashboard. Because my board has an integrated LDR sensor attached to the analog pin A0, and also an LED connected to Digital pin D13, I can read the values of the LDR and control the status of the LED.

This is how it works:



You must understand, that the beauty of all this is the fact that you do not upload any code to Arduino, its all drag-n-drop.

Another great thing of the Cayenne is that they have IOS and Android app, which makes everything very easy and comfortable. I tried also another feature called Trigger

It is similar to the If condition in arduino. I set up that If the LDR value is less than 296 Lux, then the LED is ON. And If the LDR value is more than 320 Lux, the LED is OFF. And I did it using my iPhone!)


             








Download Files:


Cayenne Arduino sketch (.ino)

Serial Communication sketch (.ino)





© 2017 Albot Dima . All rights reserved | Albot.Dumitru@hsrw.org

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.