Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
interesting way of data transfer microprocessor <> virtuino
#1
Data between the application and the module are sent in the String format in virtual pins.
This allows free transfer of any type of data (string, byte, int, long, etc.) in both directions without the need to create a data array in the module.
Below is an example of how to do this
Code:
//---VirtuinoCM  Library settings --------------
#include "VirtuinoCM.h"
VirtuinoCM virtuino;
//#define V_memory_count 100          // the size of V memory. You can change it to a number <=255)
//int V[V_memory_count];           // This array is synchronized with Virtuino V memory. You can change the type to int, long etc.
//---
String V1 = "";
String V2 = "";
String V4 = "";
String V5 = "";
String V6 = "";
String V7 = "";
Code:
//============================================================== onCommandReceived
//==============================================================
/* This function is called every time Virtuino app sends a request to server to change a Pin value
   The 'variableType' can be   V=Virtual Pin
   The 'variableIndex' is the pin number index of Virtuino app
   The 'valueAsText' is the value that has sent from the app  in Strin format */
void Read_V1(String value_Text);
void Read_V2(String value_Text);
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

    if (variableIndex == 1) Read_V1(valueAsText);
    if (variableIndex == 2) Read_V2(valueAsText);
  }
}
Code:
//==============================================================
/* 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 == 4) return  V4;
    if (variableIndex == 5) return  V5;
    if (variableIndex == 7) return  V7;
  }
  return "";
}

And an example of my code using a new way of data transmission

Code:
int V1_Value = 0;
int V2_Value = 0;

// data recive from virtuino
void Read_V1(String value_Text) {
  V1_Value = value_Text.toInt();
  Serial.println("V1=" + value_Text);
}
void Read_V2(String value_Text) {
  V2_Value = value_Text.toInt();
  Serial.println("V2=" + value_Text);
  digitalWrite(2, V2_Value);
}

// data that you want to send to virtuino
int a = 0;
void vLED_timer() {
  V5 = String(a);             //LED in virtuino
  a = !a;

  int sensorValue = random(100);
  V4 = String(sensorValue);      //value display in virtuino
  V7 = sensorValue;              // string display in virtuino in text value display
}
virtuino.blogspot.com
Reply
#2
Thanks for sharing this topic here. It looks so nice and helpful so far. Have a very good day!
Reply
#3
and here is a description of how I did it
https://virtuino.blogspot.com/2023/01/vi...sc-ii.html
virtuino.blogspot.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)