phyphox Forums
Adding a value indicator below a graph BLE - Printable Version

+- phyphox Forums (https://phyphox.org/forums)
+-- Forum: Discussion (https://phyphox.org/forums/forumdisplay.php?fid=1)
+--- Forum: General (https://phyphox.org/forums/forumdisplay.php?fid=3)
+--- Thread: Adding a value indicator below a graph BLE (/showthread.php?tid=1641)



Adding a value indicator below a graph BLE - TorstenKlf - 10-26-2022

Hello,
it must be very simple. For my ESP32 Hall-Sensor I want to show the measured valut underneath the graph. Can anybody help, pease?

Torsten


#include <phyphoxBle.h>

int AnalogPin=27;
float Messwert;
float Magnetfeld;

void setup() {
    PhyphoxBLE:Confusedtart("Magnetfeldsensor_01");                //Start the BLE server

//Experiment
    PhyphoxBleExperiment experiment;

    experiment.setTitle("Magnetfeld");
    experiment.setCategory("Arduino Experiments");
    experiment.setDescription("Plot the magnetic field of a Hall sensor over time.");

    //View
    PhyphoxBleExperiment::View view;

    //Graph
    PhyphoxBleExperiment::Graph graph;
    graph.setLabel("B over time");
    graph.setUnitX("s");
    graph.setUnitY("mT");
    graph.setLabelX("time");
    graph.setLabelY("B");

//  graph.setChannel(1,2);

    view.addElement(graph);                //Attach graph to view
    experiment.addView(view);              //Attach view to experiment
    PhyphoxBLE::addExperiment(experiment);  //Attach experiment to server

}


RE: Adding a value indicator below a graph BLE - Jens Noriʇzsɔɥ - 10-27-2022

There is an example on the phyphoxBLE GitHub that demonstrates how to mix view elements (and create multiple views): https://github.com/phyphox/phyphox-arduino/blob/master/examples/CreateExperiment/CreateExperiment.ino


RE: Adding a value indicator below a graph BLE - TorstenKlf - 10-27-2022

(10-27-2022, 02:47 PM)Jens Noritzsch Wrote: There is an example on the phyphoxBLE GitHub that demonstrates how to mix view elements (and create multiple views): https://github.com/phyphox/phyphox-arduino/blob/master/examples/CreateExperiment/CreateExperiment.ino

I know this example... and I finally got it working:
____________________________________________________________
#include <phyphoxBle.h>

int AnalogPin=27;
float Messwert;
float Magnetfeld;
float Offset;

void setup() {
    PhyphoxBLE:Confusedtart("Magnetfeldsensor_01");                //Start the BLE server

//Experiment
    PhyphoxBleExperiment experiment;

    experiment.setTitle("Magnetfeld");
    experiment.setCategory("Arduino Experiments");
    experiment.setDescription("Plot the magnetic field of a Hall sensor over time.");

    //View
    PhyphoxBleExperiment::View view;

    //Value
    PhyphoxBleExperiment::Value Value1;     
    Value1.setLabel("B = ");                           
    Value1.setUnit("mT");                   
    Value1.setChannel(1);

    //Graph
    PhyphoxBleExperiment::Graph graph;
    graph.setLabel("B over time");
    graph.setUnitX("s");
    graph.setUnitY("mT");
    graph.setLabelX("time");
    graph.setLabelY("B");


    view.addElement(graph);                //Attach graph to view
    view.addElement(Value1);
    experiment.addView(view);              //Attach view to experiment
    PhyphoxBLE::addExperiment(experiment);  //Attach experiment to server

    //Offsetkorrektur 
  Offset=0;
  for(int i=0;i<7;i++){
    Offset+=analogRead(AnalogPin);
    delay(10);
  }
  Offset=Offset/7;

}

void loop() {
Messwert=analogRead(AnalogPin);
Magnetfeld=(Messwert-Offset)*(-0.0492);
PhyphoxBLE::write(Magnetfeld);
delay(50);
}   
 
____________________________________________________
But the strange thing is that if I change details in the programm as e. g. some smoothing in the loop:

.......
 void loop() {
  for(int i=0;i<37;i++){
    Messwert+=analogRead(AnalogPin);
    delay(10);
  }
  Messwert=Messwert/37;
Magnetfeld=(Messwert-Offset)*(-0.0492);
PhyphoxBLE::write(Magnetfeld);
delay(50);
}   

the compilation stops and gives me the following mistake I don't understand. 

C:\_Phaeno\Make_Physics\B-Sensor_ESP_ValueIndicator_Smooth\B-Sensor_ESP_ValueIndicator_Smooth.ino: In function 'void setup()':
B-Sensor_ESP_ValueIndicator_Smooth:22:27: error: 'Value' is not a member of 'PhyphoxBleExperiment'
    PhyphoxBleExperiment::Value Value1;
                          ^~~~~
B-Sensor_ESP_ValueIndicator_Smooth:23:5: error: 'Value1' was not declared in this scope
    Value1.setLabel("B = ");
    ^~~~~~
C:\_Phaeno\Make_Physics\B-Sensor_ESP_ValueIndicator_Smooth\B-Sensor_ESP_ValueIndicator_Smooth.ino:23:5: note: suggested alternative: '_glue'
    Value1.setLabel("B = ");
    ^~~~~~
    _glue
Mehrere Bibliotheken wurden für "phyphoxBle.h" gefunden
Benutzt: C:\Users\klf\Documents\Arduino\libraries\phyphox-arduino-master
Nicht benutzt: C:\Users\klf\Documents\Arduino\libraries\phyphox_BLE
exit status 1
'Value' is not a member of 'PhyphoxBleExperiment'


RE: Adding a value indicator below a graph BLE - Jens Noriʇzsɔɥ - 10-27-2022

Apparently, I cannot reproduce it…

Could you please attach the two original files rather than copying and pasting.


RE: Adding a value indicator below a graph BLE - TorstenKlf - 10-28-2022

Hi Jens,
here you are. For whatever reason it likes either smoothing or the value indicator but not both.

Short update: I get the feeling that there's something wrong with my Arduino IDE. After a broken compilation I pressed inadvertently the upload button again, and after a second compilation the error disappeared and everything is working.


RE: Adding a value indicator below a graph BLE - Jens Noriʇzsɔɥ - 10-31-2022

(10-28-2022, 05:21 PM)TorstenKlf Wrote: Short update: I get the feeling that there's something wrong with my Arduino IDE. After a broken compilation I pressed inadvertently the upload button again, and after a second compilation the error disappeared and everything is working.

It looks your feeling is right: I still cannot reproduce compilation errors with your files…


RE: Adding a value indicator below a graph BLE - TorstenKlf - 10-31-2022

Thank you!