Hey everyone, I’m a bit new to arduino and c++, and am trying to combine two programs to make a dht11 temperature sensor display to an 0.96” OLED screen, using the adafruit unified sensor and u8g2 libraries respectively (using an Arduino Uno).
I’ve successfully gotten the temperature readout and hello world example programs to run separately, but how do I merge the two? I know c++ is strictured in a few parts, as far as defining variables then executing functions and loops, but I’m not sure how to put the two together. Thanks!
Thanks for the help! Well, I've at least gotten it to successfully compile and upload if I copy and paste things from their respective locations in the code, but since I'm trying to output part of it I need to insert it into where it displays "hello world". I'd imagine I would need to execute parts before and in that part, but not sure how to tell what should be where
When you run into a problem, show us your sketch and tell us what’s not working.
Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu. [code] Paste sketch here. [/code]
void loop(void)
{
u8x8.setFont(u8x8_font_chroma48medium8_r);
//u8x8.drawString(0,0,"Hello World!");
//u8x8.refreshDisplay(); // only required for SSD1606/7
delay(2000);
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println("Error reading temperature!");
u8x8.drawString(0,0,"Error reading temperature!");
u8x8.refreshDisplay(); // only required for SSD1606/7
}
...
...
}
I'm not familiar with the U8x8lib library so I'm not sure what you can pass as parameters to drawString (e.g. an integer) or if there is a drawInteger or ...
Yeah, I’ve fought with posit g code before that was too long, so I just went right to attachments. Will go ahead and read the forum guidelines real quick though
The dht unified sensor and hello world work, humidity test is mine. Yours compiled and uploaded okay, but now it displays "Hello World! 0%", and the serial monitor displays nothing.
i went ahead and bought the hardware that this code uses i am just waiting on the post man to walk from Hong kong, i think i know why it doesnt work but im not exactly certain. if you want drop me a pm and i will help you 1v1... otherwise when the hardware gets here i will code it and get back to you
I now often "write for merge" by making almost every important feature a single, named, non-blocking function. Then merging is just a matter of including the function with cut and paste or #include, and calling it inside loop().
If you do that, you can at least merge your own code.