Beginner: Converting from C to F

Newbie question! Can anyone help converting this sketch from degree C to degree F? Any help would be great!

Thanks

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//------------------------------------------
//DS18B20
#define ONE_WIRE_BUS D3 //Pin to which is attached a temperature sensor
#define ONE_WIRE_MAX_DEV 15 //The maximum number of devices

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
int numberOfDevices; //Number of temperature devices found
DeviceAddress devAddr[ONE_WIRE_MAX_DEV]; //An array device temperature sensors
float tempDev[ONE_WIRE_MAX_DEV]; //Saving the last measurement of temperature
float tempDevLast[ONE_WIRE_MAX_DEV]; //Previous temperature measurement
long lastTemp; //The last measurement
const int durationTemp = 5000; //The frequency of temperature measurement

//------------------------------------------
//WIFI
const char* ssid = “”;
const char* password = “”;

//------------------------------------------
//HTTP
ESP8266WebServer server(80);

//------------------------------------------
//Convert device id to String
String GetAddressToString(DeviceAddress deviceAddress){
String str = “”;
for (uint8_t i = 0; i < 8; i++){
if( deviceAddress < 16 ) str += String(0, HEX);
_ str += String(deviceAddress*, HEX);_
_
}_
_
return str;_
_
}_
_
//Setting the temperature sensor*_
void SetupDS18B20(){
* DS18B20.begin();*
* Serial.print("Parasite power is: ");*
* if( DS18B20.isParasitePowerMode() ){*
* Serial.println(“ON”);*
* }else{*
* Serial.println(“OFF”);*
* }*

* numberOfDevices = DS18B20.getDeviceCount();*
* Serial.print( "Device count: " );*
* Serial.println( numberOfDevices );*
* lastTemp = millis();*
* DS18B20.requestTemperatures();*
* // Loop through each device, print out address*
* for(int i=0;i<numberOfDevices; i++){*
* // Search the wire for address*
_ if( DS18B20.getAddress(devAddr*, i) ){
//devAddr = tempDeviceAddress;
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: " + GetAddressToString(devAddr));
Serial.println();
}else{
Serial.print(“Found ghost device at “);
Serial.print(i, DEC);
Serial.print(” but could not detect address. Check power and cabling”);
}
//Get resolution of DS18b20*

* Serial.print("Resolution: ");
Serial.print(DS18B20.getResolution( devAddr ));
Serial.println();
//Read temperature from DS18b20*

float tempC = DS18B20.getTempC( devAddr );
* Serial.print("Temp C: ");
Serial.println(tempC);
}
}
//Loop measuring the temperature*

void TempLoop(long now){
* if( now - lastTemp > durationTemp ){ //Take a measurement at a fixed time (durationTemp = 5000ms, 5s)
for(int i=0; i<numberOfDevices; i++){
float tempC = DS18B20.getTempC( devAddr ); //Measuring temperature in Celsius
tempDev = tempC; //Save the measured value to the array
}
DS18B20.setWaitForConversion(false); //No waiting for measurement*

* DS18B20.requestTemperatures(); //Initiate the temperature measurement*
* lastTemp = millis(); //Remember the last time measurement*
* }
}
//------------------------------------------
void HandleRoot(){
String message = "Number of devices: ";
message += numberOfDevices;
message += "\r\n*

";
* char temperatureString[6];
message += “\r\n”;
message += “\r\n”;
for(int i=0;i<numberOfDevices;i++){
dtostrf(tempDev, 2, 2, temperatureString);
Serial.print( "Sending temperature: " );
Serial.println( temperatureString );
message += “\r\n”;
message += “\r\n”;
message += “\r\n”;
}
message += “

Device id Temperature
”;
message += GetAddressToString( devAddr );
message += “
”;
message += temperatureString;
message += “
\r\n”;*_

* server.send(200, “text/html”, message );*
}
void HandleNotFound(){
* String message = “File Not Found\n\n”;*
* message += "URI: ";*
* message += server.uri();*
* message += "\nMethod: ";*
* message += (server.method() == HTTP_GET)?“GET”:“POST”;
_ message += “\nArguments: “;
message += server.args();
message += “\n”;_

for (uint8_t i=0; i<server.args(); i++){
_ message += " " + server.argName(i) + “: " + server.arg(i) + “\n”;
}
server.send(404, “text/html”, message);
}
//------------------------------------------
void setup() {
//Setup Serial port speed*

* Serial.begin(115200);
//Setup WIFI*

* WiFi.begin(ssid, password);
Serial.println(””);
//Wait for WIFI connection*

* while (WiFi.status() != WL_CONNECTED) {*
* delay(500);
Serial.print(”.");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print(“IP address: “);
Serial.println(WiFi.localIP());
server.on(”/”, HandleRoot);
server.onNotFound( HandleNotFound );
server.begin();
Serial.println("HTTP server started at ip " + WiFi.localIP().toString() );
//Setup DS18b20 temperature sensor*

* SetupDS18B20();
}
void loop() {
long t = millis();*_

* server.handleClient();*
* TempLoop( t );*
}

I don't think you even have to - just change getTempC to getTempF....

HELP

  • Please use </> code tags to present your code properly in a scrolling / formatted box.
  • Did you go to school ? They taught you how to convert between Celsius and Fahrenheit… it’s exactly the same on a computer.

Add float tempF = 1.8*tempC + 32; in "void TempLoop(long now)" finction after this line
float tempC = DS18B20.getTempC( devAddr ); //Measuring temperature in Celsius

and replace tempDev = tempC; with tempDev[ i ] = tempF;
[/i]

My first "C" class assigned program when I went to community college in Kirkland, WA.

Paul

sherzaad:
Add float tempF = 1.8*tempC + 32; in "void TempLoop(long now)" finction after this line
float tempC = DS18B20.getTempC( devAddr ); //Measuring temperature in Celsius

and replace tempDev = tempC; with tempDev[ i ] = tempF;
[/i]

You mean, replace:
tempDev = tempC;

with:
tempDev = tempF;

You have a after tempDev, that should not be there.

Changing TempC to TempF worked perfectly!

Thanks guys