element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
IoT on Wheels Design Challenge
  • Challenges & Projects
  • Design Challenges
  • IoT on Wheels Design Challenge
  • More
  • Cancel
IoT on Wheels Design Challenge
Blog BLOG 11 : Nextion Display Interface with STM32 NUCLEO [Completed]
  • Blog
  • Forum
  • Documents
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: gsgill112
  • Date Created: 13 Nov 2017 5:45 AM Date Created
  • Views 705 views
  • Likes 0 likes
  • Comments 0 comments
  • sbsr
  • nextion
  • sbsr_iotonwheels
  • iotonwheels
Related
Recommended

BLOG 11 : Nextion Display Interface with STM32 NUCLEO [Completed]

gsgill112
gsgill112
13 Nov 2017

PREVIOUS PAGE                                                                           NEXT PAGE

Hey Guys, This is another quick update on the Nextion Interface Setup and I will also demonstrate it in the video below.

As I have Blogged in my previous blogs that the RX Interrupt on Nextion display was not working and I had planned for a Parallel bus handshake between STM32 and Arduino Nano while leaving the Rx decoding part with Arduino Nano.

 

The primary reason of the Rx Interrupt failure was lack of Buffered Serial Library implementation for STM32L476R Nucleo. After couple of failed attempts of implementation myself I had to fall back on the previously mentioned method.

 

So, The way to approach was to Decode the incoming messages from the Nextion Display in Arduino and convert the data into Parallel bus oaf Arduino which we can further poll in Perodic Routine of STM32.

 

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

 

Arduino Code - For Converting the Nextion messages to Parallel bus For Arduino NANO

NOTE : I am using Official Nextion Libraries

 

Nextion messages look something like This

0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF

and details on each subsection can be found on the Nextion Instruction Set Page

#include 
#include "Timer.h"
#include 


SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino


Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps
Timer t;


void setup() {
  Serial.begin(9600);
  myNextion.init();
  pinMode(4,OUTPUT);     // Display Boot Successful
  digitalWrite(4,LOW);
  pinMode(5,OUTPUT);     // Ride Screen     
  digitalWrite(5,LOW);
  pinMode(6,OUTPUT);     // Bump Pressed
  digitalWrite(6,LOW);
  pinMode(7,OUTPUT);     // Self Check Screen
  digitalWrite(7,LOW);
  pinMode(8,OUTPUT);     // Music Screen
  digitalWrite(8,LOW);
  pinMode(9,OUTPUT);     // Music Left
  digitalWrite(9,LOW);
  pinMode(10,OUTPUT);     // Music Play Pause
  digitalWrite(10,LOW);
  pinMode(11,OUTPUT);     // Music Right 
  digitalWrite(11,LOW);
  t.every(1000, resetAll);
}


void loop() {
  String message = myNextion.listen(); //check for message
  if(message != ""){ // if a message is received...


   if( message == "6"){
    Serial.println("Booted");
    digitalWrite(6,HIGH);
   }else if (message == '0xFF'){
     Serial.println("Off");
     digitalWrite(4,LOW);
    // Ride Screen  
    digitalWrite(5,LOW);
    // Options Screen
    digitalWrite(6,LOW);
    // Self Check Screen
    digitalWrite(7,LOW);
    // Music Screen
    digitalWrite(8,LOW);
    // Music Left
    digitalWrite(9,LOW);
    // Music Play Pause
    digitalWrite(10,LOW);
    // Music Right 
    digitalWrite(11,LOW);
   }else if (message == "7"){
     Serial.println("Riding Screen");
     digitalWrite(5,HIGH);
   }else if (message == "65 7 6 0 ffff ffff ffff"){
     Serial.println("Bump Pressed");
     digitalWrite(6,HIGH);
   }else if (message == "8"){
     Serial.println("Music Controls");
     digitalWrite(8,HIGH);
   }else if (message == "65 8 4 0 ffff ffff ffff"){
     Serial.println("Left Button");
     digitalWrite(9,HIGH);
   }else if (message == "65 8 5 0 ffff ffff ffff"){
     Serial.println("Play Pause Button");
     digitalWrite(10,HIGH);
   }else if (message == "65 8 3 0 ffff ffff ffff"){
     Serial.println("Right Button");
     digitalWrite(11,HIGH);
   }else if (message == "3"){
     Serial.println("Self Check Page");
     digitalWrite(7,HIGH);
   }else {
    Serial.println("INVALID INPUT");
    digitalWrite(4,LOW);
    // Ride Screen  
    digitalWrite(5,LOW);
    // Options Screen
    digitalWrite(6,LOW);
    // Self Check Screen
    digitalWrite(7,LOW);
    // Music Screen
    digitalWrite(8,LOW);
    // Music Left
    digitalWrite(9,LOW);
    // Music Play Pause
    digitalWrite(10,LOW);
    // Music Right 
    digitalWrite(11,LOW);
   }
    Serial.println(message); //...print it out
  }


}


