My sensor is not reading more than 11 times a second, using FREQUENCY_1HZ, FREQUENCY_200HZ and FREQUENCY_0_1HZ all result in no change, 11 times a second.
I have looked on the dfrobot forums, people have had similar problems as me but with no resolution.
here is the code I am using on my Arduino Uno R4 Wifi:
#include <DFRobot_WT61PC.h>
#define FPSerial Serial1 // Use Serial1 on Arduino Uno R4 WiFi for communication
DFRobot_WT61PC sensor(&FPSerial);
void setup()
{
// Use Serial as debugging serial port
Serial.begin(115200);
// Initialize Serial1 for communication with the sensor
FPSerial.begin(9600);
/**
* @brief Revise the data output frequency of sensor
* @param frequency - FREQUENCY_0_1HZ for 0.1Hz, FREQUENCY_0_5HZ for 0.5Hz, FREQUENCY_1HZ for 1Hz,
* @n FREQUENCY_2HZ for 2Hz, FREQUENCY_5HZ for 5Hz, FREQUENCY_10HZ for 10Hz,
* @n FREQUENCY_20HZ for 20Hz, FREQUENCY_50HZ for 50Hz, FREQUENCY_100HZ for 100Hz,
* @n FREQUENCY_125HZ for 125Hz, FREQUENCY_200HZ for 200Hz.
*/
sensor.modifyFrequency(FREQUENCY_200HZ);
}
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();
}
}
So there is a record for others who may find themselves in a similar situation. The Arduino R4 has changed to a 32 bit chipset, as a result some libraries do not work and need to be ported for them to be compatible.
From the Arduino Github there is a list of libraries that have been ported and currently are working, the library for that sensor of yours is not mentioned so I would be confident is saying that it would need to be ported, if you’re capable of doing so it would be beneficial to contribute to the repo so that others can use the library.
Hi Jordan
I certainly don’t profess to be any sort of Guru when it comes to coding.
But it strikes me that you have a bit of printing going on in that “void loop()” operation in which you print different bits from your sensor. It looks like you read the sensor info in order to print it.
Now I don’t see how the frequency of reading is going to increase beyond the time it takes to carry out these tasks.
There is a method I used some time ago to get an approximate idea of how long different tasks took. This involves pulsing a GPIO and monitoring the time with an oscilloscope. The pulse was a defined duration for identification purposes. In this case I would put a pulse before the "if (sensor available()) and another between the closing curley brackets.
If you want to do this DO NOT use the “digitalWrite” command as there is a several µSec delay while the UNO does some housekeeping and the actual start of the command. instead there is a sneaky one I found called “digitalWriteFast” which pretty well removes this delay.
Just interested, what happens if the sensor is unavailable??? Does the program just sit there and wait for something to happen. Maybe it keeps looping but I don’t know. There does not seem to ba an “else” alternative but maybe not needed.
Cheers Bob
By the way. That timing experiment above was with a “Freetronics 11” which is compatible with a UNO R3. It seems the UNO R4 is a bit different, I was unaware of that so I at least have learned something.
If sensor.available() is ran and no sensor is detected, it evaluates to false after a 5 second delay.
Its not a bottleneck as it doesnt change at all, no matter which frequency I set it to, whether that’s once a second or 200 times a second, it only outputs at ~11 times a second.
Using the code below, it outputs frequency at which its outputting.
It works by counting the amount of times within a 1 second window the sensor outputs data.
#include <DFRobot_WT61PC.h>
#define FPSerial Serial1
DFRobot_WT61PC sensor(&FPSerial);
unsigned long lastTime = 0; // Store the last time we printed the frequency
unsigned long count = 0; // Store the number of times data was received in the last second
void setup()
{
//Use Serial as debugging serial port
Serial.begin(115200);
FPSerial.begin(9600);
/**
* @brief Revise the data output frequency of the sensor
* @param frequency - FREQUENCY_0_1HZ for 0.1Hz, FREQUENCY_0_5HZ for 0.5Hz, FREQUENCY_1HZ for 1Hz,
* @n FREQUENCY_2HZ for 2Hz, FREQUENCY_5HZ for 5Hz, FREQUENCY_10HZ for 10Hz,
* @n FREQUENCY_20HZ for 20Hz, FREQUENCY_50HZ for 50Hz, FREQUENCY_100HZ for 100Hz,
* @n FREQUENCY_125HZ for 125Hz, FREQUENCY_200HZ for 200Hz.
*/
sensor.modifyFrequency(FREQUENCY_200HZ);
}
void loop()
{
if (sensor.available()) {
count++; // Increment the count each time new data is received
// 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();
}
// Print the frequency of responses once every second
unsigned long currentTime = millis();
if (currentTime - lastTime >= 1000) { // If a second has passed
lastTime = currentTime; // Update the last time
Serial.print("Frequency: ");
Serial.print(count); // Print how many times data was received in the last second
Serial.println(" Hz");
count = 0; // Reset the count for the next second
}
}
Hi Jordan
Not really the full bottle on the finer points of programming but your sketch looks a bit different than the sample in the product Wiki.which can be found here
Don’t know if the differences amount to much but worth a look. It would seem that you are not getting the message across to your sensor and these differences I note have something to do with that.
Cheers Bob
Hi Jordan
The problem might be the redundant bits that have been removed. Have you tried that sketch as she is written.
Getting a count of the number of actions in 1 second is a good idea and I think should be left there as a diagnostic thing until you get this sorted.
Cheers Bob
Having a look at the library for this sensor it seems like 10Hz is coded as the default value that is then altered by modifyFrequency(). The DFRobot_WT61PC.h file in the sensor library contains this code at line 102 uint8_t Cmd[5] = {0xff, 0xaa, 0x03, FREQUENCY_10HZ, 0x00};
I would try modifying this default frequency value to see if this changes anything.
It seems that the only time a write happens to the sensor is when you call modifyFrequency
The rest is just checking if something has been received and reading data.
As such, only 2 things come to mind.
The actual sensor only supports 10 hz and the change of frequency is for a different sensor (i.e. product changed over time)
OR
The write of the serial port is not getting to the sensor for some reason.
Do you have a way to ensure the signal is getting written out if the serial port to the SEN0386?
I have not posted any code for using a software serial although i have tried using D2-13 as soft serial, the sensor still outputted ~11hz and did not change frequency.
Hi Michael
Software serial is in the code described in the product Wiki but as you say not in Jordan’s code.
I was under the impression that pins 0 and 1 could not be used if the USB communication is used. I would assume Jordan is using USB to talk to the computer terminal so pins 0 and 1 would not be available for use surely.
Cheers Bob
2 Likes
And you can get our latest projects and tips straight away by following us on: