no success setting a GPIO
Posted: Wed May 30, 2018 11:00 pm
Hi all -
Working on the ESP32-DevKitC and trying to toggle a GPIO pin.
Here's the initialization code:
Here's the code that does the work:
and here's the call:
It produces this output:
Any ideas what I'm doing wrong?
Thanks...
Working on the ESP32-DevKitC and trying to toggle a GPIO pin.
Here's the initialization code:
Code: Select all
#define BUZZER_NUM (GPIO_NUM_5)
#define BUZZER_PIN (GPIO_SEL_5)
...
Buzzer::Buzzer()
{
// create the queue for receiving button push notifications.
m_buzzerQueue = xQueueCreate(10, sizeof(BuzzerQueueEntry));
// configure the io_conf structure.
io_conf.pin_bit_mask = BUZZER_PIN;
io_conf.intr_type = static_cast<gpio_int_type_t>(GPIO_PIN_INTR_DISABLE);
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
//configure GPIO with the given settings
esp_err_t err = gpio_config(&io_conf);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "error %d configuring GPIO.", err);
}
}
Code: Select all
void Buzzer::buzzer_task()
{
BuzzerQueueEntry entry;
esp_err_t err;
uint32_t level;
while (1)
{
entry.value = 0; // reset between queue reads.
// look for a change request from our queue. Process if present.
if (xQueueReceive(m_buzzerQueue, &entry, portMAX_DELAY) == pdTRUE)
{
if (entry.value > 0)
{
// turn buzzer on
ESP_LOGI(TAG, "turning buzzer on.");
level = 1;
err = gpio_set_level(BUZZER_NUM, level);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "error enabling GPIO.");
}
ESP_LOGI(TAG, "GPIO level is %d", gpio_get_level(BUZZER_NUM));
}
else
{
// turn buzzer off
ESP_LOGI(TAG, "turning buzzer off.");
level = 0;
err = gpio_set_level(BUZZER_NUM, level);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "error disabling GPIO.");
}
ESP_LOGI(TAG, "GPIO level is %d", gpio_get_level(BUZZER_NUM));
}
}
}
}
Code: Select all
BuzzerQueueEntry buzz;
buzz.value = 1;
xQueueSendToBack(buzzQueue, &buzz, 0);
vTaskDelay(20);
buzz.value = 0;
xQueueSendToBack(buzzQueue, &buzz, 0);
(No error messages indicating that my get/set calls are failing.)I (386) Buzzer: turning buzzer on.
I (386) Buzzer: GPIO level is 0
I (586) Buzzer: turning buzzer off.
I (586) Buzzer: GPIO level is 0
Any ideas what I'm doing wrong?
Thanks...