Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to output color sensor values on Nextion Screen #201

Open
gbri29 opened this issue Apr 17, 2024 · 0 comments
Open

Unable to output color sensor values on Nextion Screen #201

gbri29 opened this issue Apr 17, 2024 · 0 comments

Comments

@gbri29
Copy link

gbri29 commented Apr 17, 2024

I am using Easy Nextion Library to output variables of a color sensor connected to an Arduino UNO. However, when I go to debug on the NextionEditor software this does not even connect to the microcontroller. Although this is working and on. I have put the color sensor code inside the trigger function and I am pasting printh 23 02 54 01 in the bottom to trigger the function. Still nothing happens. The color sensor works by itself but not once it is combined.

#include "EasyNextionLibrary.h" // Include EasyNextionLibrary
EasyNex myObject(Serial); // Create an object of EasyNex class with the name "myNex"
// Set as parameter the Serial you are going to use
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0,1); // RX, TX pins in your aduino

// Define color sensor pins
const int S0 = 2;
const int S1 = 3;
const int S2 = 4;
const int S3 = 5;
const int sensorOut = 6;

// Connections to A4988
const int dirPin = 7; // Direction
const int stepPin = 8; // Step

// Calibration Values from Calibration Sketch
int redMin = 148; // Red minimum value
int redMax = 178; // Red maximum value
int greenMin = 143; // Green minimum value
int greenMax = 167; // Green maximum value
int blueMin = 139; // Blue minimum value
int blueMax = 155; // Blue maximum value

// Motor step angle: 18 -- Motor steps per rotation: 20 (360/18)
const int STEPS_PER_REV = 20; //100 goes 3/8in = 0.375in, so every 1 moves 0.00375in (or 0.9525mm). 8mm/0.09525 = 83.989 ~ 84 (8mm is distance between center of one square on the strip to another square)

// Variables for Color Pulse Width Measurements
int redPW = 0;
int greenPW = 0;
int bluePW = 0;

// Variables for final Color values
int redValue;
int greenValue;
int blueValue;
int redVal;
int greenVal;
int blueVal;

//Variables for averages and totals of readings
int avgRed;
int avgGreen;
int avgBlue;

// Results
int pH = 0;
int Leukocytes = 0;
int Nitrite = 0;
#include <stdbool.h>
// For Nextion Display
//#include
String pHString = String(pH,2);
String LeukocytesString = String(Leukocytes,2);
String NitriteString = String(Nitrite,2);

int x = myObject.readNumber("dp"); // Store to x the ID of the current Loaded page

bool rgb_test(int minr, int maxr, int ming, int maxg, int minb, int maxb, int r, int g, int b) {
return r <= maxr && r >= minr && g <= maxg && g >= ming && b <= maxb && b >= minb;
}

}

void setup() {
myObject.begin(9600); // Begin the object with a baud rate of 9600

}
void loop(){
myObject.NextionListen(); // This function must be called repeatedly to response touch events
}
void trigger01(){

}
void begin(){
myObject.begin(115200); // for baud rate 115200
}
void writeStr(){
if(myObject.currentPageId != myObject.lastCurrentPageId){
if(myObject.currentPageId == 0){
// [send the data to refresh the page0]
}else if(myObject.currentPageId == 2){
myObject.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
myObject.writeStr("page 2"); // Sending this command to change the page we are on Nextion using pageId

    myObject.writeStr("t1.txt", pHString);
    myObject.writeStr("t2.txt", "\\r" + LeukocytesString);
    myObject.writeStr("t3.txt+", "\\r" + NitriteString);
/* By writing \\r, you send Nextion the change line character " \r "
 * The second \ is required, in order to print the \ as character
 * and not as an escape character.
 */
}

myObject.lastCurrentPageId = myObject.currentPageId;

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant