I would like to run an Adafruit soil sensor on an Adafruit HUZZAH ESP8266 breakout board and show the readings on a small LED 128x64 display (SH1106). Both, the sensor and the display are running on the i2c bus (sensor 0x36, display 0x3c) and are both connected to pins #4 and #5 on the board. The display is driven by the u8g2 library, the sensor is driven by the seesaw library. If I run each device separately, everything is ok. As soon as I run them together on the i2c bus, there seems to be a bus conflict even though the addresses are different. The display is working but the the sensor provides a max. and faulty value of 65535 (in air). It does also not change its value when put into water or when touched.
WHo can help me?
Here is the code:
Code: Select all
#include <U8g2lib.h>
#include <Adafruit_seesaw.h>
Adafruit_seesaw ss;
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
const int AirValue = 350; //you need to replace this value with Value_1
const int WaterValue = 1000; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
u8g2.begin(); //initialize
u8g2.clearBuffer(); //clear display
u8g2.setFont(u8g2_font_inb16_mf);
u8g2.setFontRefHeightExtendedText();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
u8g2.enableUTF8Print();
if (!ss.begin(0x36)) {
Serial.println("ERROR! seesaw not found");
while(1) delay(1);
} else {
Serial.print("seesaw started! version: ");
Serial.println(ss.getVersion(), HEX);
}
}
void loop() {
float tempC = ss.getTemp();
uint16_t capread = ss.touchRead(0); //put Sensor insert into soil
Serial.println(capread);
soilmoisturepercent = map(capread, AirValue, WaterValue, 0, 100);
Serial.print("Relative value: "); Serial.println(soilmoisturepercent);
if(soilmoisturepercent >= 100)
{
Serial.println("100 %");
u8g2.setCursor(15, 10);
u8g2.print("Humidity");
u8g2.setCursor(30, 40);
u8g2.print("100 %");
u8g2.sendBuffer();
delay(1000);
}
else if(soilmoisturepercent <=0)
{
Serial.println("0 %");
u8g2.setCursor(15, 10);
u8g2.print("Humidity");
u8g2.setCursor(30, 40);
u8g2.print(" 0 %");
u8g2.sendBuffer();
delay(1000);
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println("%");
u8g2.setCursor(15, 10);
u8g2.print("Humidity");
u8g2.setCursor(30, 40);
u8g2.print(" ");
u8g2.setCursor(30, 40);
u8g2.print(" ");
u8g2.print(soilmoisturepercent);
u8g2.print(" %");
u8g2.sendBuffer();
delay(1000);
}
}