Working with ESP8266 based boards
Opened this issue · 2 comments
I found your library from this (https://www.best-microcontroller-projects.com/bmp280.html) article and have found it to be perfect for my needs. However, it did not work on my chosen micro controller as-is. Some of the dependencies must be different when using ESP8266 based micro controllers. For my use, I have made the following changes that seem to be working for me. Since these changes are to one of you base classes, I don't know if there are any ramifications that should be noted.
`WirePlus::WirePlus()
{
Wire.begin(); // I2C as Master
#ifdef ESP8266
// DEC - TODO: I've added this as PORTC, TWBR were undefined
// when using on ESP8266 board. Arduino.cc pages state
// that PORTC has to do with analog pins. Why would this
// digital port library need to change these? Need to
// figure this out.
Wire.setClock(400000L);
#else
bitSet(PORTC, 4); // deactivate internal pull-ups for twi
bitSet(PORTC, 5); // as per note from atmega8 manual pg167
// switch to 400KHz I2C - eheheh
TWBR = ((F_CPU / 400000L) - 16) / 2; // see twi_init in Wire/utility/twi.c
#endif // ESP8266
};
`
I think I just ran into exactly this problem with MAG 3110 and a Wemos D1 mini ESP8266 board. Conflicts over i2c library and then the portC and clock setting things. I got fed up of trying to fix it after an hour or so and ordered another magnetometer that has more libraries that support it.
I will try the code above and see if this helps. Thanks for sharing 👍
Oh man...what I wimp I was. All I had to do was comment out the bitSet lines and it worked. I already found the clock setting part elsewhere and thought that I was going to have to find out what the ESP8266 compatible way was to do whatever it is that bitSet does (the hour I mention above was mostly trying to remember/work out how to handle overlapping dependencies like the different versions of the i2c library).