This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Adding a value indicator below a graph BLE
#1
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

}
Reply
#2
There is an example on the phyphoxBLE GitHub that demonstrates how to mix view elements (and create multiple views): https://github.com/phyphox/phyphox-ardui...riment.ino
Reply
#3
(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-ardui...riment.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'
Reply
#4
Apparently, I cannot reproduce it…

Could you please attach the two original files rather than copying and pasting.
Reply
#5
Photo 
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.


Attached Files Thumbnail(s)
   

.txt   B-Sensor_ESP_ValueIndicator_Smooth_working1.txt (Size: 1.54 KB / Downloads: 196)
.txt   B-Sensor_ESP_ValueIndicator_Smooth_working2.txt (Size: 1.53 KB / Downloads: 245)
.txt   B-Sensor_ESP_ValueIndicator_Smooth_working3.txt (Size: 1.53 KB / Downloads: 200)
.txt   B-Sensor_ESP_ValueIndicator_Smooth_workingNOT.txt (Size: 1.52 KB / Downloads: 217)
Reply
#6
(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…
Reply
#7
Thank you!
Reply


Forum Jump: