Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c200e8658d | |||
4886ba5547 |
12
README.md
12
README.md
@ -1,16 +1,10 @@
|
||||
# RF touch switch
|
||||
# nRF24 touch pad
|
||||
|
||||
Touch switch on ATmega168/328 + nRF24.
|
||||
Touch pad on ATmega328 + nRF24.
|
||||
|
||||
## Features
|
||||
|
||||
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.
|
||||
3. Automatic restart in case of a hang-up.
|
||||
4. Easy installation into any standard touch switch enclosure.
|
||||
|
||||
## Note
|
||||
|
||||
A gateway is required. For details see [RF Gateway](https://github.com/aZholtikov/RF-Gateway).
|
||||
|
||||
Any feedback via [e-mail](mailto:github@zh.com.ru) would be appreciated. Or... [Buy me a coffee](https://paypal.me/aZholtikov).
|
||||
4. Easy installation into any standard touch pad enclosure.
|
||||
|
BIN
hardware/Assy 1.jpeg
Normal file
BIN
hardware/Assy 1.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 494 KiB |
BIN
hardware/Assy 2.jpeg
Normal file
BIN
hardware/Assy 2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 915 KiB |
@ -1,63 +1,3 @@
|
||||
[env:ATmega168]
|
||||
platform = atmelavr
|
||||
board = ATmega168
|
||||
board_build.mcu = atmega168
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega168P]
|
||||
platform = atmelavr
|
||||
board = ATmega168P
|
||||
board_build.mcu = atmega168p
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega168PB]
|
||||
platform = atmelavr
|
||||
board = ATmega168PB
|
||||
board_build.mcu = atmega168pb
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega328]
|
||||
platform = atmelavr
|
||||
board = ATmega328
|
||||
@ -65,8 +5,6 @@ board_build.mcu = atmega328
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
@ -74,9 +12,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
||||
|
||||
[env:ATmega328P]
|
||||
platform = atmelavr
|
||||
@ -85,8 +23,6 @@ board_build.mcu = atmega328p
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
@ -94,9 +30,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
||||
|
||||
[env:ATmega328PB]
|
||||
platform = atmelavr
|
||||
@ -105,8 +41,6 @@ board_build.mcu = atmega328pb
|
||||
board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
board_fuses.efuse = 0x07
|
||||
@ -114,6 +48,6 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
http://git.zh.com.ru/alexey.zholtikov/zh_config.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_nrf24.git
|
||||
http://git.zh.com.ru/alexey.zholtikov/arduino_free_rtos.git
|
91
src/main.cpp
91
src/main.cpp
@ -3,22 +3,44 @@
|
||||
#include "RF24.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "semphr.h"
|
||||
#include "EEPROM.h"
|
||||
#include "ZHConfig.h"
|
||||
#include "zh_config.h"
|
||||
|
||||
void sendButtonPushing(void *pvParameters);
|
||||
float getBatteryLevelCharge(void);
|
||||
void loadId(void);
|
||||
|
||||
int16_t id{abs((int16_t)ID)};
|
||||
#define ID 1 // Unique ID of the device on the network.
|
||||
|
||||
RF24 radio(9, 10);
|
||||
SemaphoreHandle_t buttonSemaphore;
|
||||
SemaphoreHandle_t pad_pushing;
|
||||
|
||||
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()
|
||||
{
|
||||
loadId();
|
||||
|
||||
EICRA |= (1 << ISC11) | (1 << ISC10);
|
||||
EIMSK |= (1 << INT1);
|
||||
ADCSRA &= ~(1 << ADEN);
|
||||
@ -32,8 +54,8 @@ void setup()
|
||||
radio.setRetries(15, 15);
|
||||
radio.openWritingPipe(0xDDEEFF);
|
||||
radio.powerDown();
|
||||
buttonSemaphore = xSemaphoreCreateBinary();
|
||||
xTaskCreate(sendButtonPushing, "Send Button Pushing", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
|
||||
pad_pushing = xSemaphoreCreateBinary();
|
||||
xTaskCreate(send_pad_pushing, "Send Pad Pushing", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@ -46,51 +68,8 @@ void loop()
|
||||
sleep_reset();
|
||||
}
|
||||
|
||||
void sendButtonPushing(void *pvParameters)
|
||||
{
|
||||
(void)pvParameters;
|
||||
for (;;)
|
||||
{
|
||||
xSemaphoreTake(buttonSemaphore, portMAX_DELAY);
|
||||
rf_transmitted_data_t sensor{id, RFST_TOUCH_SWITCH};
|
||||
sensor.value_1 = getBatteryLevelCharge() * 100;
|
||||
radio.powerUp();
|
||||
radio.flush_tx();
|
||||
radio.write(&sensor, sizeof(rf_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);
|
||||
return (1024 * 1.1) / (ADCL + ADCH * 256);
|
||||
}
|
||||
|
||||
void loadId()
|
||||
{
|
||||
cli();
|
||||
if (EEPROM.read(511) == 254)
|
||||
EEPROM.get(0, id);
|
||||
else
|
||||
{
|
||||
EEPROM.write(511, 254);
|
||||
EEPROM.put(0, id);
|
||||
}
|
||||
delay(50);
|
||||
sei();
|
||||
}
|
||||
|
||||
ISR(INT1_vect)
|
||||
{
|
||||
cli();
|
||||
xSemaphoreGiveFromISR(buttonSemaphore, NULL);
|
||||
xSemaphoreGiveFromISR(pad_pushing, NULL);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user