changed read from int to short

pull/74/head
alanbjohnston 5 years ago committed by GitHub
parent 7d5908bac1
commit 669bc26f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@ int Sensor1 = 0;
int Sensor2 = 0;
float Sensor3 = 0;
void eeprom_word_write(int addr, int val);
int eeprom_word_read(int addr);
short eeprom_word_read(int addr);
void setup() {
@ -29,9 +29,9 @@ void setup() {
Serial.println("Starting!");
pinMode(PC13, OUTPUT);
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
if (bme.begin(0x76)) {
bmePresent = 1;
@ -39,7 +39,7 @@ void setup() {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
@ -47,33 +47,33 @@ void setup() {
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1))/100.0;
float yOffset = ((float)eeprom_word_read(2))/100.0;
float zOffset = ((float)eeprom_word_read(3))/100.0;
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5);
eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5);
eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
eeprom_word_write(0, 0xA07);
eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5);
eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5);
eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
Serial.println(((float)eeprom_word_read(1))/100.0, DEC);
Serial.println(((float)eeprom_word_read(2))/100.0, DEC);
Serial.println(((float)eeprom_word_read(3))/100.0, DEC);
Serial.println(eeprom_word_read(0), HEX);
Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC);
Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC);
Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC);
}
}
@ -86,100 +86,100 @@ void loop() {
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial.read();
// Serial.println(result);
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
setup();
}
if (result == '?')
{
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(mpu6050.getGyroZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
// Serial1.println(counter++);
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
// Serial1.println(counter++);
}
}
#else
if (Serial1.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial1.read();
// Serial1.println(result);
// Serial1.println(result);
if (result == 'R') {
Serial1.println("OK");
delay(500);
setup();
}
setup();
}
if (result == '?')
{
if (bmePresent) {
Serial1.print("OK BME280 ");
Serial1.print(bme.readTemperature());
if (bmePresent) {
Serial1.print("OK BME280 ");
Serial1.print(bme.readTemperature());
Serial1.print(" ");
Serial1.print(bme.readPressure() / 100.0F);
Serial1.print(" ");
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial1.print(" ");
Serial1.print(bme.readHumidity());
} else
{
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial1.print(" MPU6050 ");
Serial1.print(mpu6050.getGyroX());
Serial1.print(" ");
Serial1.print(bme.readPressure() / 100.0F);
Serial1.print(mpu6050.getGyroY());
Serial1.print(" ");
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial1.print(mpu6050.getGyroZ());
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(bme.readHumidity());
} else
{
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.println(Sensor3);
// Serial1.println(counter++);
}
mpu6050.update();
Serial1.print(" MPU6050 ");
Serial1.print(mpu6050.getGyroX());
Serial1.print(" ");
Serial1.print(mpu6050.getGyroY());
Serial1.print(" ");
Serial1.print(mpu6050.getGyroZ());
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.println(Sensor3);
// Serial1.println(counter++);
}
}
#endif
delay(100);
}
@ -192,7 +192,7 @@ void eeprom_word_write(int addr, int val)
}
int eeprom_word_read(int addr)
short eeprom_word_read(int addr)
{
return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}

Loading…
Cancel
Save

Powered by TurnKey Linux.