Go Down

Topic: LCD display output of time/temp/current state (Read 235 times) previous topic - next topic

MrSpiffy

Feb 15, 2015, 02:41 am Last Edit: Feb 15, 2015, 02:43 am by MrSpiffy
Hi, everyone!  I'm brand-new to the world of Arduino (and micro-controllers / electronics, in general).  I've learned a lot since I've been perusing this forum, but I'm working on my first Arduino project and am stuck, and hoping you can help me out.

I'm working on an LED light fixture for an aquarium, and planned to use an Arduino to simply dim the LEDs via PWM.  This required a real-time clock chip (RTC) for the code I found, so I purchased a breakout with the DS3231.  Along the way, I stumbled upon some modified code of the original code I had found that also incorporates a temperature probe and cooling fan controls, and so I ended up also acquiring a 20x4 LCD screen and a DS18B20 temperature probe (which hasn't arrived, yet).

Here's the part where I'm stuck:

I have no LCD output with the code I've found.

I'm using Arduino IDE 1.0.5.  (Also tried 1.5.7, but it wouldn't upload.)  And I'm connecting most wiring via a breadboard.  I'll likely solder some items after I work out the kinks, but this helps when I'm still working out what goes where.  Connections seem solid, though.

I've wired up the LCD and the RTC to my Arduino unit (Adafruit Trinket Pro 5V 16Hz).  They seem to function okay.  But this unit is USB, I do not have serial output through my connection to check if the RTC is functioning properly.  I did try uploading some code to set the time, though.  Hopefully that worked.

I tested some simple lcd.print statements to test each line of the LCD screen via LiquidCrystal (non-I2C), and those work just fine.  Although, I'm unable to use lcd.clear() to clear out more than just one line, for some reason... but at least I know the LCD works, and I can communicate with it.  I've included the 10k ohm potentiometer successfully.  It does control contrast.

The code required some adjustments.

I've gotten updated libraries that are compatible with Arduino IDE 1.0 and newer.  A few statements wouldn't compile until I updated them with new syntax.  (New libraries:  OneWire, Time, TimerOne, DS3231RTC).  I also tried the DS1307 and DS3232 libraries, without success.

I also changed the original code from LiquidCrystal_I2C to just LiquidCrystal, since I was planning to connect directly to my LCD without an I2C board.

My code compiles successfully, but I have no output on my LCD other than two rows of blocks.

I'm unsure where to go from here.  Any help would be greatly appreciated.

I've attached both the original and modified code, as well as the necessary libraries.

Pins used:

LCD: 0, 1, 13, 4, 5, 8  (RS, E, D4-D7 on the LCD, RW goes to GND)
RTC: A4, A5, +5V, GND
Fans:  6 (for PWM, not connected yet)
LEDs:  3, 11 (for PWM, not connected yet)
Timer1:  9, 10
Temp probe:  12 (not connected, yet)


Original source where I found the code
(I did post there to touch base with the original programmersl.  But I figured this would be a better place to ask these questions.)

floresta

Quote
LCD: 0, 1, 13, 4, 5, 8  (RS, E, D4-D7 on the LCD, RW goes to GND)
Your LCD is using pins 0 and 1 which are also used to download your code into the Arduino.  As a result there is a good possibility that the code is not being downloaded properly.  You should assign different pins to RS and E if possible.

You can also disconnect the LCD while you are downloading your code and reattach it afterwards.  This won't work if you are using the serial monitor (I haven't looked at your code).

Don




Nick_Pyner

Not a good idea to use pin 12 for the DS18B20. It is part of the SPI bus and you might want it for that purpose later. Same goes for pin 4, which is typically used for SD select. You make no mention of the library for the DS18B20

MrSpiffy

Thanks for the suggestions!  I'll look into all of those items.

I do have some of the analog pins that can be used as digital pins, so I could move the DS18B20 over to one of those, as well as the LCD for pin 4.  It was just convenient to have pins in order, if possible.  But that's easy enough to change with a breadboard.

Also, I'll try switching pins 0 and 1 over to something else to avoid the upload issue.

Strange that it seemed to work fine for a simple "hello world" program, though.  I'll try those and see what happens.

Sorry for not responding sooner.  For some reason it didn't notify me of any replies.

MI320

Hi
Having trouble figuring this out, any one could help me.  :smiley-eek-blue:  :smiley-sad-blue:
Its a project for college and i am trying to get the LDR's and the Laser to respond when moving an tube item away from the LDR and the reading (responses) to be show on the LCD.

This is my code below and the Diagram which i have created. (attached) PNG

Code

#include <LiquidCrystal.h>

// include the library code:
#include <LiquidCrystal.h>

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

int photoRPin = 1;
int minLight;
int maxLight;
int lightLevel;
int adjustedLightLevel;
int oldLightLevel;


void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Smoking Kills");
  Serial.begin(9600);

//Setup the starting light level limits
lightLevel=analogRead(photoRPin);
minLight=lightLevel-10;
maxLight=lightLevel;
oldLightLevel=lightLevel;

  int threshold=50;
lcd.setCursor(0, 0);
if (analogRead(A1)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A2)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A3)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A4)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A5)<threshold) lcd.print('0'); else lcd.print('1');
}


void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

 lightLevel=analogRead(photoRPin);
 delay(10);

//auto-adjust the minimum and maximum limits in real time   
 if(minLight>lightLevel){
   minLight=lightLevel;
 }
 if(maxLight<lightLevel){
   maxLight=lightLevel;
 }
 
 //Map the light level to produce a result between 1 and 28.
 adjustedLightLevel = map(lightLevel, (minLight+20), (maxLight-20), 1, 28);
 adjustedLightLevel = constrain (adjustedLightLevel, 1,28);
 
 /*Only send a new value to the Serial Port if the
   adjustedLightLevel value changes.*/
 if(oldLightLevel==adjustedLightLevel){
   //do nothing if the old value and the new value are the same.
 }else{
   //Update the oldLightLevel value for the next round
   oldLightLevel=adjustedLightLevel;
   
   /*Send the adjusted Light level result
     to Serial port (processing)*/
   Serial.println(adjustedLightLevel);
 }
}


Nick_Pyner

Strange that it seemed to work fine for a simple "hello world" program, though. 

Don't ask how that happened, getting the LCD off 0,1 is definitely a good idea.

It can be useful to make up a nice coloured spreadsheet of pin allocation and conventions

MrSpiffy

Looks like that was it.  I moved the LCD input from pins 0 and 1 over to other available pins and the code seems to work!

Thank you very, very much!

Only thing I need to tweak now is the clock time.  It's not off by more than a few minutes, but still.  I can use the setTime() function to set the Arduino clock.  Just not sure how to push that to the RTC, yet.

And, of course, it's not -1,000°C... once the probe is hooked up, that should change.


Nick_Pyner

I use this with a DS1307.

http://bildr.org/2011/03/ds1307-arduino/

You seem to have an RTC but not actually using it.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy