报一个错,找不到min函数

  1. #define min(X,Y) ((X) < (Y) ? (X) : (Y))

手动添加

 

之后不报错了

 

、最原始的采集

  1. /************************************************************
  2. MPU9250_Basic
  3. Basic example sketch for MPU-9250 DMP Arduino Library
  4. Jim Lindblom @ SparkFun Electronics
  5. original creation date: November 23, 2016
  6. https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
  7.  
  8. This example sketch demonstrates how to initialize the
  9. MPU-9250, and stream its sensor outputs to a serial monitor.
  10.  
  11. Development environment specifics:
  12. Arduino IDE 1.6.12
  13. SparkFun 9DoF Razor IMU M0
  14.  
  15. Supported Platforms:
  16. - ATSAMD21 (Arduino Zero, SparkFun SAMD21 Breakouts)
  17. *************************************************************/
  18. #include <SparkFunMPU9250-DMP.h>
  19.  
  20. #define SerialPort Serial
  21.  
  22. MPU9250_DMP imu;
  23.  
  24. void setup()
  25. {
  26. SerialPort.begin(115200);
  27.  
  28. // Call imu.begin() to verify communication with and
  29. // initialize the MPU-9250 to it's default values.
  30. // Most functions return an error code - INV_SUCCESS (0)
  31. // indicates the IMU was present and successfully set up
  32. if (imu.begin() != INV_SUCCESS)
  33. {
  34. while (1)
  35. {
  36. SerialPort.println("Unable to communicate with MPU-9250");
  37. SerialPort.println("Check connections, and try again.");
  38. SerialPort.println();
  39. delay(5000);
  40. }
  41. }
  42.  
  43. // Use setSensors to turn on or off MPU-9250 sensors.
  44. // Any of the following defines can be combined:
  45. // INV_XYZ_GYRO, INV_XYZ_ACCEL, INV_XYZ_COMPASS,
  46. // INV_X_GYRO, INV_Y_GYRO, or INV_Z_GYRO
  47. // Enable all sensors:
  48. imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
  49.  
  50. // Use setGyroFSR() and setAccelFSR() to configure the
  51. // gyroscope and accelerometer full scale ranges.
  52. // Gyro options are +/- 250, 500, 1000, or 2000 dps
  53. imu.setGyroFSR(2000); // Set gyro to 2000 dps
  54. // Accel options are +/- 2, 4, 8, or 16 g
  55. imu.setAccelFSR(2); // Set accel to +/-2g
  56. // Note: the MPU-9250's magnetometer FSR is set at
  57. // +/- 4912 uT (micro-tesla's)
  58.  
  59. // setLPF() can be used to set the digital low-pass filter
  60. // of the accelerometer and gyroscope.
  61. // Can be any of the following: 188, 98, 42, 20, 10, 5
  62. // (values are in Hz).
  63. imu.setLPF(5); // Set LPF corner frequency to 5Hz
  64.  
  65. // The sample rate of the accel/gyro can be set using
  66. // setSampleRate. Acceptable values range from 4Hz to 1kHz
  67. imu.setSampleRate(10); // Set sample rate to 10Hz
  68.  
  69. // Likewise, the compass (magnetometer) sample rate can be
  70. // set using the setCompassSampleRate() function.
  71. // This value can range between: 1-100Hz
  72. imu.setCompassSampleRate(10); // Set mag rate to 10Hz
  73. }
  74.  
  75. void loop()
  76. {
  77. // dataReady() checks to see if new accel/gyro data
  78. // is available. It will return a boolean true or false
  79. // (New magnetometer data cannot be checked, as the library
  80. // runs that sensor in single-conversion mode.)
  81. if ( imu.dataReady() )
  82. {
  83. // Call update() to update the imu objects sensor data.
  84. // You can specify which sensors to update by combining
  85. // UPDATE_ACCEL, UPDATE_GYRO, UPDATE_COMPASS, and/or
  86. // UPDATE_TEMPERATURE.
  87. // (The update function defaults to accel, gyro, compass,
  88. // so you don't have to specify these values.)
  89. imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS | UPDATE_TEMP);
  90. printIMUData();
  91. }
  92. }
  93.  
  94. void printIMUData(void)
  95. {
  96. // After calling update() the ax, ay, az, gx, gy, gz, mx,
  97. // my, mz, time, and/or temerature class variables are all
  98. // updated. Access them by placing the object. in front:
  99.  
  100. // Use the calcAccel, calcGyro, and calcMag functions to
  101. // convert the raw sensor readings (signed 16-bit values)
  102. // to their respective units.
  103. float accelX = imu.calcAccel(imu.ax);
  104. float accelY = imu.calcAccel(imu.ay);
  105. float accelZ = imu.calcAccel(imu.az);
  106. float gyroX = imu.calcGyro(imu.gx);
  107. float gyroY = imu.calcGyro(imu.gy);
  108. float gyroZ = imu.calcGyro(imu.gz);
  109. float magX = imu.calcMag(imu.mx);
  110. float magY = imu.calcMag(imu.my);
  111. float magZ = imu.calcMag(imu.mz);
  112. // long imu_temperature=imu.temperature;
  113.  
  114. SerialPort.println();
  115. SerialPort.print("Time: " + String(imu.time) + " ms");
  116. SerialPort.print("Accel: " + String(accelX) + ", " +
  117. String(accelY) + ", " + String(accelZ) + " g");
  118. SerialPort.print(" ");
  119. SerialPort.print("Gyro: " + String(gyroX) + ", " +
  120. String(gyroY) + ", " + String(gyroZ) + " dps");
  121. SerialPort.print(" ");
  122. SerialPort.print("Mag: " + String(magX) + ", " +
  123. String(magY) + ", " + String(magZ) + " uT");
  124. SerialPort.print(" ");
  125. // SerialPort.print("temperature: " +imu_temperature);
  126. }

  

增加数据库交互,增加wifi连接

修改自己的数据库地址

  1. #include <Arduino.h>
  2.  
  3. #include <WiFi.h>
  4. #include <WiFiMulti.h>
  5.  
  6. #include <HTTPClient.h>
  7.  
  8. #include <SparkFunMPU9250-DMP.h>
  9.  
  10. #define USE_SERIAL Serial
  11. #define SerialPort Serial
  12.  
  13. WiFiMulti wifiMulti;
  14.  
  15. MPU9250_DMP imu;
  16.  
  17. const char* ssid = "love";
  18. const char* password = "love123456";
  19.  
  20. // 1 WIFI连接初始化
  21. void wifi_int(){
  22. USE_SERIAL.println();
  23. USE_SERIAL.println();
  24. USE_SERIAL.println();
  25.  
  26. WiFi.begin(ssid, password);
  27. while (WiFi.status() != WL_CONNECTED) {
  28. delay(500);
  29. Serial.print(".");
  30. }
  31.  
  32. Serial.println("");
  33. Serial.println("WiFi connected.");
  34. Serial.println("IP address: ");
  35. Serial.println(WiFi.localIP());
  36.  
  37. // wifiMulti.addAP("love", "love123456");
  38. }
  39.  
  40. // 2 传感器初始化
  41. void IMU_int(){
  42. // Call imu.begin() to verify communication with and
  43. // initialize the MPU-9250 to it's default values.
  44. // Most functions return an error code - INV_SUCCESS (0)
  45. // indicates the IMU was present and successfully set up
  46. if (imu.begin() != INV_SUCCESS)
  47. {
  48. while (1)
  49. {
  50. SerialPort.println("Unable to communicate with MPU-9250");
  51. SerialPort.println("Check connections, and try again.");
  52. SerialPort.println();
  53. delay(5000);
  54. }
  55. }
  56.  
  57. // Use setSensors to turn on or off MPU-9250 sensors.
  58. // Any of the following defines can be combined:
  59. // INV_XYZ_GYRO, INV_XYZ_ACCEL, INV_XYZ_COMPASS,
  60. // INV_X_GYRO, INV_Y_GYRO, or INV_Z_GYRO
  61. // Enable all sensors:
  62. imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
  63.  
  64. // Use setGyroFSR() and setAccelFSR() to configure the
  65. // gyroscope and accelerometer full scale ranges.
  66. // Gyro options are +/- 250, 500, 1000, or 2000 dps
  67. imu.setGyroFSR(2000); // Set gyro to 2000 dps
  68. // Accel options are +/- 2, 4, 8, or 16 g
  69. imu.setAccelFSR(2); // Set accel to +/-2g
  70. // Note: the MPU-9250's magnetometer FSR is set at
  71. // +/- 4912 uT (micro-tesla's)
  72.  
  73. // setLPF() can be used to set the digital low-pass filter
  74. // of the accelerometer and gyroscope.
  75. // Can be any of the following: 188, 98, 42, 20, 10, 5
  76. // (values are in Hz).
  77. imu.setLPF(5); // Set LPF corner frequency to 5Hz
  78.  
  79. // The sample rate of the accel/gyro can be set using
  80. // setSampleRate. Acceptable values range from 4Hz to 1kHz
  81. imu.setSampleRate(10); // Set sample rate to 10Hz
  82.  
  83. // Likewise, the compass (magnetometer) sample rate can be
  84. // set using the setCompassSampleRate() function.
  85. // This value can range between: 1-100Hz
  86. imu.setCompassSampleRate(10); // Set mag rate to 10Hz
  87.  
  88. }
  89.  
  90. //3 发送数据给服务器 数据库
  91. void send_imu_http(float accelX,float accelY , float accelZ, float gyroX , float gyroY, float gyroZ,float magX,float magY,float magZ,float imu_temperature){
  92. HTTPClient http;
  93. USE_SERIAL.print("[HTTP] begin...\n");
  94. // String http_msg="http://45.76.105.89/IMU/msql_inset.php?ax=1.0&ay=2.0&az=3.0&gx=4.0&gy=5.0&gz=6.0&mx=7.0&my=8.0&mz=9.0&temperature=10.0";
  95.  
  96. // -1 修改自己的服务器
  97. String http_msg=String("")+"http://45.76.105.89/IMU/msql_inset.php?"
  98. +"ax="+accelX+"&ay="+accelY+"&az="+accelZ
  99. +"&gx="+gyroX+"&gy="+gyroY+"&gz="+ gyroZ
  100. +"&mx="+magX+"&my="+magY+"&mz="+magZ
  101. +"&temperature="+imu_temperature;
  102.  
  103. http.begin(http_msg); //HTTP
  104. USE_SERIAL.print("[HTTP] GET...\n");
  105. // start connection and send HTTP header
  106. int httpCode = http.GET();
  107. // httpCode will be negative on error
  108. if(httpCode > 0) {
  109. // HTTP header has been send and Server response header has been handled
  110. USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
  111.  
  112. // file found at server
  113. if(httpCode == HTTP_CODE_OK) {
  114. String payload = http.getString();
  115. USE_SERIAL.println(payload);
  116. }
  117. } else {
  118. USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  119. }
  120. http.end();
  121.  
  122. }
  123.  
  124. // 4 主函数 初始化
  125. void setup() {
  126.  
  127. USE_SERIAL.begin(115200);//串口初始化
  128.  
  129. wifi_int();// wifi连接初始化
  130.  
  131. IMU_int();// 传感器初始化 mpu9250
  132.  
  133. }
  134.  
  135. // 5 主函数 无限循环
  136. void loop() {
  137.  
  138. delay(9000);// 延迟9秒 程序运行约1秒 加起来10秒循环一次
  139.  
  140. // 读取传感器数据
  141. if ( imu.dataReady() )
  142. {
  143. imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS | UPDATE_TEMP);//
  144.  
  145. // 原始数据转换
  146. float accelX = imu.calcAccel(imu.ax); //加速度
  147. float accelY = imu.calcAccel(imu.ay);
  148. float accelZ = imu.calcAccel(imu.az);
  149. float gyroX = imu.calcGyro(imu.gx); // 陀螺仪
  150. float gyroY = imu.calcGyro(imu.gy);
  151. float gyroZ = imu.calcGyro(imu.gz);
  152. float magX = imu.calcMag(imu.mx);//磁力计
  153. float magY = imu.calcMag(imu.my);
  154. float magZ = imu.calcMag(imu.mz);
  155. //串口打印传感器数据
  156. SerialPort.println();
  157. SerialPort.print("Time: " + String(imu.time) + " ms");
  158. SerialPort.print("Accel: " + String(accelX) + ", " +
  159. String(accelY) + ", " + String(accelZ) + " g");
  160. SerialPort.print(" ");
  161. SerialPort.print("Gyro: " + String(gyroX) + ", " +
  162. String(gyroY) + ", " + String(gyroZ) + " dps");
  163. SerialPort.print(" ");
  164. SerialPort.print("Mag: " + String(magX) + ", " +
  165. String(magY) + ", " + String(magZ) + " uT");
  166. SerialPort.print(" ");
  167. // SerialPort.print("temperature: " +imu_temperature);
  168.  
  169. //发送给服务器数据库
  170. send_imu_http(accelX,accelY,accelZ,gyroX,gyroY,gyroZ,magX,magY,magZ,23.5);
  171. }
  172.  
  173. }

  

数据库php代码

  1. <?php
  2.  
  3. // http://45.76.105.88/IMU/msql_inset.php?ax=1.0&ay=2.0&az=3.0&gx=4.0&gy=5.0&gz=6.0&mx=7.0&my=8.0&mz=9.0&temperature=10.0
  4. echo "设备请求插入新数据:<br>";
  5. // 1获取请求参数
  6. echo "服务器时间:".date('Y-m-d H:i:s')."<br>";// 当前时间
  7.  
  8. echo "加速度 ";
  9. echo "ax: ";echo $_GET["ax"]." ";//
  10. echo "ay: ";echo $_GET["ay"]." ";//
  11. echo "az: ";echo $_GET["az"]." ";//
  12.  
  13. echo "陀螺仪 ";
  14. echo "gx: ";echo $_GET["gx"]." ";//
  15. echo "gy: ";echo $_GET["gy"]." ";//
  16. echo "gz: ";echo $_GET["gz"]." ";//
  17.  
  18. echo "磁力计 ";
  19. echo "mx: ";echo $_GET["mx"]." ";//
  20. echo "my: ";echo $_GET["my"]." ";//
  21. echo "mz: ";echo $_GET["mz"]." ";//
  22.  
  23. echo "温度 ";
  24. echo $_GET["temperature"];
  25.  
  26. echo "<br>";
  27.  
  28. // 2交互数据库
  29.  
  30. // 2-1连接
  31. $servername = "localhost";
  32. $username = "root";
  33. $password = "root";
  34. $dbname = "IMU";// 数据库
  35. $tablename = "IMU";// 数据库
  36. //创建数据库连接
  37. $conn = new mysqli($servername, $username, $password, $dbname);
  38. //检测是否连接成功
  39. if ($conn->connect_error) {
  40. die("数据库连接失败: " . $conn->connect_error."<br>");
  41. }
  42. echo "数据库连接成功<br> ";
  43.  
  44. // 2-2插入
  45.  
  46. $sql="INSERT INTO ".$tablename." (ax,ay,az,gx,gy,gz,mx,my,mz,temperature) VALUES (".$_GET["ax"].",".$_GET["ay"].",".$_GET["az"].",".$_GET["gx"].",".$_GET["gy"].",".$_GET["gz"].",".$_GET["mx"].",".$_GET["my"].",".$_GET["mz"].",".$_GET["temperature"].");";
  47.  
  48. if ($conn->query($sql) === TRUE) {
  49. echo "新记录插入成功" . "<br>";
  50. } else {
  51. echo "数据库插入失败: " . $sql . "<br>" . $conn->error;
  52. }
  53.  
  54. // 2-4关闭结束
  55.  
  56. $conn->close();
  57. //echo "数据库关闭<br>";
  58.  
  59. ?>

  

