gfurtadoalmeida / esp32-driver-nextion

ESP32 driver for Nextion displays.
MIT License
18 stars 7 forks source link

E (595) example: failed initializing device #3

Closed aledoors closed 3 years ago

aledoors commented 3 years ago

Hello Urtado, i got the issue below, can you help me?

I (314) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (325) nextion: installing driver on uart 1 with baud rate 9600 I (335) uart: queue free spaces: 10 I (335) nextion: driver installed W (455) nextion: parsed the event 151 on command handler W (455) nextion: parsed the event 234 on command handler W (455) nextion: parsed the event 230 on command handler W (465) nextion: parsed the event 158 on command handler E (475) nextion: invalid response size, expected 4 but received 9 W (475) nextion: device returned failure W (495) nextion: parsed the event 242 on command handler W (495) nextion: parsed the event 190 on command handler W (495) nextion: parsed the event 158 on command handler W (495) nextion: parsed the event 158 on command handler W (505) nextion: parsed the event 222 on command handler W (515) nextion: parsed the event 231 on command handler W (515) nextion: parsed the event 142 on command handler W (525) nextion: parsed the event 158 on command handler W (585) nextion: parsed the event 158 on command handler E (585) nextion: invalid response size, expected 4 but received 9 W (585) nextion: device returned failure E (585) nextion: failed initializing display E (595) example: failed initializing device

I use your example:

// When building using VSCode tooling, the necessary // variables are not injected in build time.

include "../build/config/sdkconfig.h"

include

include "freertos/FreeRTOS.h"

include "freertos/queue.h"

include "freertos/task.h"

include "esp_log.h"

include "driver/uart.h"

include "driver/gpio.h"

include "nextion/nextion.h"

include "nextion/page.h"

include "nextion/component.h"

const static char *TAG = "example";

static nextion_handle_t nextion_handle; static TaskHandle_t task_interface_handle; static xQueueHandle queue_handle;

static void process_touch_event(nextion_on_touch_event_t event_data); static void process_interface_queue(void *pvParameters);

void app_main(void) { esp_log_level_set("*", ESP_LOG_DEBUG);

nextion_handle = nextion_driver_install(UART_NUM_1, 9600, GPIO_NUM_17, GPIO_NUM_16);

if (nextion_handle == NULL)
{
    ESP_LOGE(TAG, "failed installing driver");
    return;
}

if (nextion_init(nextion_handle) != NEX_OK)
{
    ESP_LOGE(TAG, "failed initializing device");
    return;
}

if (!nextion_event_callback_set_on_touch(nextion_handle, &process_touch_event))
{
    ESP_LOGE(TAG, "failed registering 'on device' event callback");
    return;
}

if (nextion_page_set(nextion_handle, "0") != NEX_OK)
{
    ESP_LOGE(TAG, "failed changing to page 0");
    return;
}

queue_handle = xQueueCreate(5, sizeof(nextion_on_touch_event_t));

if (queue_handle == NULL)
{
    ESP_LOGE(TAG, "failed creating queue");
    return;
}

if (xTaskCreate(process_interface_queue,
               "interface",
                2048,
                NULL,
                20,
                &task_interface_handle) != pdPASS)
{
    ESP_LOGE(TAG, "failed creating task");
    return;
}

ESP_LOGI(TAG, "waiting for button 3 'b0', from page 0, to be pressed");

vTaskDelay(portMAX_DELAY);

// Will never reach here.
// It is just to show how to delete the driver.
if (!nextion_driver_delete(nextion_handle))
{
    ESP_LOGE(TAG, "failed deleting driver");
}

}

void process_touch_event(nextion_on_touch_event_t event_data) { xQueueSend(queue_handle, &event_data, pdMS_TO_TICKS(100)); }

void process_interface_queue(void *pvParameters) { nextion_on_touch_event_t event_data;

for (;;)
{
    if (xQueueReceive(queue_handle, &event_data, portMAX_DELAY) == pdTRUE)
    {
        ESP_LOGI(TAG, "received an event");

        if (event_data.page_id == 0 && event_data.component_id == 3 && event_data.state == NEXTION_TOUCH_RELEASED)
        {
            char text[50];
            size_t text_length = 50;
            int32_t number;

            // Get the text.
            if (nextion_component_get_text(nextion_handle, "t0", text, &text_length) == NEX_OK)
            {
                ESP_LOGI(TAG, "text: %s", text);
            }
            else
            {
                ESP_LOGE(TAG, "failed getting text");
            }

            // Get the number.
            if (nextion_component_get_value(nextion_handle, "n0", &number) == NEX_OK)
            {
                ESP_LOGI(TAG, "number: %d", number);
            }
            else
            {
                ESP_LOGE(TAG, "failed getting number");
            }
        }
    }
}

}

gfurtadoalmeida commented 3 years ago

Hi @aledoors, I've just ran the tests, and everything is fine. There might be a problem on the example. I'll let you know as soon as it is fixed.

gfurtadoalmeida commented 3 years ago

@aledoors could you download and try again? Just sent two commits that:

  1. Fixes a task priority issue.
  2. Simplifies the example.

Both tests and examples ran fine with my setup. In case you're using the HMI from ../components/nextion/test/nextion/hmi/test_display.HMI, be aware that you need to use 115200 as baud rate.

aledoors commented 3 years ago

Hello @gfurtadoalmeida , thanks in advance for your help!

I can't use that HMI file because mi HMI model is a basic one (NX4827T043_011), could be the problem i have?

gfurtadoalmeida commented 3 years ago

Hi @aledoors, I don't think so. This library is being used on another project that uses the NX4024T032, which is a basic version too, and it's working fine.

I've just updated the example and added an HMI for it, using the basic model; you will be able to run it now 🙂 The example HMI is on the examples/hmi folder.

Try running the example again and let me know if it works for you.

gfurtadoalmeida commented 3 years ago

@aledoors were you able to test it?

aledoors commented 3 years ago

@gfurtadoalmeida hi, sorry for my absence, i was working with VS Code and suddenly it stopped working. In a few days i will try and tell you.

gfurtadoalmeida commented 3 years ago

Issue closed due to inactivity. Fixes were done and tests were made, with the problem not being reproducible. In case you still have problems, feel free to open this issue or create another one.

aledoors commented 3 years ago

@gfurtadoalmeida the library doesn't works, but thanks for your help. i am using another one. Best regards.