void resetAll(void){
    digitalWrite(4,LOW);
    // Ride Screen  
    digitalWrite(5,LOW);
    // Options Screen
    digitalWrite(6,LOW);
    // Self Check Screen
    digitalWrite(7,LOW);
    // Music Screen
    digitalWrite(8,LOW);
    // Music Left
    digitalWrite(9,LOW);
    // Music Play Pause
    digitalWrite(10,LOW);
    // Music Right 
    digitalWrite(11,LOW);
  Serial.println("Reset All Lines");
}

 

 

Further Here are some Code snippets for my Perodic function checking the Arduino Lines

DEFINING THE BUS

DigitalIn  dispBoot(PC_4);            // Connected to D4 :: Display Boot Sucessful  
DigitalIn  mPnP(PB_1);            // Connected to D10 :: Music PLay n Pause
DigitalIn  mRt(PB_2);            // Connected to D11 :: Music Rt
DigitalIn  rideS(PB_11);            // Connected to D5 :: Ride Screen
DigitalIn  bumpP(PB_12);            // Connected to D6 :: Bump Pressed
DigitalIn  scS(PB_13);            // Connected to D7 :: Self Check Screen
DigitalIn  musicS(PB_14);            // Connected to D8 :: Music Screen 
DigitalIn  mLt(PB_15);            // Connected to D9 :: Music Left

 

Checking the bus in Preodic()

// Screen and Controlls Checks
    if(dispBoot){
        nextionBoot = true;
        nextionScreen ='B';
    }else if(rideS){
        nextionScreen ='R';
    }else if(bumpP){
        nextionScreen ='B';
    }else if(musicS){
        nextionScreen ='M';
    }else if(scS){
        nextionScreen ='S';
    }
    
    if(mPnP){
        nextionMusic ='P';
    }else if(mLt){
        nextionMusic ='L';
    }else if(mRt){
        nextionMusic ='R';
    }
    
    //Update the Display Screen
    if(nextionScreen =='R') {             // checking if nextio display is on rise screen
        nextion.printf(dispSpeed);                                   // updating Speed Value on Nextion Display
        nextion.printf("%d",(int)(ridingSpeed));
        nextion.printf("%c%c%c",terminator,terminator,terminator);
        
        nextion.printf(dispAvg);                                   // updating Avg Speed Value on Nextion Display
        nextion.printf("%d",(int)(avgSpeedF));
        nextion.printf("%c%c%c",terminator,terminator,terminator);
        
        nextion.printf(dispDist);                                   // updating Distance Value on Nextion Display
        nextion.printf("%d",(int)(totalDist));
        nextion.printf("%c%c%c",terminator,terminator,terminator);
    }else if(nextionScreen =='S' && scS){
        if(hum_temp->read_id(&id)){
            nextion.printf(hx_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }else {
            nextion.printf(hx_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
            nextion.printf(temp_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }
        if(press_temp->read_id(&id)){
            nextion.printf(bx_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }else{
            nextion.printf(bx_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }
        if(magnetometer->read_id(&id)){
            nextion.printf(temp_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }else {
            nextion.printf(temp_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);
        }
        if(accelerometer->read_id(&id)){
            nextion.printf(accl_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);   
        }else {
            nextion.printf(accl_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);   
        }
        if(acc_gyro->read_id(&id)){
            nextion.printf(gyro_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);   
        }else{
            nextion.printf(gyro_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);  
        }
        if(BLEStat){
            nextion.printf(ble_check);
            nextion.printf(pass);
            nextion.printf("%c%c%c",terminator,terminator,terminator);   
        }else{
            nextion.printf(ble_check);
            nextion.printf(fail);
            nextion.printf("%c%c%c",terminator,terminator,terminator);  
        }
    while(scS);
    }
   

 

Thanks For Watching

 

Regards,

GS Gill

Anonymous
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube