Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep theĀ Forum RulesĀ in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For exampleĀ “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post willĀ not bring you to the same post, in Dutch, as there is no translation for that post!



problem using MPU-6...
 
Share:
Notifications
Clear all

[Solved] problem using MPU-6050 Accel/Gyro with ESP32

98 Posts
3 Users
3 Reactions
29.8 K Views
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

@hansMy pleasure.Ā  By the way, can you change the topic title to correct my typo in Gryo?
Thanks.Ā  Looking forward to resolving this data freeze issue so I can use the project in my RC cars


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2864
 

Well thank you anyway - enough people would just walk away and not care haha ... so it si very much appreciated! 👍Ā 

I did change the title, but unfortunately, the typo will remain in the link (the forum won't let me change that).


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 

Hello Hans, hello tvr4!

Ā 

Thank you so much for the kind replies!

I cleaned out my Arduino folders and I'm in the process of installing all libraries needed for the Heltec and MPU, with nothing more, hoping to go past the initial fault and see what uploading the code (thank you!!) will do :)


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 

Hey guys,

Ā 

It seems I can't alter the previous post so I had to write a new one.

So I tried of course the whole code and I've come a little further, as far as I can see there's contact with the MPU and parameters are given, but I don't get a real read out, everything is just zeros the Vmax, the SAT, LAT MaxG, everything is 0.000000, so it's gotta be a connection thing is my guess.

Did a lot of reading and searching but the only thing I can come with is this;

in the code on line 31&32 there's a reference to the GPS RX and TX;

31 //GPS RX Pin-17 GREEN WIRE
32 //GPS TX Pin-23 YELLOW WIRE

And coming back in line 81;

81 // GPS RX=17, GPS TX=23

I lack of course both, having only VCC, GND, SCL and SDA connected, and I tried to find out where I could find these RX and TX connections eventually reading the datasheet of the MP6050 and then it hit me, there's no GPS function in this module!

Now I have the Arduino GY-521 breakout board for the MPU6050 and to the best of my knowledge there's no GPS on that, so now I'm lost again...

At first, why don't I get any readout from the GY-521 while I'm pretty certain I did everything correct and second, where does the GPS data comes from? the Heltec isn't connected to the internet and the MPU6050 doesn't have a GPS module.

I do hope you could help me with this, although I like to marvel at the technical wonders of this world, it drives me crazy! 😆

Here's a link to imgur with my little setup;Ā 

Ā 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2864
 

Since you're not able to post attachment yet (it takes a few posts before the forum allows that), I took the liberty of posting them for you (in your previous message).

I unfortunately do not have the MPU module, so there is not muhc I bring to the table. Maybe @tvr4 can give you a hint?


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

@michaelzenI do apologize for the confusion,Ā  The TX & RX lines are for the GPS module.

I was using a ublox neo-6m GPS module which has two signal lines.Ā  You are correct the accelerometer module only uses two lines SCL and SDA.Ā  I was not using the interrupt line.

Looks like you got the basic code running.Ā  What microprocessor board are you using?
I used a Heltec ESP32 Wifi v2 board.

Not sure if I mentioned this in the code notes but the MPU6050 library I used is by electronic cats.
Here is the page: https://github.com/ElectronicCats/mpu6050

Click on the green code button then select "Download Zip"

You will need to manually install that in the arduino IDE.Ā  Here is how to do that:
https://www.digikey.com/en/maker/blogs/2018/how-to-install-arduino-libraries

Let me know how this goes
It is really cool to see my code running


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 
Posted by: @hansSince you're not able to post attachment yet (it takes a few posts before the forum allows that), I took the liberty of posting them for you (in your previous message).I unfortunately do not have the MPU module, so there is not muhc I bring to the table. Maybe @tvr4 can give you a hint?
Yeah I also see that my posts need to be checked by a moderator which I can understand, so thank you for bringing the picture in etc :)
Ā 
Ā 
Ā 
Ā 
Posted by: @tvr4

