# Float value on Nextion display

**URL:** <https://forum.arduino.cc/t/float-value-on-nextion-display/958043>\
**Category:** Displays\
**Created:** [February 11, 2022, 3:24pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043 "2022-02-11T15:24:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [February 11, 2022, 3:24pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/1 "2022-02-11T15:24:11Z")

</div>

Hi everyone,

I need your direction on how to display a float value on the Nextion display with minimum 0.01.

thanks.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 11, 2022, 3:39pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/2 "2022-02-11T15:39:51Z")

</div>

I don't use Nextion (does not work with a Mac).

if printing a float is not supported, I assume printing text is ➜ build a string representing your float and print the string (you can use dtostr() for this)

---

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [February 11, 2022, 5:23pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/3 "2022-02-11T17:23:15Z")

</div>

Ok, I will try it out.

---

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [May 17, 2022, 7:01pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/4 "2022-05-17T19:01:20Z")

</div>

Hi,

Can someone help with code or reference to display character or string from matrix keypad to text box of Nextion display?

---

<div class="post-metadata">

**Author:** ![er\_name\_not\_found](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/er_name_not_found/32/647693_2.png) [@er\_name\_not\_found](https://forum.arduino.cc/u/er_name_not_found)\
**Post date:** [May 17, 2022, 7:47pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/5 "2022-05-17T19:47:03Z")

</div>

Google is your friend:  
[Nextion Display with Arduino - Getting Started | Random Nerd Tutorials](https://randomnerdtutorials.com/nextion-display-with-arduino-getting-started/)  
[Arduino Keypad 4x4 - Arduino Project Hub](https://create.arduino.cc/projecthub/jehankandt/arduino-keypad-4x4-70fca5)

---

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [May 19, 2022, 5:08am UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/6 "2022-05-19T05:08:42Z")

</div>

Thanks for the links, i will update as it progress.

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [May 19, 2022, 8:04am UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/7 "2022-05-19T08:04:52Z")

</div>

Or this [Using Nextion displays with Arduino](https://forum.arduino.cc/t/using-nextion-displays-with-arduino/580289/)

---

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [May 30, 2022, 5:53pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/8 "2022-05-30T17:53:18Z")

</div>

Hi,

thanks all for your suggestions and link, i am getting an edge on the project, i have been able to interface the keypad with nextion, my challenge is to update 5 char generated from the keypad to nextion text box to appear as float.  
i will appreciate your suggestions.

thanks

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [May 30, 2022, 6:13pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/9 "2022-05-30T18:13:41Z")

</div>

> [@Alarape](#):
>
> i will appreciate your suggestions.

My suggestions are contained in the tutorial I wrote and gave you a link to. When you have read that, used the ideas contained in it to do what you want to do and got stuck then post your best effort and I will try to help you.

Thanks,

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [May 30, 2022, 6:15pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/10 "2022-05-30T18:15:57Z")

</div>

@Alarape

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

It will help you get the best out of the forum in the future.

Thank you.

---

<div class="post-metadata">

**Author:** ![Alarape](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Alarape](https://forum.arduino.cc/u/Alarape)\
**Post date:** [May 30, 2022, 7:23pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/11 "2022-05-30T19:23:05Z")

</div>

I apologize for not taking to the rules, my project is still on arduino, nextion display and matrix keypad, i am taking it stage by stage all suggestions have been so helpfull.

below is the sketch

```cpp

#include <Keypad.h>
#include <Nextion.h> //INCLUDE NEXTION LIBRARY TO WRITE DATA FROM ARDUINO > NEXTON
//DEFINE OBJECTS TO BE USED ON NEXTION SCREEN
NexText tareweight = NexText(1, 10, "tareweight"); // NexText(page number, object number, "object name")
NexText fillingweight = NexText(1, 11, "fillingweight");
NexText totalweight = NexText(1, 12, "totalweight");
NexText activity = NexText(1, 13, "activity");
NexText statusreport = NexText(0, 14, "statusreport");
NexPage page0 = NexPage(0, 0, "page0");
NexPage page1 = NexPage(1, 0, "page1");
NexPage page2 = NexPage(2, 0, "page2");

char buffer[10] = {0}; //CREATES A BUFFER TO HOLD THE TEXT
//REGISTER OBJECTS FOR NEXTION DISPLAY
NexTouch *nex_listen_list[] =
{
  &tareweight,
  &fillingweight,
  &totalweight,
  &activity,
  &statusreport,
  &page0,
  &page1,
  &page2,
  NULL
};

int counter = 0;
float counter1 = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
//R1, R2, R3, R4, C1, C2, C3, C4.
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

  keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
  keypad.setHoldTime(2000); // Default is 1000mS
  keypad.setDebounceTime(50); // Default is 50mS
}

void loop() {
  nexLoop(nex_listen_list);
  counter1 ++;
  /* Serial.print(counter1);*/
  char key = keypad.getKey();
  if (counter == 3) {
    counter = 0; // set select button counter
  }
  if (key == '#') {
    counter++; //set # key as select button
  }
  if (counter == 1) {
    Serial.print("tareweight.bco=61280");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  else
  { Serial.print("tareweight.bco=65535");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }// conditioned counter to enable tare weight tab
  if (counter == 2) {
    Serial.print("fillingweight.bco=61280");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  else
  { Serial.print("fillingweight.bco=65535");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }// conditioned counter to enable filling weight tab
  // *****************************************************************************************************************
  // conditioned numerical keys for tare weight tab
  if (((key == '1') || (key == '2') || (key == '3') ||
       (key == '4') || (key == '5') || (key == '6') ||
       (key == '7') || (key == '8') || (key == '9') ||
       (key == '0')) && (counter == 1)) {

    Serial.print("tareweight.txt=");
    Serial.print("\"");
    Serial.println(key);
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  // *****************************************************************************************************************
  // conditioned numerical keys for filling weight tab
  if (((key == '1') || (key == '2') || (key == '3') ||
       (key == '4') || (key == '5') || (key == '6') ||
       (key == '7') || (key == '8') || (key == '9') ||
       (key == '0')) && (counter == 2)) {

    Serial.print("fillingweight.txt=");
    Serial.print("\"");
    Serial.println(key);
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  // *****************************************************************************************************************
  //conditioned alpha keys for special function
  if (key == 'A') {
    Serial.print("activity.txt=");
    Serial.print("\"");
    Serial.print("start filling");
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  if (key == 'B') {
    Serial.print("activity.txt=");
    Serial.print("\"");
    Serial.print("stop filling");
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  if (key == 'C') {
    Serial.print("activity.txt=");
    Serial.print("\"");
    Serial.print("tared");
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
  if (key == 'D') {
    Serial.print("activity.txt=");
    Serial.print("\"");
    Serial.print("enter");
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
    counter = 3;
  }
  if (key == '*') {
    Serial.print("activity.txt=");
    Serial.print("\"");
    Serial.print("zero scale");
    Serial.print("\"");
    Serial.write(0xff);
    Serial.write(0xff);
    Serial.write(0xff);
  }
}

// Taking care of some special events.
void keypadEvent(KeypadEvent key) {
  switch (keypad.getState()) {
    case HOLD:
      // *****************************************************************************************************************
      //conditioned alpha keys for special 2nd function
      if (key == 'A') {
        Serial.print("page 2");
        Serial.write(0xff);
        Serial.write(0xff);
        Serial.write(0xff);
      }
      if (key == 'B') {
        Serial.print("page 1");
        Serial.write(0xff);
        Serial.write(0xff);
        Serial.write(0xff);
      }
      break;
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 26, 2022, 7:23pm UTC](https://forum.arduino.cc/t/float-value-on-nextion-display/958043/12 "2022-11-26T19:23:55Z")

</div>

Closed on November 26, 2022, 7:23pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
