Help with RGB LCD display code

by Blimey on Sun Mar 24, 2013 9:44 pm

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 5:30 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 5:03 pm

Re: Help with RGB LCD display code

by franklin97355 on Mon Mar 25, 2013 12:24 am

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
franklin97355
 
Posts: 2671
Joined: Mon Apr 21, 2008 1:33 pm

Re: Help with RGB LCD display code

by adafruit_support_mike on Mon Mar 25, 2013 11:39 am

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 );
}
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7135
Joined: Thu Feb 11, 2010 1:51 pm

Re: Help with RGB LCD display code and library

by Blimey on Tue Mar 26, 2013 5:58 pm

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

Thanks for your help "mstone@yawp.com".

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.
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 5:03 pm

Re: Help with RGB LCD display code

by franklin97355 on Tue Mar 26, 2013 7:05 pm

User avatar
franklin97355
 
Posts: 2671
Joined: Mon Apr 21, 2008 1:33 pm

Re: Help with RGB LCD display code

by Blimey on Tue Mar 26, 2013 9:36 pm

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.
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 5:03 pm

Re: Help with RGB LCD display code

by adafruit_support_mike on Wed Mar 27, 2013 11:02 pm

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.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7135
Joined: Thu Feb 11, 2010 1:51 pm

Re: Help with RGB LCD display code

by Blimey on Thu Apr 11, 2013 2:57 pm

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!
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 5:03 pm

Re: Help with RGB LCD display code

by adafruit_support_bill on Sat Apr 13, 2013 5:37 am

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.
User avatar
adafruit_support_bill
 
Posts: 25546
Joined: Sat Feb 07, 2009 9:11 am

Re: Help with RGB LCD display code

by Blimey on Sat Apr 13, 2013 10:40 pm

Great! Works well. Thanks for your help.
Blimey
 
Posts: 22
Joined: Fri Mar 01, 2013 5:03 pm