Skip to content

Commit d79e66b

Browse files
authored
Merge pull request #3 from Dorsel89/master
Release version 1.2.0
2 parents f35d49b + d20fa64 commit d79e66b

34 files changed

+1447
-419
lines changed

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ The purpose of this library is to use the phyphox app (see www.phyphox.org) to p
77
- Arduino Nano 33 Ble
88
- Arduino Nano Sense
99
- Arduino Nano 33 IoT (see note below)
10+
- Arduino Uno R4 Wifi (see note below)
1011
- senseBox MCU with NINA-B31 module
1112
- ESP 32
1213

13-
Note: The Arduino Nano 33 IoT is somewhat unusual. You will need to install the ArduinoBLE library to use it and you will need to call "PhyphoxBLE::poll()" periodically for it to work. See the "randomNumbers-IoT" example.
14+
Note: The Arduino Nano 33 IoT and the Arduino uno R4 are somewhat unusual. You will need to install the ArduinoBLE library to use it and you will need to call "PhyphoxBLE::poll()" periodically for it to work.
1415

1516
Note: When using the NINA-B31 module you must call PhyphoxBLE::poll() periodically (in loop() ) or the library will not work.
1617

@@ -70,15 +71,22 @@ Here are some useful methods to create your own experiment:
7071
| Experiment | setDescription(char*) | Sets a description for the experiment |
7172
| Experiment | addView(View&) | Adds a view to the corresponding experiment |
7273
| Experiment | addExportSet(ExportSet&) | Adds an exportSet to the corresponding experiment |
74+
| Experiment | addSensor(Sensor&) | Data from smarpthone sensor can will be received (see getSensorDataFromSmartphone example)|
7375
| View | addElement(Element&) | Adds an element to the corresponding view |
7476
| View | setLabel(char*) | Sets a label for the view |
7577
| Graph | setLabel(char*) | Sets a label for the graph |
7678
| Graph | setUnitX(char*) | Sets the unit for x (similar with y) |
7779
| Graph | setLabelX(char*) | Sets a label for x (similar with y) |
7880
| Graph | setXPrecision(int) | Sets the amount of digits after the decimal point (similar with y)|
7981
| Graph | setChannel(int, int) | As explained above (1-5) |
80-
| Graph | setStyle(char*) | Sets the style. For more possibilities check the wiki |
82+
| Graph | addSubgraph(Subgraph) | Adds an additional subgraph (see example "multigraph") |
83+
| Graph | setStyle(char*) | Sets the style (use defines: STYLE_LINES, STYLE_DOTS). |
8184
| Graph | setColor(char*) | Sets the line color of the graph (use a 6 digit hexadecimal code) |
85+
| Graph | setMinX(int, const char *)| Sets the min x value of the co-system and a layout (auto, extend and fixed) |
86+
| Graph | setMaxX(int, const char *)| Sets the max x value of the co-system and a layout (auto, extend and fixed) |
87+
| Graph | setMinY(int, const char *)| Sets the min y value of the co-system and a layout (auto, extend and fixed) |
88+
| Graph | setMaxY(int, const char *)| Sets the max y value of the co-system and a layout (auto, extend and fixed) |
89+
| Graph | setLineWidth(float) | Sets the line width |
8290
| Separator | setHeight(float) | Creates a line to separate parts of the experiment |
8391
| Separator | setColor(char*) | Sets the color of the line (use a 6 digit hexadecimal code) |
8492
| Info | setInfo(char*) | Sets the infotext |
@@ -98,11 +106,20 @@ Here are some useful methods to create your own experiment:
98106
| ExportData | setDatachannel(int) | Defines which channel should be exported for this dataset (1-5) |
99107
| Everything | setXMLAttribute(char*) | Custom property e.g. setXMLAttribute("lineWidth=\"3\"") |
100108

109+
110+
#### Style and Layout oprtions for setStyle and setMax/setMin
111+
STYLE_LINES, STYLE_DOTS, STYLE_VBARS, STYLE_HBARS, STYLE_MAP
112+
113+
LAYOUT_AUTO, LAYOUT_EXTEND, LAYOUT_FIXED
114+
115+
#### Error messages
116+
101117
If for some reason the app shows you an error in form of "ERROR FOUND: ERR_X", with different values for X, this could be the reason:
102-
* ERR_01: The input was too long
103-
* ERR_02: The value exceeds the upper limit
104-
* ERR_03: The input was not a 6-digit hexadecimal code
105-
* ERR_04: The input does not match with a valid value
118+
* ERR_01: The input was too long.
119+
* ERR_02: The value exceeds the upper limit.
120+
* ERR_03: The input was not a 6-digit hexadecimal code.
121+
* ERR_04: The input does not match with a valid value.
122+
* ERR_05: The layout must be auto, extend or fixed.
106123

