Continued. The previous part .
Table of contents:
The choice of hardware and software is closely interrelated as "chicken and egg". Where to start, with iron, with software? If you have good hardware, but there are no drivers, libraries and software for it (IDE, firmware utilities, etc.), then it is useless, and vice versa.
Therefore, I am telling once again about the choice between the nRF24L01 + and ESP8266 for the connection of remote sensors with the central unit.
The fact is that the ESP8266 is not just a stupid WiFi adapter, it has a microcontroller onboard that is superior to Arduino in terms of power and memory. By default, the ESP8266 has a firmware in the form of a set of AT commands; in this case, ESP is used as a simple modem. But there are more advanced firmware, here ESP8266 can even act as a web server, and, of course, control sensors like Arduino.
However, all these advanced firmware have flaws that did not allow (in total with the hardware questions about which I already wrote) to apply ESP8266 in this project:
As a result, I did not find a ready-made suitable firmware, and I am not ready to create my own yet. The ESP8266 chip is an extensive and interesting topic.
In turn, standard AT firmware also has disadvantages:
On the other hand, the nRF24L01 + radio module is simple and straightforward, there is a RadioHead super library for working with it and no programming problems . The library is well documented, which is important.
RadioHead allows you to transfer data structures (and not just individual numbers), which is implemented in this project. Looking ahead, I’ll say RadioHead can reliably transfer data, with repetitions if it hasn’t reached the first time. All these things the library takes over.
To save energy, I use the Low Power Library , it is simple and contains only what you need.
Here is a piece of code:
// 2.402 GHz ( 2), 2Mbps, 0dBm rfdata.init(); // ( , ) rfdata.sendtoWait((uint8_t*)&dhtData, sizeof(dhtData), SERVER_ADDRESS); // LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);`
Everything!
In the case of the use of ESP8266 in the out-of-window sensor, I would be forced to create a WiFi access point and somehow transfer data (where is the firmware, where is the software?). Or allow the sensor to send data directly to the web server, and the central unit (which in this case stops playing the role of “central”) learn to read the data from there in order to display it on the board.
In other words, I went through more autonomy from the WiFi Internet and PHP + MySQL server. You can start “riveting” the weather station already without access to the Internet and / or hosting for the server, in this case you don’t need ESP8266, just add it later.
The Adafruit DHT Sensor Library is available for reading data from DHT sensors. Working with it is simple and straightforward.
The Adafruit BMP085 Unified library is suitable for the pressure sensor, which requires an abstract level library Adafruit Sensor .
All libraries have examples of sketches.
That's all with the theoretical part. “Our goals are clear, the objectives are defined. For the work, comrades! ”
Well, finally, after all the misrepresentations, we proceed to the assembly!
Note If you have never collected a weather station (oh well!), Then you can start without all the details at hand. For example, you can start without having a radio module and / or ESP8266. The barometric pressure sensor BMP180 may also be missing. Add later. True, in this case you will have to independently comment out in the sketch those code sections that are responsible for interacting with the missing blocks, but this is not so difficult. I'll show you how.
The main thing is that at least something gathered and earned, then more fun to continue.
As already mentioned, the central unit is based on the Arduino MEGA. We will also need:
You can buy a prototype card for desoldering from $ 1. Take a larger size to be enough for all connections. And once again: read the description before buying, not the picture.
A bounce-free fee can be purchased from $ 2. Take a larger size to be enough for all connections.
Connecting wires are of the types we need:
First of all, I disassembled the LCD-1604 scoreboard. First I soldered the pins to the board, then the connectors to the breadboard.
Bottom view.
Payal on influx without prior layout, so here no scheme will not be given. Do as it is more convenient, it will not be worse. Adhere only to the principle that the black wire is always the earth, the red is the “plus” of the power, the other colors as it is. It turned out so.
In order not to forget where there are any connectors, I “painted” with the white corrector sections of the board in the neighborhood and made the appropriate inscriptions. Ugly? But practical and fast, it's a prototype!
For more information about the display and how to work with it, google “Working with symbolic LCDs based on HD44780”. Note that you need to carefully consider the polarity of the power supply to the LCD indicator and that the supply voltage is in the range of + 4.5 ... 5.5 V. Inattentive attitude to this can lead to the indicator failure!
Pin LCD 1604 | Arduino MEGA | Arduino uno | Description |
---|---|---|---|
VSS | GND | GND | GND |
Vdd | 5 V | 5 V | 4.7 - 5.3V |
RS | 22 | four | A high level means that the signal at the outputs DB0 — DB7 is data, a low one — the command |
Rw | GND | GND | Defines the direction of the data (read / write). Since the operation of reading data from the indicator is usually unclaimed, it is possible to set a low level permanently at this input. |
E | 23 | five | A pulse with a duration of at least 500 ms on this pin determines the signal for reading / writing data from the pins DB0-DB7, RS and WR |
DB4 | 24 | eight | Incoming / outgoing data |
DB5 | 25 | 9 | |
DB6 | 26 | ten | |
DB7 | 27 | eleven | |
LED A + | + 5V or 220 ohm resistor → + 5VLED-A ![]() | ||
LED B- | GND | ||
V0 | GND or 10kΩ trimmer ![]() |
Software initialization will look like this:
// Arduino MEGA LiquidCrystal lcd(22, 23, 24, 25, 26, 27); // Arduino UNO LiquidCrystal lcd(4, 5, 8, 9, 10, 11);
Connecting temperature and humidity sensor DHT11 (SainSmart). Position the sensor face up, the findings will be described from left to right.
DHT11 | Arduino mega |
---|---|
DATA | Digital pin 2 (PWM) (see below DHTPIN) |
VCC | 3.3—5 V (5 V recommended, better external power) |
GND | GND |
Software initialization
#define DHTPIN 2 // Digital pin 2 (PWM) #define DHTTYPE DHT11 // . DHT.h // DHT dht(DHTPIN, DHTTYPE);
Connection of atmospheric pressure sensor BMP180 (barometer) + temperature via I2C / TWI interface.
BMP180 | Arduino mega |
---|---|
VCC | not connected |
GND | GND |
SCL | 21 (SCL) |
SDA | 20 (SDA) |
3.3 | 3.3 V |
For UNO: A4 (SDA), A5 (SCL).
// Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); // sensorID
Brief specifications:
Here is the pinout of the module.
Some advise you to immediately solder a 100nF ceramic capacitor (1µF, 10µF possible) to the RF power pins to avoid electrical interference.
Pinout nRF24L01 + (look at the top of the board where the chip, pins should be below):
pin 2 3.3V | pin 4 CSN | pin 6 MOSI | pin 8 IRQ |
pin 1 gnd | pin 3 CE | pin 5 sck | pin 7 MISO |
Connection for weather station:
Arduino mega | nRF24L01 + |
---|---|
3.3 V | VCC pin 2 (better external power) |
pin D8 | CE pin 3 (chip enable in) |
SS pin D53 | CSN pin 4 (chip select in) |
SCK pin D52 | SCK pin 5 (SPI clock in) |
MOSI pin D51 | SDI pin 6 (SPI Data in) |
MISO pin D50 | SDO pin 7 (SPI data out) |
IRQ pin 8 (Interrupt output) is not connected | |
GND | GND pin 1 (ground in) |
Programming of the radio module will be described in detail in the program part.
Pinout ESP8266 (look at the top of the board where the chips, pins should be below):
GND | GPIO2 | GPIO0 | Rx |
Tx | CH_PD | RESET | VCC |
ESP8266 Connection for Weather Station:
ESP8266 | Arduino mega |
---|---|
Tx | 10 pin (SoftwareSerial RX) |
Rx | 11 pin (SoftwareSerial TX) |
VCC | 3.3 V |
GND | GND |
CH_PD | Through 10K to 3.3V Arduino Resistor |
GPI0 | Not necessary. Through 10K to 3.3V Arduino Resistor |
GPI2 | Not necessary. Through 10K to 3.3V Arduino Resistor |
Central unit assembly. "Motherboard" cut out of a cardboard box from under the shoes and cogs for 3 screwed everything else to it.
As we see in this place, all the power is supplied from Arduino pins, i.e. Nothing goes directly to the power supply, and so far there is enough power.
Look like that's it. Forgot nothing.
Solder, connect. In the next part, a working sketch for the central unit will be shown and our weather station will already show something.
Source: https://habr.com/ru/post/425927/
All Articles