Compare commits
No commits in common. "main" and "v1.0" have entirely different histories.
24
README.md
24
README.md
@ -1,10 +1,28 @@
|
|||||||
# nRF24 touch pad
|
# RF touch switch
|
||||||
|
|
||||||
Touch pad on ATmega328 + nRF24.
|
Touch switch on ATmega168/328 + RF24.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
1. Power consumption in sleep mode approximately 10 μA. Up to 2 years of operation on one CR2032 battery (estimated).
|
1. Power consumption in sleep mode approximately 10 μA. Up to 2 years of operation on one CR2032 battery (estimated).
|
||||||
2. When triggered transmits battery level charge.
|
2. When triggered transmits battery level charge.
|
||||||
3. Automatic restart in case of a hang-up.
|
3. Automatic restart in case of a hang-up.
|
||||||
4. Easy installation into any standard touch pad enclosure.
|
4. Easy installation into any standard touch switch enclosure.
|
||||||
|
|
||||||
|
## 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/touch_switch"
|
||||||
|
value_template: "{{ value_json.battery }}"
|
||||||
|
force_update: true
|
||||||
|
qos: 2
|
||||||
|
```
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 494 KiB |
Binary file not shown.
Before Width: | Height: | Size: 915 KiB |
@ -1,10 +1,13 @@
|
|||||||
[env:ATmega328]
|
[env:ATmega168]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = ATmega328
|
board = ATmega168
|
||||||
board_build.mcu = atmega328
|
board_build.mcu = atmega168
|
||||||
board_build.f_cpu = 8000000L
|
board_build.f_cpu = 8000000L
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
board_fuses.efuse = 0x07
|
board_fuses.efuse = 0x07
|
||||||
@ -12,9 +15,69 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
nrf24/RF24@^1.4.5
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
|
||||||
|
[env:ATmega168P]
|
||||||
|
platform = atmelavr
|
||||||
|
board = ATmega168P
|
||||||
|
board_build.mcu = atmega168p
|
||||||
|
board_build.f_cpu = 8000000L
|
||||||
|
framework = arduino
|
||||||
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
|
board_fuses.hfuse = 0xDE
|
||||||
|
board_fuses.lfuse = 0xE2
|
||||||
|
board_fuses.efuse = 0x07
|
||||||
|
upload_flags =
|
||||||
|
-Pusb
|
||||||
|
-e
|
||||||
|
lib_deps =
|
||||||
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
|
nrf24/RF24@^1.4.5
|
||||||
|
|
||||||
|
[env:ATmega168PB]
|
||||||
|
platform = atmelavr
|
||||||
|
board = ATmega168PB
|
||||||
|
board_build.mcu = atmega168pb
|
||||||
|
board_build.f_cpu = 8000000L
|
||||||
|
framework = arduino
|
||||||
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
|
board_fuses.hfuse = 0xDE
|
||||||
|
board_fuses.lfuse = 0xE2
|
||||||
|
board_fuses.efuse = 0x07
|
||||||
|
upload_flags =
|
||||||
|
-Pusb
|
||||||
|
-e
|
||||||
|
lib_deps =
|
||||||
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
|
nrf24/RF24@^1.4.5
|
||||||
|
|
||||||
|
[env:ATmega328]
|
||||||
|
platform = atmelavr
|
||||||
|
board = ATmega328
|
||||||
|
board_build.mcu = atmega328
|
||||||
|
board_build.f_cpu = 8000000L
|
||||||
|
framework = arduino
|
||||||
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
|
board_fuses.hfuse = 0xDE
|
||||||
|
board_fuses.lfuse = 0xE2
|
||||||
|
board_fuses.efuse = 0x07
|
||||||
|
upload_flags =
|
||||||
|
-Pusb
|
||||||
|
-e
|
||||||
|
lib_deps =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
|
nrf24/RF24@^1.4.5
|
||||||
|
|
||||||
[env:ATmega328P]
|
[env:ATmega328P]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -23,6 +86,9 @@ board_build.mcu = atmega328p
|
|||||||
board_build.f_cpu = 8000000L
|
board_build.f_cpu = 8000000L
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
board_fuses.efuse = 0x07
|
board_fuses.efuse = 0x07
|
||||||
@ -30,9 +96,8 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
nrf24/RF24@^1.4.5
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
|
||||||
|
|
||||||
[env:ATmega328PB]
|
[env:ATmega328PB]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -41,6 +106,9 @@ board_build.mcu = atmega328pb
|
|||||||
board_build.f_cpu = 8000000L
|
board_build.f_cpu = 8000000L
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
|
build_flags =
|
||||||
|
-D TOUCH_SWITCH=4
|
||||||
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
board_fuses.efuse = 0x07
|
board_fuses.efuse = 0x07
|
||||||
@ -48,6 +116,5 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
feilipu/FreeRTOS@^10.5.0-0
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
nrf24/RF24@^1.4.5
|
||||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
|
||||||
|
82
src/main.cpp
82
src/main.cpp
@ -3,41 +3,23 @@
|
|||||||
#include "RF24.h"
|
#include "RF24.h"
|
||||||
#include "avr/interrupt.h"
|
#include "avr/interrupt.h"
|
||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
#include "zh_config.h"
|
|
||||||
|
|
||||||
#define ID 1 // Unique ID of the device on the network.
|
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 sendButtonPushing(void *pvParameters);
|
||||||
|
float getBatteryLevelCharge(void);
|
||||||
|
|
||||||
RF24 radio(9, 10);
|
RF24 radio(9, 10);
|
||||||
SemaphoreHandle_t pad_pushing;
|
SemaphoreHandle_t buttonSemaphore;
|
||||||
|
|
||||||
float get_battery_level_charge()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
return (1024 * 1.1) / (ADCL + ADCH * 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
void send_pad_pushing(void *pvParameters)
|
|
||||||
{
|
|
||||||
(void)pvParameters;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
xSemaphoreTake(pad_pushing, portMAX_DELAY);
|
|
||||||
rf_transmitted_data_t sensor{ID, RFST_TOUCH_PAD};
|
|
||||||
sensor.value_1 = get_battery_level_charge() * 100;
|
|
||||||
radio.powerUp();
|
|
||||||
radio.flush_tx();
|
|
||||||
radio.write(&sensor, sizeof(rf_transmitted_data_t));
|
|
||||||
radio.powerDown();
|
|
||||||
sei();
|
|
||||||
}
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -54,8 +36,8 @@ void setup()
|
|||||||
radio.setRetries(15, 15);
|
radio.setRetries(15, 15);
|
||||||
radio.openWritingPipe(0xDDEEFF);
|
radio.openWritingPipe(0xDDEEFF);
|
||||||
radio.powerDown();
|
radio.powerDown();
|
||||||
pad_pushing = xSemaphoreCreateBinary();
|
buttonSemaphore = xSemaphoreCreateBinary();
|
||||||
xTaskCreate(send_pad_pushing, "Send Pad Pushing", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
|
xTaskCreate(sendButtonPushing, "Send Button Pushing", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@ -68,8 +50,38 @@ void loop()
|
|||||||
sleep_reset();
|
sleep_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendButtonPushing(void *pvParameters)
|
||||||
|
{
|
||||||
|
(void)pvParameters;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
xSemaphoreTake(buttonSemaphore, portMAX_DELAY);
|
||||||
|
transmitted_data_t sensor{abs((int16_t)ID), TOUCH_SWITCH};
|
||||||
|
sensor.value_1 = getBatteryLevelCharge() * 100;
|
||||||
|
radio.powerUp();
|
||||||
|
radio.flush_tx();
|
||||||
|
radio.write(&sensor, sizeof(transmitted_data_t));
|
||||||
|
radio.powerDown();
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
ISR(INT1_vect)
|
ISR(INT1_vect)
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
xSemaphoreGiveFromISR(pad_pushing, NULL);
|
xSemaphoreGiveFromISR(buttonSemaphore, NULL);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user