Giter Site home page Giter Site logo

zhou-peter / tuya-iotos-embeded-demo-ble-segment-lcd-driver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tuya-community/tuya-iotos-embeded-demo-ble-segment-lcd-driver

0.0 0.0 0.0 41 KB

Tuya IoTOS Embedded Bluetooth LE Segment LCD Driver

C 100.00%

tuya-iotos-embeded-demo-ble-segment-lcd-driver's Introduction

Tuya IoTOS Embedded Bluetooth LE Segment LCD Driver

English | 中文


Introduction

In this demo, we will show you how to implement a 3-digit 7-segment LCD driver and make a segment LCD IoT-enabled. Based on the Tuya IoT Platform, we use Tuya's Bluetooth LE module, SDK, and the Tuya Smart app to connect the LCD to the cloud so that you can feed contents to the LCD using a mobile app. This demo provides segment LCD interfaces to help you quickly implement pin configuration, display content (numerals, strings, characters, and custom characters), screen on/off, blinking effects (blinking times, full-screen blinking, and portion blinking), and the blinking callback.


Get started

Set up development environment


Compile and flash

  • Edit code

    1. In tuya_ble_app_demo.h, specify the PID of the product you have created on the Tuya IoT Platform.

      #define APP_PRODUCT_ID     "xxxxxxxx"
      

      Change xxxxxxxx to the PID.

    2. In tuya_ble_app_demo.c, specify the authkey and UUID.

      static const char auth_key_test[] = "yyyyyyyy";
      static const char device_id_test[] = "zzzzzzzz";
      

      Change yyyyyyyy to your authkey and zzzzzzzz to your UUID.

  • Compile code

    Compile the edited code, download the code to the hardware, and run it. You may need to download the stack and bootloader depending on your chip models. Check the logs and use the third-party Bluetooth debugging app (such as LightBlue for iOS) to verify the Bluetooth broadcast.


File introduction

├── src         /* Source code files */
|    ├── sdk
|    |    └── tuya_uart_common_handler.c        /* Code for UART communication */
|    ├── driver
|    |    └── tuya_seg_lcd.c                    /* Segment LCD driver */
|    ├── platform
|    |    ├── tuya_gpio.c                       /* GPIO driver */
|    |    └── tuya_timer.c                      /* Timer driver */
|    ├── tuya_ble_app_demo.c                    /* Entry file of application layer */
|    └── tuya_demo_seg_lcd_driver.c             /* Sample code */
|
└── include     /* Header files */
     ├── common
     |    └── tuya_common.h                     /* Common types and macros */
     ├── sdk
     |    ├── custom_app_uart_common_handler.h  /* Code for UART communication */
     |    ├── custom_app_product_test.h         /* Implementation of custom production test items */
     |    └── custom_tuya_ble_config.h          /* Application configuration file */
     ├── driver
     |    └── tuya_seg_lcd.h                    /* Segment LCD driver */
     ├── platform
     |    ├── tuya_gpio.h                       /* GPIO driver */
     |    └── tuya_timer.h                      /* Timer driver */
     ├── tuya_ble_app_demo.h                    /* Entry file of application layer */
     └── tuya_demo_seg_lcd_driver.h             /* Sample code */

Entry to application

Entry file: /tuya_ble_app/tuya_ble_app_demo.c

  • void tuya_ble_app_init(void) is executed to initialize Tuya IoTOS Embedded Bluetooth LE SDK. This function is executed only once.
  • void app_exe() is used to execute the application code. It is executed in a loop.

Data point (DP)

Function tuya_ble_dp_data_report
Function prototype tuya_ble_status_t tuya_ble_dp_data_report(uint8_t *p_data,uint32_t len);
Feature overview Reports DP data.
Parameters p_data [in]: DP data.
len[in]: data length. It cannot exceed TUYA_BLE_REPORT_MAX_DP_DATA_LEN.
Return value TUYA_BLE_SUCCESS: sent successfully.
TUYA_BLE_ERR_INVALID_PARAM: invalid parameter.
TUYA_BLE_ERR_INVALID_STATE: failed to send data due to the current Bluetooth connection, such as Bluetooth disconnected.
TUYA_BLE_ERR_NO_MEM: failed to request memory allocation.
TUYA_BLE_ERR_INVALID_LENGTH: data length error.
TUYA_BLE_ERR_NO_EVENT: other errors.
Notes application calls this function to send DP data to the mobile app.

Parameter description:

The Tuya IoT Platform manages data through DPs. The data generated by any device is abstracted into a DP. DP data consists of four parts, as described below.

  • Dp_id: the DP ID of a data point defined on the Tuya IoT platform. It is one byte.

  • Dp_type: the data type. It is one byte.

    #define DT_RAW 0 raw type.

    #define DT_BOOL 1 Boolean type.

    #define DT_VALUE 2 value type. The value range is specified when a DP of value type is created on the Tuya IoT Platform.

    #define DT_STRING 3 string type.

    #define DT_ENUM 4 enum type.

    #define DT_BITMAP 5 bitmap type.

  • Dp_len: It can be one byte or two bytes. Currently, Bluetooth only supports one byte, so the data of a single DP can be up to 255 bytes.

  • Dp_data: the DP data, with dp_len byte(s).

The data that the parameter p_data points to must be packaged in the following format for reporting.

DP 1 data DP n data
1 2 3 4 n n+1 n+2 n+3
Dp_id Dp_type Dp_len Dp_data Dp_id Dp_type Dp_len Dp_data

When this function is called, the maximum data length is TUYA_BLE_REPORT_MAX_DP_DATA_LEN, which is 255+3 currently.


Pin configuration

Peripherals I/O Peripherals I/O
Segment LCD-COM1 PA1 Segment LCD-SEG1 PA0
Segment LCD-COM2 PC2 Segment LCD-SEG2 PC0
Segment LCD-COM3 PC3 Segment LCD-SEG3 PD3
Segment LCD-COM4 PB4 Segment LCD-SEG4 PC1
Segment LCD-SEG5 PC4
Segment LCD-SEG6 PB5

Reference


Technical support

You can get support from Tuya with the following methods:


tuya-iotos-embeded-demo-ble-segment-lcd-driver's People

Contributors

fangamy avatar coral-hu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.