Sample Rate

Hello! To work with the MPU 6050, I need to set the sample rate in the Arduino board. I found one of the methods for setting the frequency divider, but I’m not sure if it’s correct. Could you help me understand this question.

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

int pinIn = A0; // Пин аналогового входа

void setup() {
pinMode(pinIn, INPUT);
sbi(ADCSRA, ADPS2); //Биту ADPS2 присваиваем единицу
cbi(ADCSRA, ADPS1); //Битам ADPS1 и ADPS0 присваиваем нули
sbi(ADCSRA, ADPS0);
Serial.begin(9600);
}

void loop() {
Serial.println(analogRead(pinIn));
delay(1000);
}

RegistersAr.ino (750 Bytes)

Could you help me understand this question.

What is the question?

What are you trying to set the sample rate to?

What are you reading the analog pin for?

Why are you using delay() at all?

I want to know how to set the sampling rate in Arduino. I don't understand, how to do this

SadAlphaMiks:
I want to know how to set the sampling rate in Arduino.

What sampling rate?

In the program you posted in your Original Post the frequency of calling analogRead() is determined by the line delay(1000);

...R

I need to set the sample rate in the Arduino UNO board itself. And this is not my program, I found it, but it seems that it does not work

SadAlphaMiks:
I need to set the sample rate in the Arduino UNO board itself. And this is not my program, I found it, but it seems that it does not work

That is not an answer to Reply #3.

There isn't any such thing on an Arduino Uno as "the sample rate". But you can program it to do things at a specified interval.

Saying that a program "does not work" does not convey any useful information with which to help you. Tell us what the program actually does and what you want it to do that is different.

...R

There are two different “rates” to consider, and there may be a language issue. There is the sample rate which in your code is 1Hz as determined by the delay(1000) between readings. Then there is the internal conversion rate of the ADC which is controlled by the ADCSRA bits which you are changing from the default settings of the Arduino IDE.

How do you know that the conversion rate was not changed?

Nick Gammons excellent tutorial on the Arduino ADC may be of interest
https://www.gammon.com.au/adc

cattledog:
Then there is the internal conversion rate of the ADC which is controlled by the ADCSRA bits which you are changing from the default settings of the Arduino IDE.

If the sample rate is of the order of 1 sample per second there does not seem to be any reason to change the internal settings.

...R

To work with the MPU 6050, I need to set the sample rate in the Arduino board.

No, you don't.

The MPU6050 communicates using the I2C bus, not the analog to digital converter.

Delete that code and start over with something intended for the MPU6050, for example this tutorial.