I am trying to get my DHT20 and OLED (both from the Arduino Sensor Kit) to work at the same time. I am able to get them working separately with their respective test codes, but when I try to combine the codes the OLED display no longer works. Both are I2C connections but I checked and each device has a different address so that shouldn't be a problem.
Here is my DHT20 test code:
#include "Arduino_SensorKit.h"
//uncomment line below if using DHT20
#define Environment Environment_I2C
void setup() {
//uncomment line below if using DHT20
Wire.begin();
Serial.begin(9600);
Environment.begin();
}
void loop() {
Serial.print("Temperature = ");
Serial.print(Environment.readTemperature()); //print temperature
Serial.println(" C");
Serial.print("Humidity = ");
Serial.print(Environment.readHumidity()); //print humidity
Serial.println(" %");
delay(2000);
}
Here is my OLED display test code:
#include "Arduino_SensorKit.h"
void setup() {
Oled.begin();
Oled.setFlipMode(true);
}
void loop() {
int random_value = random(0, 1023); // create a random value
Oled.setFont(u8x8_font_chroma48medium8_r);
Oled.setCursor(0, 3);
Oled.print("Value: ");
Oled.print(random_value);
delay(1000);
}
This is the code where I tried to get both devices working at the same time:
#include "Arduino_SensorKit.h"
#define Environment Environment_I2C
void setup() {
Oled.begin();
Oled.setFlipMode(true);
Wire.begin();
Serial.begin(9600);
Environment.begin();
}
void loop() {
Oled.setFont(u8x8_font_chroma48medium8_r);
Oled.setCursor(0, 3);
Oled.print("Testing");
Serial.print("Temperature = ");
Serial.print(Environment.readTemperature()); //print temperature
Serial.println(" C");
Serial.print("Humidity = ");
Serial.print(Environment.readHumidity()); //print humidity
Serial.println(" %");
delay(2000);
}
When I use this code the temp and humidity values are printed in the serial monitor but the OLED does not display anything.
Any help is much appreciated!
setup()
?