完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,
我正在尝试将传感器数据从 NodeMCU 发送到我的 PC。我一直在从 MPU6050 读取 ACC 和陀螺仪数据。我想将其发送到 PC 并在那里进行分析。 我用一个独立的 ESP8266 和一个 Arduino Uno 来做这件事并让它完美地工作,但我想使整个包更小所以我决定使用 NodeMCU。 所以我想我已经设法读取了传感器数据,现在我想将它发送到 PC。 我正在使用示例中的“WiFi 接入点”,但无法正常工作。 我需要使用“server.handleClient();”吗?在循环的开始? 每次我想发送东西时都需要这样做吗? 什么是“server.handleClient();” 甚至?(我的 C++ 技能有限) server.send 的第一个参数是什么?(它必须是 200 还是 404) 有人可以帮助我吗? 代码:全选 * Copyright (c) 2015, Majenko Technologies * All rights reserved. #include #include #include #include long accelX, accelY, accelZ; float gForceX, gForceY, gForceZ; long gyroX, gyroY, gyroZ; float rotX, rotY, rotZ; /* Set these to your desired credentials. */ const char *ssid = "ESP"; const char *password = "thereisnospoon"; String tmp = ""; ESP8266WebServer server(80); /* Just a little test message. Go to http://192.168.4.1 in a web browser * connected to this access point to see it. */ void handleRoot() { server.send(200, "text/html", " You are connected");} void setup() { delay(1000); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); //MPU Wire.begin(4, 5); setupMPU(); } void loop() { server.handleClient(); delay(100); recordAccelRegisters(); recordGyroRegisters(); tmp = String(gForceX) + " " + String(gForceY) + " " + String(gForceZ) + " " + String(rotX) + " " + String(rotY) + " " + String(rotZ) + "rn"; Serial.print(tmp); server.send(200, "text/plain", tmp); } 这只是我从 MPU6050 获取数据的部分: 代码:全选void setupMPU(){ Wire.beginTransmission(0b1101000); //This is the I2C address of the MPU (b1101000/b1101001 for AC0 low/high datasheet sec. 9.2) Wire.write(0x6B); //Accessing the register 6B - Power Management (Sec. 4.28) Wire.write(0b00000000); //Setting SLEEP register to 0. (Required; see Note on p. 9) Wire.endTransmission(); Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4) Wire.write(0x00000000); //Setting the gyro to full scale +/- 250deg./s Wire.endTransmission(); Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5) Wire.write(0b00000000); //Setting the accel to +/- 2g Wire.endTransmission(); } void recordAccelRegisters() { Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x3B); //Starting register for Accel Readings Wire.endTransmission(); Wire.requestFrom(0b1101000,6); //Request Accel Registers (3B - 40) while(Wire.available() < 6); accelX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX accelY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY accelZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ processAccelData(); } void processAccelData(){ gForceX = accelX / 16384.0; gForceY = accelY / 16384.0; gForceZ = accelZ / 16384.0; } void recordGyroRegisters() { Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x43); //Starting register for Gyro Readings Wire.endTransmission(); Wire.requestFrom(0b1101000,6); //Request Gyro Registers (43 - 48) while(Wire.available() < 6); gyroX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX gyroY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY gyroZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ processGyroData(); } void processGyroData() { rotX = gyroX / 131.0; rotY = gyroY / 131.0; rotZ = gyroZ / 131.0; } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
733 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
444浏览 5评论
445浏览 4评论
417浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 10:36 , Processed in 0.825442 second(s), Total 45, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号