Nextion LCD Arduino with DC motor help

Hi,

I new to Nextion. I'm using Arduino Uno and I need help coding to get a DC motor controlled by Nextion LCD to turn ON, OFF, and - + speed. So far, these buttons aren't operating the motor when pressed.

I have ran the DC motor with Arduino by themselves and it works, like shown in the picture.!

I am copying these tutorials:

> #include <doxygen.h>
> #include <NexButton.h>
> #include <NexConfig.h>
> #include <NexCrop.h>
> #include <NexGauge.h>
> #include <NexHardware.h>
> #include <NexHotspot.h>
> #include <NexObject.h>
> #include <NexPage.h>
> #include <NexPicture.h>
> #include <NexProgressBar.h>
> #include <NexSlider.h>
> #include <NexText.h>
> #include <Nextion.h>
> #include <NexTouch.h>
> #include <NexWaveform.h>
> 
> //DC motor
> 
> 
> int motorPin = 3;
> int fanSpeed = 100; // Counter
> 
> 
> 
> //Declare Fan page buttons
> NexButton bON = NexButton(3, 3, "bON");
> NexButton bOFF = NexButton(3, 4, "bOFF");
> NexButton bMenuF = NexButton(3, 6, "bMenuF");
> NexButton bFMinus = NexButton(3, 7, "bFMinus");
> NexButton bFPlus = NexButton(3, 8, "bFPlus");
> 
> NexTouch *nex_listen_list[] =
> {
>   //Declare Fan page buttons and slider
>   &bON,
>   &bOFF,
>   &bMenuF,
>   &bFMinus,
>   &bFPlus,
>   NULL
> };
> 
> // Touch events
> 
> void bONPopCallback(void *ptr)  // Release event for button
> {
>   analogWrite(motorPin, 100);  // Turn ON fan
> }
> 
> void bOFFPopCallback(void *ptr)  // Release event for button
> {
>   analogWrite(motorPin, 0);  // Turn OFF fan
> }
> 
> void bFMinusPopCallback (void *ptr)
> {
>   fanSpeed = fanSpeed - 5; //Minus 5 to current value of counter
> }
> 
> void bFPlusPopCallback (void *ptr)
> {
>   fanSpeed = fanSpeed + 5; //Plus 5 to current value of counter
> }
> 
> 
> 
> void setup() {
>   // put your setup code here, to run once:
>   pinMode(motorPin, OUTPUT);
>   Serial.begin(9600);
>   //Serial.println("Give a number from 50 to 255.");
> 
>   //analogWrite(motorPin, 0); //Fan always off when system powered on
> 
> 
>   // Register the event callback fns of each touch event
>   // Format for press events: <object name>.attachPush(<object name>PushCallback);
>   // Format for release events: <object name>.attachPop(<object name>PopCallback);
>   bON.attachPop(bONPopCallback);
>   bOFF.attachPop(bOFFPopCallback);
>   bFMinus.attachPop(bFMinusPopCallback);
>   bFPlus.attachPop(bFPlusPopCallback);
> }
> 
> void loop() {
> 
> 
>   nexLoop (nex_listen_list); //Check for any touch event
> }

Since I am using Arduino, do I need to code in the events tab in Nextion Editor as well?

253719241_10161459745807166_6493442446503631143_n3

Many thanks

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Silly me. I had the Tx and Rx wires the wrong way around!

ON and OFF button works now. Need to get the -+ speed buttons working.

Thanks!

If you want to do things directly on the Nextion, or want to manage the host communication
differently, you have to put code in those tabs.
For a simple Nextion-style touch event, you only require the checkmark, as shown in your picture.

Isn't unplugging the Nextion to upload code to the Arduino annoying,
or does it work despite the duplicate Serial attachment?

You can not use Serial for debugging, which makes it hard.