greetings, I'm almost new in the forum first I apologize if the topic does not go according, I'm developing a project I'm using the MPU6050(only the accelerometer) and arduous MEGA2560
I need to acquire from time to time the readings in this case angle and I have to use the TimerOne and the problem is that it does not print the data on the serial monitor
You can't use Serial.print etc. in the context of a timer callback routine.
In the ISR, collect, as global variables, the values you want, then print these in the loop().
Thank you very much for the help and if now I understand that within ISR more if tegno that to use timer they have informed to me that making use of flags could be done but I do not find information on how to implement it
andresz96:
Basically, as I understand it, I can't interrupt an I2c communication?
There would rarely be any reason to interrupt an I2C communication. There are very few reasons to use an interrupt and most "newbies" do not understand what their actual purpose is and are prone to imagine they are for things they are not.
It is most improbable you will need to time something with more resolution than a millisecond, so you have no need to use a timer. You use millis().
And as always, once you understand these, you can move beyond the "XY Problem" and ask the proper questions as to how to do the thing you really wish to do.
andresz96:
Thank you very much for the help and if now I understand that within ISR more if tegno that to use timer they have informed to me that making use of flags could be done but I do not find information on how to implement it
thank you for your help
You have said you have to use timer1 in your first post. If that is the case, you can set a flag in the ISR of timer1. You can test this flag in the loop() and then request data from the mpu6050 and reset the flag. There would, however, be better ways of achieving the same thing.
Further, it is possible to configure the Mpu6050 to generate an interrupt on some event, such as new data available to read. You could also handle this interrupt, set a flag and test it in the loop() and proceed as above.
It all depends on what task you have been given.