Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2022:long_distance_communication [2023/01/19 18:23]
ioan.turturea
iothings:proiecte:2022:long_distance_communication [2023/01/20 08:14] (current)
ioan.turturea
Line 3: Line 3:
 ====== Introduction ====== ====== Introduction ======
  
-This project has as final purpose, transmitting data over a long range, to a node which is an internet gate (in this case the ESP).+This project has as final purpose, transmitting ​sensor ​data over a long distance, to a node which is an internet gate (in this case the ESP32 nodeand from there to plot received data on a chart from a website created by the ESP32.
  
 ====== Hardware ====== ====== Hardware ======
  
-== Bill of materials (BOM) ==+===== Bill of materials (BOM) =====
  
 - 1 x ESP32 WROVER KIT (in this case: T18 3.0) - 1 x ESP32 WROVER KIT (in this case: T18 3.0)
Line 22: Line 22:
  
  
-== Schematic ==+===== Schematic ​=====
  
 {{schematic.png?​700x300}} {{schematic.png?​700x300}}
Line 28: Line 28:
 ---- ----
  
-== Experimental setup ==+===== Experimental setup =====
  
 {{experiment.png?​700x300}} {{experiment.png?​700x300}}
Line 34: Line 34:
 ---- ----
  
-== Description of the setup ==+===== Description of the setup =====
  
-1. nRF24L01+ PA + LNA+==== 1. nRF24L01+ PA + LNA ====
  
 It is a low cost wireless communication module, created by Nordic Semiconductor,​ that comes with an antenna for long distance range. It is a low cost wireless communication module, created by Nordic Semiconductor,​ that comes with an antenna for long distance range.
Line 42: Line 42:
 It's range varies from 250m to 1100m. It's range varies from 250m to 1100m.
 Maybe the most helpful feature is has is that the communication range can be traded-off with the data bandwidth. Possible combinations are: Maybe the most helpful feature is has is that the communication range can be traded-off with the data bandwidth. Possible combinations are:
 +
 2Mbps for 250 meters, 2Mbps for 250 meters,
 +
 1Mbps for 500 meters, ​ 1Mbps for 500 meters, ​
 +
 250kbps for 1100 meters (open field) 250kbps for 1100 meters (open field)
 +
 It's frequency in the 2.4 GHz ISM band, or more precisely, any frequency between 2.400 and 2.525 GHz (2400 to 2525 MHz).  It's frequency in the 2.4 GHz ISM band, or more precisely, any frequency between 2.400 and 2.525 GHz (2400 to 2525 MHz). 
 Also one channel has a bandwidth of almost 1MHz, means that it gives us 125 possible channels with a 1MHz spacing. Also one channel has a bandwidth of almost 1MHz, means that it gives us 125 possible channels with a 1MHz spacing.
Line 52: Line 56:
 Also it is worth mentioning that one device can communicate up to 8 devices. Also it is worth mentioning that one device can communicate up to 8 devices.
  
 +
 +{{:​iothings:​proiecte:​2022:​nrf24l01.jpg?​200x200|}}
 +
 +{{:​iothings:​proiecte:​2022:​pinout-nrf24l01.png?​400|}}
 +
 +
 +
 +==== 2. Sound sensor module ====
 +
 +This is very cheap sound sensor, with a very simple interface, with digital output.
 +This module contains a trigger Schmitt, so it can only detect sound presence and can not be used to measure sound intensity, frequency or any analog parameter.\\
 +It also contains an potentiometer to adjust the offset of the amplifier for the specific application.\\
 +
 +{{:​iothings:​proiecte:​2022:​senzor-sunet.jpg?​200|}}
 +
 +
 +
 +===== Real setup =====
 +
 +ESP32 setup:\\
 +{{:​iothings:​proiecte:​2022:​img_20230118_163822_2.jpg?​500x300|}}
 +
 +Arduino setup:\\
 +{{:​iothings:​proiecte:​2022:​img_20230118_164223_2.jpg?​500x300|}}
 +
 +
 +As can the seen, the Arduino board has to be powered from battery because it will be placed far away from the computer.
  
 ====== Software ====== ====== Software ======
  
-Because the nRF24L01 module is using SPI communication,​ first step is to assure the ESP32 TTY board supports SPI communication and find out pins of this specific module board. Easy task, just run a small script to findout SPI pinouts'​MISO'​'​MOSI',​ '​SS',​ '​CLK'​.+Tools usedArduino IDEnRF24L01 library.\\
  
  
  
 +Because the nRF24L01 module is using SPI communication,​ step zero is to assure the ESP32 TTY board supports SPI communication and find out pins of this specific module board. Easy task, just run a small script to findout SPI pinouts: '​MISO',​ '​MOSI',​ '​SS',​ '​CLK'​.
 +
 +Next step is to establish the wireless communication between the 2 master modules: Arduino and ESP32.\\
 +Arduino is the transmitter and ESP32 is the receiver.\\
 +
 +A demo code for the Arduino (Uno - matters only for the pinout) can be seen in the code appendix ((Arduino transmitter code example)).\\
 +And the ESP32 will be the received, code example here ((ESP32 code receiver)).\\
 +
 +(note: nRF24L01 module can operate in full duplex mode, but in this project, only one way communication was used).\\
 +
 +It is very important to test the setup in the environment in which will be used, because the distance between the 2 nodes can vary from 1100m in open field to even meter in, for example, concrete walls on the way.
 +
 +
 +
 +After the communication between the modules was established,​ it is time to send real data from the sound sensor. \\
 +As stated in the description of the sound sensor module, it can only transmit digital level to detect sound, not reply sound fidelity. \\
 +So in order to hack this ;-) a simple script to count time while sound level is high was used.\\
 +Visualizing such data in the Serial Plotter, looks like a real microphone recording. Code is the appendix ((sound sensor))
 +
 +{{:​iothings:​proiecte:​2022:​plotter_serial.png?​700x200|}}
 +
 +
 +
 +Last step is to create a web page hosted by the ESP32, that will be accessed by a PC to view collected data on charts.\\ ​
 +For this, laboratory 3 was used:
 +[[https://​ocw.cs.pub.ro/​courses/​iothings/​laboratoare/​2022/​lab3]]
 +
 +
 +Final information plotted in a chart on the webpage look like:\\
 +{{:​iothings:​proiecte:​2022:​chart.png?​600|}}
  
 ====== Bibliography ====== ====== Bibliography ======
Line 65: Line 126:
  
 [[https://​lastminuteengineers.com/​nrf24l01-arduino-wireless-communication/​]] [[https://​lastminuteengineers.com/​nrf24l01-arduino-wireless-communication/​]]
 +
 +
 +====== Appendix ======
 +
 +Arduino transmitter code example:\\
 +
 +<​code>​
 +#include <​SPI.h>​
 +#include "​nRF24L01.h"​
 +#include "​RF24.h"​
 +char msg[10] = "​Hello!";​
 +
 +#define CE_PIN 9
 +#define CSN_PIN 10
 +
 +RF24 radio(CE_PIN,​ CSN_PIN);
 +
 +const uint64_t pipe = 0xE8E8F0F0E1LL;​
 +
 +void setup(void){ ​
 +  radio.begin();​
 +  radio.setChannel(2);​
 +  radio.setPayloadSize(7);​
 +  radio.setDataRate(RF24_250KBPS);​
 +  radio.openWritingPipe(pipe);​
 +}
 +
 +void loop(void)
 +{    ​
 +    radio.write(msg,​ 10);    ​
 +    delay(100);
 +}
 +</​code> ​
 +
 +
 +ESP32 received code example:\\
 +
 +<​code>​
 +#include <​SPI.h>​
 +#include "​nRF24L01.h"​
 +#include "​RF24.h"​
 +char msg[10];
 +#define CE_PIN 4
 +#define CSN_PIN 5
 +RF24 radio(CE_PIN,​ CSN_PIN);
 +const uint64_t pipe = 0xE8E8F0F0E1LL;​
 +
 +void setup(void){
 + ​Serial.begin(115200);​
 + ​radio.begin();​
 + ​radio.setChannel(2);​
 + ​radio.setPayloadSize(7);​
 + ​radio.setDataRate(RF24_250KBPS);​
 + ​radio.openReadingPipe(1,​pipe);​
 + ​radio.startListening();​
 +}
 +
 +void loop(void){
 + if (radio.available()){  ​
 +     ​radio.read(msg,​ 6);      ​
 +     ​Serial.println(msg);​
 +     ​delay(100);​
 + }
 + else{
 + }
 +}
 +</​code>​
 +
 +
 +Sound sensor code:
 +<​code>​
 +int soundPin = A0;
 +
 +const int OUT_PIN = 8;
 +const int SAMPLE_TIME = 10;
 +unsigned long MillisCurrent;​
 +unsigned long MillisLast;
 +unsigned long MillisElapsed;​
 +int SampleBufferValue = 0;
 +
 +void setup(void){
 + ​Serial.begin(115200);​
 +}
 +
 +void loop(void)
 +{
 +    MillisCurrent = millis();
 +    MillisElapsed = MillisCurrent - MillisLast;
 +    if(digitalRead(OUT_PIN) == HIGH)
 +    {
 +      SampleBufferValue++;​
 +    }
 +
 +    if(MillisElapsed > SAMPLE_TIME){
 +      Serial.println(SampleBufferValue);​
 +      SampleBufferValue = 0;
 +      MillisLast = MillisCurrent;​
 +    }    ​
 +}
 +</​code>​
  
iothings/proiecte/2022/long_distance_communication.1674145403.txt.gz · Last modified: 2023/01/19 18:23 by ioan.turturea
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0