ESP32 SDA and SCL question - Page 1
Forum section: electronics / general

author: Hextejas
author_rank: Frequent Contributor
timestamp: November 26, 2020, 08:46:44 pm
content: I have the Feather ESP32 board and want to use it with 2, slave boards.1) PCA96852) BNO055The notes on the ESP32 says this:QuoteI don't understand the concept of a pull up and don't know what to do.Also, I am presuming that I will need to connect these via a breadboard so where does the pull up resistor fit in there in a diagram similar to this?Trying to figure out how to do the image.

author: I wanted a rude username
author_rank: Frequent Contributor
timestamp: November 26, 2020, 09:01:53 pm
content: That Adafruit MC9808 module actuallyincludes I2C pull-ups, so your breadboard diagram is fine and I would expect it to work as is.I2C requires pull-ups to work, because all devices connected to the bus only ever pull itdownto GND, or release it. The pull-ups pull the bus voltage back to VCC. The ESP32 does have weak internal pull-ups, which you can enable, but we generally use external ones because the microcontroller ones tend to be too weak (high number of ohms) for I2C.Pull-ups are used for other purposes too, throughout digital electronics. Here's a short explanation:

author: james_s
author_rank: Super Contributor
timestamp: November 26, 2020, 09:10:34 pm
content: A pull-up is a very basic concept that you're going to encounter all over the place and need to understand. Think of it as a spring or bungee cord that holds something up out of the way so it doesn't flap around in the breeze. You can grab onto it and pull it down when you want it there but when you release it the pull-up will pull it back up out of the way.In electronics a pull-up (or pull-down) provides a default logic level, without it an input that is not actively being driven to one state or another would be floating at some undefined level and may drift to high or low depending on static electricity, radio waves and other stray signals and that will cause unpredictable behavior.

author: Hextejas
author_rank: Frequent Contributor
timestamp: November 26, 2020, 09:15:00 pm
content: Quote from: james_s on November 26, 2020, 09:10:34 pmThis is beginning to sink in and leads me to ask: Does the presence of a slave device serve the purpose of a pull up resistor ? IE, if I have a slave device, I do not need a pull up resistor or do I ?After watching the excellent video I think that I answered my own question. The pull up(or pull down I guess) resistor is to assure me that the pin that I am interested in, is in a neutral state, or not floating.

author: Hextejas
author_rank: Frequent Contributor
timestamp: November 26, 2020, 09:53:29 pm
content: I am trying to fit the lesson of the film to my specific case. It was the pin on the Arduino that was floating, HIZ .And I guess that the HIZ state could happen to any digital pin. YesOr to any device as well ? Yes ??Yikes !!!I think that I will need a pull up resistor to the SDA pin of the ESP32 as well as to any other I2C device that I plan to use.I guess that the resistor is not necessary if the device already has a resistor embedded. (No wait a minute ! It is the ESP32 pin that might float not the PCA9685). Although I suppose that the slave devices could also have an SDA pin that floats !Which means a separate bus for the SDA (and SCL) pins.Oops, this kinda assumes that the neutral state for all the devices on the buss are the same !!Am I thinking this correctly or am I overcomplicating it ?I think that I will need to do more reading.thanks

author: james_s
author_rank: Super Contributor
timestamp: November 26, 2020, 10:31:11 pm
content: With I2C you always need pullup resistors. They may be integrated into the board with a device but it always has to be there. The I2C signal lines are open-collector, that is they can be pulled down to low but they are never driven high, there has to be a pullup resistor to pull it back up when it isn't being pulled down.In most cases the value of the pullup is not critical and you can just add a resistor pulling the line up to Vcc whether there is another pullup somewhere else on the line or not. Certainly you won't hurt anything by trying.

author: Nusa
author_rank: Super Contributor
timestamp: November 26, 2020, 10:41:41 pm
content: Let's start with terminology. Don't abbreviate abbreviations, especially if you don't even understand them. It's High impedance or floating or tri-state or high-Z or hi-Z or hi Z, but not HIZ. (Z is the traditional math symbol for impedance, but that's not clear if it's not its own word.)Neutral? If you're referring to high impedance, that's the wrong word entirely. Floating is not neutral, it's indeterminate. If you mean high or low, also wrong. If you mean default, default state is what pull-up resistors are used for. Bottom line, neutral is only a good electronics word if you define it before using it.Yes, SDA and SDL are signal lines, each of which may need a pull-up, but still only one bus (a group of signal lines).Yes, there may often be multiple pull-up resistors on the bus, but in your case the distances are so short that there's not much point. The wires aren't long enough to have much resistance, and all the devices are using the same power source.

author: ejeffrey
author_rank: Super Contributor
timestamp: November 26, 2020, 10:52:14 pm
content: Standard digital outputs (not I2C) can drive the output active high or active low and have separate transistors for high and low. This is good because it provides a nice strong drive capable of several milliamps to charge the load capacitance and also draws zero power when idle in either state if the load (such as a digital input ) is high impedance.However this is a problem if two devices are capable of driving the same pin. If there is a chance one will drive high and the other low they will "fight" and draw a large current and create an indeterminate logic voltageThere are two common solutions to this problem. The first is to make sure that only one device drives the bus at a time. This typically requires some additional logic or protocol to decide who gets to talk at any given time.The other solution is to have each driver on the bus only able to drive "low". They just don't have the high side transistors that would be needed to drive an output high. Now there is no possibility of conflict because if two outputs drive low at the same time the output is just low. However you now need a pull-up resistor such that if no devices are actively driving low the signal should go high.The pull-up value is a trade-off. Too low resistance and the drivers will have to sink too much current and dissipate too much power. Too high a resistance and the signal will be slow because the pull-up is weak and takes a long time to pull the signal high. However for low speed protocols like I2C it is simple and effective.

author: Hextejas
author_rank: Frequent Contributor
timestamp: November 27, 2020, 03:46:20 am
content: I would like to get this accurate and I am trying to get the proper word to describe a pin that is neither + nor - nor Hi Z.Dang but It's hard to put i to words. Its state is whatever the opposite of on is. Can somebody help me here ? I thought that neutral described it but apparently not. It is not floating, it is either + or - awaiting something to turn it on or off.If positive indicates some event has taken place, then it will be negative. And vice-versa.Phew.

author: james_s
author_rank: Super Contributor
timestamp: November 27, 2020, 05:14:07 am
content: When speaking of digital logic, a pin is either high, low, or indeterminate, nothing else. Indeterminate is not a useful state and is a condition you always want to avoid, any signal should always be either high or low, 1 or 0, True or False, nothing else, that's why it's called binary.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 27, 2020, 11:28:50 am
content: If you want to work with I2C you probably should dive deeper into that bus and read how that whole protocol works and why it's built as it is.I find the old NXP (Philips) AN about I2C quite good, but there are plenty of resources for this 30+ year old bus around.