智能压力检测仪

操作系统 云服务/平台 技术难度 关注领域
RTOS Gizwits Cloud 中级 Healthcare,Sensors

 

任务目标

主要是将Fsr402传感器连接到Gokit开发板提供的ADC接口,以收集压力值信息,当压力值变化超出设定阈值时,LED亮起。

 

 

智能压力检测仪,使用Gokit4开发板

 

 

使用数据线给Gokit4开发板供电

 

 

使用Fsr402压力传感器检测压力值

 

 

用来作为连接线

 

 

作为信号灯,当压力值超出设定阈值时,它会被点亮

所需材料/所需清单/工具

  • BG96

  • Gokit4

  • ADXL345 sensor

  • Led

  • Dupoint line

源码/示例/可执行的应用程序

  • Source Code

附加资料

  • 智能压力检测仪(网盘密码:1ajf)

搭建/在组装说明

使用的零件

以下是此项目中使用的项目。

1. windows7 台式机。

2. Gokit4开发板

3. ADXL345传感器,用来检测轴加速度值。

4.led灯,当轴加速度值变化超过设定的阈值时,点亮led灯。

5.杜邦线,用来作为导线连接其他部件。

 

部署项目

1.根据demo需求,结合Gokit4开发板载资源购买合适的器件。

2. 测试选择的器件是否可用。

3.搭建和调试硬件电路。

4.创建本地项目“demo-Smart-Pressure-detector”。

5.移植相关源码。

6.开发压力数据采集相关功能。

7.联合调试。

8.上传代码到github。

 

工作流程

以下是测试项目的一些说明。。

现在介绍“demo-Smart-Pressure-detector”的工作流程。

gagentMain---->sensorInit---->led_init---->motion_init---->tx_timer_create

在接口“tx_timer_create”中注册回调,当时间到,调用名为“userTimerCB”的回调函数。

demo-Smart-Pressure-detector/main/main.c

 

void gagentMain( void )

{

    getFreeHeap();

    user_init();

}

 

GAgent调用了名为gagentMain的函数,GAgent的主要作用是数据转发,它是设备数据,云计算和应用程序端(APP)之间的数据交互桥梁。在函数user_init中,做一些初始化。

 

void user_init(void)

{

    int32 ret = -1;

    gizLog(LOG_INFO,"Sensor initialization ...\n");

       led_init();

    txm_module_object_allocate(&userTimer, sizeof(TX_TIMER));

    ret = tx_timer_create(userTimer, "userTimer", userTimerCB, NULL, 1,20, TX_AUTO_ACTIVATE);

    if(ret != TX_SUCCESS)

    {

        gizLog(LOG_WARNING,"Failed to create UserTimer.\n");

    }

}

 

void led_init()

{

       gizLog(LOG_INFO,"in led init...\n");

       led_gpio_config();

       led_on_off(false,led_green);     //init status is off

}

 

demo-Smart-Pressure-detector/driver/gpio.c

void led_on_off(bool on, uint8_t pin_gpio)

{

    if (on)

   {

      qapi_TLMM_Drive_Gpio(gpio_id_tbl[pin_gpio]

      gpio_map_tbl[pin_gpio].gpio_id, QAPI_GPIO_LOW_VALUE_E);

   }

   else

   {

      qapi_TLMM_Drive_Gpio(gpio_id_tbl[pin_gpio]

      gpio_map_tbl[pin_gpio].gpio_id, QAPI_GPIO_HIGH_VALUE_E);

   }

}

 

void ICACHE_FLASH_ATTR userTimerCB(void)

{

   gizLog(LOG_INFO,"in userTimerCB.....\n");

   int16_t quality;

 

   quality = fsr402_pressure_adc_read();   //get quality value.

   if(quality >= 1000)

   {

     led_on_off(true,led_green);

     qapi_Timer_Sleep(100, QAPI_TIMER_UNIT_MSEC, true);

     led_on_off(false, led_green);

   }

   else if(quality == -1)

   {

     led_on_off(true,led_red);

     qapi_Timer_Sleep(100, QAPI_TIMER_UNIT_MSEC, true);

     led_on_off(false, led_red);

   }

}

demo-Smart-Pressure-detector/driver/adc/fsr402_pressure_adc.c

//used to get quality value

int fsr402_pressure_adc_read(void)

