社区导航

 

搜索
查看: 1652|回复: 1

[设计过程分享] 体感手套 #5 项目综合调试

[复制链接]

238

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2017-9-22 13:00 | 显示全部楼层 |阅读模式
本帖最后由 北方 于 2017-9-22 13:09 编辑

1. 在项目中增加了串口的输出,选择UART2,即P3_1和P3_0作为串行输出,把采集的位置信号传输到蓝牙模块// Hardware serial port over UART2
Serial btlink(P3_1, P3_0); // serial(Tx,Rx); UART2
2. 在项目中,输出量化采集的信号。
        c = xyDirection;
        btlink.putc(c);
3. 代码如下

  1. #include "mbed.h"
  2. #include "max32630fthr.h"
  3. #include "bmi160.h"

  4. #define xyTHRESHOLD 0.1   //THRESHOLD for x-y gyroDATA
  5. uint8_t xyDirection;
  6. void sendingBY(uint8_t xyDirection);

  7. void dumpImuRegisters(BMI160 &imu);
  8. void printRegister(BMI160 &imu, BMI160::Registers reg);
  9. void printBlock(BMI160 &imu, BMI160::Registers startReg, BMI160::Registers stopReg);

  10. // Hardware serial port over UART2
  11. Serial btlink(P3_1, P3_0); // serial(Tx,Rx); UART2

  12. int main()
  13. {
  14.     //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
  15.      
  16.     DigitalOut rLED(LED1, LED_OFF);
  17.     DigitalOut gLED(LED2, LED_OFF);
  18.     DigitalOut bLED(LED3, LED_OFF);
  19.    
  20.     I2C i2cBus(P5_7, P6_0);
  21.     i2cBus.frequency(400000);
  22.     BMI160_I2C imu(i2cBus, BMI160_I2C::I2C_ADRS_SDO_LO);
  23.    
  24.     printf("\033[H");  //home
  25.     printf("\033[0J");  //erase from cursor to end of screen
  26.    
  27.     uint32_t failures = 0;
  28.     int c;

  29.    
  30.     if(imu.setSensorPowerMode(BMI160::GYRO, BMI160::NORMAL) != BMI160::RTN_NO_ERROR)
  31.     {
  32.         printf("Failed to set gyroscope power mode\n");
  33.         failures++;
  34.     }
  35.     wait_ms(100);
  36.    
  37.     if(imu.setSensorPowerMode(BMI160::ACC, BMI160::NORMAL) != BMI160::RTN_NO_ERROR)
  38.     {
  39.         printf("Failed to set accelerometer power mode\n");
  40.         failures++;
  41.     }
  42.     wait_ms(100);
  43.    
  44.    
  45.     BMI160::AccConfig accConfig;
  46.     //example of using getSensorConfig
  47.     if(imu.getSensorConfig(accConfig) == BMI160::RTN_NO_ERROR)
  48.     {
  49.         printf("ACC Range = %d\n", accConfig.range);
  50.         printf("ACC UnderSampling = %d\n", accConfig.us);
  51.         printf("ACC BandWidthParam = %d\n", accConfig.bwp);
  52.         printf("ACC OutputDataRate = %d\n\n", accConfig.odr);
  53.     }
  54.     else
  55.     {
  56.         printf("Failed to get accelerometer configuration\n");
  57.         failures++;
  58.     }
  59.    
  60.     //example of setting user defined configuration
  61.     accConfig.range = BMI160::SENS_4G;
  62.     accConfig.us = BMI160::ACC_US_OFF;
  63.     accConfig.bwp = BMI160::ACC_BWP_2;
  64.     accConfig.odr = BMI160::ACC_ODR_8;
  65.     if(imu.setSensorConfig(accConfig) == BMI160::RTN_NO_ERROR)
  66.     {
  67.         printf("ACC Range = %d\n", accConfig.range);
  68.         printf("ACC UnderSampling = %d\n", accConfig.us);
  69.         printf("ACC BandWidthParam = %d\n", accConfig.bwp);
  70.         printf("ACC OutputDataRate = %d\n\n", accConfig.odr);
  71.     }
  72.     else
  73.     {
  74.         printf("Failed to set accelerometer configuration\n");
  75.         failures++;
  76.     }
  77.    
  78.     BMI160::GyroConfig gyroConfig;
  79.     if(imu.getSensorConfig(gyroConfig) == BMI160::RTN_NO_ERROR)
  80.     {
  81.         printf("GYRO Range = %d\n", gyroConfig.range);
  82.         printf("GYRO BandWidthParam = %d\n", gyroConfig.bwp);
  83.         printf("GYRO OutputDataRate = %d\n\n", gyroConfig.odr);
  84.     }
  85.     else
  86.     {
  87.         printf("Failed to get gyroscope configuration\n");
  88.         failures++;
  89.     }
  90.    
  91.     wait(1.0);
  92.     printf("\033[H");  //home
  93.     printf("\033[0J");  //erase from cursor to end of screen
  94.    
  95.     if(failures == 0)
  96.     {
  97.         float imuTemperature;
  98.         BMI160::SensorData accData;
  99.         BMI160::SensorData gyroData;
  100.         BMI160::SensorTime sensorTime;
  101.         
  102.         while(1)
  103.         {
  104.             xyDirection = 0;
  105.             imu.getGyroAccXYZandSensorTime(accData, gyroData, sensorTime, accConfig.range, gyroConfig.range);
  106.             imu.getTemperature(&imuTemperature);
  107.             
  108.             //  printf("ACC xAxis = %s%4.3f\n", "\033[K", accData.xAxis.scaled);
  109.             //  printf("ACC yAxis = %s%4.3f\n", "\033[K", accData.yAxis.scaled);
  110.             //  printf("ACC zAxis = %s%4.3f\n\n", "\033[K", accData.zAxis.scaled);
  111.             
  112.             printf("GYRO xAxis = %s%5.1f\n", "\033[K", gyroData.xAxis.scaled);
  113.             printf("GYRO yAxis = %s%5.1f\n", "\033[K", gyroData.yAxis.scaled);
  114.             printf("GYRO zAxis = %s%5.1f\n\n", "\033[K", gyroData.zAxis.scaled);
  115.             
  116.             //  printf("Sensor Time = %s%f\n", "\033[K", sensorTime.seconds);
  117.             //  printf("Sensor Temperature = %s%5.3f\n", "\033[K", imuTemperature);
  118.             
  119.             if (gyroData.xAxis.scaled > 1*xyTHRESHOLD) {
  120.                 xyDirection=6;}
  121.                 else if (gyroData.xAxis.scaled < (-1)*xyTHRESHOLD) {
  122.                     xyDirection=4;}
  123.                     else if (gyroData.yAxis.scaled > 1*xyTHRESHOLD) {
  124.                         xyDirection=8;}
  125.                         else if (gyroData.yAxis.scaled < (-1)*xyTHRESHOLD) {
  126.                             xyDirection=2;}
  127.                            
  128.             printf("xyDirection = %s%x\n", "\033[K", xyDirection);
  129.             sendingBY(xyDirection); //Sending xyDirection to bluetooth via UART


  130.             
  131.             printf("\033[H");  //home
  132.             gLED = !gLED;
  133.             

  134.         c = xyDirection;
  135.         btlink.putc(c);

  136.         }
  137.     }
  138.     else
  139.     {
  140.         while(1)
  141.         {
  142.             rLED = !rLED;
  143.             printf("Fail to read. CHECK the wiring.");  //Fail and check.
  144.             wait(0.25);
  145.         }
  146.     }
  147. }


  148. //*****************************************************************************
  149. void dumpImuRegisters(BMI160 &imu)
  150. {
  151.     printRegister(imu, BMI160::CHIP_ID);
  152.     printBlock(imu, BMI160::ERR_REG,BMI160::FIFO_DATA);
  153.     printBlock(imu, BMI160::ACC_CONF, BMI160::FIFO_CONFIG_1);
  154.     printBlock(imu, BMI160::MAG_IF_0, BMI160::SELF_TEST);
  155.     printBlock(imu, BMI160::NV_CONF, BMI160::STEP_CONF_1);
  156.     printRegister(imu, BMI160::CMD);
  157.     printf("\n");
  158. }


  159. //*****************************************************************************
  160. void printRegister(BMI160 &imu, BMI160::Registers reg)
  161. {
  162.     uint8_t data;
  163.     if(imu.readRegister(reg, &data) == BMI160::RTN_NO_ERROR)
  164.     {
  165.         printf("IMU Register 0x%02x = 0x%02x\n", reg, data);
  166.     }
  167.     else
  168.     {
  169.         printf("Failed to read register\n");
  170.     }
  171. }


  172. //*****************************************************************************
  173. void printBlock(BMI160 &imu, BMI160::Registers startReg, BMI160::Registers stopReg)
  174. {
  175.     uint8_t numBytes = ((stopReg - startReg) + 1);
  176.     uint8_t buff[numBytes];
  177.     uint8_t offset = static_cast<uint8_t>(startReg);
  178.    
  179.     if(imu.readBlock(startReg, stopReg, buff) == BMI160::RTN_NO_ERROR)
  180.     {
  181.         for(uint8_t idx = offset; idx < (numBytes + offset); idx++)
  182.         {
  183.             printf("IMU Register 0x%02x = 0x%02x\n", idx, buff[idx - offset]);
  184.         }
  185.     }
  186.     else
  187.     {
  188.         printf("Failed to read block\n");
  189.     }
  190. }


  191. //******sendingBY(xyDirection)***************
  192. void sendingBY(uint8_t xyDirection)
  193. {
  194.     //printf("Sending direction OK, which is %u",xyDirection);

  195.     printf("\n");
  196. }
复制代码

附件:
MBED所build的可执行文件FTHR_Gloove_MAX32630FTHR.bin
FTHR_Gloove_MAX32630FTHR.bin (26.96 KB, 下载次数: 2)


回复

使用道具 举报

9424

TA的帖子

133

TA的资源

管理员

Rank: 13Rank: 13Rank: 13Rank: 13

发表于 2017-10-2 15:39 | 显示全部楼层
汇总贴在此:
体感手套—by 北方
http://bbs.eeworld.com.cn/forum. ... 4975&fromuid=536508
(出处: 电子工程世界-论坛)

玩板看这里:

http://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

关闭

站长推荐上一条 /5 下一条

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2019-9-22 22:37 , Processed in 0.102124 second(s), 17 queries , Gzip On, MemCache On.

快速回复 返回顶部 返回列表