Help with RGB LCD display code

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 6:03 pm

Help with RGB LCD display code

Post by Blimey »

I'm new to programming and Arduino, so have been going through tutorials and googling examples, but am stuck...

I am using an Arduino Uno R3 and RGB positive LCD (adafruit ID 398).

Following examples and tutorials both work, but I am struggling to get the Arduino Analog Read Voltage example (http://arduino.cc/en/Tutorial/ReadAnalogVoltage) to display on the RGB LCD.

I've played around with this for several hours and am embarrassed to admit I'm obviously confused!

Can you help with the simplest method of displaying this on the LCD rather than serial monitor?

The basic code is:

Code: Select all

/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}
Last edited by adafruit_support_bill on Mon Mar 25, 2013 6:30 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Help with RGB LCD display code

Post by Franklin97355 »

It helps if you show us the actual code you are having trouble with and describe the problem you are having. If you have the LCD code working then all you need to do is send the value to the LCD rather than the serial port.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with RGB LCD display code

Post by adafruit_support_mike »

You need to include the RGB LCD libraries, do a bit of housekeeping so the LCD knows where you want the data to appear, then use the 'lcd.print()' function:

Code: Select all

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup () {
    lcd.begin( 16, 2 );         //  tell the library it's a 16x2 LCD
    lcd.setBacklight( 0x7 );    //  set the backlight to white (r=1, g=1, b=1)
    
    Serial.begin( 9600 );       // set this up to double-check
}

void loop () {
    lcd.setCursor( 0, 0 );                          //  move to column 0, row 0

    int sensorValue = analogRead(A0);               //  read the analog value
    float voltage = sensorValue * (5.0 / 1023.0);   //  scale it to the 0-5 range
    Serial.println( voltage );                      //  send that number to the serial monitor
    lcd.print( voltage );                           //  display it on the LCD

    delay( 250 );
}

Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 6:03 pm

Re: Help with RGB LCD display code and library

Post by Blimey »

Where would I find the RGB LCD library for the Adafruit ID #398?

Thanks for your help "[email protected]".

Where would I find the RGB LCD library, you speak of? I have searched Adafruit's website and googled it with no luck. The LCD I bought was Adafruit ID #398 and as I say, I see no mention of a library or code to download for that item listing. https://www.adafruit.com/product/398

Thanks again.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Help with RGB LCD display code

Post by Franklin97355 »

http://arduino.cc/en/Reference/LiquidCr ... LCDLibrary It's part of the included libraries.

Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 6:03 pm

Re: Help with RGB LCD display code

Post by Blimey »

Err, sorry, I still don't get it. The given example sketch starts with:

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

Where does this specific definition come from? Particularly <Adafruit_MCP23017.h>
Without having to inquire here, how would I know where to find this information?

It would be helpful if this detail be included with any purchased item.

I looked at the suggested link:
http://arduino.cc/en/Reference/LiquidCr ... LCDLibrary

But, I cannot see any reference to the above sketch definition.

I'd appreciate a little expanded guidance here. Thanks.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help with RGB LCD display code

Post by adafruit_support_mike »

The Adafruit tutorial for the RGB LCD is here: http://learn.adafruit.com/character-lcds . It's linked from the 'Tutorials' button under the product photos.

The code I gave you used the libraries for the RGB LCD shield, which has a built-in I2C port expander. That was a mistake on my part, mostly because I had that shield sitting right on my desk when I read your first post. The bare LCD doesn't require those libraries, but does use more pins from your Arduino. I apologize for the confusion.

The bare LCD works with the LiquidCrystal library included with every copy of the Arduino IDE. You do need to make sure your wiring matches some "this signal is carried by this pin" configuration information in the library, but the tutorial linked above goes into extensive detail, and includes photos of an LCD with an Arduino and a breadboard.

Running the RGB backlights is a little more complicated with a bare display, but the tutorial has a page devoted to that subject, including sample code.

Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 6:03 pm

Re: Help with RGB LCD display code

Post by Blimey »

Thanks for your help so far... However, I have run into an observation that I need help with:
I can get the RGB LCD to display text on both lines, either with or without the backlight being on - as long as the text is in the void setup part of the sketch.

Code: Select all

    //Text Code in void setup() section

#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 

int brightness = 255; 

void setup() 
{
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Arduino  ");
  lcd.setCursor(0,1);
  lcd.print(" Uno R3  ");  // scroll?  
}
 void loop()
{  } 
However, if I cut the code and paste it into the void loop part of the sketch, the LCD does not print anything other than some strange 'blobs' at the top of the LCD that could be the very tops of the letters.
Why can I not get the text to work in void loop section?

Code: Select all

    //Text Code in void loop() section

#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 

int brightness = 255; 
void setup() 
  { }
 
void loop()
{
   lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Arduino  ");
  lcd.setCursor(0,1);
  lcd.print(" Uno R3  ");  // scroll?
 }  
Why can I not get the text to work in void loop section? Thanks!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help with RGB LCD display code

Post by adafruit_support_bill »

With the lcd.begin() in the loop, you are continuously resetting your display.
Put the lcd.begin() in the setup, so it is only called once. Then you can put your 'print()' statements in the loop.

Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 6:03 pm

Re: Help with RGB LCD display code

Post by Blimey »

Great! Works well. Thanks for your help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”