@michaelzenI do apologize for the confusion,Ā  The TX & RX lines are for the GPS module.

I was using a ublox neo-6m GPS module which has two signal lines.Ā  You are correct the accelerometer module only uses two lines SCL and SDA.Ā  I was not using the interrupt line.

Looks like you got the basic code running.Ā  What microprocessor board are you using?
I used a Heltec ESP32 Wifi v2 board.

Not sure if I mentioned this in the code notes but the MPU6050 library I used is by electronic cats.
Here is the page: https://github.com/ElectronicCats/mpu6050

Click on the green code button then select "Download Zip"

You will need to manually install that in the arduino IDE.Ā  Here is how to do that:
https://www.digikey.com/en/maker/blogs/2018/how-to-install-arduino-libraries

Let me know how this goes
It is really cool to see my code running

Ah well at least that gives some understanding why I can't get a GPS readout, and thinking simple, maybe because of the lack of the GPS module also the other readouts are prohibited because it first wants the GPS read before it processes the GY-521 data?

My board is also the Heltec ESP32 Wifi V2 so no difference there, but only connected is that accelerometer which should give some feedback, but it doesn't.

I was already using the electronic cats library but installed it again manually, but it doesn't make any difference still all numbers are zeros :(

And having your code running and seeing the board actually do something different then the provided example setups is as awesome for me as for you! :)


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

Here is the wiring diagram for the project. Check the wiring and let me know how it goes

Ā 


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 
Posted by: @tvr4

Here is the wiring diagram for the project. Check the wiring and let me know how it goes

Ā 

This changes everything 😀Ā 

As I had my SCL and SDA still connected to pin 21 and 22 it couldn't get the readout, but I chnged them to 4 and 15 and now the Accelerometer works beautiful!

Thank you! I just ordered the NEO-M8N GPS module so when that arrives I can go on with this project, for now thank you both so much, I'm happy it works!

Ā 

Ā 


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 

Hi Guys,

Ā 

So my GPS module arrived and I finally had some time to try things out, but during compiling I got this error message;

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "WiFi LoRa 32(V2), Disabled, 240MHz (WiFi/BT), 921600, None, REGION_EU868, None"

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp: In member function 'int8_t MPU6050::GetCurrentFIFOPacket(uint8_t*, uint8_t)':

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2763:32: error: 'BUFFER_LENGTH' was not declared in this scope

uint8_t Trash[BUFFER_LENGTH];

^

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2769:39: error: 'Trash' was not declared in this scope

getFIFOBytes(Trash, (uint8_t)RemoveBytes);

^

exit status 1

Error compiling for board WiFi LoRa 32(V2).

Ā 

Now before I came barging in in this topic about the code you were talking about the fifo buffer problems and I have read extensively on the posts made.

I tried altering the .cpp and code but it did nothing, it just gave more error codes 🙄Ā 

Then another thing, I have the Ublox Neo M8N and from what I've found on google it works only with the neoGPS library while here tiny GPS is used, and from what I've seen the code is very different, so my guess is that this is also gonna be a problem, but first things first there needs some Trash be declared 🙃Ā 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2864
 

Seems you forgot to define BUFFER_LENGTH.

Either like so (123 being an arbitrary number)

#define BUFFER_LENGTH 123

or something like this:

int BUFFER_LENGTH=123;

Hope this helpsĀ  😊


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

@hansCan you recommend a setting for this buffer length?


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2864
 

Just a guess based on what I have seen in the examples for ElectronicCats/mpu6050 on GitHub and they all seem to used 64. 😊Ā 


   
ReplyQuote
(@michaelzen)
Active Member
Joined: 5 years ago
Posts: 10
 
Posted by: @hans

Seems you forgot to define BUFFER_LENGTH.

Either like so (123 being an arbitrary number)

#define BUFFER_LENGTH 123

or something like this:

int BUFFER_LENGTH=123;

