hi everyone, I am facing some problems while working on a project
i am trying to use the position of gyro (using GY6050.h library) to rotate the servo motors. Down below is the following code.
for head transmitter.
/*
* Acceleration- Transmitter mit Wemos D1 mini pro
*/
#include <Wire.h>
#include <GY6050.h>
#include <ESP8266WiFi.h>
const char *ssid = "ESP32 AP";
const char *password = "";
// Use WiFiClient class to create TCP connections
WiFiClient client;
const char * host = "192.168.2.13";
const int httpPort = 80;
// Set your Static IP address
IPAddress local_IP(192, 168, 4, 14);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
GY6050 gyro(0x68); // Create Gyro object with "0x68" as I2C addres (most likely the address of your MPU6050)
int GyroX, GyroY, GyroZ;
int servoX1, servoX2, servoX3;
float posXsmoothed, posYsmoothed, posZsmoothed;
float posXold, posYold, posZold;
int16_t ax, ay, az ;
//Servo servoX; Servo servoY; Servo servoZ;
int posX = 90; //10-170
int posY = 60; //0-180
int posZ = 90; //60-120
int posact = 90;
void setup() {
Serial.begin(115200);
delay(10);
//Wire.begin(4,5); // depends on your ESP device
Wire.begin(0,2);
gyro.initialisation();
Serial.println("MPU6050 Test");
delay(1000);
// Explicitly set the ESP8266 to be a WiFi-client
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println();
Serial.print("IP Address: "); Serial.println(WiFi.localIP());
}
void loop() {
// read the sensor values
//Serial.print("AcX = ");
//Serial.print(gyro.refresh('A', 'X')); // Ask for the X axis of the Accelerometer and print it
GyroX = (gyro.refresh('A', 'X'));
//Serial.print(" | AcY = ");
//Serial.print(gyro.refresh('A', 'Y'));
GyroY = (gyro.refresh('A', 'Y')); // Ask for the Y axis of the Accelerometer and print it
//Serial.print(" | GyZ = ");
GyroZ = (gyro.refresh('G', 'Z'));
//Serial.println(gyro.refresh('G', 'Z')); // Ask for the Z axis of the Gyroscope and print it, then carriage return
posX = map(GyroX, -60, 90, 170, 10);
posY = map(GyroY, -90, 90, 180, 0);
posZ = map(GyroZ, -110, 110, -30, 30);
Serial.print(posX); Serial.print(" ");
Serial.print(posY); Serial.print(" ");
Serial.print(posZ); Serial.println(" ");
posZ = posact + posZ; // add gyro value to actual position
posact = posZ; // save actual servo position
char intToPrint1[5]; char intToPrint2[5]; char intToPrint3[5];
itoa(posX, intToPrint1, 10);
itoa(posY, intToPrint2, 10);
itoa(posZ, intToPrint3, 10);
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request. Something like /data/?sensor_reading=123
String url1 = "/data1/"; String url2 = "/data2/"; String url3 = "/data3/";
url1 += "?sensor_1="; url2 += "?sensor_2="; url3 += "?sensor_3=";
url1 += intToPrint1; url2 += intToPrint2; url3 += intToPrint3;
// This will send the request to the server
client.print(String("GET ") + url1 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: keep-alive\r\n\r\n");
client.print(String("GET ") + url2 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: keep-alive\r\n\r\n");
client.print(String("GET ") + url3 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: keep-alive\r\n\r\n");
delay(40);
}
the errors:
c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp: In member function 'int GY6050::refresh(char, char)':
c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp:38:37: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
38 | Wire.requestFrom(address, 14, true); // request a total of 14 registers
| ^
In file included from c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp:11:
C:\Users\Asus\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\Wire/Wire.h:74:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
74 | uint8_t requestFrom(int, int, int);
| ^~~~~~~~~~~
C:\Users\Asus\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\Wire/Wire.h:68:13: note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)'
68 | size_t requestFrom(uint8_t address, size_t size, bool sendStop);
| ^~~~~~~~~~~
c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp:38:37: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
38 | Wire.requestFrom(address, 14, true); // request a total of 14 registers
| ^
In file included from c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp:11:
C:\Users\Asus\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\Wire/Wire.h:74:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
74 | uint8_t requestFrom(int, int, int);
| ^~~~~~~~~~~
C:\Users\Asus\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\Wire/Wire.h:68:13: note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)'
68 | size_t requestFrom(uint8_t address, size_t size, bool sendStop);
| ^~~~~~~~~~~
c:\Users\Asus\Documents\Arduino\libraries\GY6050-master\GY6050.cpp:78:1: error: control reaches end of non-void function [-Werror=return-type]
78 | }
| ^
cc1plus.exe: some warnings being treated as errors
exit status 1
Compilation error: exit status 1
kindly help me solve the issue