{

   int ret = -1;

   int32_t m_voltage = 0;

   int16_t quilty = 0;

   qapi_ADC_Read_Result_t result;

   qapi_Status_t status = QAPI_ERROR;

 

   const char *channel_name_adc0 = ADC_INPUT_ADC0;

   qapi_Adc_Input_Properties_Type_t Properties_ADC0;

 

/*get an adc handle*/

status = adc_open_handle();

   if(status != QAPI_OK)

   {

     gizLog(LOG_ERROR,"Get ADC Handle ERROR!\n");

      return status;

   }

/*get the adc channel configuration*/

   status = adc_get_properties(channel_name_adc0, &Properties_ADC0);

if(status != QAPI_OK)

   {

     gizLog(LOG_ERROR,"Get ADC channel-%s Configuration ERROR!\n", channel_name_adc0);

     return status;

   }

/*read channel ADC0*/

memset(&result, 0, sizeof(result));

   status = qapi_ADC_Read_Channel(adc_handle, &Properties_ADC0, &result);

   if(QAPI_OK == status)

  {

   if(ADC_RESULT_VALID == result.eStatus)

   {

     m_voltage = result.nMicrovolts /1000;

     quilty = to_quality(m_voltage);

     if(quilty > 0)

     {

       gizLog(LOG_INFO,"Input %s Voltage: %d mV about %d g\n", channel_name_adc0, m_voltage, quilty);

     }

     else if (quilty == 0)

     {

       gizLog(LOG_INFO,"no press.\n");

     }

     else

     {

       gizLog(LOG_INFO,"Out of range!\n");

     }

   }

  }

status = qapi_ADC_Close(adc_handle, false);

   if(QAPI_OK != status)

   {

     gizLog(LOG_ERROR,"Free ADC Handle ERROR!\n");

   }

   return quilty;

}

qapi_Status_t adc_open_handle(void)

{

   qapi_Status_t status = QAPI_ERROR;

status = qapi_ADC_Open(&adc_handle, 0);

   if (QAPI_OK != status)

   {

     gizLog(LOG_ERROR, "open adc error!\n");

   }

   return status;

}

qapi_Status_t adc_get_properties(const char *Channel_Name_Ptr,

  qapi_Adc_Input_Properties_Type_t *Properties_Ptr)

{

qapi_Status_t status = QAPI_ERROR;

  uint32_t Channel_Name_Size = strlen(Channel_Name_Ptr) + 1;

  status = qapi_ADC_Get_Input_Properties(adc_handle, Channel_Name_Ptr, Channel_Name_Size, Properties_Ptr);

  if (QAPI_OK != status)

  {

    gizLog(LOG_ERROR, "ADC Get Channel-%s Properties ERROR!\n", Channel_Name_Ptr);

  }

  return status;

}

//Find the corresponding quality value from the array based on the voltage value.(根据电压值,从数组中找到对应的质量值。)

int16_t to_quality(int32 m_voltage)

{

  uint8_t i =0;

  int16_t quilty = 0;

  for(i = 0; i < V_TO_Q_SIZE; i++)

  {

    if(m_voltage <= voltage_to_quality[i].voltage)

    {

      quilty = voltage_to_quality[i].quality;

      return quilty;

    }

    i++;

  }

  if(i >= V_TO_Q_SIZE)

    return -1;

}

1.从该github链接地址处下载代码。

2.编译代码,烧录镜像到Gokit4开发板。

3.将Fsr402传感器连接到Gokit4开发板的ADC接口上。

4.将LED的一个引脚连接到开发板的D9引脚,另一个引脚连接到VCC。

5.USB数据线连接到电脑和开发板。

6.打卡串口调试助手。

7.将手指放到压力传感器的待测面,就可以看见数据变化。

8.当压力值变化超过设定的阈值,led灯会被点亮。

 

贡献者信息

姓名 公司

Zhen

sunzhen@thundersoft.com
Thundersoft

Rong

yangrong0925@thundersoft.com
Thundersoft

Jie

wangjie0508@thundersoft.com
Thundersoft

Kou

kouzw0723@thundersoft.com
Thundersoft

Eric

yansh0810@thundersoft.com
Thundersoft

>>浏览更多Qualcomm硬件案例:http://qualcomm.csdn.net/m/zone/qualcomm2016/project

Qualcomm 解决方案

 

高通 AI Hub

全新高通 AI Hub 包含预优化AI模型库,支持在搭载骁龙和高通平台的终端上进行无缝部署。
该模型库为开发者提供超过75个主流的AI和生成式AI模型,比如Whisper、ControlNet、Stable Diffusion和Baichuan-7B,可在不同执行环境(runtime)中打包,能够在不同形态终端中实现卓越的终端侧AI性能、降低内存占用并提升能效。所有模型均经过优化,以充分利用高通AI引擎内所有核心(NPU、CPU和GPU)的硬件加速能力,从而使推理速度提升4倍。

了解更多

SDK 下载

本版块下载 SDK,只需简单注册,就可轻松下载。