Compare commits
3
Commits
cb4411b40e
...
a795dfedc7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a795dfedc7 | ||
|
|
0d2625df7f | ||
|
|
bdecf0331c |
No files matched your search
@@ -1,3 +1,4 @@
|
||||
.vscode
|
||||
.DS_Store
|
||||
build
|
||||
.pio
|
||||
@@ -6,7 +6,7 @@
|
||||
2. Power consumption in the sleep mode approximately 2 uA.
|
||||
3. Transmits device identifier and battery voltage level on each touch event.
|
||||
4. Battery measurement through internal ADC with 1.1 V bandgap reference.
|
||||
5. Wake-up from power-down mode by external interrupt on falling edge.
|
||||
5. Wake-up from power-down mode by external interrupt on rising edge.
|
||||
6. Supports ATMega168, ATMega168P, ATMega168PB, ATMega328, ATMega328P, ATMega328PB.
|
||||
7. Easy installation into any standard touch pad enclosure.
|
||||
|
||||
@@ -25,9 +25,3 @@ In an existing PlatformIO project, run the following command to install the firm
|
||||
cd your_project
|
||||
git clone https://github.com/aZholtikov/zh_avr_touch_pad
|
||||
```
|
||||
|
||||
In the `platformio.ini`, select the target microcontroller environment and upload:
|
||||
|
||||
```bash
|
||||
pio run -e ATmega328P -t upload
|
||||
```
|
||||
@@ -11,6 +11,8 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
|
||||
[env:ATmega168P]
|
||||
platform = atmelavr
|
||||
@@ -25,6 +27,8 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
|
||||
[env:ATmega168PB]
|
||||
platform = atmelavr
|
||||
@@ -39,6 +43,8 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
|
||||
[env:ATmega328]
|
||||
platform = atmelavr
|
||||
@@ -53,6 +59,8 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
|
||||
[env:ATmega328P]
|
||||
platform = atmelavr
|
||||
@@ -67,6 +75,8 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
|
||||
[env:ATmega328PB]
|
||||
platform = atmelavr
|
||||
@@ -81,3 +91,5 @@ board_fuses.efuse = 0x07
|
||||
upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
https://github.com/aZholtikov/zh_rf_config
|
||||
+20
-7
@@ -3,6 +3,7 @@
|
||||
#include "avr/fuse.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "util/delay.h"
|
||||
#include "zh_rf_config.h"
|
||||
|
||||
#if defined(__AVR_ATmega328PB__)
|
||||
#ifndef SPCR
|
||||
@@ -31,7 +32,6 @@
|
||||
#define GATEWAY_CHANNEL 120
|
||||
#define GATEWAY_ADDRESS 0xDDEEFF
|
||||
#define DEVICE_ID 6
|
||||
#define DEVICE_TYPE 4
|
||||
|
||||
#define NRF_CMD_W_REGISTER 0x20
|
||||
#define NRF_CMD_W_TX_PAYLOAD 0xA0
|
||||
@@ -60,7 +60,7 @@
|
||||
/**
|
||||
* @brief Initialize INT1 external interrupt for the touch-pad wake-up signal.
|
||||
*
|
||||
* Configures PD3 as a falling-edge triggered external interrupt source and
|
||||
* Configures PD3 as a rising-edge triggered external interrupt source and
|
||||
* enables the INT1 interrupt mask bit. The ISR sets the send_request flag
|
||||
* to trigger a radio transmission from the main loop.
|
||||
*/
|
||||
@@ -164,6 +164,8 @@ static float zh_get_battery_voltage(void);
|
||||
|
||||
static volatile uint8_t send_request = 0;
|
||||
|
||||
zh_rf_sensor_transmitted_data_t transmitted_data = {DEVICE_ID, ZH_RF_SENSOR_TOUCH_SWITCH, 0, 0, 0, 0, 0};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cli();
|
||||
@@ -171,19 +173,28 @@ int main(void)
|
||||
zh_spi_init();
|
||||
zh_nrf24_init();
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
sleep_enable();
|
||||
sei();
|
||||
for (;;)
|
||||
{
|
||||
if (send_request == 1)
|
||||
{
|
||||
cli();
|
||||
send_request = 0;
|
||||
int16_t data[] = {DEVICE_ID, DEVICE_TYPE, (int16_t)(zh_get_battery_voltage() * 100.0), 0, 0, 0, 0};
|
||||
zh_nrf24_send((uint8_t *)data, sizeof(data));
|
||||
sei();
|
||||
transmitted_data.battery_voltage = (int16_t)(zh_get_battery_voltage() * 100.0);
|
||||
zh_nrf24_send((uint8_t *)&transmitted_data, sizeof(transmitted_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep_cpu();
|
||||
cli();
|
||||
if (send_request == 0)
|
||||
{
|
||||
sleep_enable();
|
||||
sei();
|
||||
sleep_cpu();
|
||||
}
|
||||
sei();
|
||||
sleep_disable();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -225,6 +236,8 @@ static void zh_nrf24_init(void)
|
||||
_delay_ms(100);
|
||||
DDRB |= (1 << PB1);
|
||||
PORTB &= ~(1 << PB1);
|
||||
DDRD &= ~(1 << PD2);
|
||||
PORTD |= (1 << PD2);
|
||||
uint64_t gateway_address = GATEWAY_ADDRESS;
|
||||
zh_nrf24_write_register(NRF_REG_CONFIG, 0x00);
|
||||
zh_nrf24_write_register(NRF_REG_EN_AA, 0x01);
|
||||
@@ -249,7 +262,7 @@ static void zh_nrf24_send(uint8_t *buf, uint8_t size)
|
||||
uint8_t count = 0;
|
||||
while ((PIND & (1 << PD2)) != 0)
|
||||
{
|
||||
if (++count > 50)
|
||||
if (++count > 100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user