Need Help - Programming With Visuino To Control Relay Board From Nextion HMI

Hello,

I have some very basic coding experience and have been working on this project for a while now.

The reason I have decided to use Visuino instead of the Arduino IDE is my lack of programming skills – the Nextion library is confusing to me.

I would like to use this to control pneumatic valves. There are 4 valve manifolds and each valve manifold has an intake and exhaust valve (all together 8 valves hence the 8 relay module).

Hardware:

  • Arduino UNO
  • 8 Relay Module
  • 3.2" Nextion

Here is my goal:
I would like 4 dual state buttons on the Nextion to correspond to each valve manifold.
2 momentary buttons on Nextion to control intake or exhaust for the duration of the button press.

This way I can intake or exhaust any combination of the valves.

So far, I have two problems:

  • The relays (normally open) are triggered (closed) when pin output voltage is low, therefore all are triggered upon startup and my controls just open the relay switch. I would like this to be the other way around
  • The buttons work as I had hoped (aside from being backwards in problem 1), except when I toggle off the dual state button nothing happens. So if I wanted to control manifold 1, I could, but if I now want to control manifold 2 (I “select” 2 and “deselect” 1 on the corresponding dual state buttons) both manifolds 1 and 2 are controlled until I restart the Arduino

I have tried sending the component ID for the dual-state buttons for both press and release events, but my program only seems to work when the press event is sent.

The intake and exhaust momentary buttons send both press and release events.

Here is my generated code from Visuino:

//----------------------------------------------
//
//        Sketch Generated by Visuino
//              www.visuino.com
//          Version  7.8.2.134
//
//------------------ Source --------------------
//
// Test 2 boolean.owarduino
//
//----------------------------------------------

#define VISUINO_ARDUINO_UNO
#define __32BIT_GRAPHICS_COORDINATES__

#include <OpenWire.h>
#include <Mitov.h>
#include <Mitov_FormattedSerial.h>
#include <Mitov_LogicGates.h>
#include <Mitov_Display_Nextion.h>

// Arduino Board Declarations

namespace BoardDeclarations
{
Mitov::SerialPort<SERIAL_TYPE, &Serial> SerialPort0;
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_4( 4 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_5( 5 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_6( 6 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_7( 7 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_8( 8 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_9( 9 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_10( 10 );
Mitov::ArduinoDigitalInputChannel ArduinoDigitalChannel_11( 11 );
} // BoardDeclarations

// Declarations

namespace Declarations
{
Mitov::BooleanAnd<2> And1;
Mitov::BooleanAnd<2> And2;
Mitov::BooleanAnd<2> And3;
Mitov::BooleanAnd<2> And4;
Mitov::BooleanAnd<2> And5;
Mitov::BooleanAnd<2> And6;
Mitov::BooleanAnd<2> And7;
Mitov::BooleanAnd<2> And8;
Mitov::DisplayNextion DisplayNextion1 = Mitov::DisplayNextion( BoardDeclarations::SerialPort0 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton1( DisplayNextion1, "bt0", 0, 1 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton2( DisplayNextion1, "bt1", 0, 2 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton3( DisplayNextion1, "bt2", 0, 3 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton4( DisplayNextion1, "bt3", 0, 4 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton5( DisplayNextion1, "b0", 0, 5 );
Mitov::DisplayNextionElementButton TArduinoDisplayNextionElementButton6( DisplayNextion1, "b1", 0, 6 );
} // Declarations

//The setup function is called once at startup of the sketch
void setup()
{
  Declarations::And1.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_4.DigitalInputPin );
  Declarations::And2.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_5.DigitalInputPin );
  Declarations::And3.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_6.DigitalInputPin );
  Declarations::And4.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_7.DigitalInputPin );
  Declarations::And5.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_8.DigitalInputPin );
  Declarations::And6.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_9.DigitalInputPin );
  Declarations::And7.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_10.DigitalInputPin );
  Declarations::And8.OutputPin.Connect( BoardDeclarations::ArduinoDigitalChannel_11.DigitalInputPin );
  Declarations::TArduinoDisplayNextionElementButton1.OutputPin.Connect( Declarations::And2.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton1.OutputPin.Connect( Declarations::And1.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton2.OutputPin.Connect( Declarations::And4.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton2.OutputPin.Connect( Declarations::And3.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton3.OutputPin.Connect( Declarations::And6.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton3.OutputPin.Connect( Declarations::And5.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton4.OutputPin.Connect( Declarations::And8.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton4.OutputPin.Connect( Declarations::And7.InputPins[ 0 ] );
  Declarations::TArduinoDisplayNextionElementButton5.OutputPin.Connect( Declarations::And7.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton5.OutputPin.Connect( Declarations::And5.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton5.OutputPin.Connect( Declarations::And3.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton5.OutputPin.Connect( Declarations::And1.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton6.OutputPin.Connect( Declarations::And8.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton6.OutputPin.Connect( Declarations::And6.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton6.OutputPin.Connect( Declarations::And4.InputPins[ 1 ] );
  Declarations::TArduinoDisplayNextionElementButton6.OutputPin.Connect( Declarations::And2.InputPins[ 1 ] );

  OpenWire::Component::_SystemInit();
}

// The loop function is called in an endless loop
void loop()
{
  OpenWire::Component::_SystemLoop();
}

I have attached the .ino file for the code, a .png of the Nextion screen, and a .pdf of the Visuino.

Any help is greatly appreciated.

Thank you.

Visuino.pdf (466 KB)

RelayControl.ino (4.82 KB)

The reason I have decided to use Visuino instead of the Arduino IDE is my lack of programming skills -- the Nextion library is confusing to me.

So, you've decided to use some software that generates Arduino code that is 9 times as complicated as needed. Well, good luck with that mess.

PaulS:
So, you've decided to use some software that generates Arduino code that is 9 times as complicated as needed. Well, good luck with that mess.

Slightly incorrect statement :wink: .
As you can see from the code Visuino has generated extremely good code for something as complex as controlling and communicating with Nextion Display :wink: .
But you are right, he should not be messing with the code that Visuino has generated. if he wants to change the functionality, he should do it in Visuino, and generate new code.
The Nextion library that I wrote, is specifically designed to be used by Visuino (I write practically all the libraries for Visuino, and they are all open source - Bitbucket ).

snowbro:
I have some very basic coding experience and have been working on this project for a while now.

The reason I have decided to use Visuino instead of the Arduino IDE is my lack of programming skills – the Nextion library is confusing to me.

I would like to use this to control pneumatic valves. There are 4 valve manifolds and each valve manifold has an intake and exhaust valve (all together 8 valves hence the 8 relay module).

This will be better answered in the Visuino community - https://plus.google.com/communities/116125623808250792822 .
This forum is mostly for the hardcore Arduino developers, ind we should avoid spamming it with Visuino questions :wink: . It is unlikely that they will be able to answer it, only will irritate them unnecessary.
There is no need for you to modify the generated code.
To get notification for both press and release of the button, in the Nextion Editor you need to check both the “Touch Press” and “Touch Release” events for the button.

Cheers,
Boian

mitov:
This will be better answered in the Visuino community - Sign in - Google Accounts .
This forum is mostly for the hardcore Arduino developers, ind we should avoid spamming it with Visuino questions :wink: . It is unlikely that they will be able to answer it, only will irritate them unnecessary.
There is no need for you to modify the generated code.
To get notification for both press and release of the button, in the Nextion Editor you need to check both the "Touch Press" and "Touch Release" events for the button.

Cheers,
Boian

Boian,

Thank you for the reply. I will join the Visuino group and seek help there.