Start a new topic

8 Channel Relay Control

 

 Hello everyone. I am new here and also new to these types of devices. I do have a little experience with linux and raspberry pi's and can follow some code when trying to figure out what it does. With all that being said here is my question.


Is it possible to have the enhanced Nextion's control a relay without the need of an arduino? One of these to be exact, http://a.co/4hO1RJs


All I want to do is have a screen that has 8 on/off switches that turns each relay on or off. No additional features. I have an arduino to use if its absolutely needed but I am wanting this package to be as small as possible.


Also what is a good resource for me to learn the basics for a project such as this? I am more of a visual learner.


Thanks in advance.


The Nextion is a serial device with a few text based commands.

- This is to say it would work with any MCU that can generate serial over its lines. (... Pie is Good)


I haven't looked to see if 20ma on each of the extended pins is within limits or used that relay, but personally, I would opt for an appropriate MCU for driving the relays and not solely off the Nextion

For me it is better to blow a $3 MCU than cripple my beloved Nextion.


I haven't seen many Pi examples or discussions on here, but this is simple serial

- All commands to Nextion and responses from Nextion are terminated with ÿÿÿ or 0xFF 0xFF 0xFF

The Nextion Instruction Set is https://www.itead.cc/wiki/Nextion_Instruction_Set


So after you create you HMI in the Nextion Editor you will build your TFT with the Compile Button.

The TFT file is located with the File Menu -> Open Build Folder.

Either Upload this via serial through the Editor, or via microSD

So, for eight relays - I assume a dual-state button or dual state logic 1 / 0 in your HMI project

- You can check the Send Component ID under the Touch Release of each Dual State


Text Based Command examples


So when you want to toggle the dual-state button on page0 bt0 from the MCU, serially send:

bt0.val=1ÿÿÿ for on or bt0.val=0ÿÿÿ for off (or even page0.bt0.val=1-page0.bt0.valÿÿÿ)

Simple enough


IF Send Component ID is checked in Touch Release of the Dual-State Button page0 bt0

-  the Nextion will send the Touch Return Code 0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF

First Byte is the Return Code type - 0x65 is Touch Event

Second Byte 0x00 is PageID Number (left of pagename in Editor)

Third Byte 0x01 is Component .id attribute (found when you click on the Component in Attribute pane)

Forth Byte 0x00 is Touch Event Type 1 is pressed, 0 is released

0xFF 0xFF 0xFF is data termination as stated previously.


Each of your eight Dual States will have their unique .id in the Third Byte.


The rest of you project is some programming logic and glue,

and some beautifying of your HMI, maybe a bit of Nextion side logic


As far as Visual Learning ... I would say it is tough to learn this visually

- serial communications and programming logic is a non visual

- The Nextion Editor is Visual


There are Visual Platforms existing in the market, and MIT also attempts a visual programming

- but mostly these will lock you into their platform and make the simple more complex.



Thank you for the detailed info. I will use the Arduino. You make a good point about protecting the more expensive component. By visually learning I meant someone showing how to do simple projects with explainations of how it's all working together. I just need to read over the wiki a few more times though. I'll pick it up after that.

Please visit the Announcement section of the Forum


Nextion user manual (updating)

http://support.iteadstudio.com/discussions/topics/1000065323

- Contains examples for beginners to more advanced


Also the many links inside the Nextion FAQs

http://support.iteadstudio.com/discussions/topics/11000002523


This will help get you started.


And to peak at a bit more advanced, I have two Tutorials that walk through

step by step that may provide some Nextion coding techniques

Look for these in the Free Chat section (or using search bar above)

- Creating a Yahtzee Game within Nextion Logic

- Creating a Nextion Piano within Nextion Logic

Digging deep into the STM32 specs Section 6.2 Absolute Maximum Ratings


- Max 25ma by any I/O and control pin

- Max 80ma as the sum of ALL pins.


Exactly how much of this total is already used by the Nextion, I am uncertain

But this is indeed shared, eight relays wanting 20ma each = 160ma.


 See. I told you i was a noob to this type of thing. I didnt even think about power consumption. I have finished wiring everything up and have started reading through the links you suggested. Thanks again for all of the help.

There is certainly nothing wrong with having the sites set on a longer goal, but always good to start with the basics.  And although it goes against the nature to read the manuals first  -- the manuals should be read.  I am not sure what you are going to connect to your relays but you certainly don't want to put them at risk.  There may also be some other components that can assist, I am told a darlington array can help - but loads of reading to understand the entire circuit as a whole.

Ok. So I'm running into an issue very early in this project. I have my 8 duel state buttons and have them all set to send component id. Debug shows the output you described when I toggle the buttons. I can't get the arduino serial monitor to detect and input. I feel that I can get the remaining coding to work if I could only get this part going. here is how I have it all wired up. Nextion 4 pin + to the arduino uno 5v pin, - to the gnd pin, (have also tried these two wires to the usb connector that was supplied with the nextion. ) , tx to arduino rx digital pin 0, rx to tx digital pin 1. Do I need to enable the nextion serial or is it on at 9600 by default?

If using the Arduino library, check NexHardware.cpp nexInit() function ...

baudrate will need to match Nextion

Also check NexConfig.h ... by default Nextion is on Serial2 .. configured for ATMega 2560.

readme.md will example about aliasing Nextion to to different serial if need be

- For an uno, there is only one serial.

  - "serial" usage for Debug should be disabled

  - "serial2" for Nextion should be renamed to "serial" - readme.md

You may need to use a SoftwareSerial for debug if need be

  - I am not best to ask on this yet, still working on it, SoftwareSerial to me introduces issues I rather not have

    - but is completely doable, maybe at a lower baudrate.


Depending on Nextion model, you should be powering Nextion on 5V reliable power

The current draw (varies by model but is in data sheet) is sometimes above current draw is too high to power off of the Arduino pins.

- ensure you are tying ground used for Nextion to ground used for Arduino.

Login or Signup to post a comment