Networking and Communications

Assignment - Networking and Communications

  • I -- individual assignment:
  • design, build, and connect wired or wireless node(s) with network or bus addresses
  • II -- group assignment:
  • send a message between two projects

Individual assigment


This weekly assignment is very interesting for me because of my final project. In my final project - a sensor lamp - I need to connect the lamp to a mobile phone, ie the data that the sensors receive should be sent to the display of the lamp itself and to the mobile phone. So I paid special attention to this task and set out to explore slowly. I had multiple components I could use and I moved on in order.

  • Transmitter
  • - Operating Voltage: DC 3.5-12V
    - Size: 19mm x 19mm
    - AM transfer rate: 4KB / S
    - Transmitting Power: 10mW
    - Amplitude Modulation: ASK or OOK
    - Launch Distance: 20-200 Metres (dependent on supply voltage)
    - Transfer Rate: <10Kbps
    - > Emission frequency: 433M
  • Receiver
  • - Voltage: 5VDC
    - Current: 4mA
    - Frequency: 433mZ
    - Size: 30mm x 14mm x 7mm
    - Receiver Sensitivity: -103DBm

Nowadays, it’s hard to imagine life without wifi. There are a lot of different modules of method connection methods etc. Since I work from home, I chose the 315 mhz rf wireless transmitter + receiver module. I will use arduino and croduin for communication between receiver and transmitter.
Because we are experimenting with devices that transmit radio waves we need to be aware of the regulations regarding unlicensed radio transmitters. These regulations will differ depending upon what area of the world you live in. For my country regulatory body responsible for radio communications is Croatian Post and Electronic Communications Agency - HAKOM.
But my project operate at low power, it doesn’t transmit continuously (digital data is intermittent so it satisfies this requirement) and it does not transmit voice (digitized voice or sound is OK).

There are many methods of sending digital data over radio:
- Frequency Shift Keying or FSK. In this method the digital signal modifies the frequency of the carrier wave.
- Phase Shift Keying or PSK. This works by modifying the phase of the carrier in response to the input signal.
- Amplitude Shift Keying or ASK. This is a simpler method, similar to Amplitude Modulation or AM radio.
In Amplitude Shift Modulation the amplitude of the carrier wave is changed in response to the incoming data signal. This is sometimes called Binary Amplitude Shift Modulation as there really are only two levels to be concerned with:
Digital 1 – This drives the carrier at full strength.
Digital 0 – This cuts the carrier off completely.
ASK is susceptible to interference from other radio devices and background noise. But as long as we keep our data transmission to a relatively slow speed it can work reliably in most environments.
Or we can use antenna. The antenna that you use for both the transmitter and receiver can really affect the range.
For my project, I used plain copper wire 17.3 cm long which is recommended for working at this frequency. For frequency 433, a length of 69.24 cm is recommended. For other radio transmitters that use different frequencies we need to calculate the required antenna length using their wavelength. This - online wavelength calculator that can assist us in determining how long to make our antenna.

To control receiver I used a CROduino instead of an Arduino.
Croduino Basic2 PB.
The Croduino is a version of the Arduino. Croduino is the first Croatian Arduino compatible board. The Croduino Basic and Basic2 are identical to the Arduino Nano, it is slightly smaller in size and has two more pins. First I had to install the drivers for the Croduin and choose its tile.
Drivers for Croduino Basic2 PB.

To connect the transmitter I used a croduino by connecting GND to GND, VCC to 5 V and DATA to pin 12.

I used another laptop and an Arduino to connect the receiver. I connected GND -GND, VCC to 5 V and DATA - pin 11. The second DATA pin is free.

Now that I have connected both the receiver and the transmitter they need to be programmed. For this I need the RadioHead Library file which can be found at this link.
RadioHead Library

After that, I entered the code into the arduino IDE, especially for the transmitter on one laptop and especially for the receiver on the other laptop.
I could do the same, but this way I could connect both the receiver and the transmitter immediately and correct the code as needed.
The code can be viewed in zip files.

Code for transmiter I begin by loading the RadioHead ASK library. I also include the Arduino SPI Library as the ASK library is dependant upon it. Than I create an ASK object to work with, I called mine “rf_driver”. In the setup I need to initialize the ASK object. In the loop I have to encoding a message. This needs to be a char data type. This is stored in a variable named “msg”. The message is a text string and have 24 characters. I then send my message and wait for it to be sent. I apply a delay to give receiver time to respond.
The receive code starts exactly the same as the transfer code, loading both the RadioHead and SPI libraries and creating an ASK object. In the setup, I initialized the ASK object and set up a serial monitor, so I could see if the receiver was receiving my message. In the loop, I set up a clipboard that matches the size of the transmitted message. Since my message is 24 characters long, I used the value 24. We adjust this as needed, ie the length of the message we send. We need to include spaces and punctuation because they all count as characters. We then check to see if we have received a valid package. If we do, we print it to a serial monitor. Then we go back to the beginning of the loop and do it all over again. After loading the code, we open the serial monitor. on which I see my message.