Hope this helpsĀ  😊

To be honest, I didn't forgot, it's on line 12 of the code provided by tvr4 on page 5 and what I really don't understand is that the code has run on my Heltec, see the pic posted on this page and now when I wanted to implement the Neo it flaws, shoot me why, but I have no idea.

Then I played around with the position of the define or int function but both kept giving error codes, this is what I get with #define BUFFER_LENGTH 64 on line 12;

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "WiFi LoRa 32(V2), Disabled, 240MHz (WiFi/BT), 921600, None, REGION_EU868, None"

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp: In member function 'int8_t MPU6050::GetCurrentFIFOPacket(uint8_t*, uint8_t)':

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2763:32: error: 'BUFFER_LENGTH' was not declared in this scope

uint8_t Trash[BUFFER_LENGTH];

^

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2769:39: error: 'Trash' was not declared in this scope

getFIFOBytes(Trash, (uint8_t)RemoveBytes);

^

exit status 1

Error compiling for board WiFi LoRa 32(V2).

Ā 

And this when I switch to int, again on line 12;

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "WiFi LoRa 32(V2), Disabled, 240MHz (WiFi/BT), 921600, None, REGION_EU868, None"

Heltc32GPSthingy:12:19: error: expected initializer before numeric constant

int BUFFER_LENGTH 64

^

C:\Users\Michi\AppData\Local\Temp\arduino_modified_sketch_395157\Heltc32GPSthingy.ino: In function 'int8_t GetCurrentFIFOPacket(uint8_t*, uint8_t)':

Heltc32GPSthingy:362:15: error: 'BUFFER_LENGTH' was not declared in this scope

uint8_t Trash[BUFFER_LENGTH];

^

Heltc32GPSthingy:368:18: error: 'Trash' was not declared in this scope

mpu.getFIFOBytes(Trash, (uint8_t)RemoveBytes);

^

exit status 1

expected initializer before numeric constant

And I really tried to get a grasp of this C++ programming, read a lot, watched tutorials and tried my best, but I'm not an inch further then copying other ones code, fumbling with it in trail and error and hoping for the best, but I really don't understand a thing of what is happening and I start to think that Arduino is not for me...

Ā 

Ā 

Ā 

Ā 

Ā 

Ā 

Ā 

Ā 

Ā 

This post was modified 4 years ago 2 times by michaelzen

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2864
 

Hi Michael,

don't worry - happens to me quite often as well 😊Ā 
I'd be happy to help.

Ā 

What I read from your first error message is this:

1. one of the parameter functions of "GetCurrentFIFOPacket" has issues

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp: In member function 'int8_t MPU6050::GetCurrentFIFOPacket(uint8_t*, uint8_t)':

2. Undefined "BUFFER_LENGHT" (in the scope where this line is)

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2763:32: error: 'BUFFER_LENGTH' was not declared in this scope
uint8_t Trash[BUFFER_LENGTH];

3. Undefined "Trash" (a consequence of BUFFER_LENGTH not being defined, so you can ignore this one for now)

C:\Users\Michi\Documents\Arduino\libraries\MPU6050\MPU6050.cpp:2769:39: error: 'Trash' was not declared in this scope
getFIFOBytes(Trash, (uint8_t)RemoveBytes);

So in essence, because BUFFER_LENGTH is unknown/undefined in the scope of the code, so "Trash" cannot be properly defined either, which results in the "GetCurrentFIFOPacket" to fail since one of its required parameters is missing.

Ā 

Ā 

As for your second attempt error (using int), you made a typo:

According to the error you typed:

int BUFFER_LENGTH 64

However this should have been:

int BUFFER_LENGTH=64;

(common mistake when swapping out a #define with a variable)

The errors that follow is just a consequence of that first error.

Ā 

Feel free to post your full code if you still keep running into this issue.
Hope this helps 😊Ā 


   
ReplyQuote
Page 6 / 7
Share: