Hi everyone,
Only newly registered to the forums, although I have been browsing around a little. Glad I signed up, start giving and getting some more ideas for projects
Im having a bit of a problem with a script I am trying to work out. I am getting a temperature from a Dallas1wire setup and then posting to serial aswell as to a 20x4 LCd with LCD3wire.
My serial prints out fine, but when I am printing to the LCD it is just a blank space. Its been bugging me for ages and I just cant figure it out. Here is the code:
#include <OneWire.h>
#include <LCD3Wire.h>
#include <DallasTemperature.h>
#include <stdio.h>
#define LCD_LINES 2
#define DOUT_PIN 3
#define STR_PIN 2
#define CLK_PIN 4
#define ONE_WIRE_BUS 5
#define RELAY_A 6
#define RELAY_B 7
#define LDR 0
#define POT 1
#define BUTTON 2
int temp = 0;
int button_val = 0;
int lcd_clear = 0;
int ldr_val = 0;
char buf[8]="0";
/* LCD KS0066 4-bit data interface, 3 Arduino pins and MC14094 8-bit register
*
* MC14094 input: Arduino digital pin 2=Clock, pin 4=Data, pin 7=Strobe
* MC14094 output: Q8=DB4, Q7=DB5, Q6=DB6, Q5=DB7, Q4=E, Q3=RW, Q2=RS, Q1=None
*
* +--------------------------------------------+
* | Arduino (ATMega 168 or 328) |
* | D02 D03 D04 |
* +----+-------------+-------------+-----------+
* |4 |5 |6
* |1 |2 |3
* +----+-------------+-------------+-----------+
* | Strobe Data Clock |
* | MC14094 8-bit shift/latch register |
* | Q8 Q7 Q6 Q5 Q4 Q3 Q2 Q1 |
* +----+----+----+----+----+----+----+----+----+
* |11 |12 |13 |14 |7 |6 |5 |4
* |11 |12 |13 |14 |6 |5 |4
* +----+----+----+----+----+----+----+---------+
* | DB4 DB5 DB6 DB7 E RW RS |
* | LCD KS0066 |
* +--------------------------------------------+
*/
/* Button Input values
*
*
* +-----------+-----------+
* | | |
* | | |
* 1 2 3
* | | |
* 815 703 512
* \ / \ /
* 597 416
* \ /
* 377
*/
LCD3Wire lcd = LCD3Wire(LCD_LINES, DOUT_PIN, STR_PIN, CLK_PIN);
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
lcd.init();
pinMode(RELAY_A, OUTPUT);
pinMode(RELAY_B, OUTPUT);
lcd_clear = 1;
}
void loop(void)
{
//Clear LCD once only
if(lcd_clear == 1){
lcd.clear();
//Add +1 to make sure clear is not triggered again
lcd_clear ++;
}
lcd.cursorTo(1,0);
lcd.printIn("Welcome to Pebble");
lcd.cursorTo(2,1);
lcd.printIn("v1.02 CCHS");
//delay(50);
button_val = analogRead(BUTTON);
//When button is pressed, show temp
while(button_val >= 810 && button_val <= 820) {
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature for the device 1 (index 0) is: ");
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn("Temperature:");
lcd.cursorTo(1,13);
lcd.print(temp);
//Update lcd_clear to trigger a lcd.clear() when Porgram is restarted
lcd_clear = 1;
//Update value to check if state has changed
button_val = analogRead(BUTTON);
}
//When button is pressed, Show LDR sensor
while(button_val >= 700 && button_val <= 708) {
// request to all devices on the bus
Serial.print("Reading LDR...");
ldr_val = analogRead(LDR);
Serial.println("DONE");
Serial.print("Light reading for sensor is: ");
Serial.println(ldr_val);
lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn("Light Level:");
lcd.cursorTo(1,12);
lcd.printIn(itoa(ldr_val, buf, 10));
delay(500);
//Update lcd_clear to trigger a lcd.clear() when Porgram is restarted
lcd_clear = 1;
//Update value to check if state has changed
button_val = analogRead(BUTTON);
}
}
Here is a snippet of the serial output:
Requesting temperatures…DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures…DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures…DONE
Temperature for the device 1 (index 0) is: 28.31
Requesting temperatures…DONE
Temperature for the device 1 (index 0) is: 28.31
The temperature part is in the first while() loop, I just included the whole script for general reference.
Any help would be great thank you.
John