Example Project

Last Updated on : 2025-03-04 07:06:45Copy for LLMView as MarkdownDownload PDF

Basic functional examples

Wukong AI Hardware Development Framework provides basic functional examples, including systems, drivers, and networks. For more information, see Networked Product Development Framework > Example Project Description.

AI toy example

tuyaos_demo_ai_toy is an AI toy demo application that supports the following features:

  • Voice agent in Tuya IoT Cloud
  • Hold to talk
  • Various status prompt tones, such as pairing, going offline, and low battery.
  • Low power consumption, with up to 10 days of standby time and support for 10 hours of continuous talk
  • Dual-color (red and green) indicator light that can switch colors based on battery level and charging status
  • Volume control on the app
  • Battery level reporting

Initialization code

OPERATE_RET __soc_device_init(VOID_T)
{
    OPERATE_RET rt = OPRT_OK;

    // …
    // …
    TY_AI_TOY_PARA_T para = TY_AI_PROC_PARA_AIBOX_HOLD;
    /* Network button initialization */
    app_key_init(para.reset_key_pin);
    /* AI toy initialization */
    TUYA_CALL_ERR_RETURN(ty_ai_toy_init(&para));
    TUYA_CALL_ERR_RETURN(ty_ai_toy_start());
    return 0;
}

Configure pins and modes

You need to configure several pins for the AI toy to enable features such as system reset, wake-up, and speaker on/off. In the demo, parameters are set by the TY_AI_TOY_PARA_T struct, and five basic parameters are preset for a quick start. You can select or modify them as needed.

TY_AI_PROC_PARA_DEF
TY_AI_PROC_PARA_DEF2
TY_AI_PROC_PARA_CUSTOM
TY_AI_PROC_PARA_AIBOX
TY_AI_PROC_PARA_AIBOX_HOLD (default configuration)

The triggering methods include press for continuous talk and press and hold for talk. Currently, the demo is optimized only for long-press triggering.

Initialize system reset pin

Initialize the reset pin. Press and hold the pin for five seconds and the device will reset and re-enter pairing mode.

/**
* @brief init key
* @param[in] pin_id: key pin number
*/
VOID_T app_key_init(TUYA_GPIO_NUM_E pin_id);

Initialize AI toy

Initialize the features of the AI ​​toy.

/**
* @brief init ai toy demo
* 
* @param[in/out] para: init parameters
* @return OPERATE_RET: OPRT_OK on success, others on failed
*/
OPERATE_RET ty_ai_toy_init(TY_AI_TOY_PARA_T *para);

Start AI toy

Start the features of the AI ​​toy.

/**
* @brief start ai toy demo
* 
* @return OPERATE_RET: OPRT_OK on success, others on failed
*/
OPERATE_RET ty_ai_toy_start(void);

Notes

The demo also includes battery level detection. If the specified development board does not have the battery level detection feature, you can comment out the calls to the tuya_ai_toy_battery_init and tuya_ai_toy_battery_uninit interfaces in the code.