Graph PWM Signal Generated from Arduino Mega on Nextion Display

Good Morning, I have generated a Normal PWM signal and I want to graph it on Nextion Display "NX8048T070-011"
My Code is simple:

#include "EasyNextionLibrary.h"

EasyNex myNex(Serial2);

const int pwmPin = 5;
uint16_t voltageGraph;
const int REFRESH_TIME = 100;           
unsigned long refresh_timer = millis();

void setup() {
  // Set the PWM pin as an output
  pinMode(pwmPin, OUTPUT);
  myNex.begin(9600);
}

void loop() {
  // Generate PWM signal with varying duty cycle
   if((millis()-refresh_timer) > REFRESH_TIME){
    for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
      analogWrite(pwmPin, dutyCycle);
      delay(10); // Adjust the delay based on your requirements
      myNex.writeNum("NvoltageGraph.val", dutyCycle);
    }
    refresh_timer = millis();
   }
}

so how i can graph the PWM signal on Nextion varies with Time?

Welcome to the forum

Your topic has been moved to the Programming category of the forum. Please take care when deciding to create a new topic

Does the library have functions to draw lines and/or turn a single pixel on/off ?

no, the library has 5 Function (Begin, writeNum, writeStr, readNumber, and trigger)

Then it sounds like you need a library with more functions

do you have any suggestions?

Sorry, but I have no experience of using a Nextion display

@PerryBebbington may be able to help

Hello @elkafafy,

I don't support Easy Nextion Library, if you want help with that you need to ask its author @Seithan , although I notice he's not posted anything since March 2022.

As to your PM to me, anything you can do with a library you can do without, the question are: How easy it to do without a library, and does the library support what you want to do?

If you look at the Nextion instruction set Instruction Set - Nextion you will see that to send something to a graph you need to use the 'add' instruction to add a single point to a waveform. I suggest you play around with using 'add' to see how it works, then use it multiple times to get some kind of waveform.

You need to find a way to sample the PWM output and make the samples into something you can send to the Nextion to display as you want. I suggest you first find out how to send stuff successfully to the Nextion, the work on getting the PWM data, then combine the 2 things together to display what you want.

I don't know what your level of programming expertise is, but I get the impression you are one step above beginner. I suggest you need to learn to write code in separate functions and call those from the loop function, rather than trying to do everything in the look function, as you are now. Any of my tutorials illustrate how to do this.

Have you considered using their software and then communicating the data over modbus or other method?

@PerryBebbington Thanks for the input

1 Like

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