Use two sensors on one Arduino nano with separate baud rates

Hello! So I have a BMP280 sensor, and an MPU6050 sensor both connected to an Arduino nano at the same time. They both work with their separate libraries at different times on their own, even when they are both connected. So what I want to do is combine those two libraries into one, and then print the values read from both sensors at the same time to the serial monitor. But the problem is, they each have two separate baud rates. I just need to know how to print both values read from the sensors with different baud rates. I did ALOT of googling, but nothing helped me. thanks in advanced.

both sensors appear to have I2C interfaces so should connect to the same I2C hardware interface
the majority of I2C devices will operate at various frequencies - experiment until you find one which works with both

What do you mean frequencies? Do you mean if I keep changing the baud rate in the serial monitor one of them would work for both? Thanks for the response btw

Baud rate in the serial monitor has nothing to do with the i2c communication speed...


If each work separately, they should be able to be put on the same i2c lines... and you should be able to call each library to handle each device and then display them on the screen..

:smiley_cat:

I thought you were talking about the SCL clock frequency of the I2C interface

I usually run the serial monitor at 115200baud
implement seperate programs for each device and get them operational
then merge the two programs - sometimes simple sometimes very difficult

So do you have any solutions to my problem?

Please clarify what you mean by "baud rate"?

I'm not sure you are using the correct terminology.

Yeah so I am in the process of merging them. That is what is really difficult. Each program works well separately at different baud rates.

So The BMP280 uses the baud rate of 9600, and the MPU-6050 has a baud rate of 115200. Sorry if I said something wrong.

I think your terminology is hosed... These both work on the same buss, how are you changing 'baud' between them?

Now I'll have to go...

:smiley_cat:

set Serial to use 115200baud - don't attempt to change it in mide program
I have run programs using a BMP280 at 115200 without problems

No they don't. I think you are referring to the baud rate that the seperate sketches talk to the serial monitor? Just make them both 115200.

Both these devices use I2C to communicate to the Uno. This is not related to the baud rate above.

So I can use the BMP280 library at 115200 baud with the Arduino Nano?

The baud rate you are referring to has nothing to do with the BMP280. It is the speed that the Nano talks to the Serial Monitor. Yes you can use 115200. Try it.

So what I found out is that I can't change the baud while it is running, but I have to change it in the code when it does System.begin(); When I change the baud while it is running, a bunch of empty squares pop up.

You mean Serial.begin() ?

Whatever number you put in Serial.begin() (for example 115200) needs to match the baud rate in the serial monitor, here...

That's the speed you are talking between the Arduino and the Monitor... the numbers need to match.

Ah I see now. Thank you so so much for your help! Just a side note, how come it breaks when the numbers dont match(Im just curious)?

If the numbers don't match then the sending and receiving of data is happening at difference rates and data gets lost.

If I expect 100 bits a second to be received, and you send me 500 bits a second... then I get confused.

Wow. It all make sense now, thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.