Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
V-memory variable update problem
#1
Hi
There is a strange problem

I have Arduino sketch working with stepper motors.
Connection to Virtuino - Bluetooth

If I disable logic of steppers (skip it) Virtuino screen works properly.
If I add steppers logic Virtuino screen works partually:
I can press button to change V-memory variable and the program(sketch) reacts properly.
But the same variable is not updated on the screen.
Maybe somebody have an idea ?

Thanks
Reply
#2
Hi,

I am not sure but I think that the Software Serial library doen't work with the Servo library.

The solutions:
1. You have to test your arduino code using different Servo Library
2. You have to stop use the Software serial library. Try to replace it with the Serial.

I have modify the first VirtuinoCM library example. I have replace the SoftwareSerial with the Hardware Serial of Arduino board
You have to move the connected wires from the pins 2-3 to the Serial pins 0-1. But you have to do it after uploadind the following code because
the Serial uses the pins 0-1 fot the uploading.
I have removed all the Serial.print... functions of the code too
You can't use the serial monitor anymore with this sketch

Code:
//#include <SoftwareSerial.h>
//SoftwareSerial espSerial =  SoftwareSerial(2,3);      // arduino RX pin=2  arduino TX pin=3    connect the arduino RX pin to esp8266 module TX pin   -  connect the arduino TX pin to esp8266 module RX pin

//-------------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 = true;              // set this variable to false on the finale code to decrease the request time.

//============================================================== setup
//==============================================================
void setup() {
  if (debug) {
    Serial.begin(9600);
    while (!Serial) continue;
  }
// espSerial.begin(9600); 
// espSerial.setTimeout(50);
 
  Serial.setTimeout(50);

  virtuino.begin(onReceived,onRequested,256);  //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();        // Necessary function to communicate with Virtuino. Client handler
  vDelay(1000);     // This is an example of the recommended delay function. Remove this if you don't need
}


Code:
void onReceived(char variableType, uint8_t variableIndex, String valueAsText){     
    if (variableType=='V'){
        float value = valueAsText.toFloat();        // convert the value to float. The valueAsText have to be numerical
        if (variableIndex<V_memory_count) V[variableIndex]=value;              // copy the received value to arduino V memory array
    }
}

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
  }
  return "";
}

  void virtuinoRun(){
    while (Serial.available()) {
        char tempChar=Serial.read();
        if (tempChar==CM_START_CHAR) {             
              virtuino.readBuffer=CM_START_CHAR;   
              virtuino.readBuffer+=Serial.readStringUntil(CM_END_CHAR);
              virtuino.readBuffer+=CM_END_CHAR;
              String* response= virtuino.getResponse(); 
              Serial.print(*response);
              break;
         }
    }
}

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


Forum Jump:


Users browsing this thread: 1 Guest(s)