DHT11 and OLED problem


#1

Hello Dear Forum Members,

My name is Mahir, a newcomer to the forum and an enthusiastic hobbyist coder. I’m thrilled to be a part of this fantastic community and eager to learn more about coding.

I’m currently working on a project and have encountered some issues. I’ve browsed through previous posts related to the topic, but couldn’t quite find a solution to my specific problem.

Command failed: avr-toolchain\bin\avr-g++ -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I"C:\Users\Public\Programs\mblock\resources\app\mlink-v1\external\arduino\avr-library\variants\standard" -I"avr-library/cores/arduino" -I"arduino-libraries/makeblock/src" -I"arduino-libraries/makeblock/src/utility/avr" -I"avr-library/libraries/Wire/src/utility" -I"avr-library/libraries/Wire/src/" -I"avr-library/libraries/EEPROM/src/" -I"avr-library/libraries/SPI/src/" -I"avr-library/libraries/SoftwareSerial/src/" -I"arduino-libraries/arduino/WiFi/src/" -I"arduino-libraries/arduino/SD/src/" -I"arduino-libraries/arduino/Bridge/src/" -I"arduino-libraries/arduino/Temboo/src/" -I"arduino-libraries/arduino/Servo/src/" -I"arduino-libraries/arduino/Ethernet/src/" -I"arduino-libraries/arduino/TFT/src/" -I"arduino-libraries/arduino/SpacebrewYun/src/" -I"arduino-libraries/arduino/LiquidCrystal/src/" -I"arduino-libraries/arduino/GSM/src/" -I"arduino-libraries/arduino/Adafruit_Circuit_Playground/" -I"arduino-libraries/arduino/Adafruit_Circuit_Playground/utility/" -I"arduino-libraries/arduino/Esplora/src/" -I"arduino-libraries/arduino/Firmata/" -I"arduino-libraries/arduino/Firmata/utility/" -I"arduino-libraries/arduino/Keyboard/src/" -I"arduino-libraries/arduino/Mouse/src/" -I"arduino-libraries/arduino/Robot_Control/src/" -I"arduino-libraries/arduino/Robot_Motor/src/" -I"arduino-libraries/arduino/RobotIRremote/src/" -I"arduino-libraries/arduino/Stepper/src/" “C:\Users\mahir\mblock-avr\temp\build\code.cpp” -o “C:\Users\mahir\mblock-avr\temp\build\code.o” C:\Users\mahir\mblock-avr\temp\build\code.cpp: In function ‘void setup()’: C:\Users\mahir\mblock-avr\temp\build\code.cpp:51:49: error: no matching function for call to ‘U8X8_drawString(int, int, float)’ U8X8_drawString(0,3,dht_11_1.readTemperature()); ^ C:\Users\mahir\mblock-avr\temp\build\code.cpp:30:6: note: candidate: void U8X8_drawString(int, int, char*) void U8X8_drawString(int x, int y, char *str){ ^~~~~~~~~~~~~~~ C:\Users\mahir\mblock-avr\temp\build\code.cpp:30:6: note: no known conversion for argument 3 from ‘float’ to ‘char*’ C:\Users\mahir\mblock-avr\temp\build\code.cpp:33:6: note: candidate: void U8X8_drawString(int, int, String) void U8X8_drawString(int x, int y, String str){ ^~~~~~~~~~~~~~~ C:\Users\mahir\mblock-avr\temp\build\code.cpp:33:6: note: no known conversion for argument 3 from ‘float’ to ‘String’

Failed to compile file code.cpp

arduino build failed.

image

In this error, it seems to be asking me to convert the data type. Could you please provide a small visual example on how to do that?

If you can provide assistance or point me in the right direction, I would greatly appreciate it. As a new user, your insights or collaborative problem-solving would be immensely valuable.

Thank you in advance for any help you can offer!


#2

These are problems with the extensions. Most likely the OLED one. You can use the DHT11 one I made (just search Best_codes), and you can try to find a better OLED one. If you can give me the part # of your OLED screen, I might be able to make an extension for it as well, but that might be a while. Otherwise, you might try using the code from the blocks in the mBlock Arduino C editor for UNOs. Also, which UNO device in mBlock are you using?

P.S. Welcome to the forum!


#3

“Hello again, and thank you for your response. I have an Arduino Uno at my disposal. The screen I’m using is 1.3 inches, and I can only get a proper display using the ‘U8g2/U8x8lib.h’ library in mBlock. I didn’t opt for other screens as they are a bit small, but I later realized that there is much more documentation and resources for them. I would truly appreciate your assistance in creating an extension for my screen.”

The number on the OLED screen should not mislead you; I wrote it for a test.


Thank you for your support. After overcoming these stages and coding, I hope to have the opportunity to help beginners like you.


#4

I’'ll see what I can do! Please allow a long time though…


#5

No problem at all, thank you for taking the time.

// generated by mBlock5 for
// codes make you happy

#include “src/DHT.h”
#include “U8g2/U8x8lib.h”

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

float sicaklik = 0;
float nem = 0;

DHT dht_11_1(8, DHT11);
#define U8X8_MODEL 1

#if U8X8_MODEL==1
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
#elif U8X8_MODEL==2
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
#endif

void U8X8_drawString(int x, int y, char *str){
u8x8.drawString(x, y, str);
}
void U8X8_drawString(int x, int y, String str){
u8x8.drawString(x, y, str.c_str());
}
int U8X8_CURRENTLINE=0;

void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
dht_11_1.begin();
u8x8.begin();
u8x8.setPowerSave(0);

u8x8.setFont(u8x8_font_pressstart2p_f);
u8x8.clearDisplay();
U8X8_CURRENTLINE=0;
U8X8_drawString(0,3,String(dht_11_1.readTemperature()).toInt());
U8X8_drawString(0,U8X8_CURRENTLINE * 1,"");
U8X8_CURRENTLINE++;
if (U8X8_CURRENTLINE * 1 > 64) {u8x8.clearDisplay(); U8X8_CURRENTLINE=0;}
U8X8_drawString(0,0,“NEM”);
U8X8_drawString(0,U8X8_CURRENTLINE * 1,"");
U8X8_CURRENTLINE++;
if (U8X8_CURRENTLINE * 1 > 64) {u8x8.clearDisplay(); U8X8_CURRENTLINE=0;}

}

void _loop() {
}

void loop() {
_loop();
}


#6

Try this code manually:


#include <DHT.h>
#include <U8g2lib.h>

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

float sicaklik = 0;
float nem = 0;

DHT dht_11_1(8, DHT11);
U8G2_SH1106_128X64_NONAME_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  dht_11_1.begin();
  u8g2.begin();
  u8g2.setPowerSave(0);

  u8g2.setFont(u8g2_font_pressstart2p_f);
  u8g2.clearDisplay();

  u8g2.drawStr(0, 3, String(dht_11_1.readTemperature()).c_str());
  u8g2.drawStr(0, 6, "");
  u8g2.drawStr(0, 0, "NEM");
  u8g2.drawStr(0, 9, "");
  u8g2.sendBuffer();
}

void loop() {
  float temperature = dht_11_1.readTemperature();
  float humidity = dht_11_1.readHumidity();

  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_pressstart2p_f);
  u8g2.setCursor(0, 3);
  u8g2.print(temperature);
  u8g2.setCursor(0, 6);
  u8g2.print(humidity);
  u8g2.sendBuffer();

  delay(2000);
}

Hope this helps. The error is with the curly quotes in “DHT.h”. They should be normal.


#7

Adafruit_SH1106-master.zip (15.4 KB)

I can capture images from the screen with the library I added. I included it in case you want to take a look because I don’t know how to transfer this library to mBlock. I might need a bit of help to do it through the code. I hope we can overcome this issue together.

I will attach some photos and video


#8

It might be a while… I have been really busy. :confused:


#9

I looked, and it is a bit too complicated for me to make right now, sorry. :confused:
You can try making an extension here:
https://ext.mblock.cc/