Closed AzezurRehman closed 9 months ago
//#define TXD_PIN 35 // Define your ESP32 TX pin ---> GPIO35 is INPUT ONLY.
#define TXD_PIN 32 // Define your ESP32 TX pin
//uart_param_config(uart, &uart_config);
//uart_set_pin(uart, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
//uart_driver_install(uart, RX_BUF_SIZE, 0, 0, NULL, 0);
uart_driver_install(uart, RX_BUF_SIZE, 0, 0, NULL, 0);
uart_param_config(uart, &uart_config);
uart_set_pin(uart, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
i have solved these issue
Answers checklist.
IDF version.
ESP-IDF 5.1
Espressif SoC revision.
ESP32 -WROOM-32
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32 -WROOM-32
Power Supply used.
External 5V
What is the expected behavior?
it want to print dust sensor value which is connect to GPIO 34 as RX and GPIO 35 as TX
What is the actual behavior?
E (335) uart: uart_set_pin(645): tx_io_num error
Steps to reproduce.
include "driver/uart.h"
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include
define FW_VERSION "AAS_LDS_UNO_v1.3"
define SAMPLE_RATE 2000
define SENSOR_BAUD 9600
define uart UART_NUM_1
define TXD_PIN 35 // Define your ESP32 TX pin
define RXD_PIN 34 // Define your ESP32 RX pin
int PM1value; int PM25value; int PM10value;
static const int RX_BUF_SIZE = 1024;
int checkDustSensor(); void getDustValue(); void dust_sensor_task(void *pvParameters);
void app_main() { uart_config_t uart_config = {.baud_rate = 115200, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE};
uart_param_config(uart, &uart_config); uart_set_pin(uart, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); uart_driver_install(uart, RX_BUF_SIZE, 0, 0, NULL, 0);
printf("Amphenol Advanced Sensors\n"); printf("%s\n", FW_VERSION);
if (checkDustSensor()) { printf("Dust Sensor Detected\n"); } else { printf("Dust Sensor not detected. Please check connections.\n"); }
xTaskCreate(dust_sensor_task, "dust_sensor_task", 4096, NULL, 5, NULL); }
int checkDustSensor() { printf("check dust sensor enterf"); const char checkCmd[] = "BM\xe1\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; uart_write_bytes(uart, checkCmd, sizeof(checkCmd)); vTaskDelay(10 / portTICK_PERIOD_MS);
uint8_t data; uart_get_buffered_data_len(uart, &data); return data > 0; }
void getDustValue() { printf("get dust sensor entered "); uint8_t data[32]; uint8_t message[64]; int CRC = 0;
uart_read_bytes(uart, message, 64, portMAX_DELAY);
for (uint8_t i = 0; i < 32; i++) { if (message[i] == 0x42 && message[i + 1] == 0x4D) { for (uint8_t j = 0; j < 32; j++) { data[j] = message[i]; i++; } break; } }
for (int i = 0; i < 30; i++) { CRC += data[i]; }
if ((data[30] * 256 + data[31]) == CRC) { PM1value = (data[4] & 0x3F) << 8 | data[5]; PM25value = (data[6] & 0x3F) << 8 | data[7]; PM10value = (data[8] & 0x3F) << 8 | data[9]; } else { PM25value = 999; } }
void dust_sensor_task(void *pvParameters) { while (1) { printf("while loop entered"); // if (millis() >= SAMPLE_RATE) { getDustValue(); printf(",PMA1: %d, PMA25: %d, PMA10: %d\n", PM1value, PM25value, PM10value);
} }
Debug Logs.
More Information.
No response