Sets transmitting power to +8dB
|
|
@ -26,6 +26,8 @@
|
|||
// Interval between advertising packets.
|
||||
// From the specs, this value has to be greater or equal 20ms.
|
||||
#define PRST_BLE_ADV_INTERVAL_IN_MS 30
|
||||
// Possible values are ..., -8, -4, 0, 4, 8.
|
||||
#define PRST_BLE_ADV_TX_POWER 8
|
||||
|
||||
// PWM.
|
||||
#define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 5)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "app_timer.h"
|
||||
#include "ble_advdata.h"
|
||||
#include "bsp.h"
|
||||
#include "nordic_common.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_rtc.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "prst/adc.h"
|
||||
#include "prst/ble.h"
|
||||
#include "prst/pwm.h"
|
||||
|
|
@ -22,34 +14,30 @@
|
|||
#include "prst/shtc3.h"
|
||||
#include "prst_config.h"
|
||||
|
||||
// #define DEAD_BEEF 0xDEADBEEF
|
||||
// void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) {
|
||||
// app_error_handler(DEAD_BEEF, line_num, p_file_name);
|
||||
// }
|
||||
|
||||
// A small wrap-around counter for deduplicating BLE packets on the receiver.
|
||||
static uint8_t run_counter = 0;
|
||||
|
||||
static void log_init(void) {
|
||||
ret_code_t err_code = NRF_LOG_INIT(NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
|
||||
NRF_LOG_DEFAULT_BACKENDS_INIT();
|
||||
NRF_LOG_INFO("Log inited");
|
||||
NRF_LOG_INFO("Log inited.");
|
||||
}
|
||||
|
||||
static void leds_init(void) {
|
||||
static void gpio_init(void) {
|
||||
nrf_gpio_cfg_output(PRST_LED_PIN);
|
||||
NRF_LOG_INFO("Leds inited");
|
||||
nrf_gpio_cfg_output(PRST_FAST_DISCH_PIN);
|
||||
NRF_LOG_INFO("GPIO pins inited.");
|
||||
}
|
||||
|
||||
#define FPU_EXCEPTION_MASK 0x0000009F
|
||||
|
||||
static void power_management_init(void) {
|
||||
ret_code_t err_code;
|
||||
err_code = nrf_pwr_mgmt_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
APP_ERROR_CHECK(nrf_pwr_mgmt_init());
|
||||
NRF_LOG_INFO("GPIO pins inited.");
|
||||
}
|
||||
|
||||
// This FPU exception mask trick is recommended for avoiding unwanted
|
||||
// interupts from the floating point unit. This would be pretty bad,
|
||||
// since it would wake us up from deep sleep for nothing.
|
||||
#define FPU_EXCEPTION_MASK 0x0000009F
|
||||
static void power_manage(void) {
|
||||
__set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK));
|
||||
(void)__get_FPSCR();
|
||||
|
|
@ -57,8 +45,13 @@ static void power_manage(void) {
|
|||
nrf_pwr_mgmt_run();
|
||||
}
|
||||
|
||||
// Here we need to be extra careful with what operations we do. This callback
|
||||
// has to return fast-ish, otherwise we hit some hard exceptions.
|
||||
// This is the RTC callback in which we do all of our work as quickly as
|
||||
// possible:
|
||||
// - Measure the soil moisture;
|
||||
// - Measure the air temperature and humidity;
|
||||
// - Encode the measurements into the BLE advertisement packet;
|
||||
// - Turn on BLE advertising for a while;
|
||||
// - Turn everything off and return back to sleep.
|
||||
static void rtc_callback() {
|
||||
nrf_gpio_pin_set(PRST_LED_PIN);
|
||||
prst_shtc3_read_t temp_humi = prst_shtc3_read();
|
||||
|
|
@ -71,7 +64,6 @@ static void rtc_callback() {
|
|||
nrf_gpio_pin_clear(PRST_FAST_DISCH_PIN);
|
||||
prst_ble_update_adv_data(batt_read.millivolts, temp_humi.temp_millicelcius,
|
||||
temp_humi.humidity, soil_read.relative, run_counter);
|
||||
NRF_LOG_FLUSH();
|
||||
prst_adv_start();
|
||||
nrf_delay_ms(PRST_BLE_ADV_TIME_IN_MS);
|
||||
prst_adv_stop();
|
||||
|
|
@ -82,8 +74,7 @@ static void rtc_callback() {
|
|||
|
||||
int main(void) {
|
||||
log_init();
|
||||
nrf_gpio_cfg_output(PRST_FAST_DISCH_PIN);
|
||||
leds_init();
|
||||
gpio_init();
|
||||
power_management_init();
|
||||
prst_ble_init();
|
||||
prst_adc_init();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
// 10 bits resoltuion.
|
||||
#define PRST_ADC_RESOLUTION 10
|
||||
|
||||
// #define PRST_ADC_BATT_INPUT NRF_SAADC_INPUT_VDD
|
||||
#define PRST_ADC_BATT_INPUT NRF_SAADC_INPUT_VDD
|
||||
#define PRST_ADC_BATT_CHANNEL 0
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// I previously did a hacky linear regression to estimate them, but I'm
|
||||
// not super sure how useful that is.
|
||||
#define PRST_SOIL_WET 200
|
||||
#define PRST_SOIL_DRY 500
|
||||
#define PRST_SOIL_DRY 450
|
||||
|
||||
typedef struct prst_adc_batt_val {
|
||||
int16_t raw;
|
||||
|
|
|
|||
|
|
@ -152,9 +152,9 @@ void prst_ble_update_adv_data(uint16_t batt_millivolts,
|
|||
}
|
||||
|
||||
void prst_adv_start() {
|
||||
ret_code_t err_code;
|
||||
err_code = sd_ble_gap_adv_start(adv_handle_, PRST_CONN_CFG_TAG);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
APP_ERROR_CHECK(sd_ble_gap_adv_start(adv_handle_, PRST_CONN_CFG_TAG));
|
||||
APP_ERROR_CHECK(sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV,
|
||||
adv_handle_, PRST_BLE_ADV_TX_POWER));
|
||||
#if PRST_BLE_DEBUG
|
||||
NRF_LOG_INFO("[ble] Advertising started.\n");
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -34,8 +34,14 @@ prst_shtc3_read_t prst_shtc3_read() {
|
|||
// Wake the sensor up.
|
||||
write_cmd(PRST_SHTC3_CMD_WAKEUP);
|
||||
nrf_delay_ms(1);
|
||||
|
||||
// Request measurement.
|
||||
write_cmd(PRST_SHTC3_CMD_MEASURE_TFIRST_LOW_POWER);
|
||||
write_cmd(PRST_SHTC3_CMD_MEASURE_TFIRST_NORMAL);
|
||||
|
||||
// Reading in normal (not low power) mode can take up to 12.1 ms, according to
|
||||
// the datasheet.
|
||||
nrf_delay_ms(15);
|
||||
|
||||
// Read temp and humidity.
|
||||
while (nrf_drv_twi_rx(&twi_, PRST_SHTC3_ADDR, buff, 6) != 0) {
|
||||
nrf_delay_ms(10);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#define PRST_SHTC3_CMD_SLEEP 0xb098
|
||||
#define PRST_SHTC3_CMD_WAKEUP 0x3517
|
||||
#define PRST_SHTC3_CMD_MEASURE_TFIRST_LOW_POWER 0x609c
|
||||
#define PRST_SHTC3_CMD_MEASURE_TFIRST_NORMAL 0x7866
|
||||
|
||||
typedef struct prst_shtc3_values {
|
||||
// Temperature in millicelcius. To get the temp in Celcius, divide this by
|
||||
|
|
|
|||
67
data/adc-moisture-estimation/dry.csv
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
input_voltage,adc_output
|
||||
2.05,400
|
||||
2.05,401
|
||||
2.18,410
|
||||
2.18,409
|
||||
2.18,409
|
||||
2.19,410
|
||||
2.19,410
|
||||
2.24,413
|
||||
2.25,413
|
||||
2.24,413
|
||||
2.33,418
|
||||
2.34,418
|
||||
2.36,418
|
||||
2.38,420
|
||||
2.41,423
|
||||
2.42,422
|
||||
2.41,422
|
||||
2.42,421
|
||||
2.41,421
|
||||
2.41,421
|
||||
2.42,423
|
||||
2.45,423
|
||||
2.48,424
|
||||
2.53,427
|
||||
2.54,428
|
||||
2.56,428
|
||||
2.61,431
|
||||
2.65,434
|
||||
2.66,434
|
||||
2.67,433
|
||||
2.72,437
|
||||
2.73,436
|
||||
2.75,436
|
||||
2.79,438
|
||||
2.83,439
|
||||
2.87,441
|
||||
2.88,442
|
||||
2.92,442
|
||||
2.92,442
|
||||
2.94,444
|
||||
2.94,443
|
||||
2.98,445
|
||||
3.01,446
|
||||
3.03,447
|
||||
3.04,448
|
||||
3.07,447
|
||||
3.11,449
|
||||
3.12,450
|
||||
3.12,449
|
||||
3.15,450
|
||||
3.16,451
|
||||
3.18,452
|
||||
3.20,451
|
||||
3.22,453
|
||||
3.24,454
|
||||
3.25,453
|
||||
3.27,455
|
||||
3.29,455
|
||||
3.30,455
|
||||
3.32,456
|
||||
3.31,455
|
||||
3.31,456
|
||||
3.34,456
|
||||
3.43,459
|
||||
3.46,460
|
||||
3.51,460
|
||||
|
43
data/adc-moisture-estimation/wet.csv
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
input_voltage,adc_output
|
||||
2.18,225
|
||||
2.19,227
|
||||
2.20,230
|
||||
2.22,230
|
||||
2.21,234
|
||||
2.22,237
|
||||
2.25,235
|
||||
2.29,236
|
||||
2.35,234
|
||||
2.36,234
|
||||
2.43,239
|
||||
2.45,242
|
||||
2.45,241
|
||||
2.49,239
|
||||
2.53,238
|
||||
2.58,238
|
||||
2.64,241
|
||||
2.64,242
|
||||
2.72,247
|
||||
2.74,250
|
||||
2.78,251
|
||||
2.82,252
|
||||
2.90,252
|
||||
2.95,252
|
||||
2.96,250
|
||||
3.01,253
|
||||
3.06,257
|
||||
3.09,261
|
||||
3.11,261
|
||||
3.18,260
|
||||
3.20,260
|
||||
3.24,259
|
||||
3.26,260
|
||||
3.28,261
|
||||
3.32,265
|
||||
3.38,266
|
||||
3.39,268
|
||||
3.40,267
|
||||
3.45,265
|
||||
3.46,263
|
||||
3.49,262
|
||||
3.51,264
|
||||
|
BIN
img/orig/img1.jpg
Executable file
|
After Width: | Height: | Size: 4.7 MiB |
BIN
img/orig/img2.jpg
Executable file
|
After Width: | Height: | Size: 3.1 MiB |
BIN
img/resized/img1.jpg
Executable file
|
After Width: | Height: | Size: 1 MiB |
BIN
img/resized/img2.jpg
Executable file
|
After Width: | Height: | Size: 314 KiB |
BIN
img/scope/0dbm-across-10ohm.png
Executable file
|
After Width: | Height: | Size: 40 KiB |
BIN
img/scope/0dbm-no-led-across-10ohm.png
Executable file
|
After Width: | Height: | Size: 41 KiB |
BIN
img/scope/8dbm-across-10ohm.png
Executable file
|
After Width: | Height: | Size: 50 KiB |