Skip to content

Commit

Permalink
Merge pull request #3 from Dorsel89/master
Browse files Browse the repository at this point in the history
Release version 1.2.0
  • Loading branch information
Staacks authored Sep 15, 2023
2 parents f35d49b + d20fa64 commit d79e66b
Show file tree
Hide file tree
Showing 34 changed files with 1,447 additions and 419 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ The purpose of this library is to use the phyphox app (see www.phyphox.org) to p
- Arduino Nano 33 Ble
- Arduino Nano Sense
- Arduino Nano 33 IoT (see note below)
- Arduino Uno R4 Wifi (see note below)
- senseBox MCU with NINA-B31 module
- ESP 32

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.
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.

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

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


#### Style and Layout oprtions for setStyle and setMax/setMin
STYLE_LINES, STYLE_DOTS, STYLE_VBARS, STYLE_HBARS, STYLE_MAP

LAYOUT_AUTO, LAYOUT_EXTEND, LAYOUT_FIXED

#### Error messages

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:
* ERR_01: The input was too long
* ERR_02: The value exceeds the upper limit
* ERR_03: The input was not a 6-digit hexadecimal code
* ERR_04: The input does not match with a valid value
* ERR_01: The input was too long.
* ERR_02: The value exceeds the upper limit.
* ERR_03: The input was not a 6-digit hexadecimal code.
* ERR_04: The input does not match with a valid value.
* ERR_05: The layout must be auto, extend or fixed.

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

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

## Credits

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.
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.

## Licence

Expand Down
50 changes: 17 additions & 33 deletions examples/CreateExperiment/CreateExperiment.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <phyphoxBle.h>

float editValue = 0;

