Serial 6-axis accelerometer wont change sampling frequency

userHead 991cw 2025-07-11 02:49:45 334 Views2 Replies

I have been using this code from the website but any tinme i try to change the sampling frequency it does not change. It is always stuck at 10Hz. I have tried send it the raw code but it still wont work. I have set it up exactly like the guide says to. Is there something obvious that I am missing from my code below.
/*!
* @file getData.ino
* @brief Set the frequency of data output by the sensor, read the acceleration, 
* @n angular velocity, and angle of X, Y, and Z axes.
* @n Experimental phenomenon: when the sensor starts, it outputs data at the set 
* @n frequency and the data will be displayed on serial monitor.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [huyujie]([email protected])
* @version V1.0
* @date 2023-07-12
* @url https://github.com/DFRobot/DFRobot_WT61PC
*/
#include <DFRobot_WT61PC.h>


#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

DFRobot_WT61PC sensor(&FPSerial);

void setup()
{
 //Use Serial as debugging serial port 
 Serial.begin(115200);

#if (defined ESP32)
 FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
 FPSerial.begin(9600);
#endif


void loop()
{
 if (sensor.available()) {
   Serial.print("Acc\t"); Serial.print(sensor.Acc.X); Serial.print("\t");
   Serial.print(sensor.Acc.Y); Serial.print("\t"); Serial.println(sensor.Acc.Z); //acceleration information of X,Y,Z
   Serial.print("Gyro\t"); Serial.print(sensor.Gyro.X); Serial.print("\t");
   Serial.print(sensor.Gyro.Y); Serial.print("\t"); Serial.println(sensor.Gyro.Z); //angular velocity information of X,Y,Z
   Serial.print("Angle\t"); Serial.print(sensor.Angle.X); Serial.print("\t");
   Serial.print(sensor.Angle.Y); Serial.print("\t"); Serial.println(sensor.Angle.Z); //angle information of X, Y, Z 
   Serial.println();
 }
}

 

2025-07-11 18:58:25

Add a call to sensor.setOutputFreq(<desired_frequency>) in your setup() function. For example, to set it to 100 Hz, do this:

void setup()
{
 // Debug serial
 Serial.begin(115200);

#if (defined ESP32)
 FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
 FPSerial.begin(9600);
#endif

 // Wait for sensor to initialize
 delay(1000);

 // Initialize sensor
 sensor.begin();

 // Set data output frequency (possible values: 0x01 (1Hz), 0x02 (2Hz), ..., 0x63 (100Hz))
 sensor.setOutputFreq(100);  // Set to 100 Hz, change as needed
}
 

userHeadPic ahsrab.rifat
2025-07-11 03:02:41

Here is the command i use for changing the frequency. i put it at the end of the void setup(). Here is the line: sensor.modifyFrequency(FREQUENCY_100HZ)

userHeadPic 991cw