107124
If you realize that the microcontroller is continiously rebooting, you maybe added too many elements.
108125

@@ -129,7 +146,7 @@ If you can help with this, we are happy to receive a pull request. You can conta
129146

130147
## Credits
131148

132-
This library has been developed by the phyphox team at the RWTH Aachen University. In particular, the foundations and basic concept was created by Alexander Krampe as part of his Master thesis. The library has been further improved and is now maintained by Dominik Dorsel, our PhD student who also supervised Alexander's thesis.
149+
This library has been developed by the phyphox team at the RWTH Aachen University. In particular, the foundations and basic concept was created by Alexander Krampe as part of his Master thesis. The library has been further improved and is now maintained by Dominik Dorsel, our PhD student who also supervised Alexander's thesis. The library was also further optimized and extended with new features by Marcel Hagedorn and Edward Leier.
133150

134151
## Licence
135152

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#include <phyphoxBle.h>
22

3-
float editValue = 0;
4-
53
void setup()
64
{
75
Serial.begin(115200);
8-
PhyphoxBLE::start("My Device");
9-
PhyphoxBLE::configHandler = &receivedData; // used to receive data from PhyPhox.
6+
PhyphoxBLE::start("create experiment");
107

118
//Experiment
129
PhyphoxBleExperiment plotRandomValues; //generate experiment on Arduino which plot random values
1310

14-
plotRandomValues.setTitle("Random Number Plotter");
11+
12+
plotRandomValues.setTitle("Create Experiment");
1513
plotRandomValues.setCategory("Arduino Experiments");
1614
plotRandomValues.setDescription("Random numbers are generated on Arduino and visualized with phyphox afterwards");
1715

@@ -23,6 +21,8 @@ void setup()
2321

2422
//Graph
2523
PhyphoxBleExperiment::Graph firstGraph; //Create graph which will plot random numbers over time
24+
firstGraph.setMinY(0, LAYOUT_FIXED);
25+
firstGraph.setMaxY(100, LAYOUT_FIXED);
2626
firstGraph.setLabel("Random number over time");
2727
firstGraph.setUnitX("s");
2828
firstGraph.setUnitY("");
@@ -38,29 +38,31 @@ void setup()
3838
*/
3939

4040
firstGraph.setChannel(0, 1);
41-
41+
4242
//Second Graph
43+
4344
PhyphoxBleExperiment::Graph secondGraph; //Create graph which will plot random numbers over time
4445
secondGraph.setLabel("Random number squared over random number");
4546
secondGraph.setUnitX("");
4647
secondGraph.setUnitY("");
4748
secondGraph.setLabelX("random number");
4849
secondGraph.setLabelY("squared");
49-
secondGraph.setStyle("dots");
50+
secondGraph.setStyle(STYLE_DOTS);
5051
secondGraph.setColor("2E728E"); //Sets Color of line
51-
52+
5253
/* Assign Channels, so which data is plotted on x or y axis
5354
first parameter represents x-axis, second y-axis
5455
Channel 0 means a timestamp is created after the BLE package arrives in phyphox
5556
Channel 1 to N corresponding to the N-parameter which is written in server.write()
5657
*/
57-
58+
5859
secondGraph.setChannel(1, 2);
60+
5961

6062
//Info
6163
PhyphoxBleExperiment::InfoField myInfo; //Creates an info-box.
62-
myInfo.setInfo("In this view you can set a value between 1 and 10. The squared random value will be multiplied by this value and can be seen here.");
63-
//myInfo.setColor("404040"); //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
64+
myInfo.setInfo("This is an Info field!");
65+
myInfo.setColor("890128"); //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
6466
myInfo.setXMLAttribute("size=\"1.2\"");
6567

6668
//Separator
@@ -72,24 +74,14 @@ void setup()
7274
PhyphoxBleExperiment::Value myValue; //Creates a value-box.
7375
myValue.setLabel("Number"); //Sets the label
7476
myValue.setPrecision(2); //The amount of digits shown after the decimal point.
75-
myValue.setUnit("u"); //The physical unit associated with the displayed value.
77+
myValue.setUnit("unit"); //The physical unit associated with the displayed value.
7678
myValue.setColor("FFFFFF"); //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
77-
myValue.setChannel(3);
79+
myValue.setChannel(0);
7880
myValue.setXMLAttribute("size=\"2\"");
7981

80-
//Edit
81-
PhyphoxBleExperiment::Edit myEdit;
82-
myEdit.setLabel("Editfield");
83-
myEdit.setUnit("u");
84-
myEdit.setSigned(false);
85-
myEdit.setDecimal(false);
86-
myEdit.setChannel(1);
87-
myEdit.setXMLAttribute("max=\"10\"");
88-
8982
//Export
9083
PhyphoxBleExperiment::ExportSet mySet; //Provides exporting the data to excel etc.
9184
mySet.setLabel("mySet");
92-
9385
PhyphoxBleExperiment::ExportData myData1;
9486
myData1.setLabel("myData1");
9587
myData1.setDatachannel(1);
@@ -105,7 +97,7 @@ void setup()
10597
secondView.addElement(myInfo); //attach info to view
10698
secondView.addElement(mySeparator); //attach separator to view
10799
secondView.addElement(myValue); //attach value to view
108-
secondView.addElement(myEdit); //attach editfield to view (Linked to value)
100+
109101
plotRandomValues.addView(firstView); //attach view to experiment
110102
plotRandomValues.addView(secondView);
111103
mySet.addElement(myData1); //attach data to exportSet
@@ -117,22 +109,14 @@ void setup()
117109

118110
void loop()
119111
{
120-
121112
float randomValue = random(0, 100); //create random number between 0 - 100
122113
float randomValue2 = randomValue * randomValue;
123114

124115
/* The random number is written into Channel 1
125116
Up to 5 Channels can written at the same time with server.write(randomDistance, valueChannel2, valueChannel3.. )
126117
*/
127-
float tmp = randomValue2*editValue;
128-
PhyphoxBLE::write(randomValue, randomValue2, tmp);
118+
PhyphoxBLE::write(randomValue, randomValue2);
129119
delay(50);
130120

131121
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
132-
}
133-
134-
void receivedData() { // get data from PhyPhox app
135-
float readInput;
136-
PhyphoxBLE::read(readInput);
137-
editValue = readInput;
138122
}

examples/getDataFromSmartphone/getDataFromSmartphone.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bool led = true;
1111

1212
void setup()
1313
{
14-
PhyphoxBLE::begin(&Serial);
14+
Serial.begin(115200);
1515
PhyphoxBLE::start();
1616
PhyphoxBLE::configHandler=&receivedData;
1717
pinMode(LED_BUILTIN, OUTPUT);
@@ -42,14 +42,13 @@ void setup()
4242

4343
void loop()
4444
{
45-
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
45+
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
4646

4747
if(millis()-lastTimestamp>blinkInterval){
4848
lastTimestamp = millis();
4949
led=!led;
5050
digitalWrite(LED_BUILTIN, led);
5151
}
52-
5352
}
5453

5554
void receivedData(){
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <phyphoxBle.h>
2+
3+
void setup() {
4+
Serial.begin(115200);
5+
6+
PhyphoxBLE::start();
7+
PhyphoxBLE::configHandler=&receivedData;
8+
9+
PhyphoxBleExperiment getDataFromSmartphonesensor;
10+
getDataFromSmartphonesensor.setTitle("Get Accelerometer Data");
11+
getDataFromSmartphonesensor.setCategory("Arduino Experiments");
12+
getDataFromSmartphonesensor.setDescription("Send smartphone accelerometer data to an arduino/esp32");
13+
14+
PhyphoxBleExperiment::View firstView;
15+
firstView.setLabel("FirstView"); //Create a "view"
16+
17+
PhyphoxBleExperiment::InfoField infoText;
18+
infoText.setInfo("Acc data is sent to smartphone");
19+
firstView.addElement(infoText);
20+
21+
PhyphoxBleExperiment::Sensor smartphoneAcc; // add new sensor
22+
23+
// Set type of sensor:
24+
// SENSOR_ACCELEROMETER
25+
// SENSOR_ACCELEROMETER_WITHOUT_G
26+
// SENSOR_GYROSCOPE
27+
// SENSOR_MAGNETOMETER
28+
// SENSOR_PRESSURE
29+
smartphoneAcc.setType(SENSOR_ACCELEROMETER);
30+
smartphoneAcc.setAverage(true);
31+
smartphoneAcc.setRate(80);
32+
33+
// map sensor channel to incoming data channels
34+
smartphoneAcc.mapChannel("x",1);
35+
smartphoneAcc.mapChannel("y",2);
36+
smartphoneAcc.mapChannel("z",3);
37+
38+
getDataFromSmartphonesensor.addView(firstView);
39+
getDataFromSmartphonesensor.addSensor(smartphoneAcc);
40+
41+
PhyphoxBLE::addExperiment(getDataFromSmartphonesensor);
42+
PhyphoxBLE::printXML(&Serial); //print the generated xml file into the serial monitor
43+
}
44+
45+
void loop() {
46+
delay(100);
47+
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
48+
}
49+
50+
void receivedData(){
51+
Serial.println("data:");
52+
float x,y,z;
53+
PhyphoxBLE::read(x,y,z);
54+
Serial.print("x: ");
55+
Serial.print(x);
56+
57+
Serial.print(" y: ");
58+
Serial.print(y);
59+
60+
Serial.print(" z: ");
61+
Serial.println(z);
62+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <phyphoxBle.h>
2+
3+
void setup() {
4+
Serial.begin(115200);
5+
PhyphoxBLE::start();
6+
PhyphoxBLE::experimentEventHandler = &newExperimentEvent; // declare which function should be called after receiving an experiment event
7+
PhyphoxBLE::printXML(&Serial);
8+
}
9+
10+
void loop() {
11+
float randomNumber = random(0,100); //Generate random number in the range 0 to 100
12+
PhyphoxBLE::write(randomNumber); //Send value to phyphox
13+
delay(100);
14+
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
15+
16+
}
17+
18+
//declare function which is called after phyphox wrote to the event characteristic
19+
void newExperimentEvent(){
20+
Serial.println("New experiment event received:");
21+
Serial.print("Event type: ");
22+
Serial.print(PhyphoxBLE::eventType);
23+
Serial.println(" (0 = Paused, 1 = Started, 255 = SYNC)");
24+
Serial.print("Experiment time [ms]: ");
25+
Serial.println(PhyphoxBLE::experimentTime);
26+
Serial.print("Unix system time [ms]: ");
27+
Serial.println(PhyphoxBLE::systemTime);
28+
}

examples/multigraph/multigraph.ino

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <phyphoxBle.h>
2+
#include <math.h>
3+
#define PI 3.1415926535897932384626433832795
4+
float periodTime = 2.0;//in s
5+
6+
void setup() {
7+
Serial.begin(115200);
8+
PhyphoxBLE::start();
9+
10+
PhyphoxBleExperiment MultiGraph;
11+
12+
MultiGraph.setTitle("Multi Graph Example");
13+
MultiGraph.setCategory("Arduino Experiments");
14+
MultiGraph.setDescription("ArduinoBLE Example");
15+
16+
PhyphoxBleExperiment::View firstView;
17+
firstView.setLabel("FirstView"); //Create a "view"
18+
19+
//Multiple graphs in one plot can be realised by two different methods.
20+
// OPTION 1 is do create a graph as usual and add additional datastreams the following way
21+
PhyphoxBleExperiment::Graph myFirstGraph;
22+
myFirstGraph.setChannel(1,2);
23+
myFirstGraph.setStyle(STYLE_DOTS);//"lines" are used if you dont set a style
24+
myFirstGraph.setColor("ffffff");
25+
myFirstGraph.setLinewidth(2);//if you dont select a linewidth, a width of 1 is used by default
26+
27+
PhyphoxBleExperiment::Graph::Subgraph additionalData;
28+
additionalData.setChannel(1,3);
29+
additionalData.setStyle(STYLE_LINES);
30+
additionalData.setColor("ff00ff");
31+
additionalData.setLinewidth(1);
32+
33+
myFirstGraph.addSubgraph(additionalData);
34+
35+
//OPTION 2: you can also skip editing the graph object and just add datastreams
36+
PhyphoxBleExperiment::Graph mySecondGraph;
37+
38+
PhyphoxBleExperiment::Graph::Subgraph firstData;
39+
firstData.setChannel(1,2);
40+
firstData.setColor("ffffff");
41+
firstData.setStyle(STYLE_DOTS);
42+
firstData.setLinewidth(2);
43+
44+
mySecondGraph.addSubgraph(firstData);
45+
46+
PhyphoxBleExperiment::Graph::Subgraph secondData;
47+
secondData.setChannel(1,3);
48+
secondData.setColor("ff00ff");
49+
secondData.setLinewidth(1);//if you dont select a linewidth, a width of 1 is used by default
50+
secondData.setStyle(STYLE_LINES); //"lines" are used if you dont set a style
51+
52+
53+
mySecondGraph.addSubgraph(secondData);
54+
55+
firstView.addElement(myFirstGraph);
56+
firstView.addElement(mySecondGraph);
57+
58+
MultiGraph.addView(firstView);
59+
60+
PhyphoxBLE::addExperiment(MultiGraph);
61+
62+
PhyphoxBLE::printXML(&Serial);
63+
}
64+
65+
void loop() {
66+
67+
float currentTime = millis()/1000.0;
68+
float sinus = generateSin(currentTime);
69+
float cosinus = generateSin(currentTime+0.5*periodTime);
70+
PhyphoxBLE::write(currentTime,sinus,cosinus);
71+
delay(100);
72+
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
73+
}
74+
75+
float generateSin(float x){
76+
return 1.0 * sin(x*2.0*PI/periodTime);
77+
}

0 commit comments

Comments
 (0)