-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Dorsel89/master
Release version 1.2.0
- Loading branch information
Showing
34 changed files
with
1,447 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
examples/getSensorDataFromSmartphone/getSensorDataFromSmartphone.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.