Nextion and relays programming

I am very new to xod and arduino, so please forgive me, Could someone help. I need a simple program in xod that thurs a 5v relay on and off on a bread board. I have the nextion all set with a dual state switch so it can toggle the relay. But I can’t get it to communicate with the relay. i am using Wayland library. Thank you so much

There is a relay node (which is basically just a digital-write). Use it to send 0/false (off) or 1/true (on) to the port the relay is wired to. relay-ON is the pin to determine if relay is on or off. relay-ACT (active) must be true for relay to change (otherwise relay-ON is ignored)


Thank you for the response. This is how I have it set up the leds work with the buttons but the relay still does not. What am I missing?

Is relay really connected to pin D0? If you swap relay and LED, does LED still work with bt2 & relay not work with bt1?

II replaced all the led with relays. I found the issue it was a wiring issue. What seems to happen I bt0 works and drives the relay it is assigned. But bt1 stops driving its relay. bt2 works and dirves its relay. I erase the nodes for bt1 (string constant and read number and put news ones in and then bt0 stops works and bt1 and bt 2 work fine. (even when I cut and paste or put in new node from scratch. it does not matter.) this issues can rotate . is there a bug in Xod when driving more than 1 relay?

sorry it does not make any sense. It does this error with both led or relays

“driving the relay” is just doing a digital write to a specific pin, so more than one is not a problem UNLESS there are multiple “relay” nodes with the same pin specified. If you have more than one node controlling the same pin, then only one can be active at a time. You can use the relay-ACT pin to make only one active at a time, but generally the better solution is to only have one “relay” node for each relay.

If it works fine when using 3 LEDs, but relay doesn’t work, then probably either pin numbers are wrong on your relay nodes, or there is a wiring problem.

Thanks for the follow up. I checked all wires no issues. each relay is driven by a different pin, different switch. It just seems like there is a bug it does the same thing on both relays and Led. one switch will work one will not. Then I delete the switch not working on xod and renter the info again and it works and the other one does not. all wiring is staying the same. all pins the same. only does this when i use the nextion switches and wayland read-number. please see example of the program in question

please ignore bt2 thank you

You say you are using switches, but you are using analog-read. LED will work with analog input, but relay is expecting digital input (0 or 1, not a number between 0 and 1).

I don’t know what your write-number/read-number nodes are supposed to do, but you are writing val0, then reading bt0. I suspect your problem is with how you are using these. You can verify by connecting the button output directly to the LED or relay.

thank you for following up. I should of mentioned I did directly go to the relay and leds. Like I said it works. The question I have is why does it work and then other times not work? It seems like the switches are good but then one of them stops and once I remove it and readd it, it works again then the other switch stops working

You have the same problem without the write-numer, read-number nodes? What kind of switches are you using that you are reading with the analog-read? If they are on/off switches, you should be using digital-read instead of analog-read. Do you have pull-up (or pull-down depending on wiring) resistors on your switches? Without those, the value of the switch will “float” when the switch is off, so the arduino will not know for sure if it is on or off.

the switches I am using are called dual state buttons on the nextion. The nextion is the switches (dual state buttons) in my project. yes they are simple on and off. I don’t know if you can see the code from xod I posted? If so do you still use pull up or pull down nodes? I am so thankful for all your help

I should add do you still also need resistors for the switches (buttons on nextion) for pull up and down or nodes with pull up or down? I am using wayland nextion library example and his nodes

If they are on/off switches, you should be using digital-read instead of analog-read.

If the resistors are not built in to the switches, you will need to add them to the wiring. If your switch is wired from Arduino pin to V+, then the pin should have a resistor to ground (usually about 10K ohms resistor; exact value doesn’t matter, but it should be pretty high to avoid creating a short). If your switch is wired from pin to ground, then the pin should have a resistor to V+ instead of ground. This gives the Arduino a specific value to read when the switch is off, but the high resistance allows the switch to over ride that value when the switch is on.

the switches are designed in nextion tft. The nextion is a touch screen and i am using the switched (dual state button) on the nextions touch screen. the the nextion is the the switch sending rx tx serial signal to the relays. So the read function that wayland has in his example are wrong? there would be no way to put resistors on a tft touch screen switch since it is in image of a switch on a touch screen. does that help explain it more?

the library I used is wayland nextion

Sorry. Resistor and digital-read comments won’t apply to this project. You are using virtual buttons on a display not physical buttons.

The example uses va0.val for write-number. You use val0.val, which could be a problem.

The XOD library isn’t very clear what these nodes are actually doing. Open the nextion-serial1 node and open the not-implemented-in-xod node. At the top of the code, the #pragma XOD require line indicates this is a wrapper for https://github.com/Seithan/EasyNextionLibrary. Opening that URL, there are instructions that indicate the write-number nodes are for updating the nextion display and have nothing to do with what is read using read-number nodes. The github page offers some insight, but it is not very clear what CMD options are available beyond giving a few examples. I’m guessing there is nextion usage documents that would provide that information. https://nextion.tech/ has some information, but it is focused on their editor for programming the display, not interfacing to it.

If you can run your code in debug mode and still communicate with the nextion, replace the relay/led nodes with watch nodes to see what values are actually being returned. Trying to run serial communication to nextion & your computer for debug at the same time may not work with your Arduino model. I assume you have the display programmed with at least 3 buttons and fields to display the numeric data you are trying to write using write-number…

Hi @marcod,

Sorry it’s taken me a while to respond. If you simply want to control two relays using dual-state buttons on the nextion display, the following patch will work:
relay-patch

XODBALL:
relay-test.xodball (3.7 KB)

This can be paired with the following Nextion GUI with two buttons named bt0 and bt1:

The command sent to read-number comprises two parts separated by a dot. The part before the dot is the name of the object in the gui, in this case a button called bt0 or bt1. The part after the dot is the attribute of that object we would like to read, in this case val (value).

I’ve tested the patch on an Arduino mega and Nextion NX8048K070_11. Hopefully this will work for you, but please let me know if you run into any problems.

thank you so much for the follow up Wayland. What I am noticing is that one of the nextion switch seem to stop working. But the other works. I am not sure why. It is hard to explain it on here. Maybe a call would be easier to explain? Are you in the USA? I am and maybe we could could discuss? I have set up the exact same way you have in your example.