I have tried and tried to get this sorted for ages, and I am having to resort to asking on here, (sorry) I know this is probably an obvious one for some of you guys. I have been only playing with arduino's now for two years, still alot to learn, anyway...
Have a Ekitszone 2 line LCD and I am trying to display three temperatures on it,
the three intergers are tture1 tture2 and tture3 and I need to display them to the lcd with one decimal place only
funny thing is in another project, using a 128 colour LCD display this never was a problem. I think the library for that LCD has int conversion biult in, but Im not knowledgable enough to sift through it.
/*ReadDS18B20three
Reading three DS18B20s
*/
#include <LCD4Bit_mod.h>
#include <stdio.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
#define tture1 2
#define tture2 3
#define tture3 10
//from readTture(Pin), and to send data to printTture...
int pumpon = false;
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
void setup() {
lcd.init();
lcd.clear();
lcd.printIn("CT");
lcd.cursorTo(2, 0);
lcd.printIn("BT");
lcd.cursorTo(2, 8);
lcd.printIn("Pump");
lcd.cursorTo(1, 10);
lcd.printIn("TT");
//For each tture sensor: Do a pinMode and a digitalWrite
pinMode(tture1, INPUT);
pinMode(tture2, INPUT);
pinMode(tture3, INPUT);
digitalWrite(tture1, LOW);//Disable internal pull-up.
digitalWrite(tture2, LOW);
digitalWrite(tture3, LOW);
Serial.begin(9600);
delay(300);//Wait for newly restarted system to stabilize
Serial.print("Temperature measurement, two sensors:\n\n\n");
}
void loop(){
readTture(tture1);//N.B.: Values passed back in globals
printTture();//N.B.: Takes values from globals. Also...
//no newline part of pritTture;
Serial.print(" ");
delay(220);// Delay... must not be too short.
readTture(tture2);//Now read and report 2nd tture.
printTture();
delay(220);// Delay... must not be too short.
Serial.print(" ");//Start new line
readTture(tture3);//N.B.: Values passed back in globals
printTture();//N.B.: Takes values from globals. Also...
Serial.print("\n");
delay(220);// Delay... must not be too short.
//lcd.cursorTo(1, 2); //line=2, x=0
// lcd.printIn(tture1); //this of course wont work
if (pumpon == false) {
lcd.cursorTo(2, 13);
lcd.printIn("OFF");
}
if (pumpon == true) {
lcd.cursorTo(2, 13);
lcd.printIn("ON");
}
}
void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}//end OneWireReset
void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}
d=d>>1; // now the next bit is in the least sig bit position.
}
}//end OneWireOutByte
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;
for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(50);
d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return(d);
}//end OneWireInByte
void readTture(byte Pin){
//Pass WHICH pin you want to read in "Pin"
//Returns values in... (See global declarations)
OneWireReset(Pin);
OneWireOutByte(Pin, 0xcc);
OneWireOutByte(Pin, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset(Pin);
OneWireOutByte(Pin, 0xcc);
OneWireOutByte(Pin, 0xbe);
LowByte = OneWireInByte(Pin);
HighByte = OneWireInByte(Pin);
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
};//end readTture
void printTture(){//Uses values from global variables.
//See global declarations.
//N.B.: No new line inside printTture
if (SignBit) // If it's negative
{
Serial.print("-");
};
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
};
Serial.print(Fract);
};//end printTture