Start a new topic

Arduino Nextion HMI

Kenneth Blanch
started a topic 21 hours ago

Could someone tell me why this sketch doesn’t work I am using the  ITEADLIB_Arduino_Nextion-master library  

When combining “AnalogInOutSerial” from the built in examples  and “CompNumber” example from  ITEADLIB_Arduino_Nextion-master library I am expecting the “outputValue” (analog reading from a potentiometer) to be displayed in the  Number component on the screen, I get “0”.


ino
(2.61 KB)

yes it works it wasn't the wiring I made your suggested changes to code   thanks very much my reading are erratic jumping from 12 to 255 I think i will try another potentiometer.

but i have output to the screen, now I may make some progress  with my project until i come across another road block.

'

I've just checked your code and it all works fine !
Here a video: CompNumber Test video

I think you need to check your +5V wire connection to your potentiometer.

 

Try this:

void loop(void)
{
   // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the serial monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
    /*
     * When a pop or push event occured every time, 
     * the corresponding component[right page id and component id] in touch event list will be asked.
     */
     uint32_t number;
     number = outputValue;
     n0.setValue(number);//Delete this line if it dosent work
     nexLoop(nex_listen_list);
}

  I haven't test this, I'm now at my work.

the SoftwareSerial function is written into the library 'NexHardware'

 

Sorry I may have not explained myself very well there is no problem with the interface

between Arduino and Nextion the example from the Library“CompNumber” works fine.

but when i try to adapt this to display the value for the  potentiometer it  shows "0".

Kenneth,

You will need a SoftwareSerial function !
Please check this topic, to get the info:
SoftwareSerial How To

The main problem is, the Uno or Nano boards don't have more than one Hardware Serial RX / TX !
If I'm looking to your sketch, you are using this RX and TX for debugging.
(and the Arduino IDE needs these RX and TX also, to upload the sketch)
This means, you can't use it to communicate with the Nextion.

I hope this helps you.

 

firstly the pins are defined in  the library "NexHardware"  and the circuit works it feed the pot values to the Serial Monitor but not to the Nextion screen so i am still puzzled as to how to get this to work thank for looking into it.

HMI
(1.27 MB)

I had said I don't do Arduino, but would Arduino not require defining which pins you are using for serial communications to the Nextion?  I see you had two pins defined in this piece of the source, one for an LED and the other to your potentiometer.  In your HMI (not included) you need a number component, and according to this file that number component needs to be ID 3 on Page 0.  If your serial pins have been defined the source for it is not included.  And with Arduino there are many source files that could be causing it to not work.  It could be an electrical issue (one guy on here changed his wire and all worked, another tied ground on the Arduino with ground on the Nextion and all worked).  You really haven't provided much to work with.  But it is usually the many source .cpp and .h files for why I don't do Arduino.

I am sorry for not understanding the thanks.  Your issue is resolved?  Or that I responded and you are still looking?

thanks the code is just cut and pasted parts  from Examples the examples work fine on my Arduino UNO and NANO and I have been seaching post threads for week.


Kenneth


I hope some of the Arduino guys are on the board over the weekend with the Olympics on.  I don't do Arduino otherwise I might have taken a peek.  Not everyone visits the forum as frequently as I have been as of late, so waiting for someone here may be a while.  I would recommend also making use of the many Arduino sites on the net and especially blogs (Google search of Nextion and the specific type of Arduino you are using) where people love to post details of their successes.  Arduino is such a broad term, and "why does my code not work" is too generic and may not get as many takers as a specific question.   There are many threads on here that have Arduino related topics where the solutions have been posted.  So couple the question of "did you post without even reading any of the other threads?" with "Arduino is not an issue with the Nextion Display, it is an issue with the MCU you have chosen to use to connect to a Nextion" and some of the posters might pass it over without giving it a second thought.


But I do remember seeing that Edwin created a simplified Arduino library not that long ago (so not too too deep into the Free Chat section) that maybe of some use for you.  Again, I don't do Arduino.

Login or Signup to post a comment