Started on DS18B20 and PMS5003
Didn't realise DS18B20 was 1-Wire Will probably just find a library for that one - can't be arsed doing more bit banging
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
#include "dht22.h"
|
||||
#include "esp_log.h"
|
||||
#include "hal/gpio_types.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <rom/ets_sys.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "hal/gpio_types.h"
|
||||
#include "sdkconfig.h"
|
||||
#include <rom/ets_sys.h>
|
||||
|
||||
#ifndef CONFIG_DHT22_DATA_GPIO
|
||||
#define DATA_GPIO 2
|
||||
#else
|
||||
#define DATA_GPIO CONFIG_DHT22_DATA_GPIO
|
||||
#endif /* CONFIG_DHT22_DATA_GPIO */
|
||||
|
||||
#if DATA_GPIO == -1
|
||||
#error "Please define your DHT22 GPIO Data Pin"
|
||||
@@ -70,7 +74,8 @@ dht22_error dht22_read() {
|
||||
gpio_set_direction(DATA_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
// Wait here until it goes high DHT "responds" after being pulled high
|
||||
// The 40 is pretty arbitrary - but there's probably a problem if it goes higher
|
||||
// The 40 is pretty arbitrary - but there's probably a problem if it goes
|
||||
// higher
|
||||
uint32_t elapsed_time;
|
||||
elapsed_time = wait_for_signal_to_change_from(1);
|
||||
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
||||
@@ -105,17 +110,17 @@ dht22_error dht22_read() {
|
||||
*/
|
||||
uint8_t data[5] = {0, 0, 0, 0, 0};
|
||||
for (uint8_t i = 0; i < 40; i++) {
|
||||
elapsed_time = wait_for_signal_to_change_from(0);
|
||||
if (elapsed_time == DHT22_TIMEOUT_ERROR || elapsed_time < 30 ||
|
||||
elapsed_time > 80) {
|
||||
portENABLE_INTERRUPTS();
|
||||
return DHT22_TIMEOUT_ERROR;
|
||||
}
|
||||
elapsed_time = wait_for_signal_to_change_from(0);
|
||||
if (elapsed_time == DHT22_TIMEOUT_ERROR || elapsed_time < 30 ||
|
||||
elapsed_time > 80) {
|
||||
portENABLE_INTERRUPTS();
|
||||
return DHT22_TIMEOUT_ERROR;
|
||||
}
|
||||
|
||||
elapsed_time = wait_for_signal_to_change_from(1);
|
||||
if (elapsed_time > 50) {
|
||||
data[i / 8] |= (1 << (7 - (i % 8)));
|
||||
}
|
||||
elapsed_time = wait_for_signal_to_change_from(1);
|
||||
if (elapsed_time > 50) {
|
||||
data[i / 8] |= (1 << (7 - (i % 8)));
|
||||
}
|
||||
}
|
||||
portENABLE_INTERRUPTS();
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ menu "DS18B20"
|
||||
|
||||
config DS18B20_GPIO_PIN
|
||||
int "GPIO Pin used for 1-Wire DS18B20"
|
||||
default 10
|
||||
default 15
|
||||
depends on DS18B20_ENABLED
|
||||
|
||||
config DS18B20_PERIOD_POLL
|
||||
int "Period to poll the DS18B20 in seconds"
|
||||
default 8000
|
||||
default 8
|
||||
depends on DS18B20_ENABLED
|
||||
endmenu
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
int test() {
|
||||
int i = 5;
|
||||
return i;
|
||||
#include "ds18b20.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef CONFIG_DS18B20_ENABLED
|
||||
|
||||
int ds18b20_read(void) {
|
||||
esp_err_t ret = gpio_set_pull_mode(CONFIG_DS18B20_GPIO_PIN, GPIO_PULLUP_ONLY);
|
||||
return DS18B20_OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DS18B20_ENABLED */
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
int ds18b20_read(void);
|
||||
|
||||
typedef enum {
|
||||
DS18B20_OK,
|
||||
} ds18b20_error;
|
||||
|
||||
@@ -3,13 +3,23 @@ menu "PMS5003"
|
||||
bool "PMS5003 Enabled"
|
||||
default y
|
||||
|
||||
config PMS5003_UART
|
||||
int "PMS5003 UART Port"
|
||||
default 1
|
||||
config PMS5003_UART_PORT
|
||||
int "PMS5003 UART PORT"
|
||||
default 0
|
||||
depends on PMS5003_ENABLED
|
||||
|
||||
config PMS5003_UART_TX
|
||||
int "PMS5003 UART Tx GPIO Pin"
|
||||
default 4
|
||||
depends on PMS5003_ENABLED
|
||||
|
||||
config PMS5003_UART_RX
|
||||
int "PMS5003 UART Rx GPIO Pin"
|
||||
default 5
|
||||
depends on PMS5003_ENABLED
|
||||
|
||||
config PMS5003_PERIOD_POLL
|
||||
int "Period to poll the PMS5003 in ms"
|
||||
default 8000
|
||||
int "Period to poll the PMS5003 in seconds"
|
||||
default 8
|
||||
depends on PMS5003_ENABLED
|
||||
endmenu
|
||||
endmenu
|
||||
|
||||
@@ -1,4 +1,29 @@
|
||||
int test() {
|
||||
int i = 5;
|
||||
return i;
|
||||
#include "pms5003.h"
|
||||
#include "driver/uart.h"
|
||||
#include "hal/uart_types.h"
|
||||
|
||||
#define START_CHAR_1 0x42
|
||||
#define START_CHAR_2 0x4d
|
||||
|
||||
#define DEFAULT_BAUD 9600
|
||||
|
||||
static const char* TAG = "PMS5003";
|
||||
|
||||
pms5003_err pms5003_init() {
|
||||
const uart_port_t uart_num = CONFIG_PMS5003_UART_PORT;
|
||||
uart_set_pin(uart_num, CONFIG_PMS5003_UART_TX, CONFIG_PMS5003_UART_RX, -1, -1);
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = DEFAULT_BAUD,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 122,
|
||||
};
|
||||
return PMS5003_OK;
|
||||
}
|
||||
|
||||
pms5003_err pms5003_read(void) {
|
||||
|
||||
return PMS5003_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum { PMS5003_OK } pms5003_err;
|
||||
|
||||
pms5003_err pms5003_read(void);
|
||||
|
||||
Reference in New Issue
Block a user