Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
App is lagging and tends to Crash
#4
Hey,

Thanks for the reply!!!

so yes at the bottom there is the whole code. Well I am using for my actual project a few stepper motors and stuff where it needs to be quite accurate, time wise. 
But the updating of the string does not work properly such as the buttons already as shown in the code below. 

As already said the buttons tend to bounce and the text sometimes updates "YesYes" to "YesYesYes" in the text value display. It also never updates to "No". 
I set the Buttons to switch mode and only turn on if the value is 1 and off if it is 0 or any other value. 

I assumed that it could be because of an issue with the Buffer, meaning that it is maybe Flooded with requests and replies, so it reads it continously over several requests and repiles 
Instead of checking the request for a Value, then printing it, and then again check for new values. 

Also as you said it could be because the loop is too long. Is there a method to reqeust and write pin values singularly? I have seen that the method to write and read commands from the buffer itself is stated here https://virtuino.com/index.php/virtuino/...and-format but should I just Print the commands to the Serial connection with the bluetooth module? Would be very helpful because this way i would be able to make my code work way quicker! 

Thank you very much for your time, here is the code now: 

/* Example: Bluetooth HC-05 + Arduino MEGA - getting started
* Created by Ilias Lamprou
* Modified: Sep/9/2019
*/
//-------------VirtuinoCM Library and settings --------------
#include "VirtuinoCM.h"
VirtuinoCM virtuino;
#define V_memory_count 32 // the size of V memory. You can change it to a number <=255)
float V[V_memory_count]; // This array is synchronized with Virtuino V memory. You can change the type to int, long etc.
boolean debug = false; // set this variable to false on the finale code to decrease the request time.
String V36 = "Hello";
//============================================================== setup
//==============================================================
void setup() {
if (debug) {
Serial.begin(9600);
while (!Serial) continue;
}
Serial.begin(19200);
Serial1.begin(9600);
Serial1.setTimeout(50);
V[1] = 0;
V[2] =0;


virtuino.begin(onReceived,onRequested,512); //Start Virtuino. Set the buffer to 256. With this buffer Virtuino can control about 28 pins (1 command = 9bytes) The T(text) commands with 20 characters need 20+6 bytes
//virtuino.key="1234"; //This is the Virtuino password. Only requests the start with this key are accepted from the library

pinMode(4, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(13, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(6, INPUT); // On Virtuino panel add a led to get the state of this pin
pinMode(7, INPUT); // On Virtuino panel add a led to get the state of this pin
}
//============================================================== loop
//==============================================================
void loop() {
virtuinoRun();

if (V[1]==1){
V36 = "NoNo";
Serial.println("V1 pressed");
}
if (V[2]==1){
V36 = "YesYes";
Serial.println("V2 pressed");
}
Serial.println("V36"+V36);
}








//============================================================== onCommandReceived
//==============================================================
/* This function is called every time Virtuino app sends a request to server to change a Pin value
* The 'variableType' can be a character like V, T, O V=Virtual pin T=Text Pin O=PWM Pin
* The 'variableIndex' is the pin number index of Virtuino app
* The 'valueAsText' is the value that has sent from the app */
void onReceived(char variableType, uint8_t variableIndex, String valueAsText){
if (variableType=='V'){
if (variableIndex<V_memory_count) {
float value = valueAsText.toFloat(); // convert the value to float. The valueAsText have to be numerical
V[variableIndex]=value; // copy the received value to arduino V memory array
}
if (variableIndex== 36 ) V36= valueAsText;

}
}
//==============================================================
/* This function is called every time Virtuino app requests to read a pin value*/
String onRequested(char variableType, uint8_t variableIndex){
if (variableType=='V') {
if (variableIndex<V_memory_count) return String(V[variableIndex]); // return the value of the arduino V memory array
if (variableIndex==36) return V36;

}
return "";
}
//============================================================== virtuinoRun
void virtuinoRun(){
while (Serial1.available()) {
char tempChar=Serial1.read();
if (tempChar==CM_START_CHAR) { // a new command is starting...
virtuino.readBuffer=CM_START_CHAR; // copy the new command to the virtuino readBuffer
virtuino.readBuffer+=Serial1.readStringUntil(CM_END_CHAR);
virtuino.readBuffer+=CM_END_CHAR;
if (debug) Serial.println("\nCommand= "+virtuino.readBuffer);
String* response= virtuino.getResponse(); // get the text that has to be sent to Virtuino as reply. The library will check the inptuBuffer and it will create the response text
if (debug) Serial.println("Response : "+*response);
Serial1.print(*response);
break;
}
}
}

//============================================================== vDelay
void vDelay(int delayInMillis){long t=millis()+delayInMillis;while (millis()<t) virtuinoRun();}
Reply


Messages In This Thread
App is lagging and tends to Crash - by Nils.Sky - 02-03-2023, 01:15 PM
RE: App is lagging and tends to Crash - by Nils.Sky - 02-08-2023, 04:23 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)