simple pushbutton nextion to arduino

Projecten die niet passen in bovenstaande onderwerpen
Berichten: 26
Geregistreerd: 23 Aug 2014, 09:38
Woonplaats: heteren

simple pushbutton nextion to arduino

Berichtdoor donnyrijken » 18 Sep 2016, 16:16

ik ben bezig met een nextion schermpje met touch nu wil ik graag
de button die ik heb gemaakt in de nextion laten fungeren als pushbutton dus indrukken poort aansturen los laten uitschakelen

ik heb het volgende gemaakt bij de arduino

php code
int char1,char2;
int charflag=0;

void setup() {
Serial.begin(9600);
pinMode(8,OUTPUT);
}

void loop() {
if (Serial.available()>1)
{
if (charflag)
{
char2=Serial.read();
if (char2==0) digitalWrite(8,HIGH);
else if (char2==0x01) digitalWrite(8,LOW);
charflag=0;
}
else
{
char1=Serial.read();
if(char1==0x65) charflag=1;
}
}
}


als ik serieel uitlees stuurt de button van de nextion
dit uit

dit is knop ingedrukt en los laten

101
2
1
255
255
255
101
2
0
255
255

dit is knop ingedrukt en los laten
dit is knop ingedrukt houden

101
2
1
255
255

Advertisement

Berichten: 26
Geregistreerd: 23 Aug 2014, 09:38
Woonplaats: heteren

Re: simple pushbutton nextion to arduino

Berichtdoor donnyrijken » 18 Sep 2016, 16:20

als ik deze combinatie gebruik dan wordt poort 8 high maar valt niet meer naar low

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: simple pushbutton nextion to arduino

Berichtdoor nicoverduin » 18 Sep 2016, 17:04

Waarom gebruik je niet gewoon de Arduino library van Nextion niet?

Met 2 knoppen ff een button aan en een voor uit zetten:
cpp code
#include "Nextion.h"

// Master RX, TX, connect to Nextion TX, RX

SoftwareSerial HMISerial(10,11);

#define LED A5

/**
* Create a button array containing all buttons used in the system.
* No need to fill in the name. The Arduino library does not use it. Pid and Cid are relevant.
*/
NexButton buttonArray[2] = {
NexButton(0, 1, NULL), // Aan
NexButton(0, 2, NULL) // Uit
};
/**
* Create a parallel enumeration of the names of the buttons we will be using
* in the system
*/
enum {
Aan,
Uit
};

/**
* Create a listen array for Nextion. Can we generate this
*/
NexTouch *nex_listen_list[] =
{
&buttonArray[Aan],
&buttonArray[Uit],
NULL
};

/**
* @name buttonPopCallback
* @param ptr is a pointer to the button object. It contains the address within the buttonArray
* If any button is released after a push and it is in the button array, this function is called.
*/
void buttonPopCallback(void *ptr)
{
//
// get our button pointer
//
int8_t index = -1; // index in buttonArray of object
//
// find button object in array
//
for (uint8_t i = 0; i < (sizeof(buttonArray) / sizeof(NexButton)); i++) {
if (&buttonArray[i] == ptr) {
//
// found it so quit searching
//
index = i;
break;
}
}
//
// act on pressed button. Since we use an enumeration, this makes programming clearer
//
switch (index) {
case Aan:
digitalWrite(LED, HIGH); // or call a function
break;
case Uit:
digitalWrite(LED, LOW); // or call a function
break;
}
}

void setup(void)
{
//
// generic initialization
//
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
//
// init the nextion library
//
nexInit();
//
// register all our callbacks to the same callback routine
//
for (uint8_t i = 0; i < (sizeof(buttonArray) / sizeof(NexButton)); i++) {
buttonArray[i].attachPop(buttonPopCallback, &buttonArray[i]);
}
}

void loop(void)
{
//
// this checks if any events happened on the Nextion.
//
nexLoop(nex_listen_list);
}
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 26
Geregistreerd: 23 Aug 2014, 09:38
Woonplaats: heteren

Re: simple pushbutton nextion to arduino

Berichtdoor donnyrijken » 18 Sep 2016, 17:56

hoi nico bedankt voor de reactie ik wil hier een luchtklep mee aansturen die moet dus eigenlijk meteen weer dichtvallen na loslaten

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: simple pushbutton nextion to arduino

Berichtdoor nicoverduin » 18 Sep 2016, 17:58

Nou dan pas je hem toch aan? Je hebt een attachPush en attachPop. Push als hij ingedrukt wordt en pop als hij losgelaten wordt.

Dit is de meest eenvoudige oplossing:
cpp code
#include "Arduino.h"
#include "Nextion.h"

// Master RX, TX, connect to Nextion TX, RX
SoftwareSerial HMISerial(10,11);// let erop dat je ook de juiste NexConfig.h gebruikt voor Software Serial

#define KLEP 13 // hier kun je dus je klep aan toewijzen

NexButton klep (0, 1, NULL); // bij buttons is de naam overbodig. Wordt toch niet naar gekeken

/**
* Aan deze objecten gaat NexLoop() naar kijken of daar een bericht van is binnengekomen.
*/
NexTouch *nex_listen_list[] =
{
&klep,
NULL
};

/**
* event ON_klepKnopLosgelaten
* Wordt aangeroepen als de klep knop is losgelaten
*/
void ON_klepKnopLosgelaten(void *ptr) {
//
// de knop is losgelaten dus klep dicht
//
digitalWrite(KLEP, LOW);
}
/**
* event ON_klepKnopIngedrukt
* Wordt aangeroepen als de klep knop is ingedrukt
*/
void ON_klepKnopIngedrukt(void *ptr) {
//
// de knop is losgelaten dus klep dicht
//
digitalWrite(KLEP, HIGH);
}

void setup()
{
//
// algemene initialisatie
//
pinMode(KLEP, OUTPUT);
digitalWrite(KLEP, LOW);
//
// Nextion initialisatie
//
nexInit();
//
// koppel de routines die aangeroepen worden bij het indrukken en loslaten van de knop klep
//
klep.attachPop(ON_klepKnopLosgelaten, &klep);
klep.attachPush(ON_klepKnopIngedrukt, &klep);
}

void loop()
{
//
// hier alleen luisteren of de Nextion berichten heeft verstuurd naar de Arduino
//
nexLoop(nex_listen_list);
}


Let op
Ik maak gebruik van SoftwareSerial voor de Nextion en dan kan ik dbSerial gebruiken voor boodschappen richting serial monitor. Wel moet je een Nexconfig.h vervangen door onderstaand:
cpp code
/**
* @file NexConfig.h
*
* Options for user can be found here.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__

/**
* @addtogroup Configuration
* @{
*/
/**
* If using SoftwareSerial use the following define
*/

#define USE_SOFTWARE_SERIAL

/**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
#define DEBUG_SERIAL_ENABLE

/**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial

/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#ifdef USE_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
extern SoftwareSerial HMISerial;
#define nexSerial HMISerial
#else
#define nexSerial Serial2
#endif

#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a)
#else
#define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) do{}while(0)
#endif

/**
* @}
*/

#endif /* #ifndef __NEXCONFIG_H__ */


En een regel ff becommentariëren in NexUpload.cpp regel 21
Dus zo:
cpp code
//SoftwareSerial dbSerial(3, 2); /* RX:D3, TX:D2 */

Ik heb hiervoor net de allerlaatste versie van de Nextion library gedownload van Github:
https://github.com/itead/ITEADLIB_Arduino_Nextion
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 26
Geregistreerd: 23 Aug 2014, 09:38
Woonplaats: heteren

Re: simple pushbutton nextion to arduino

Berichtdoor donnyrijken » 20 Sep 2016, 21:11

hoi nico bedankt welke library,s heb je er nog meer in zitten ik krijg de ene na de andere fout

In file included from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master/Nextion.h:21:0,
from sketch_sep20a.ino:2:
C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master/NexConfig.h:43:28: fatal error: SoftwareSerial.h: No such file or directory
#include <SoftwareSerial.h>

na deze library toegevoegd te hebben het volgende


In file included from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:16:0:
C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.h:19:17: fatal error: SPI.h: No such file or directory
#include <SPI.h>

na deze library toegevoegd te hebben het volgende

C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp: In member function 'bool NexUpload::_checkFile()':
C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:96:29: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
if(!SD.exists(_file_name))
^
In file included from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.h:20:0,
from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:16:
C:\Program Files (x86)\arduino-1.6.4-\arduino-1.6.4\libraries\SD\src/SD.h:76:11: error: initializing argument 1 of 'boolean SDClass::exists(char*)' [-fpermissive]
boolean exists(char *filepath);
^
Fout bij compileren.

ik heb even geen idee meer hoe dit op te lossen

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: simple pushbutton nextion to arduino

Berichtdoor nicoverduin » 20 Sep 2016, 22:54

Migreer eerst je IDE naar 1.6.9. Daarmee compileer ik onder Eclipse.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 26
Geregistreerd: 23 Aug 2014, 09:38
Woonplaats: heteren

Re: simple pushbutton nextion to arduino

Berichtdoor donnyrijken » 25 Sep 2016, 20:28

hoi nico bedankt voor je hulp ik krijg het niet voor elkaar

dit is de fout



Warning: platform.txt from core 'Arduino AVR Boards' contains deprecated recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}", automatically converted to recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{preprocessed_file_path}". Consider upgrading this core.
C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:21:24: error: conflicting declaration 'SoftwareSerial Serial'

SoftwareSerial dbSerial(3, 2); /* RX:D3, TX:D2 */

^

In file included from C:\Users\asus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.9\cores\arduino/Arduino.h:224:0,

from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.h:18,

from C:\Users\asus\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:16:

C:\Users\asus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.9\cores\arduino/HardwareSerial.h:143:25: error: 'Serial' has a previous declaration as 'HardwareSerial Serial'

extern HardwareSerial Serial;

^

exit status 1
Fout bij het compileren van board Arduino/Genuino Mega or Mega 2560

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: simple pushbutton nextion to arduino

Berichtdoor nicoverduin » 25 Sep 2016, 21:46

Maak van die regel maar een commentaar regel zoals ik je een paar posts terug heb gezegd.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: simple pushbutton nextion to arduino

Berichtdoor shooter » 26 Sep 2016, 10:07

Woord Serial is al gedefinieerd dus je moet de lib een andere naam geven, bijv serialsoft
paul deelen
shooter@home.nl

Volgende

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 16 gasten