Help with output of serial data to LCD

Hello. I have a simple project and need some help. I am using a Sensirion SHT-11 temp/humidity sensor with Arduino Duemilanove and an Electronic Brick 1602 LCD. The sensor works fine and is outputting to serial. I have tried sample LCD code and that works, so my pinouts/hookup is fine. The code I am using prints this data to serial. I want to print this to a 16x2 LCD. I have tried using printlcd commands, using a serial to lcd print code all to no avail. You can't print floats to LCD as far as I can tell, how do I do this?

Where's your non-working code?

Why did you make a SerialPrintFloat()? Serial can print float just fine.

As far as I can tell the Electronic Brick 1602 LCD uses the LiquidCrystal library to display information on the LCD display. You have 'included' the LiquidCrystal library in the sketch that you have provided but you haven't used any of it's commands. I would expect to see (at least) an lcd.begin command and one or more lcd.print commands.

Don

Serialprintfloat() is an OLD, I mean real old... routine that I created before we had that feature built in. Sorry for my old code being resurrected. Blame google. My code predates version 0018

Two of us responded within a few hours to the question Icepuppy had. Now it's more than three days later and he hasn't responded to ours. Maybe he thinks we are overcharging him for the help.

Don

Sorry guys, no it's not that I do not appreciate the help, I was unable to get online for a few days.

Yes I am using the brick and using the LCD library, I have been playing with the code but I didn't include it because it is the standard code for the lcd and I was just trying different print commands. My programming skills are pretty limited, hardware and electronics skills are much better.

I will try serialprintfloat and then post what I did.

Ok, so this is one attempt I used with an existing code for printing serial to LCD, this so far does not work. Serial output is fine on the serial monitor, nothing on the LCD. I figured this might have something to do with characters or too much info to fit on the LCD so I modified the code to output the info in a format like this which will fit on a 16x2 LCD. T: 26.73 H: 59.63

Still no joy with the LCD messages. I have used the hello world type code and no problems with that.

Code below...

Is that your code you are trying to run?

When posting code please select it and use the # icon, that way the forum software doesn't mangle it.

All #includes must be at the start of the code before anything else. You have it inside your loop().

Hello, thanks for the tips. Changed the quote and deleted the second reference to the lcd code.

Plus, what you were doing was probably a kind of code bending/or else, using brute force and think that will work. You just opened the bracket of serialprintfloat and copy+paste everything from a sample code inside and re-closed it, without reading the code. Very not cool.

Did you read the credit part of that pasted code to find out what it actually does? Not what you want for sure cause I read it.

First of all for you, have respect for those that made suggestions. The original programmer that wrote the serialprintfloat told you it’s old code so you should toss it and just do Serial.println(a_floating_point_number).

Second, you’ve not read carefully the code you just copy and paste. You should read from now on. Those words tell you exactly what the code is for, which is why it doesn’t work for you. I did notice you got rid of the duplicate steup() and loop() and then some more but that alone was not good enough.

Third, please use the code button when including code. Modify your two posts and keep using the code button for any future code. It’s much easier that way.

code_button.png

Grumpy_Mike: Is that your code you are trying to run?

When posting code please select it and use the # icon, that way the forum software doesn't mangle it.

All #includes must be at the start of the code before anything else. You have it inside your loop().

Mike, let's wait for the OP to read the credit part of his copy+pasted code before we answer him again. If he read it, he'd know what the code does, not what he wants. Then he may ask more relevant questions.

Hello, thanks for the tips. Changed the quote and deleted the second reference to the lcd code.

Let us see the code that you are using now. We may be interpreting your description of your changes differently than you are.

Don

Mike, let's wait for the OP to read the credit part of his copy+pasted code before we answer him again.

OK, but he needs to know he used the quote icon not the # icon next to it.

I’ll try again, I edited the post and the # icon was not available. I see now that I quoted instead of insert code :blush:

I have edited the delays (serialprint and the LCD wait, I am now getting a flash across the LCD of what seems to be dashes (-----------), this i flashing according to my delay, so I’m getting something.

#include <LiquidCrystal.h>

#include <SHT1x.h>

/*
 * Query a SHT10 temperature and humidity sensor
 *
 * A simple example that queries the sensor every 3 seconds
 * and communicates the result over a serial connection.
 * Error handling is omitted in this example.
 */

#include "Sensirion.h"

const uint8_t dataPin  =  8;
const uint8_t clockPin =  9;

float temperature;
float humidity;
float dewpoint;

Sensirion tempSensor = Sensirion(dataPin, clockPin);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  tempSensor.measure(&temperature, &humidity, &dewpoint);

  Serial.print("T:");
  serialPrintFloat(temperature );
  Serial.print("H:");
  serialPrintFloat(humidity);

  

  delay(10000);  
}

void serialPrintFloat(float f){
  Serial.print((int)f);
  Serial.print(".");
  int decplace = (f - (int)f) * 100;
  Serial.print(abs(decplace));

/*
  LiquidCrystal Library - Serial Input
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch displays text sent over the serial port 
 (e.g. from the Serial Monitor) on an attached LCD.
 
 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);

  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(300);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}

liudr: Plus, what you were doing was probably a kind of code bending/or else, using brute force and think that will work. You just opened the bracket of serialprintfloat and copy+paste everything from a sample code inside and re-closed it, without reading the code. Very not cool.

I stated I was using existing code, I did read it but I am not an expert so it may seem not cool to you but I am trying to learn, were you always an expert?

Did you read the credit part of that pasted code to find out what it actually does? Not what you want for sure cause I read it.

I want to print what is going to the serial monitor to the LCD. That is exactly what the comments say, did I read it incorrectly?

First of all for you, have respect for those that made suggestions. The original programmer that wrote the serialprintfloat told you it's old code so you should toss it and just do Serial.println(a_floating_point_number).

Second, you've not read carefully the code you just copy and paste. You should read from now on. Those words tell you exactly what the code is for, which is why it doesn't work for you. I did notice you got rid of the duplicate steup() and loop() and then some more but that alone was not good enough.

I am figuring this out as I go, I am not intentionally making mistakes

Third, please use the code button when including code. Modify your two posts and keep using the code button for any future code. It's much easier that way.

Here is what you said:

The code I am using prints this data to serial. I want to print this to a 16x2 LCD.

So I understand that you want to display your measurement on LCD instead of over serial. Am I correct? Let's make sure this is your intention.

This is what the credit said:

This sketch displays text sent over the serial port (e.g. from the Serial Monitor) on an attached LCD.

If I understand this correctly, also you ran the code yourself as an example so you know too, it relays what you type IN serial monitor TO LCD. It doesn't take a programmer to tell you that is not what you want. You want you arduino measurement to display on LCD, not messages someone type on serial monitor to display on LCD.

So do you want Serial->LCD or do you want sensor results->LCD?

Not being an expert is not an excuse to stuff one program inside another. You wouldn't do that with two screen plays, or two movies, or two articles. Doing it and not getting some blame is unrealistic. If I said you're doing all great and then tell you not to do this will that make a difference with you?

You have 2 Serial.begin(9600); statements - not sure if this has anything to do with your issue, but I would get rid of one of them - probably the second one.

All of this stuff ...

/*
  LiquidCrystal Library - Serial Input

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch displays text sent over the serial port 
 (e.g. from the Serial Monitor) on an attached LCD.

 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);

... which really boils down to this ...

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  lcd.begin(16, 2);

  Serial.begin(9600);

... belongs in setup, so that it will only be done once. And since you already have a serial.begin there it just boils down to this which has to be moved:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  lcd.begin(16, 2);

Don

[Edit] I see that you correctly put

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

before setup, where it belongs.

Not being an expert is not an excuse to stuff one program inside another.

And when you do try to combine two programs, especially Arduino 'sketches', you generally have to combine the setup code and the loop code separately. You can't put the setup code from the second program into the loop part of the first (as you did).

Don

Found another sketch that is what I need and it works fine. Now I just need some help with the rest of the project. Ultimately I want to display temp and humidity, and use outputs to energize relays based on set points. I have a terrarium with a python, and I am currently using an industrial process controller with an RTD. I would like to be able to switch my heaters and a humidity system automatically. I will need to build some delays in to the code as I will need the Arduino to ignore the readings for a period of time after I have energized the heater and/or humidifier, in essence a hysteresis type effect. This has the LCD working the way I want, I will use the second line to display the status of the 2 outputs I require (heater:on/off, humidity:on/off)

#include <SHT1x.h>
#include <LiquidCrystal.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin 8
#define clockPin 9

float temp_c;
float temp_f;
float humidity;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
SHT1x sht1x(dataPin, clockPin);

void setup()
{
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  Serial.begin(9600); // Open serial connection to report values to host
  Serial.println("Starting up");
}

void loop()
{
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  //temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  Serial.print("Temperature: ");
  Serial.print(temp_c,1);
  Serial.print("C / ");
  Serial.print("Humidity: ");
  Serial.print(humidity,1);
  Serial.println("%");

  lcd.setCursor(0,0); // 1st row display
  lcd.print(" T:");
  lcd.print(temp_c,1);
  lcd.print(" H:");
  lcd.print(humidity,1);  
  lcd.print("%");
  
  //Wait before we fetch next sample
  delay(1000);
}