14°- CONNECTING THINGS


Networking and Communications

Inicio

Wednesday ,April 21

Hello everybody! I hope you are doing very well, this week I will be direct and apply one of the greatest methodologies of my life, the minmax, which tells us that with fewer resources we can wait. This week we have to connect some devices to each other using any type of module, at first I had the idea of ​​doing it through TCP / IP protocols or some wireless wifi module, but I was surprised that the goblins that hide things in me My wifi modules disappeared (haha it's a lie I don't believe in elves, those modules must be around there), so I found some old radio frequency modules that I had used for a remote control cart, so I disassembled it and I will use it (forgive me cart but this mission will not be done alone), so without more to say !Let's do it¡ .

Components/Functioning/Circuit/Video

First Mission

In this mission I have carried out two tests, the first one is made around different devices than the second test.

Components:


The components that we are going to use are the following:
-Xbee: This is a long-distance communication module, it works through the zigbee communication protocol, which guarantees the correct arrival and sending of information. Therefore, we need 2 of these so that one can send information and the other receive it.We can see more information about this xbee on the manufacturer's page (Sparkfun).


-Parkyt: Our favorite board of all this fabacademy can also participate in this mission because the attiny85 can also communicate serially through its digital pins, this makes things much easier because the communication of our xbee module works through serial communication.

-Arduino Nano:We also need our friend the arduino, actually we could do it with two parkyt boards but since we only have one, we are going to make the data reception module controlled with an arduino nano.

-LCD - I2C :In order to show the messages that come through the modules, we need somewhere to show them and that is why we will use our lcd screen with its i2c module to make the connection more efficient.

For the development of this mission it is very important that we know that this system has 2 subsystems, the emitter and the receiver, which have different components and circuits, as we can see in the image.


Transmitter:
The transmitter is the simplest part of the system because its connections are direct as we saw in the image of the circuit.


As for the code that our Parkyt will have, it is also something basic, first we must know that the serial communication pins are not predetermined, that is why by programming we must use two of its pins to be its serial port.

#include <SoftwareSerial.h>
const int rx=3;
const int tx=1;
					
SoftwareSerial emisor(rx,tx);
					
void setup()
{
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
mySerial.begin(9600);
}
					
void loop()
{
					
emisor.println("FABACADEMY");
delay(1000);
emisor.println("2022");
delay(1000);
emisor.println("HAYASHI MATEO :D");
delay(1000);
}
					
					

Now it is our xbee's turn, the xbee modules have different modes but this time we are interested in the transmitter or router mode, through this mode we can only send messages to other modules, for this we must first download and install the program on the following page.


By connecting our xbee and opening the program, we can see that the module is recognized, then we must configure it as a router, for this we only need to modify the 2 parameters that are in the image, the first is the PAN ID, this is the number with the which all the modules that have the same will be able to communicate, finally put the coordinator option disabled and that's it we already have our modules configured.

Receiver:
This part of our system may be a little more complicated than the previous one due to the connections that have to be made, but nevertheless they are already in the previous images, to make these connections we use jumpers to facilitate the connections.


In turn, the programming of this is not so complicated because they are all known modules, as you can see the programming is at the bottom.

	#include <Wire.h> 
	#include <LiquidCrystal_I2C.h>
	LiquidCrystal_I2C lcd(0x27,16,2);  
	void setup(){
	  lcd.init();                     
	  lcd.backlight();
	  Serial.begin(9600);
	}
		
	void loop(){
	  if (Serial.available()) {
	    delay(100);
	    lcd.clear();
	    while (Serial.available() > 0) {
	      lcd.write(Serial.read());
	    }
	 }
	}
		
		

In the case of the xbee, now we have to be able to configure it as a coordinator, because it will be the one that will receive all the messages from the router, for this we only have to connect our module and then put the same PAN ID number and place the option of enabled. coordinator.


Finally we have the end result of our mission.

Group assignment

The challenge for this week is a little simpler than the previous ones, we must connect 2 devices and send data to each other, for this as I mentioned earlier I am going to use radio frequency modules from a cart I had (RIP cart), but the question is "What will you do with those modules?" well what I will do is that in the emitter I will place a potentiometer and in the receiver I will place a led, the potentiometer will send analog data and this will be received by the receiver and then sent to the led by means of a digital pin, simple right? Haha don't worry, I'll do it step by step, in the end the project will look like this:

Do you want to know how I did it? Join me to see it.

The components

