# Simple code returning 0.000000 for gyroscope sensor data

**URL:** <https://discourse.libsdl.org/t/simple-code-returning-0-000000-for-gyroscope-sensor-data/59126>\
**Category:** SDL Development\
**Created:** [April 8, 2025, 6:03pm UTC](https://discourse.libsdl.org/t/simple-code-returning-0-000000-for-gyroscope-sensor-data/59126 "2025-04-08T18:03:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheTitaniumTitan](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TheTitaniumTitan](https://discourse.libsdl.org/u/TheTitaniumTitan)\
**Post date:** [April 8, 2025, 6:03pm UTC](https://discourse.libsdl.org/t/simple-code-returning-0-000000-for-gyroscope-sensor-data/59126/1 "2025-04-08T18:03:02Z")

</div>

Here is my code:

> #include \<SDL3/SDL.h\>  
> #include
> 
> int main(int argc, char\* argv) {
> 
> ```
> SDL_Init(SDL_INIT_GAMEPAD);
> 
> int gamepadCount = 69;
> SDL_GetGamepads(&gamepadCount);
> printf("Number of gamepads detected: %d\n", gamepadCount);
> 
> SDL_Gamepad* gamepad_id = SDL_OpenGamepad(1);
> 
> float data_rate = 21;
> 
> data_rate = SDL_GetGamepadSensorDataRate(gamepad_id, SDL_SENSOR_GYRO);
> 
> printf("%f", data_rate);
> 
> bool sensorState = SDL_SetGamepadSensorEnabled(gamepad_id, SDL_SENSOR_GYRO, true);
> 
> printf("\n%s", sensorState ? "true" : "false");
> 
> SDL_Delay(1000); // wait 100 milliseconds
> 
> float gyro_data[3] = {21.0};
> 
> bool sensorData = SDL_GetGamepadSensorData(gamepad_id, SDL_SENSOR_GYRO, gyro_data, 3);
> 
> printf("\n%s", sensorData ? "true" : "false");
> 
> printf("\n%f %f %f", gyro_data[0], gyro_data[1], gyro_data[2]);
> 
> SDL_Quit();
> 
> return 0;
> 
> ```
> 
> }

And it prints this when compiled:  
Number of gamepads detected: 1  
250.000000  
true  
true  
0.000000 0.000000 0.000000

That should mean that it can see the gamepad. The gamepad is opened because it returns SDL\_GAMEPAD\* which is used in other functions. It successfully returns the sensor data rate (its a dualsense so 250 is correct). It returns a success for enabling gyro sensor data. It returns a success for reading gyro sensor data, but I just get 0s clearly, why?

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [April 8, 2025, 6:11pm UTC](https://discourse.libsdl.org/t/simple-code-returning-0-000000-for-gyroscope-sensor-data/59126/2 "2025-04-08T18:11:21Z")

</div>

You need to process events or call `SDL_UpdateGamepads()` to get data from the controller.

---

<div class="post-metadata">

**Author:** ![TheTitaniumTitan](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TheTitaniumTitan](https://discourse.libsdl.org/u/TheTitaniumTitan)\
**Post date:** [April 8, 2025, 6:14pm UTC](https://discourse.libsdl.org/t/simple-code-returning-0-000000-for-gyroscope-sensor-data/59126/3 "2025-04-08T18:14:16Z")

</div>

Thank you very much bro, its working now 👌
