Go Down

Topic: First Time arduino/microcontroller user working with the LSM303C mag sensor (Read 13748 times) previous topic - next topic


The LSM303DHL (the other one, the older DHL) is like two sensors melted in a single package. The magnetometer and accelerometer have both an I2C address. The sparkfun code tries to encapsulate that, so only the register address is used as parameter.


Aug 04, 2014, 08:59 pm Last Edit: Aug 04, 2014, 10:50 pm by GettingAlong Reason: 1
How exactly would that change things for my sensor? The sections in the data sheets for both sensors for the I2C magnetometer stuff are basically identical. I just can't figure out how they came up with the #define hex values.

hold the phone...I believe I figured out what was confusing me. In the data sheet for I2C read/write for the magnetometer the address given is 0011110b which is 0x3C for write and 00111101b which is 0x3D. If the mode bit is dropped I get 0x1E for the mag device address which is what the pre-made code uses.


Would you be able to offer any critques/input if I drew up a picture of my circuit to make sure I have everything correct?


Sure, we do that all day  8)

Below the text input field (when writing a post), you see "Additional Options...". You can use that to upload a photo of a drawing. Any drawing is okay.


YAY! That would be a big help. One last question before I take a crack and assembling and drawing the picture.

The data sheet says I must connect SDA/SLC to VDD_IO through a pullup resistor. How would I determine what resistance t use?


Alright here is what I believe to be the correct circuit diagram for my project. I am still unsure hat to set the SDA/SCL pull-up resistor as because there is nothing stated in data sheet to point me in the right direction.


In your schematic, the 3.3V is not used to power the MPU-6050, and the SDA and SCL are shortcut, using the same pullup resistor.
I don't know what to think about your schematic.

This page has a schematic of a MPU-6050 module. http://wiki.jmoon.co/sensors/imu/mpu6050/
Click on the schematic for a larger version. Can you compare it and check the differences ?
Such a module costs less than 3 dollars (inclusive shipping).


Aug 05, 2014, 10:01 pm Last Edit: Aug 05, 2014, 10:30 pm by GettingAlong Reason: 1
The module you are suggesting will take way too long to mail here and it won't work with the project I am doing.

The level shifter I used is this.


Looking over this guide has me confused in the second picture I posted from sparkfun. Why is the 5V from the arduino connected to high voltage side and the 3.3V from the arduino is then connected to the low voltage side then from there connected to the device?

And yes I realized the SDA/SCL connection was all kinds of wrong until I set each one through its on resistor to VDD_IO.

made changes to SDA/SCL-> VDD_IO connection


The level shifter connects a 5V I2C bus to a 3.3V I2C bus in both ways.
It does not convert the 5V to 3.3V just like that, and it does not increase the 3.3V to 5V. The I2C bus is an open-collector bus and the level shifter pulls the other side low if a low is on one side. Therefor you have to apply both the higher voltage and the lower voltage.

I have been looking at the datasheet of the MPU-6050 and the schematic in that link : http://wiki.jmoon.co/sensors/imu/mpu6050/
That I understand.
Then I look at your schematic, but I don't know whether that is a MPU-6050. I can't tell if every pin is connected okay, since you have other pins.
Sorry, I would like to help, but I don't know how anymore.


I think I see where you are confused. I am not using the MPU-6050 at all in my circuit.
here is a list of everything I am using:

sensor: LSM303C

level shifter: BOB-12009

It is the read device between the sensor and the arduino. The link below leads to the device.


arduino: Arduino mega 2560

I labeled the two devices to help clear up any confusion in the picture on this post.


Oops, my fault  :smiley-eek-blue: Sorry.
I was also answering questions about the MPU-6050 in other threads in this forum...

The LSM303C is also a 3.3V chip, and SDA and SCL can't handle 5V, so all the talking about voltages and level shifters still applicable.

The Vdd and Vdd_io both to 3.3V, that is good, the rest is also okay.

And connect the Mega 5V to HV of the level shifter, and Mega 3.3V to LV of level shifter.


Aug 06, 2014, 07:33 pm Last Edit: Aug 06, 2014, 07:38 pm by GettingAlong Reason: 1
Might explain why the ATmega 3.3V must be connected to the LV of the shifter?

I also posted new revision of the circuit based on your suggestions, with recommendation to use 4.7k-10k pullups on the SDA/SCL lines. Those values seem fair?


The Sparkfun level shifter has 10k pullup resistor on both the 3.3V side and the 5V side.
So that is already a combined pullup of 5k.
The Mega board has 10k onboard, en when you also add 10k, you have 4*10k pullup, which makes 2k5 pullup impedance.
In this case you don't have to add extra pullup resistors. The two 10k in the levelshifter and the one 10k on the Mega board is more than enough.

I tried to explain why the 3.3V of the Mega should be connected to the LV of the level shifter. To understand it, you should have a look at the schematic of the level shifter, and see how the mosfets are used.
The simple explanation is : That is how the level shifter works  :D


My problems is I have never heard of a mosfet. :P
In my electronics class pretty much all we messed with were BJTs.

Ok I'll drop those 10ks on the SDA/SCL, leaving them just connected to Vdd.

Judging by what you're saying, if I didn't have the level shifter I would need to include those pull-ups?

revised diagram below


When you connect a 5V I2C device to the Mega, you don't need pullup resistors. The Arduino Mega has 10k pullup resistors on the board.
When you connect a I2C device to an Arduino Uno (without the level shifter) you should use pullup resistors.

Go Up