void setup()
{
Serial.begin(115200);
PhyphoxBLE::start("My Device");
PhyphoxBLE::configHandler = &receivedData; // used to receive data from PhyPhox.
PhyphoxBLE::start("create experiment");

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

plotRandomValues.setTitle("Random Number Plotter");

plotRandomValues.setTitle("Create Experiment");
plotRandomValues.setCategory("Arduino Experiments");
plotRandomValues.setDescription("Random numbers are generated on Arduino and visualized with phyphox afterwards");

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

//Graph
PhyphoxBleExperiment::Graph firstGraph; //Create graph which will plot random numbers over time
firstGraph.setMinY(0, LAYOUT_FIXED);
firstGraph.setMaxY(100, LAYOUT_FIXED);
firstGraph.setLabel("Random number over time");
firstGraph.setUnitX("s");
firstGraph.setUnitY("");
Expand All @@ -38,29 +38,31 @@ void setup()
*/

firstGraph.setChannel(0, 1);

//Second Graph

PhyphoxBleExperiment::Graph secondGraph; //Create graph which will plot random numbers over time
secondGraph.setLabel("Random number squared over random number");
secondGraph.setUnitX("");
secondGraph.setUnitY("");
secondGraph.setLabelX("random number");
secondGraph.setLabelY("squared");
secondGraph.setStyle("dots");
secondGraph.setStyle(STYLE_DOTS);
secondGraph.setColor("2E728E"); //Sets Color of line

/* Assign Channels, so which data is plotted on x or y axis
first parameter represents x-axis, second y-axis
Channel 0 means a timestamp is created after the BLE package arrives in phyphox
Channel 1 to N corresponding to the N-parameter which is written in server.write()
*/

secondGraph.setChannel(1, 2);


//Info
PhyphoxBleExperiment::InfoField myInfo; //Creates an info-box.
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.");
//myInfo.setColor("404040"); //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
myInfo.setInfo("This is an Info field!");
myInfo.setColor("890128"); //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
myInfo.setXMLAttribute("size=\"1.2\"");

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

//Edit
PhyphoxBleExperiment::Edit myEdit;
myEdit.setLabel("Editfield");
myEdit.setUnit("u");
myEdit.setSigned(false);
myEdit.setDecimal(false);
myEdit.setChannel(1);
myEdit.setXMLAttribute("max=\"10\"");

//Export
PhyphoxBleExperiment::ExportSet mySet; //Provides exporting the data to excel etc.
mySet.setLabel("mySet");

PhyphoxBleExperiment::ExportData myData1;
myData1.setLabel("myData1");
myData1.setDatachannel(1);
Expand All @@ -105,7 +97,7 @@ void setup()
secondView.addElement(myInfo); //attach info to view
secondView.addElement(mySeparator); //attach separator to view
secondView.addElement(myValue); //attach value to view
secondView.addElement(myEdit); //attach editfield to view (Linked to value)

plotRandomValues.addView(firstView); //attach view to experiment
plotRandomValues.addView(secondView);
mySet.addElement(myData1); //attach data to exportSet
Expand All @@ -117,22 +109,14 @@ void setup()

void loop()
{

float randomValue = random(0, 100); //create random number between 0 - 100
float randomValue2 = randomValue * randomValue;

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

PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
}

void receivedData() { // get data from PhyPhox app
float readInput;
PhyphoxBLE::read(readInput);
editValue = readInput;
}
5 changes: 2 additions & 3 deletions examples/getDataFromSmartphone/getDataFromSmartphone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool led = true;

void setup()
{
PhyphoxBLE::begin(&Serial);
Serial.begin(115200);
PhyphoxBLE::start();
PhyphoxBLE::configHandler=&receivedData;
pinMode(LED_BUILTIN, OUTPUT);
Expand Down Expand Up @@ -42,14 +42,13 @@ void setup()

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

if(millis()-lastTimestamp>blinkInterval){
lastTimestamp = millis();
led=!led;
digitalWrite(LED_BUILTIN, led);
}

}

void receivedData(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <phyphoxBle.h>

void setup() {
Serial.begin(115200);

PhyphoxBLE::start();
PhyphoxBLE::configHandler=&receivedData;

PhyphoxBleExperiment getDataFromSmartphonesensor;
getDataFromSmartphonesensor.setTitle("Get Accelerometer Data");
getDataFromSmartphonesensor.setCategory("Arduino Experiments");
getDataFromSmartphonesensor.setDescription("Send smartphone accelerometer data to an arduino/esp32");

PhyphoxBleExperiment::View firstView;
firstView.setLabel("FirstView"); //Create a "view"

PhyphoxBleExperiment::InfoField infoText;
infoText.setInfo("Acc data is sent to smartphone");
firstView.addElement(infoText);

PhyphoxBleExperiment::Sensor smartphoneAcc; // add new sensor

// Set type of sensor:
// SENSOR_ACCELEROMETER
// SENSOR_ACCELEROMETER_WITHOUT_G
// SENSOR_GYROSCOPE
// SENSOR_MAGNETOMETER
// SENSOR_PRESSURE
smartphoneAcc.setType(SENSOR_ACCELEROMETER);
smartphoneAcc.setAverage(true);
smartphoneAcc.setRate(80);

// map sensor channel to incoming data channels
smartphoneAcc.mapChannel("x",1);
smartphoneAcc.mapChannel("y",2);
smartphoneAcc.mapChannel("z",3);

getDataFromSmartphonesensor.addView(firstView);
getDataFromSmartphonesensor.addSensor(smartphoneAcc);

PhyphoxBLE::addExperiment(getDataFromSmartphonesensor);
PhyphoxBLE::printXML(&Serial); //print the generated xml file into the serial monitor
}

void loop() {
delay(100);
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
}

void receivedData(){
Serial.println("data:");
float x,y,z;
PhyphoxBLE::read(x,y,z);
Serial.print("x: ");
Serial.print(x);

Serial.print(" y: ");
Serial.print(y);

Serial.print(" z: ");
Serial.println(z);
}
28 changes: 28 additions & 0 deletions examples/getSystemAndEventTime/getSystemAndEventTime.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <phyphoxBle.h>

void setup() {
Serial.begin(115200);
PhyphoxBLE::start();
PhyphoxBLE::experimentEventHandler = &newExperimentEvent; // declare which function should be called after receiving an experiment event
PhyphoxBLE::printXML(&Serial);
}

void loop() {
float randomNumber = random(0,100); //Generate random number in the range 0 to 100
PhyphoxBLE::write(randomNumber); //Send value to phyphox
delay(100);
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.

}

//declare function which is called after phyphox wrote to the event characteristic
void newExperimentEvent(){
Serial.println("New experiment event received:");
Serial.print("Event type: ");
Serial.print(PhyphoxBLE::eventType);
Serial.println(" (0 = Paused, 1 = Started, 255 = SYNC)");
Serial.print("Experiment time [ms]: ");
Serial.println(PhyphoxBLE::experimentTime);
Serial.print("Unix system time [ms]: ");
Serial.println(PhyphoxBLE::systemTime);
}
77 changes: 77 additions & 0 deletions examples/multigraph/multigraph.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <phyphoxBle.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795
float periodTime = 2.0;//in s

void setup() {
Serial.begin(115200);
PhyphoxBLE::start();

PhyphoxBleExperiment MultiGraph;

MultiGraph.setTitle("Multi Graph Example");
MultiGraph.setCategory("Arduino Experiments");
MultiGraph.setDescription("ArduinoBLE Example");

PhyphoxBleExperiment::View firstView;
firstView.setLabel("FirstView"); //Create a "view"

//Multiple graphs in one plot can be realised by two different methods.
// OPTION 1 is do create a graph as usual and add additional datastreams the following way
PhyphoxBleExperiment::Graph myFirstGraph;
myFirstGraph.setChannel(1,2);
myFirstGraph.setStyle(STYLE_DOTS);//"lines" are used if you dont set a style
myFirstGraph.setColor("ffffff");
myFirstGraph.setLinewidth(2);//if you dont select a linewidth, a width of 1 is used by default

PhyphoxBleExperiment::Graph::Subgraph additionalData;
additionalData.setChannel(1,3);
additionalData.setStyle(STYLE_LINES);
additionalData.setColor("ff00ff");
additionalData.setLinewidth(1);

myFirstGraph.addSubgraph(additionalData);

//OPTION 2: you can also skip editing the graph object and just add datastreams
PhyphoxBleExperiment::Graph mySecondGraph;

PhyphoxBleExperiment::Graph::Subgraph firstData;
firstData.setChannel(1,2);
firstData.setColor("ffffff");
firstData.setStyle(STYLE_DOTS);
firstData.setLinewidth(2);

mySecondGraph.addSubgraph(firstData);

PhyphoxBleExperiment::Graph::Subgraph secondData;
secondData.setChannel(1,3);
secondData.setColor("ff00ff");
secondData.setLinewidth(1);//if you dont select a linewidth, a width of 1 is used by default
secondData.setStyle(STYLE_LINES); //"lines" are used if you dont set a style


mySecondGraph.addSubgraph(secondData);

firstView.addElement(myFirstGraph);
firstView.addElement(mySecondGraph);

MultiGraph.addView(firstView);

PhyphoxBLE::addExperiment(MultiGraph);

PhyphoxBLE::printXML(&Serial);
}

void loop() {

float currentTime = millis()/1000.0;
float sinus = generateSin(currentTime);
float cosinus = generateSin(currentTime+0.5*periodTime);
PhyphoxBLE::write(currentTime,sinus,cosinus);
delay(100);
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
}

float generateSin(float x){
return 1.0 * sin(x*2.0*PI/periodTime);
}
Loading

0 comments on commit d79e66b

Please sign in to comment.