Author Topic: NHD-0420CW-AB3-ND Display variables  (Read 2090 times)

homerjay

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
NHD-0420CW-AB3-ND Display variables
« on: June 05, 2017, 11:40:27 PM »
Hello,

I'm trying to display some sensor variables along with some static text for the labels. Something like this...
Code: [Select]
Temperature        xx.xC
Humidity           xx.x%

For reference my sensor is a DHT11.

My controller is an arduino UNO connected to the display via SPI and so far I've only been able to modify the code found here to simply change the text and include the DHT11 sensor. I am having a hard time understanding how I send data to the display. I'm a beginner with the arduino so I am only familiar with the standard LCD library commands, such as LCD.print, LCD.setcursor, etc. none of which work here it would seem. The way that this display gets its data is kind of foreign to me. If someone could perhaps show some example code for writing a variable or perhaps point me in the right direction for some reading on how to accomplish this that would be awesome.

Thank you so much for your time,
Homerjay

P.S. did anyone else experience artifacts followed by eventual freezing with this display when connected via I2C using the I2C example code?
« Last Edit: June 05, 2017, 11:43:44 PM by homerjay »

DataL

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: NHD-0420CW-AB3-ND Display variables
« Reply #1 on: January 13, 2018, 04:05:57 PM »
Hi Homerjay,

Did you find a solution to your question?

I have found myself in exactly the same boat. It's a steep learning curve!

I haven't tried I2C just yet.

DataL

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: NHD-0420CW-AB3-ND Display variables
« Reply #2 on: January 18, 2018, 06:41:38 AM »
For anybody trying to solve this issue in the future:

Code: [Select]
// global variables
char textbuffer[21];         // 20 characters plus the end marker
const int value1Pin = A0;    // sensor 1 input
int Value1;                  // sensor 1 value

void output(void);
{
   Value1 = analogRead(value1Pin);      // Capture the value of the pin
   snprintf (textbuffer1, 21, "Value 1 =  %d   ", Value1);  // Where "Value 1 = " may be any text, and %d means insert the variable after the comma (Value 1)

   r= 0;                                    // For line 1 only ("1" for line 2, "2" for 3 etc)
      command(new_line[r]);                 // Moves the cursor to the first column of that line
      for (c=0; c<COLUMN_N; c++)  {         // One character at a time,
        data(textbuffer1[c]);  }            // Displays the corresponding string
}


If you want to place two values per line or add a unit like "C" or "PSI" after the value, and don't want the second string dancing around as the first changes in size (eg; "99" to "100"):

Code: [Select]
// Not forgetting these:
const int value2Pin = A1;    // sensor 2 input
int Value2;                  // sensor 2 value

void output(void);
{
   Value2 = analogRead(value2Pin);                          // Capture the value of the pin
   snprintf (textbuffer1, 21, "Val1= %d   ", Value1);       // As above
   snprintf (textbuffer1+10, 21-10, "Val2= %d   ", Value2); // Where textbuffer1+10 starts this addition to the buffer at character 11, 21-10 means it only adds 11 characters from this position.
}

With many thanks for the good folk on forum.arduino.cc

DataL

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: NHD-0420CW-AB3-ND Display variables
« Reply #3 on: January 22, 2018, 04:59:53 PM »
And after much struggling, here is how to display an array of strings that have been saved in PROGMEM:

Code: [Select]
const char welcome0[21] PROGMEM = "X     Arduino      X";
const char welcome1[21] PROGMEM = "        Uno         ";
const char welcome2[21] PROGMEM = "        with        ";
const char welcome3[21] PROGMEM = "X    NHD-0420-CW   X";
const char* const welcometable[] PROGMEM = {welcome0, welcome1, welcome2, welcome3};
char welcome[21];

void LCDwelcome()  {
  Serial.println(F("Arduino Uno with NHD-0420-CW"));
  byte r = 0;                         // Row index
  byte c = 0;                         // Column index
  command(0x01);                      // Clears display (and cursor home)
  delay(2);                           // After a clear display, a minimum pause of 1-2 ms is required
    for (int r = 0; r < 4; r++)  {
      strcpy_P(welcome, (char*)pgm_read_word(&(welcometable[r])));
        command(new_line[r]);            // Moves the cursor to the first column of line [i]
        for (c=0; c<COLUMN_N; c++)  {    // One character at a time,
          data(welcome[c]);              // Displays the corresponding string
}   }   }

 

Blank Display on NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM

Started by SteveCBoard Character LCDs

Replies: 3
Views: 7408
Last post May 13, 2014, 12:04:36 AM
by SteveC
NHD‐C12864A1Z‐FSW‐FBW‐HTT display clears after draw

Started by EdAverillBoard Graphic LCDs

Replies: 6
Views: 9049
Last post November 07, 2014, 08:25:20 AM
by Michael_L
NHD‐4.3‐480272EF‐ATXL#‐CTP | FAN5333 | BBB | Nothing on the Display

Started by Alias_AliasBoard TFTs

Replies: 1
Views: 6137
Last post September 25, 2015, 03:09:24 PM
by Paul_B
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 14622
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD-0420DZW-AG5 - Display "sometimes" shows only 2 lines

Started by stylonurusBoard OLEDs

Replies: 5
Views: 8567
Last post June 18, 2014, 10:09:49 AM
by Michael_L