Interface MPU6050/GY-521 with STM32 || LCD 20x4 || CubeMx || HAL || SW4STM
HTML-код
- Опубликовано: 5 сен 2024
- Purchase the Products shown in this video from :: controllerstec...
________________________________________________________________________________________
type -u _printf_float in the linker flag.
To download the code and for more explanation, goto
controllerstec...
Check out more VIDEOS on MODULES/SENSORS with STM32 • STM32 and SENSORS/MODULES
________________________________________________________________________________________
****** SUPPORT US BY DONATING*****
paypal.me/cont...
******Join the Membership******
/ @controllerstech
Join the Discord Server / discord
Join the Telegram Group t.me/controlle...
Follow me on Instagram / controllerstech
For more info, visit www.controller... Наука
I could see the acceleration values in Live View tab. For testing purposes, it worked fine. Thanks for sharing
In my case, one of them works at a time, either Display or MPU. What could be issue?
Hello, i try this on H723 Nucleo its not working at all... LCD is working but X, Y Z values are not changing...Why?
Thank you very much, you makes me clearly know how does it work.
Thank you very much. You just helped me alot with this video. But I have a littke problem because the values that I get are a little bit high and if I want to calculate the momentary angle, it just keep counting up. Could someone help me?
很棒!非常感谢!
No value of check is being returned. Please help!
After HAL_Init(); in main , stm32 out off order, i have test next block again chip out of order.. i am block ///HAL_Init(); every thing work correct..Thank
hi
why data array Rec_Data has type uint8_t, while sum of two first numbers of this array (Rec_Data[0]
In fact you have configured the MPU6050 in one of your videos I would like to know how to get a curve from it. If you could make a small video to show how to get a curve of the gyro and acceleration parameters. Thanks
I have a problem. When I turn on USB FS and set clock 48MHz, I can't communication with I2C. please tell me why. thank you so much!
pay more attention to the address of mpu6050 is 0xD0 not 0x68 in HAL, otherwise it will return HAL_ERROR
The linker flags part does not appear at 15.38 minutes, can you help me?
In cubeIDE, you can enable it in Properties-> C/C++ Build -> Settings -> MCUSetting. You will see the checkbox there to enable it.
hello , its very helpfull video , but do u have any suggestion if i want to get the data exactly 1K data per second ( 1 Khz ) or 500 Hz
Please correct me if I am wrong in a statement or otherwise, #define MPU6050_ADDR 0xD0 where the value 0xD0 is obtained from 7 bits + RW . From 7 bits (MSB) depending on pin level AD0, in this case let's say 0x68(AD0 at low level). and RW means do we want to write or read, my question is when we use "HAL_I2C_Mem_Write" do we keep using 0xD0 and not using 0xD1? Thank you sir I'm a beginner to learn STM and MPU sensors
The R/W bit should be 0 for write and 1 for read.
But we don't need to worry about the read address. The HAL adds that 1 during the read operation.
@@ControllersTech ok sir, what if now i change the address with 0xD1 will HAL also add automatically too or will it be a problem?
Nope. It only takes care of receive address.
i don't know how to calculate pitch, roll and yaw please help me
Hi sir, may I ask for code because the link you gave you can not be accessed
Thank you for a very informative tutorial, I tried the same way to communicate with my accelerometer, but i can't able to get output from my port. While at compiling it shows o errors and 0 warnings and successfully deployed, but i can't able to get any output form the module. And the LD4 in ST link continues to blink from green to red, even during debugging. Can you help me to sort out the issue. And at I did step into debug, which shows variables have a value both raw and float, but if I try to print those values via putty, its not showing anything. And it seems to be like constant.
absolutely brilliant, thanks for all
Thanks for the contribution man. Really appreciate it... 👍
@@ControllersTech I always say: Left hand help right hand and both wash my face
can you build a reaction wheel following this code?
Can this be used for MPU6500(with stm32) as well or are there any register changes? has any one tried that?
I am getting the wrong values while interfacing MPU6050 Accelerometer with STM32F446RE.
For Example for value of X, Y, Z axis as 0 , 0, 1 i am getting 0, 3.16, 1 for 0 ,1, 0 i am getting 3.16, 3.16, 0 and so on i am continuously getting this unexpected 3.16.
i have chosen accelerometer range as +/-2g, I2C1 peripheral with Standard mode and 50% duty cycle and APB1 clock as 16MHz
help me in getting my values correctly
If you are continuously getting same value, that means your configuration is not right.
Check the calculation part for for the range you have chosen
Hello mate did you made second video?
thank you! I was successful.
Hello, thank you for the video, how can i find the part 2?, isit still in the making?
There is no part 2..
hi, I try a little to get euler angles from dmp(digital motion processor) but I couldn't do that. do you know how I can get that from easy way? any source or whatever? I will use complementary filter or mahony filter if dmp is so exhausting. thanks in advance
I didn't tried it. I tried some algorithms to stabilize the gyro, but that didn't worked. I will try it again after few days ( I am out of my workstation right now)
Excuse me, where do I go to find the header file "i2c-lcd.h" and the source file "i2c-lcd.c"?
Link is in the description and files are in the src and inc folders..
thank you!
Hi, how to convert angular velocity to regular angle?
I have to start working on the angle part. I forgot as it was due for a while. The problem is that the error get developed in the gyro as the time passes. There are some algorithms to solve the issue. I'll take a look.
If you want to use angular velocity to do so, you can use the formula (w = ∆theta/∆t)
if i using cubeide, and i couldn't found the part that said linker flags where i can put the -u _printf_float
It's in project setting -> c/c++ build -> setting -> tool setting -> mcu setting and enable u printf float
Window not?
Hello
Controllers Tech! First of all I'd like to thank you for your video.
I have encountered some problems with the displaying part of the accel value.
1. After I builded the programm, I received an error. "buf" is undeclared. I cant recalled you declared a char volatile buf variable to use it in the sprintf function, or?
2. I dont get any value on the display.
What could be the problem? Does anyone else encountered this?
You should work on them separately first and then combine the codes. Better focus on LCD alone and when you understand it, then check the MPU6050.
@@ControllersTech Understood. Thx for replying.
Thank you sir
Hi, I created my own I2c library in stm32f I am doing bare metal, the only confusion I have is that my stm32 only detects mpu6050 when I give it address (0x68
Because that's the address of the slave (mpu6050)
@@ControllersTech yes I know that but I mean while check slave address on arduino we give 0x68 but on stm32 we have to shift 1 bit why is that?
Because Arduino takes 7 bit address. STM needs 8 bits (7 bits + read/write)
@@ControllersTech thank you
can you make a Video about the 16x2 i2c LCD without this library?!
It's already there on my channel search it
Hi, is it possible to plot the acceleration and gyroscope curve?
yes but you need some application which can do the plotting for you.
Then use uart to send the data to the app and it will plot the curve
@@ControllersTech Okay, thanks! I'll give it a try.
@@ControllersTech In fact you have configured the MPU6050 in one of your videos I would like to know how to get a curve from it. If you could make a small video to show how to get a curve of the gyro and acceleration parameters. Thanks
does not work check stays as 0
How can i download these libraries ??
Pls help me, thank you !!!
Goto the link in the description.. at the end of the post, there is a download button
Hello, I want to process the signal from the accelerometer. Because the read function is in the main loop which goes at a much faster rate than the 1kHz defined for the accelerometer, will the samples be red multiple times? Should interrupts or DMA be used to get samples at the exact sampling rate I want?
It doesn't go faster than 1KHz. If you read every 1 ms, that would be 1KHz.
@@ControllersTech hello, but to restrict it to read every 1ms you would need a delay or a timer interrupt. Otherwise it would sample as fast as the while loop goes. That's how I understood it.
Yeah you put a delay of 1 ms in the while loop
@@ControllersTech thanks for the reply, I have 1 just one more question, does it make sense to work with timer interrupts or DMA to get the sampling timing more accurate.
hey can i know where did we innitialize Accel_X_RAW ,Accel_Y_RAW & Accel_Z_RAW?
Right click on it and goto declaration
@@ControllersTech ooo okay, can i know where i can find your sample code?, because on your website i cant seem to find it(the one you put on your discription), anyways, thanks for your awesome tutorial, it helped me a lot !!
it's there... at the bottom of the page
@@ControllersTech yup i found it just a second ago, there is a downlaod button. Thank you
Great video! Maybe just a small clarification if it's possible, I'm not so good at coding. Maybe someone could explain.
For example for acceleration: How do we get the reading for all the axes both for H and L part, given the fact that there is only one command where only the ACCEL_XOUT_H_REG is read?
How does this command "HAL_I2C_Mem_Read (&hi2c1, MPU6050_ADDR, ACCEL_XOUT_H_REG, 1, Received_Data, 6, 1000);" knows that I also want to read ACCEL_XOUT_L_REG, ACCEL_YOUT_H_REG, ACCEL_YOUT_L_REG and so on...? Thanks!
In that function we are reading 6 registers starting from the ACCEL_H_REG. If you check the datasheet of the device, you will find out the next 5 registers.
@@ControllersTech Thanks! And one more thing regarding the values of the gyro. I have managed to build the setup but from what I see the generated values doesn't take into consideration the previous value. If for example I move the gyro at a certain angle I can see an instant change in the value but if I keep the senzor in the same position then the next values will start from zero instead of taking into consideration the angle. Did you manage to solve this issue? I know from Arduino implementation that the read values took into account the position of the sensor instead of creating a reference to zero at each new reading.
Thanks!
You can define the variable as static..
For eg- Static float angle;
Hi, It's a good tutorial, thanks
Anyway, I'm trying to make this working together with a LCD display and a PCF8574 module. Both working except GY521.
I tried to debug and I found I get HAL_Status error in the call of I2C_WaitOnFlagUntilTimeout in stmf1xx_hal_i2c.c . This is insider of first call of HAL_I2C_Mem_Read
I will buy another GY521,... only thing I can think of is the module is faulty.
Hi sir , i read your comment and i think i get the same error ..
Did you buy another GY521 ? and Did it work after that ?
Thanks.
@@achoangnguyen8796 Hi, no I did not continue this project. Sorry
Check tha address. Also check the connections. Use 4K7 pull up resistors on the sck and sda lines
Hi friend. First of all thx for this video.
Could you show, how to measure current angle? I measure ticks at start loop and end loop. Get difference between ticks. Then I get gyro dps and multiply on tick difference. The result I add to float vareable. Unfortunately, I didn't get axpected result. Could you help me?
There are lot of errors and other things to be taken into consideration while measuring angle. Like I mentioned in the video I'll make another one involving all those things soon. Or you can refer any arduino based code and port it. It should work
@@ControllersTech Thx for answer. I'll try it... again :)
@@ControllersTech you did not do it yet right?
what Os?
how will the sensor be filtered?
What you mean filtered ?
@@ControllersTech I want to filter my pressure, acceleration sensors. Is this something done during coding?
I still don't understand what you mean by filter the acceleration..
But anyway yes you have to do all at the time of coding itself.
If your query is more related to sensor, you can check the datasheet. There might be some register which can help you
@@ControllersTech thank you anyway, I couldn't explain myself.
The readings are coming but the values are unreliable, Can you help me to config it? Also you have commented the gyro config ..should we enable it for good values..
Right now only acceleration values are usable. I tested some theories and some other methods to calibrate gyro but wasn't successful. They always drift away 🤦♂️. I will soon start working on dmp port from arduino. That will definitely stabilize the gyro
@@ControllersTech Any joy with porting DMP to STM32?
It is redundant WHO_AM_I register, I think. Because if I'm not address it correctly, the device will not ACK
I don't think that affects it.
That's just to confirm if the device is connected and is responding
@@ControllersTech Hello.Thank you for your great tutorial!
I tried a lot but i couldn't receive correct data from MPU6050.
I followed everything that you said.
Also why do you Define MPU address D0? shouldn't it be 0x68 or 0x69?
Regards
Thank you !