For the needs of my final project, I connected a temperature sensor and a DHT11 humidity sensor to the croduino. Characteristics:
Temperature measurement range: 0 ° - 50 ° C
Humidity measurement range: 20% - 90%
Measurement deviation temp: +/- 2 ° C
Deviation when measuring humidity: +/- 5%
Voltage: 3V - 5V
Current: 100uA (standy), 2.5mA (measurement)
I needed to install an additional library to work with this sensor. It can be installed using zip files or library managers. Link for download - DHT11 Library
I connected GND to GND, VCC-5 V, DATA to pin A0 since these are analog values ​​that the sensor reads.

The next one I used was the wifi module ESP8266-01, datasheets ESP8266 ESP-01.
I sought help on the page HELP.
and flashing ESP8266-01.

To put the new firmware on ESP8266 I used FT232RL FT232 FTDI USB To TTL 3.3V 5.5V Serial Adapter Module For Arduino Mini Port

I first connected the appropriate pins. The pins are shown in the right picture.

For a 3.3V power supply I took an external power supply.

Now that I've put it all together I've opened an arduino program for a serial monitor to make it easier to keep track of what's going on with the ES8266-01.
The next program I need is esp8266_flasher.

I first checked the current firmware version by opening Tools -> Serial Monitor. I checked the port where it is connected FT232 FTDI - COM port 10.
When checking the version, the GP00 is disconnected and the power is turned off for a second, then the power is restored but not the GP00.
Then I typed AT + GMR.
The result is displayed on the serial monitor.

Then I selected a file for the new firmware - AiThinker_ESP8266_ DIO_ 8M_8M_ 20160615_V1. 5.4 and clicked on download. Before that I put the GP00 back in GND.

The process of loading new firmware can be followed in the program window and can take a few minutes.

When the process was done I checked the firmware version again.

Then I changed the baud rate from 115200 to 9600.

Now it was time to connect the PCB to the wifi. week15.

Group assigment

For the group assignment we had to send a message between two projects, so I chose two of my previously made boards. Up one is the master and the down is the secondary.
I deceided to send a message over I2C protocol.
I needed TinyWireM library for master and TinyWireS for secondary device. I found it here. .
I found help also playground arduino and attiny85-i2c-protocol-tutorial. On my secondary device I have LED so I send a message to turn the LED on and off every two seconds. I also used SoftwareSerial to output message in serial monitor. This site . very helpful with sending message between two ATtiny’s . I have to connect a two 4.7 kΩ resistors between SDA, SCK pins and ground.

I2C or Inter Integrated circuit is another popular serial communication protocol built in almost every modern microcontrollers. This protocol uses full duplex communication and uses only two wires to exchange data.
ATtin85 microcontroller is equipped with Universal Serial interface aka USI which can be configured to operate in I2C mode. I2C mode using this USI interface is also referred as Two wire mode.

I2C is a popular serial communication protocol where the data bits transmission takes place via two wires – SDA and SCL.
SDA is the data line in which the data bits are transmitted and received. I2C is a half duplex communication since there is one data line. SCL is the clock signal line which is used to synchronize the communication. Similar to SPI communication, I2C protocol establishes communication by assigning devices as Master and Slave. The device which generates clock signal will be the master device. But unlike SPI protocol which uses a dedicated pin SS to select slave device for communication. I2C protocol uses slave address for selecting the slave which master wishes to communicate.
When master need to communicate it will send slave address via data line SDA.
The slaves connected to master will receive the address. And then only the slave matching the address will store the incoming data from master device and other slaves will discard the incoming data from master.
In ATtiny85 microcontroller SDA pin is PB0 and SCL pin is PB2.

To be able to make a program master I had to load the TinyWireM library, and for the secondary I had to load the TinyWireS library.

//master code

#define device (1)
#define SLAVE_ADDR 0x6 //define the address for the slave

#include //add library to be able to use the serial monitor
int rxPin = 4; //the receiving pin
int txPin = 1; //the transmitting pin
SoftwareSerial serial(rxPin, txPin); // to set up the serial object

void setup() {
pinMode(rxPin, INPUT); //the rx pin is the input of the communication
pinMode(txPin, OUTPUT); //the tx pin is the output of the communication
serial.begin(4800); //begin communication with computer

void loop() {
msg();//receive message

msg();//receive message

void msg()
volatile byte msg =0; //treat as variable
TinyWireM.requestFrom(SLAVE_ADDR,1);//request from slave address

if (TinyWireM.available()){ //to make sure the master is available
msg = TinyWireM.receive();//receive message

if (msg ==4){//if this message
serial.println("It's day!");}//print this in serial monitor
else if (msg ==5){//if this message
serial.println("It's night!");}//print this in serial monitor

//secondary code

#define output (4)
#define I2C_SLAVE_ADDR 0x6

void setup() {
// put your setup code here, to run once:
pinMode(output, OUTPUT);

volatile byte msg = 0;

void loop() {
if (TinyWireS.available()){
msg = TinyWireS.receive();

if (msg == 1){
digitalWrite(output, HIGH);
TinyWireS.send(5); //send message
else if (msg == 0){
digitalWrite(output, LOW);
TinyWireS.send(4);//send message

Result is ...