-Emitter Arduino:
The emitter Arduino can be any Arduino that we have available or any microcontroller that has pins 11 and 12 available because the library that we will use works with those pins (if you work with another library you can use any Arduino), in my case arduino receiver is the arduino uno.
-Arduino receiver:
The arduino receiver has the same requirements as the arduino emitter, it is only required to have pins 11 and 12 because the library works with these pins, in my case the arduino receiver is the arduino mega.
-Potentiometer:
The potentiometer will be in charge of sending the signal between 0 to 255 so that the receiver, upon receiving it, can control the light intensity of the led.
-RF 433 Mhz:
These will be the modules which will be in charge of sending the data between them, the curious thing about these modules is that they can withstand voltages of up to 12v and as the voltage increases their range of reach also increases, being able to reach approximately 4 meters. Keep in mind that these modules come without an antenna so you must solder a cable that serves as an antenna.
-Led:
Finally we need a led to be able to see if the data sent by the receiver is being received and also sent to the digital pin of the led.
-Power supply:
Im using a portable charger in the case of the transmitter and in the case of the receiver I use the PC because I am also seeing the data received by the serial monitor.

Circuit and programming-Individual assignment

For the circuit we will make a simple connection in which we will have the 433 Mhz transmitter and the potentiometer to our arduino uno, on the other hand we will have our 433 Mhz receiver and our led connected to our arduino mega receiver, The wiring diagram for both cases is the following:

For programming it is necessary to download the following library and then copy it to the arduino libraries folder, you can find the library at the following http://www.airspayce.com/mikem/arduino/RadioHead/, upon entering you must download the library from the link that appears enclosed in red in the image below:

RadioHead

Once installed, it is time to program our devices, for them we will work one by one:

-Emitter:
Im using a portable charger in the case of the transmitter and in the case of the receiver I use the PC because I am also seeing the data received by the serial monitor.

#include <RH_ASK.h>    // incluye libreria RadioHead.h
#include <SPI.h>    // incluye libreria SPI necesaria por RadioHead.h
		 
RH_ASK rf_driver;   // crea objeto para modulacion por ASK
#define size 1
byte TX_buffer[size]={0};
		 
void setup(){
   rf_driver.init();   // inicializa objeto con valores por defecto
   pinMode(13,OUTPUT);
   digitalWrite(13,HIGH);
}
		 
void loop(){
 int val = map(analogRead(A0),0,1023,0,255); //transforma la entrada de señal a0
 TX_buffer[0] = val;  
 rf_driver.send((uint8_t *)TX_buffer, strlen(TX_buffer));// envio del mensaje
 rf_driver.waitPacketSent();     // espera al envio correcto
 delay(100);        // demora de 100 ms entre envios
 }
		

* The mapping transformation “map (analogRead (A0), 0,1023,0,255)” is due to the fact that the analog input signal has a resolution of 10 bits, while the output resolution through the digital pins only reaches the 8 bits, it is for them that we must make a simple rule of three to vary the scale from 0 -1023 to 0-255 and that is what the map function is for.On the other hand, for this programming I had to feed the potentiometer with a digital pin already I was using the 5V power from the arduino to power up the RF receiver module.


-Receiver :

#include <RH_ASK.h>    // incluye libreria RadioHead.h
#include <SPI.h>    // incluye libreria SPI necesaria por RadioHead.h
	
RH_ASK rf_driver;   // crea objeto para modulacion por ASK
int valor_pot = 0;  // variable para el valor del potenciometro recibido
	
void setup(){
   rf_driver.init();   // inicializa objeto con valores por defecto
   Serial.begin(9600);   // inicializa monitor serie a 9600 bps
   pinMode(13,OUTPUT);   // Lo uso para alimentar el potenciometro
}
	 
void loop(){
   uint8_t buf[1];      // espacio para almacenar mensaje recibido
   uint8_t buflen = sizeof(buf); // longitud del buffer de mensaje
   
   if (rf_driver.recv(buf, &buflen)) // si existen datos correctos recibidos
   {
         for (int i = 0; i < buflen; i++)
   {
     valor_pot = map(valor_pot,80,240,0,260); // mapeo de calibración
     valor_pot = buf[i];
   }
     Serial.print("Valor: ");  // imprime Mensaje:
     Serial.println(valor_pot);   // imprime buffer de mensaje        
   analogWrite(13, valor_pot); // manda la señal al led
   }
}
	
	
* Because the voltage of the potentiometer connected to the emitter is unstable because it is connected to a digital pin, it caused me an input variation in the data received by the receiver, but i was able to solve with the mapping function without much problem.


Finally we have as a result the following interaction between both modules connected wirelessly:

Next-Week 12 Previous-Week 10