DCC++ Nextion Displays - Direct Base Station Control.

UK Steve Apr 14, 2017

  1. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hey Guys

    Some of you have invested in the Nextion Touch Screen displays since I brought them to the attention of this forum. Today I hacked up a little throttle interface that can directly control a Base Station without intermediate devices like Arduino. Yes, that means hooking the Blue wire from Nextion to Pin 0 on base station, and you're good to go. This screenshot is nothing pretty and I've no intention of developing further. Just a proof of concept. If a few of you are up for some tinkering and input of your own, I can show you how to proceed in this thread. There will be no 'free stuff' HMI files from me though, time for you guys to 'make' something.
    Please comment and register an interest if you would like to proceed.

    With Nextions powerful onboard MCU, some truly complex and innovative designs are possible, and it's much easier than writing 100's of lines of C/C++
    My PoC design is a fully functional 3 channel throttle and took around 90 minutes to make in Nextion Editor.
    No, there are no function keys but you could add those as well with not a lot of additional effort.

    Steve.


    NexThrottle.PNG
     
  2. Spuddo

    Spuddo New Member

    2
    3
    4
    Steve,

    I like the idea of the Nextion displays. Relatively easy to program and offers great flexibility. For now I have built up a couple of controllers based on Dave Bodnar's, but with substantial modification. When time permits I may buy a Nextion and start experimenting.

    Russell
     
    Scott Eric Catalano likes this.
  3. VaBEast

    VaBEast TrainBoard Member

    31
    5
    15
    Which Nextion are you using?
     
    Scott Eric Catalano likes this.
  4. VaBEast

    VaBEast TrainBoard Member

    31
    5
    15
    I should have been a little clearer in my question: Enhanced or Basic?
     
    Scott Eric Catalano likes this.
  5. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    My Nextion is the 3.5" enhanced version, but for the purpose of what I wanted to do here, it doesn't matter what size or type of Nextion you have.
    The idea was to get users exploring the possibilities of interface design just using the Nextion Editor app.

    So you don't have to be good at writing C/C++ for Arduino. Indeed as in my PoC example, the simple throttle works as explained and I did the whole thing in under 90 minutes and the underlying code is real easy to understand. I was hoping for example that someone might want to design say a graphical switch controller with their Nextion rather like Greggs DCC++ Controller does in Processsing on the PC. What about a CV programmer with that too? You could with minimal effort do something similar on your Nextion. I can point users toward achieving their goals with discussion and a few tutorials. Over to you guys...
     
    Atani and Scott Eric Catalano like this.
  6. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    Steve I would love to help on this. Although I will say the Nextion piece for me has been the hardest and I still have yet to get the original through an Arduino working properly. I'm pretty handy with understanding and looking through code and logic so for me I'm not sure if I'll be help or hindrance but would be willing to experiment and mess around. I think the multiscreen aspect of the Nextion as well as the graphical interface has lots of possibilities for sure. I do have a spare one to "play around" with.
     
    Scott Eric Catalano likes this.
  7. HansB

    HansB New Member

    8
    8
    1
    I've just been playing around for a while with the Nextion editor to see how it works and with the goal to build a GUI for a DCC++ command station. Now I got the basics working on the GUI and its time to start with the link to the Arduino. What was your approach? Just RX/TX to pin 0/1, set baudrate and send the DCC++ commands from the Nextion without touching the Arduino code?
     
    Scott Eric Catalano likes this.
  8. HansB

    HansB New Member

    8
    8
    1
    I did some tests and yes it was actually that easy that I guessed. However when I took the next step and tried to read the replies from the Arduino I bumbed into some problems. The Nextion-display provides a print command that enables me to send nicely formated ascii commands, just like the DCCpp BaseStation commands, to the Arduino. However there are no corresponding read command. Instead all data that is to be sent from the Arduino needs to be handled in a specific way. This means that I need to alter the DCCpp code.
     
    Scott Eric Catalano likes this.
  9. HansB

    HansB New Member

    8
    8
    1
    Today I did some more analysis on the issue with data transfer from the Arduino to the Nextion display. Its not that tricky to get it up and running and I made a small proof of concept. But I see that its required to do some rewriting of the DCC++ code to have it fully implemented in a nice way. It can be done by adding another wrapper for the Serial.print called NextionSerial.print that addes the extra characters that are required by the nextion before and after each DCC++ reply sent. However the current code sometimes uses several calls to the Serial.print for a single reply. That means that the code needs to be rewritten to make single calls to the print method to keep the code clean. Tomorrows forecast states rain so I guess there is a high chance that I sit down tomorrow and just do it. :whistle:
     
    Scott Eric Catalano likes this.
  10. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    So what do you need to be returned to Nextion in your design?

    Indeed, the data would need reformatting, but that is no big deal, I can sort that for you :)
     
    Scott Eric Catalano likes this.
  11. HansB

    HansB New Member

    8
    8
    1
    Well, in theory all DCC++ commands returns some kind of response that should be handled by the display. But those who dont contain any info could probably be ignored. There are some related to programming, sensors and such that contains interesting info to be displayed to the user.

    I've no problem to sort that out either. But I see two major options here and need to decide wich way to go.

    Option a) Make my own branch of the DCC++ command station Arduino code. Add the support for Nextion that suits my needs. Make it easy such as to ignore support for Ethernet, other board models and similar that I dont need.

    Option b) Participate in creation of a new stable release of the command station that also include some generic support for the Nextion display.

    I think I'll go for option "a" as a start.
     
    Scott Eric Catalano likes this.
  12. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    Hans/Steve any further experimenting here? I've finally gotten around to figuring out a decent amount with the nextion and have it working and been tweaking etc but still through an Arduino to the base station. getting rid of a piece of hardware always a good thing though.
     
    Scott Eric Catalano likes this.
  13. HansB

    HansB New Member

    8
    8
    1
    Hi Keith!
    No need to have an extra Arduino as its possible to connect the display direct to the Arduino that runs the base station. But if you want to have feedback from the Base station to be displayed or otherwise handled by the display, you must alter the base station code.

    I came that far that I think I figured out how everything could be done and did some tests to proof it. Then I put that project aside for some time as I got some other things that stole my attention. Hopefully I will be able to pick ut that project again in a week or two.

    // Hans
     
    Scott Eric Catalano likes this.
  14. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hey Guys

    Here's a little something to play around with :)

    It features some advanced programming techniques that I personally discovered some time ago (hats off to the Itead team, but it would have been nice to have this documented) Yeah I could have developed this further, but that would spoil the fun :)

    Run it in Nextion Editor, it's a fully working 10 channel throttle with direct output to Base Station. For sure adding function, CV, Switch, control is not beyond the reach of the devices. They are extremely powerful.

    Need to know more..........

    I hope the re designation of the .HMI to dot doc doesn't destroy the file data (yes you need to change it back to .HMI)

    I'll put an alternative link up if we are having problems :)


    Thottle.PNG
     

    Attached Files:

    Scott Eric Catalano likes this.
  15. HansB

    HansB New Member

    8
    8
    1
    Looks very interesting. Will for sure play and see.

    // Hans
     
    Scott Eric Catalano likes this.
  16. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    I started messing with last night. I'll have to spend some time on this weekend. It's made for a much larger screen (I have 3.2") so my first step is just a formatting exercise but takes time non the less. I am probably going to reduce locos to 5, etc.

    Once I get that done I can attempt to actually figure out what it's doing :) :)
     
    Scott Eric Catalano likes this.
  17. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hi All,

    I've just today got a rotary encoder attached directly to a Nextion and hacked up some code to do the 0 - 126 throttle adjustment. For folks that prefer the physical twiddly thing to adjust their throttles, this might just be the answer, I've incorporated a slider onscreen also. Coarse on slider, fine on RE? This is only possible on 'enhanced' versions of the display, and is still just Proof of Concept. However it may lead to much simpler designs that still don't need the intermediate MCU. For example, one could design a compact wireless device with just a Nextion and HC-12 serial to radio module :).
    Thoughts....
     
    Scott Eric Catalano likes this.
  18. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    Always moving forward .... just Nextion & HC 12....... how great would that be?
     
    Scott Eric Catalano likes this.
  19. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    All do-able Steve

    and here's the ISR on Nextion, so much easier than doing it in 'C' on Arduino or ESP8266.

    Code:
    if(pio1==1)
    {
      if(n0.val>0)
      {
        n0.val--
      }
    }else if(n0.val<126)
    {
      n0.val++
    }
    h0.val=n0.val
    tm0.en=1
     
    Scott Eric Catalano likes this.
  20. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    Steve I finally did get a version of the early working on my smaller non-enhanced display. I might have to order me an enhanced display now. I still honestly haven't had the time to sit down and study enough to know more then the basics but I certainly see the potential here for sure.
     
    Scott Eric Catalano likes this.

Share This Page