Skip to content

14. Networking and 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

GROUP ASSIGNMENT

  • Remote side programWe have 2 ways of communicating devices: wired and wireless. What I will do is to communicate two devices, my Attiny44 ISP PCB and the ATMega328P (Arduino) wirelessly..

  • Take as a reference the work of Rob Hart, I saw that he did something similar to what I intend to do, I will serve to implement the wireless network between two devices. Here is the schematic:

  • These are the devices I will use. For wireless, RF communication, I use the NRF24L01 device.

  • NRF24L01 Wireless Transceiver Module: It is a small wireless transceiver (transmitter/receiver) with very low power consumption that operates in the 2.4 GHz range. It can send and receive data but cannot do so at the same time. This makes it very low cost and very simple and robust to operate. It is used in any project that needs to send and/or receive data wirelessly up to a radius of approximately 200m. The ideal is to have a pair and make a complete link between two nodes. It is fully compatible with the ATmega and ATTiny AVRs, among others..

  • Some outstanding features of the NRF24L01 are:

* Power supply voltage: 1.9 ~ 3.6V
* SPI port operating voltage: 0 ~ 3.3v / 5v (Tolerant to 5V)
* Current consumption: 60 mA
* RF chip: NRF24L01+
* Digital interface: SPI
* Modulation: GFSK (high noise immunity)
* Transmit Rate: +7 dB
* Receive Sensitivity: ≤ -90dB
* Antenna on PCB
* Transmitting range: 250m in open area (line of sight) * Transmitting range: 250m in open area (line of sight)
  • Pines ISP del NRF24L01:

  • Program for the base device (Receiver):
/*
  Program that runs the Base (RX) section of an RF link with the NRF24L01 modules.
  Receives a text from the Remote end and displays it on a serial monitor, then sends a text response.
  Librery: RadioHead (RH_NRF24.h)
  Author: bitwiseAr  
*/

// Base side program

#include <SPI.h>      // incluye libreria SPI para comunicacion con el modulo
#include <RH_NRF24.h> // incluye la seccion NRF24 de la libreria RadioHead

RH_NRF24 nrf24(8,10);       // crea objeto con valores por defecto para bus SPI
                      // el pin digital numero 8 para CE y 10 para CSN
void setup() 
{
  Serial.begin(9600);   // inicializa monitor serie a 9600 bps
  if (!nrf24.init())    // si falla inicializacion de modulo muestra texto
    Serial.println("Initialization failure");
  if (!nrf24.setChannel(2)) // si falla establecer canal muestra texto
    Serial.println("Failure to establish channel");
  if (!nrf24.setRF(RH_NRF24::DataRate250kbps, RH_NRF24::TransmitPower0dBm)) // si falla opciones 
    Serial.println("RF options failure");             // RF muestra texto

    Serial.println("Base started");  // texto para no comenzar con ventana vacia
}

void loop()
{
  if (nrf24.available())      // si hay informacion disponible
  {  
    uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];  // buffer con longitud maxima de 32 bytes
    uint8_t len = sizeof(buf);      // obtiene longitud de la cadena
    if (nrf24.recv(buf, &len))      // si hay informacion valida en el buffer
    {
      Serial.print("Received: ");   // muestra texto
      Serial.println((char*)buf);   // muestra contenido del buffer

      uint8_t data[] = "Hello remote device"; // se almacena texto a enviar
      nrf24.send(data, sizeof(data));   // envia texto
      nrf24.waitPacketSent();     // espera hasta realizado el envio
      Serial.println("Responding");   // muestra texto
    }
    else                          // si falla la recepcion
    {
      Serial.println("Reception failure"); // muestra texto
    }
  }
}
  • Program for remote device (Transmitter):
/*
  Program that executes the Remote (TX) section of an RF link with the NRF24L01 modules.
  Sends text to the base and then waits to receive one from the base.
  Librery: RadioHead (RH_NRF24.h)
  Author: bitwiseAr  
*/

// Remote side Program

#include <SPI.h>      // incluye libreria SPI para comunicacion con el modulo
#include <RH_NRF24.h> // incluye la seccion NRF24 de la libreria RadioHead

RH_NRF24 nrf24(8,10);       // crea objeto con valores por defecto para bus SPI
                            // el pin digital numero 8 para CE y 10 para CSN
void setup() 
{
  Serial.begin(9600);   // inicializa monitor serie a 9600 bps
  if (!nrf24.init())    // si falla inicializacion de modulo muestra texto
    Serial.println("fallo de inicializacion");
  if (!nrf24.setChannel(2)) // si falla establecer canal muestra texto
    Serial.println("fallo en establecer canal");
  if (!nrf24.setRF(RH_NRF24::DataRate250kbps, RH_NRF24::TransmitPower0dBm)) // si falla opciones 
    Serial.println("fallo en opciones RF");             // RF muestra texto
}

void loop()
{
  Serial.println("Enviando mensaje a la base"); // muestra texto
  uint8_t data[] = "Hola desde lejos!";   // almacena texto a enviar
  nrf24.send(data, sizeof(data));   // envia el texto

  nrf24.waitPacketSent();           // espera hasta realizado el envio 

  uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];  // buffer con longitud maxima de 32 bytes
  uint8_t len = sizeof(buf);        // obtiene longitud de la cadena

  if (nrf24.available())            // si hay informacion disponible
  {    
    if (nrf24.recv(buf, &len))      // si hay informacion valida en el buffer
    {
      Serial.print("Recibido: ");   // muestra texto
      Serial.println((char*)buf);   // muestra contenido del buffer
    }
    else          // si falla la recepcion
    {
      Serial.println("fallo en recepcion"); // muestra texto
    }
  }
  delay(1000);    // demora de 1 segundo entre envios
}
  • Once the correct library is installed, there are many on the web, I compile and transfer to each microcontroller respectively..

  • The connection is as follows. Note that pins 8 and 10 may vary depending on the pin selection you use.

  • I then verify its correct operation.

  • See here the video of both sides (Base and remote):

INDIVIDUAL ASSIGNMENTS

Setting up the Bluetooth Module HC-05: Using HC-05 for ON/OFF LED in ATtiny_Hello_Board

  • Due to time constraints, I decided to use the Bluetooth HC-05 module in solving the ISP.h library problem for the ATTiny44. The connection of this module is simple, I just have to connect VCC to 5V and GND to power the module and connect Bluetooth TX to the RX of the ATTiny44 and Bluetooth RX to the TX of the ATTiny44. The connection is shown below:

  • Then I transfer the program to ATTiny in the Arduino IDE. This is the code:
/*
  ATTiny44 and Bluetooth comunicate LED ON/OFF via APP
*/

#include <SoftwareSerial.h>
SoftwareSerial myBLUETOOTH(0, 1); //define SoftwareSerial RX first then TX

#define LED 3 // Define on board LED connected to pin 3
char state;   // Define a variable to save the reads char

void setup() {

  myBLUETOOTH.begin(9600); // Begin SoftwareSerial
  pinMode(LED, OUTPUT); // sets LED pin as OUTPUT pin
}

void loop() {
  if (myBLUETOOTH.available()) { // if SoftwareSerial recived any data

    state = myBLUETOOTH.read();  //Reads the received char and store it at "state"

    if (state == '1')           // If you recived Y
      digitalWrite(LED, HIGH);  //Turn LED on
    if (state == '2') {         // If you recived n
      digitalWrite(LED, LOW);   //Turn LED off
    }
  }
}
  • Using FabISP to program ATTiny44

  • Months ago I built an APP that turns on and off a LED via bluetooth. This is the application:

  • To the wireless data frame I assign “1” to turn on and “2” to turn off the LED.

  • Then I download the APP to install on my cell phone.

  • I check and see that the LED lights up from the cell phone APP.

  • Here is a video where you can see the process:
What did I learn?

Communications between different devices can be by cable, by RF and wireless signal and by light. Each one handles a different communication protocol. Nowadays communication when devices talk to each other is known as the internet of things or IoT.

Design Files

Description Files
Base_NRF24L01 Base_NRF24L01.ino
Remoto_NRF24L01 Remoto_NRF24L01.ino
ATtiny44_Bluetooth_LED ATtiny44_Bluetooth_LED.ino
APP ON/OFF LED EnciendeLED.apk