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.

Using PhyPhox for lsm9ds1 accelerometer
#1
Hi there,

I am using the Nano 33 BLE board to receive accelerometer data to upload onto 3 separate channels. However I am unable to do so, because whenever I write code for the lsm9ds1 my phone cannot find my Arduino via bluetooth. It just doesn't show up. When I write my own code I am able to connect to my Arduino and display two separate channels. I have included my code below, if possible could someone help guide me towards the solution? Thank you so much  Smile




Code:

#include <phyphoxBle.h>
#include <Arduino_LSM9DS1.h>

void setup() {
  Serial.begin(115200);
  PhyphoxBLE:Confusedtart("Experiment");

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

  Experiment.setTitle("Experiment");
  Experiment.setCategory("Arduino Experiments");

  //View
  PhyphoxBleExperiment::View firstView;
  firstView.setLabel("FirstView"); //Create a "view"
  PhyphoxBleExperiment::View secondView;
  secondView.setLabel("SecondView"); //Create a "view"
  PhyphoxBleExperiment::View thirdView;
  thirdView.setLabel("ThirdView"); //Create a "view"

  //First Graph
  PhyphoxBleExperiment::Graph xGraph;      //Create graph which will plot random numbers over time
  xGraph.setLabel("Graphing x-acceleration");
  xGraph.setUnitX("s");
  xGraph.setUnitY("m/s/s");
  xGraph.setLabelX("time");
  xGraph.setLabelY("x-acceleration");
  xGraph.setColor("FF0000");                //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()
  */

  xGraph.setChannel(0, 1);

  //Second Graph
  PhyphoxBleExperiment::Graph yGraph;      //Create graph which will plot random numbers over time
  yGraph.setLabel("Graphing y-acceleration");
  yGraph.setUnitX("s");
  yGraph.setUnitY("m/s/s");
  yGraph.setLabelX("time");
  yGraph.setLabelY("y-acceleration");
  yGraph.setColor("00FF00");                //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()
  */

  yGraph.setChannel(0, 2);

  //Third Graph
  PhyphoxBleExperiment::Graph zGraph;      //Create graph which will plot random numbers over time
  zGraph.setLabel("Graphing z-acceleration");
  zGraph.setUnitX("s");
  zGraph.setUnitY("m/s/s");
  zGraph.setLabelX("time");
  zGraph.setLabelY("z-acceleration");
  zGraph.setColor("0000FF");                //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()
  */

  zGraph.setChannel(0, 3);

  //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.setXMLAttribute("size=\"1.2\"");

  //Separator
  PhyphoxBleExperiment::Separator mySeparator;      //Creates a line to separate elements.
  mySeparator.setHeight(0.3);                      //Sets height of the separator.
  mySeparator.setColor("404040");                  //Sets color of the separator. Uses a 6 digit hexadecimal value in "quotation marks".

  //Value
  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.setColor("FFFFFF");                  //Sets font color. Uses a 6 digit hexadecimal value in "quotation marks".
  myValue.setChannel(3);
  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);

  PhyphoxBleExperiment::ExportData myData2;
  myData2.setLabel("myData2");
  myData2.setDatachannel(2);

  PhyphoxBleExperiment::ExportData myData3;
  myData3.setLabel("myData3");
  myData3.setDatachannel(3);

  //attach to experiment

  firstView.addElement(xGraph);            //attach graph to view
  firstView.addElement(yGraph);            //attach second graph to view
  firstView.addElement(zGraph);
  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)
  thirdView.addElement(myInfo);                //attach info to view
  thirdView.addElement(mySeparator);          //attach separator to view
  thirdView.addElement(myValue);              //attach value to view
  thirdView.addElement(myEdit);              //attach editfield to view (Linked to value)
  Experiment.addView(firstView);        //attach view to experiment
  Experiment.addView(secondView);
  Experiment.addView(thirdView);
  mySet.addElement(myData1);                  //attach data to exportSet
  mySet.addElement(myData2);                  //attach data to exportSet
  mySet.addElement(myData3);
  Experiment.addExportSet(mySet);        //attach exportSet to experiment
  PhyphoxBLE::addExperiment(Experiment);      //attach experiment to server

}

void loop() {
  float x, y, z;
  IMU.readAcceleration(x, y, z);
  PhyphoxBLE::write(x, y, z);
    delay(1);

}
Reply
#2
Hey,

your code looks good! I think the problem is within your loop-block:


Code:
  IMU.readAcceleration(x, y, z);

This line will return a 1 when new data is available (and the datapoints itself of course). If the accelerometer is not ready, you get an 0 and NAN as you can see in the libraries repository:

https://github.com/arduino-libraries/Ard...1.cpp#L109

Since the loop is basicly running with no delay (except this very small 1ms) you will call some "readAccelertion" while no data is available. You should get new data every ~10ms, since the output data rate is fixed to 104Hz in this library (if you want to change the data rate, you might switch to another library - i think the sparkfun one is able to set some settings).

To avoid this, you could go with this: 
Code:
if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);
    PhyphoxBLE::write(x, y, z);
}
Next issue might be the limiting bluetooth low energy rate. Depending on your smartphone and connection quality you will not be able to reach 115Hz. You should also check the phyphoxBLE example "connectionParamter" which allows to tweak the bluetooth paramter. This thread might be helpful aswell, since our french colleagues where able to get this rate with the same arduino setup:
https://phyphox.org/forums/showthread.php?tid=1026