项目(1-2)ES32获取mpu9250传入数据库的更多相关文章

  1. 项目(1-1)ES32获取mpu9250数据网页交互显示

    教程 https://www.hackster.io/donowak/esp32-mpu9250-3d-orientation-visualisation-467dc1 项目地址 https://gi ...

  2. 大项目之网上书城(八)——数据库大改&添加图书

    目录 大项目之网上书城(八)--数据库大改&添加图书 主要改动 1.数据库新增表 代码 2.数据库新增触发器 3.其他对BookService和BookDao的修改 代码 4.addBook. ...

  3. AngularJS进阶(三十一)AngularJS项目开发技巧之获取模态对话框中的组件ID

    AngularJS项目开发技巧之获取模态对话框中的组件ID 需求 出于项目开发需求,需要实现的业务逻辑是:药店端点击查看"已发货""已收货"订单详情时,模块弹出 ...

  4. 项目管理---git----快速使用git笔记(四)------远程项目代码的首次获取

    使用git最常见的场景是 你需要参与到一个项目中,而这个项目的代码,同事已经上传到github或者https://coding.net了. 这时候他会给你一个项目代码的远程仓库链接. 例如: http ...

  5. Flutter实战视频-移动电商-09.首页_项目结构建立和获取数据

    09.首页_项目结构建立和获取数据 在config下创建service_url.dart 用来配置我们后端接口的配置文件 一个变量存 接口地址,一个接口方法地址 所有后天请求数据的方法都放在这个文件夹 ...

  6. mysql 获取所有的数据库名字

    mysql 获取所有的数据库名字 一.如果使用的是mysqli: $con = @mysqli_connect("localhost", "root", &qu ...

  7. WebRTC从摄像头获取图片传入canvas

    WebRTC从摄像头获取图片传入canvas 前面我们已经能够利用WebRTC的功能,通过浏览器打开摄像头,并把预览的图像显示在video元素中. 接下来我们尝试从视频中截取某一帧,显示在界面上. h ...

  8. C#Winform从页面获取数据,传入数据库

    环境: 1.SQLite数据库新建数据表,设置相应的字段.(其他数据库形式都相似,using相应数据库的包即可) 2.页面有两个textBox:textBox1.textBox2, 3.一个保存按钮: ...

  9. android项目 之 记事本(11) ----- 加入数据库

    本文是自己学习所做笔记.欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 通过之前的10节,已实现了记事本的大部分功能,有加入拍照.加入照片,加入录音,加 ...

随机推荐

  1. k8s-Annotation(注解)

    k8s-Annotation(注解) Annotation与Label类似,也使用key/value键值对的形式进行定义. Label具有严格的命名规则,它定义的是Kubernetes对象的元数据(M ...

  2. SQL Server优化之SET STATISTICS开关(转载)

    一.准备工作 缓存对于某个查询的性能影响十分之大,所以优化之前要清空缓存. 清除Buffer Pool里面的所有缓存 DBCC DROPCLEANBUFFERS 清除Buffer Pool里的所有缓存 ...

  3. vs2015下编译免费开源的jpeg库,ijg的jpeg.lib

    vs2015下编译免费开源的jpeg库,ijg的jpeg.lib 1. 去Independent JPEG Group官网www.ijg.org下载jpegsrc,我下载的版本是jpegsrc9c.z ...

  4. Oracle分页查询和SQL server分页查询总结

    分页查询是项目中必不可少的一部分,难倒是不难,就是这些东西,长时间不用,就忘的一干二净了.今天特此总结一下这两款数据库分页查询的实现过程(只记录效率比较高的) 一.Oracle中的分页查询 1.通用分 ...

  5. vuejs应用开发前后端分离

    我们知道,无论是web应用还是app应用都有一个前后端,前端主要负责界面交互,后端负责数据持久化.在正规公司中一般是由两个团队来分别完成前端和后端的开发,在小公司或者个人开发的项目中,前后端很有可能是 ...

  6. centos从零开始安装elasticSearch

    前言:elasticSearch作为一款优秀的分布式搜索工具,被广泛用在数据搜集和整理的业务中,知名的比如有github就是采用es来精准的搜索几千万行代码,百度也大量应用es做数据爬取分析,本篇博客 ...

  7. 前端1-----块级标签(独占一行),排版标签(样式排版),其他标签,form表单(input的多种类型)

    前端1-----块级标签(独占一行),排版标签(样式排版),其他标签,form表单(input的多种类型) 一丶HTML块级标签 排版标签 p 标签: 段落标签,会自动在段落上下加上空白来分开 p标签 ...

  8. spark存储管理之磁盘存储--DiskStore

    DiskStore 接着上一篇,本篇,我们分析一下实现磁盘存储的功能类DiskStore,这个类相对简单.在正式展开之前,我觉得有必要大概分析一下BlockManager的背景,或者说它的运行环境,运 ...

  9. kubernetes V1.16 Ingress-nginx部署

    Ingress 在Kubernetes中,服务和Pod的IP地址仅可以在集群网络内部使用,对于集群外的应用是不可见的.为了使外部的应用能够访问集群内的服务,在Kubernetes中可以通过NodePo ...

  10. 创建mybatis的逆向工程

    1.mybatis的逆向工程(我使用的是maven仓库创建) 工作原理:反向工程(通过数据库中的表和字段信息去生成对应的增删改查方法) 其实就是一个自动生成工具 生成实体类(pojo)和映射文件(ma ...