-->
Page 1 of 1

Proper I2C configuration

PostPosted: Mon May 11, 2015 8:21 am
by Leandro Silva
I'm developing a project using Arduino IDE + HMC5883L + ESP8266. I need to read data from HMC5883L using ESP, but it always give me wrong values. I've tested it directly on Arduino UNO and the sensor is OK. Here follows my code:

Code: Select all#include <HMC5883L.h>
#include <Wire.h>

HMC5883L magnetometer;
MagnetometerScaled scaledVals;

void setup() {
  Serial.begin(115200);
  delay(20);

  Wire.begin(0, 2);
  Wire.setClock(400000);

  Serial.println("Initializing HMC5883L");
  magnetometer = HMC5883L();
  magnetometer.SetScale(1.3);
  magnetometer.SetMeasurementMode(Measurement_Continuous);

}

void loop() {
  scaledVals = magnetometer.ReadScaledAxis();
  printScaled(scaledVals);
  delay(200);
}

void printScaled(MagnetometerScaled scaled)
{
    Serial.print(scaled.XAxis);
    Serial.print(" | ");
    Serial.print(scaled.YAxis);
    Serial.print(" | ");
    Serial.print(scaled.ZAxis);
    Serial.print("\n");
    Serial.flush();
}


It was supposed to print the output like '235.00 | -129.32 | -321.54' but instead, I have '25.00 | 65129.32 | 65321.54'.

Note that this values are only examples that I made from my mind right now.

Can someone see anything wrong with my code?

Re: Proper I2C configuration

PostPosted: Thu May 21, 2015 4:45 am
by tytower
What GPIO pins are you using for I2C ? Silly me its in the code 0,2

This chip is probably running a lot faster than an arduino. Have you made allowance for that . If so tell me how as I don't know either.

On a DHT22 sensor a speed can be passed 6 is default for Arduino generally and as high as 30 for something running at 89MHz . My problem is I am using GPIOpin 2 for this sensor and its working well

So I'm working on BMP180 atm and have not got it going yet because it does not seem to be able to read the sensor. I have it on GPIO 4,5 and I think its finding it just not reading it slowly enough

Edit - I am using the Arduino 1.6.4 latest and the I2C pins are different I think .I assume the question below is for the OP... hey and I just saw the ..Wire.setClock(400000); I don't think this should be so high . It may be affecting the output . Why 400000 , does 100000 make a difference?

Re: Proper I2C configuration

PostPosted: Thu May 21, 2015 5:03 am
by ficeto
which version of the IDE are you using?

Re: Proper I2C configuration

PostPosted: Fri May 29, 2015 9:20 pm
by tytower
Not sure if this is what caused my problem BMP180 readings to be corrected , ficeto may know more .

I was looking at issues in the git hub and found this https://github.com/sparkfun/BMP180_Breakout/issues/1
The suggested change to the line was interesting so I changed it in the BMP180 library . When I started working on the chip sending data to Thingspeak it was suddenly reading I2c correctly ?

There was also the possibility that an update of the ESP8266/Arduino library may have done it but I could not see any changes in the new packages files