Let me know if its still not working.

Cheers,
Dominik
Reply
#3
(05-06-2022, 11:41 AM)Hey Dominik,Thank you for your response. I tried to increase the delay but had no success. Thus I read the thread you posted and concluded that I needed to include the first 4 lines of code in the connectionParameters example. I tweaked them to Gautier's numbers as below:  PhyphoxBLE::minConInterval = 6; //6 = 7.5ms Wrote:   PhyphoxBLE::maxConInterval = 6; //6 = 7.5ms

  PhyphoxBLE:ConfusedlaveLatency = 0; //
  PhyphoxBLE::timeout = 10; //10 = 100ms

However the Arduino still isn't showing up on my phyphox app. Is there something else I am missing? Thank you for your help Dominik!








Dominik DorselHey,

your code looks good! I think the problem is within your loop-block:


Code:
  IMU.readAcceleration(x, y, z);

This line will return a 1 when new data is available (and the datapoints itself of course). If the accelerometer is not ready, you get an 0 and NAN as you can see in the libraries repository:

https://github.com/arduino-libraries/Ard...1.cpp#L109

Since the loop is basicly running with no delay (except this very small 1ms) you will call some "readAccelertion" while no data is available. You should get new data every ~10ms, since the output data rate is fixed to 104Hz in this library (if you want to change the data rate, you might switch to another library - i think the sparkfun one is able to set some settings).

To avoid this, you could go with this: 
Code:
if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);
    PhyphoxBLE::write(x, y, z);
}
Next issue might be the limiting bluetooth low energy rate. Depending on your smartphone and connection quality you will not be able to reach 115Hz. You should also check the phyphoxBLE example "connectionParamter" which allows to tweak the bluetooth paramter. This thread might be helpful aswell, since our french colleagues where able to get this rate with the same arduino setup:
https://phyphox.org/forums/showthread.php?tid=1026

Let me know if its still not working.

Cheers,
Dominik

Sorry for the weird previous font. On another note I did some digging and found Gautier's published code. I edited to the following (below) and I got the acceleration in the right format. However, my goal was to create channels of my own, to allow for maximum customizeability. My guess is that the maxConinterval on my previous code isn't the right number, because I am transmitting more data than what Gautier is using. Is there a method to find the maxConinterval I need?

Gautier's Code (edited with my project):

/* Link between Arduino Nano 33 BLE Sense and phyphox app v1
* Allows to choose which experiment the Arduino Nano 33 BLE Sense should execute, using Phyphox.
* by Gautier Creutzer and Frédéric Bouquet, La Physique Autrement / Physics Reimagined, Laboratoire de Physique des Solides / Laboratory of Solid state Physics, Université Paris-Saclay / Paris-Saclay University
* Check our other projects in English and French: www.physicsreimagined.com
*
* This work is based on the phyphox Arduino library developed by the phyphox team at the RWTH Aachen University, which is released under the GNU Lesser General Public Licence v3.0 (or newer).
* This work is released under the GNU Lesser General Public Licence v3.0 (or newer).
*/

#include <phyphoxBle.h>
#include <Arduino_LSM9DS1.h>


char board_name[] = "nano_6"; // to change the name displayed by the board using BLE: no space and no special character

float accx, accy, accz, acc;
unsigned long initial_time, first_time, fourth_time;
float first_difference_float, fourth_difference_float;



void setup()

  PhyphoxBLE::minConInterval = 6; //6 = 7.5ms
  PhyphoxBLE::maxConInterval = 6; //6 = 7.5ms
  PhyphoxBLE:ConfusedlaveLatency = 0; //
  PhyphoxBLE::timeout = 10; //10 = 100ms
 
  if (!IMU.begin()) { // starting all useful sensors
    while (1);
  }
  PhyphoxBLE:Confusedtart("Manvir's Board"); // the name of the board can be changed at the beginning of the program
}

void loop() { // if the sensor is available, the acceleration and a timestamp are written to the BLE server, and then to the Phyphox app
    if (IMU.accelerationAvailable()) {
      first_time = millis();
      IMU.readAcceleration(accx, accy, accz);
      first_difference_float = ((float)first_time-(float)initial_time)/1000;
      acc = sqrt(pow(accx, 2) + pow(accy, 2) + pow(accz, 2));
      PhyphoxBLE::write(first_difference_float, accx, accy, accz, acc);
      delay(100);
    }
}
Reply
#4
Hey,

sorry for my late replay. 


Quote:However, my goal was to create channels of my own, to allow for maximum customizeability.

Sorry I donnt get it. What do you want to achieve?


Quote:My guess is that the maxConinterval on my previous code isn't the right number, because I am transmitting more data than what Gautier is using. Is there a method to find the maxConinterval I need?
The connection interval is the time interval between each data package (which is usually 20 bytes). Since you are limited to 5 floats (on the arduino nano), which are 20 bytes, the connection interval is independent from the number of floats you are transfering with phyphoxBLE::write(); So I think you can stick to Gautiers settings.

Cheers,
Dominik
Reply


Forum Jump: