Convert the Celsius temp to a Fahrenheit

So I need to read temp and humidity using a AM2301 or DHT21

it defaults to Celsius

I am Displaying it on a SSD1306 using the following code The question is how would I get it to display in Fahrenheit. (°C x 9/5 + 32 = °F) how do I write this into this code???

#include "U8glib.h"
#include "dht.h"

#define dht_apin A0

dht DHT;

U8GLIB_SSD1306_128X64 u8g(12, 11,U8G_PIN_NONE, 9 , 8 ); // (SCL pin 12, SDA pin 11, RST pin 8, D/C pin 9)

void draw(void) {

u8g.setFont(u8g_font_unifont); // select font
u8g.drawStr(0, 12, " Temp: "); // put string of display at position X, Y
u8g.drawStr(0, 25, "Humid: ");
u8g.setPrintPos(48, 12); // set position
u8g.print(DHT.temperature, 0); // display temperature from DHT21
u8g.drawStr(64, 12, "c ");
u8g.setPrintPos(48, 25);
u8g.print(DHT.humidity, 0); // display humidity from DHT21
u8g.drawStr(64, 25, "% ");
}

void setup(void) {
}

void loop(void) {
DHT.read21(dht_apin); // Read apin on DHT21

u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );

delay(5000); // Delay of 5sec before accessing DHT21 (min - 2sec)
}

hunicombs:
(°C x 9/5 + 32 = °F) how do I write this into this code???

float Fahrenheit;
float Celsius;
Fahrenheit = Celsius * 9/5 + 32;

Does anyone read Nick Gammon's two posts at the top of the Forum before they start posting? I'll bet I've written a 100 posts telling people to read his posts before posting their own. I feel like I'm talking to a rock.

Thanks I got it figured out I needed to add the line

u8g.print(DHT.temperature *9 / 5 + 32,0 );

econjack:
Does anyone read Nick Gammon's two posts at the top of the Forum before they start posting? I'll bet I've written a 100 posts telling people to read his posts before posting their own. I feel like I'm talking to a rock.

Apparently so, Jack. :smiley: (Notice how the OP completely ignored your post?)

As you know, this is my pet peave too.

I started to type the answer to this post long ago, but decided to abort because I'm just plain sick of people posting their code inline, making it harder on everyone. Sick of typing the suggestion to edit and wrap their code in code tags, too.

OldSteve:
Apparently so, Jack. :smiley: (Notice how the OP completely ignored your post?)

As you know, this is my pet peave too.

I started to type the answer to this post long ago, but decided to abort because I'm just plain sick of people posting their code inline, making it harder on everyone. Sick of typing the suggestion to edit and wrap their code in code tags, too.

Maybe we should have a standard reply like:
"Your question will not be answered until you have correctly posted all of your code."

Henry_Best:
Maybe we should have a standard reply like:
"Your question will not be answered until you have correctly posted all of your code."

Yeah. The trouble is that many people reply anyway, so that our suggestions to post correctly are just totally ignored by the OP. (Or as happens now and then, we get a rude reply.)

I suggested yesterday in another thread that perhaps new members should have to read the required guidelines AND answer a simple questionaire before posting is enabled. (It would never happen, of course, but it would almost totally eliminate the problem.)

OldSteve:
Yeah. The trouble is that many people reply anyway, so that our suggestions to post correctly are just totally ignored by the OP. (Or as happens now and then, we get a rude reply.)

I suggested yesterday in another thread that perhaps new members should have to read the required guidelines AND answer a simple questionaire before posting is enabled. (It would never happen, of course, but it would almost totally eliminate the problem.)

The problem with your suggestion is that the poster will have to be able to read for comprehension, something that not all of them can do.

Henry_Best:
The problem with your suggestion is that the poster will have to be able to read for comprehension, something that not all of them can do.

Now that's my other pet peave. :smiley:
In English-speaking countries, don't they teach English any more?

In English-speaking countries, don't they teach English any more?

Nope. I do a fair amount of writing and am called a "grammar Nazi" by some close friends. How many times have you seen "then" used when it should have been "than". Or how about: "He's the man that saved my life" instead of the correct form: "He's the man who saved my life." It's a fingernails-on-chalkboard to me. English "teachers" today would rather teach about symbolism in a phone book than proper grammar.

On the other hand, there are a lot of readers and posters here where English is their second language and they do a lot better than I could in their language. So, rather than correct them, I let it go because I really don't know if the poster is the victim of our lousy English education in the US or a talented writer who is writing in English as a second language.

econjack:
Nope. I do a fair amount of writing and am called a "grammar Nazi" by some close friends. How many times have you seen "then" used when it should have been "than". Or how about: "He's the man that saved my life" instead of the correct form: "He's the man who saved my life." It's a fingernails-on-chalkboard to me. English "teachers" today would rather teach about symbolism in a phone book than proper grammar.

On the other hand, there are a lot of readers and posters here where English is their second language and they do a lot better than I could in their language. So, rather than correct them, I let it go because I really don't know if the poster is the victim of our lousy English education in the US or a talented writer who is writing in English as a second language.

You forgot the lousy English education in the UK, Australia and New Zealand, to name a few other locations.
Nowadays, nobody speaks proper English, like what I does. :astonished:

Henry_Best:
You forgot the lousy English education in the UK, Australia and New Zealand, to name a few other locations.
Nowadays, nobody speaks proper English, like what I does. :astonished:

Don’t forget us Americans. I bet we got y’all all beat on stupids.

Delta_G:
Don’t forget us Americans. I bet we got y’all all beat on stupids.

And you’re showing an example of that.
Read econjack’s last sentence again, this time for comprehension.

Henry_Best:
And you're showing an example of that.
Read econjack's last sentence again, this time for comprehension.

That was exactly my point. I was trying to be funny. Plus the Americans have to be the best at everything idiom applied ironically to being the stupidest.

Delta_G:
That was exactly my point. I was trying to be funny. Plus the Americans have to be the best at everything idiom applied ironically to being the stupidest.

Irony doesn't show up well in a text medium.