Version 1.0

Initial version.
This commit is contained in:
Alexey Zholtikov 2022-12-09 17:06:53 +03:00
parent 6fedef7560
commit 5350034e63
10 changed files with 5610 additions and 1 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.pio
.vscode
.DS_Store

View File

@ -1,2 +1,44 @@
# RF-Climate-Sensor-BMP280
# RF climate sensor (BMP280)
Climate sensor on ATmega328 + RF24 + BMP280.
## Features
1. Power consumption in sleep mode approximately 5 μA. Up to 3 years of operation on one CR2450 battery (estimated).
2. Transmits battery level charge, temperature and air pressure every 5 min (can be changed up to 65535 seconds).
3. Automatic restart in case of a hang-up.
## Note
A gateway is required. For details see "RF - ESP-NOW Gateway".
## Full config example for Home Assistant
```yml
mqtt:
sensor:
- name: "NAME"
device_class: "voltage"
unit_of_measurement: "V"
state_topic: "homeassistant/rf_sensor/ID/bmp280"
value_template: "{{ value_json.battery }}"
expire_after: 375
force_update: true
qos: 2
- name: "NAME"
device_class: "temperature"
unit_of_measurement: "°C"
state_topic: "homeassistant/rf_sensor/ID/bmp280"
value_template: "{{ value_json.temperature }}"
expire_after: 375
force_update: true
qos: 2
- name: "NAME"
evice_class: "pressure"
unit_of_measurement: "мм"
state_topic: "homeassistant/rf_sensor/ID/bmp280"
value_template: "{{ value_json.pressure }}"
expire_after: 375
force_update: true
qos: 2
```

BIN
hardware/BOM.xlsx Normal file

Binary file not shown.

BIN
hardware/CR2450 holder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
hardware/Gerber.zip Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 KiB

5415
hardware/Schematic.pdf Normal file

File diff suppressed because it is too large Load Diff

65
platformio.ini Normal file
View File

@ -0,0 +1,65 @@
[env:ATmega328]
platform = atmelavr
board = ATmega328
board_build.mcu = atmega328
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = usbasp
build_flags =
-D portUSE_WDTO=WDTO_1S
-D BMP280=2
-D ID=$UNIX_TIME
board_fuses.hfuse = 0xDE
board_fuses.lfuse = 0xE2
board_fuses.efuse = 0x07
upload_flags =
-Pusb
-e
lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.6
feilipu/FreeRTOS@^10.5.0-0
nrf24/RF24@^1.4.5
[env:ATmega328P]
platform = atmelavr
board = ATmega328P
board_build.mcu = atmega328p
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = usbasp
build_flags =
-D portUSE_WDTO=WDTO_1S
-D BMP280=2
-D ID=$UNIX_TIME
board_fuses.hfuse = 0xDE
board_fuses.lfuse = 0xE2
board_fuses.efuse = 0x07
upload_flags =
-Pusb
-e
lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.6
feilipu/FreeRTOS@^10.5.0-0
nrf24/RF24@^1.4.5
[env:ATmega328PB]
platform = atmelavr
board = ATmega328PB
board_build.mcu = atmega328pb
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = usbasp
build_flags =
-D portUSE_WDTO=WDTO_1S
-D BMP280=2
-D ID=$UNIX_TIME
board_fuses.hfuse = 0xDE
board_fuses.lfuse = 0xE2
board_fuses.efuse = 0x07
upload_flags =
-Pusb
-e
lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.6
feilipu/FreeRTOS@^10.5.0-0
nrf24/RF24@^1.4.5

84
src/main.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "Arduino.h"
#include "Arduino_FreeRTOS.h"
#include "Adafruit_BMP280.h"
#include "RF24.h"
typedef struct
{
int16_t sensor_id{0};
int16_t sensor_type{0};
int16_t value_1{0};
int16_t value_2{0};
int16_t value_3{0};
int16_t value_4{0};
int16_t value_5{0};
} transmitted_data_t;
void sendSensorsValue(void *pvParameters);
float getBatteryLevelCharge(void);
RF24 radio(9, 10);
Adafruit_BMP280 bmp;
void setup()
{
ADCSRA &= ~(1 << ADEN);
radio.begin();
radio.setChannel(120);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MAX);
radio.setPayloadSize(14);
radio.setAddressWidth(3);
radio.setCRCLength(RF24_CRC_8);
radio.setRetries(15, 15);
radio.openWritingPipe(0xDDEEFF);
radio.powerDown();
bmp.begin(0x76);
bmp.setSampling(Adafruit_BMP280::MODE_FORCED,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16);
xTaskCreate(sendSensorsValue, "Send Sensors Value", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
}
void loop()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
portENTER_CRITICAL();
sleep_enable();
portEXIT_CRITICAL();
sleep_cpu();
sleep_reset();
}
void sendSensorsValue(void *pvParameters)
{
(void)pvParameters;
for (;;)
{
transmitted_data_t sensor{abs((int16_t)ID), BMP280};
bmp.takeForcedMeasurement();
sensor.value_1 = getBatteryLevelCharge() * 100;
sensor.value_2 = bmp.readTemperature();
sensor.value_3 = bmp.readPressure() * 0.00750062;
radio.powerUp();
radio.flush_tx();
radio.write(&sensor, sizeof(transmitted_data_t));
radio.powerDown();
vTaskDelay(300);
}
vTaskDelete(NULL);
}
float getBatteryLevelCharge()
{
ADMUX = (1 << REFS0) | (1 << MUX3) | (1 << MUX2) | (1 << MUX1);
ADCSRA |= (1 << ADEN);
delay(10);
ADCSRA |= (1 << ADSC);
while (bit_is_set(ADCSRA, ADSC))
;
ADCSRA &= ~(1 << ADEN);
float value = ((1024 * 1.1) / (ADCL + ADCH * 256));
return value;
}