Jump to content

How to program OLED with STM32

RTX 3090
2 minutes ago, RTX 3090 said:

did PB11 and PB10 for SDA and SCL

That's I2C #2. Try PB6 and PB7, which is I2C #1. The STM32F103C8 has two I2C-channels and each can be used separately.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, WereCatf said:

That's I2C #2. Try PB6 and PB7, which is I2C #1. The STM32F103C8 has two I2C-channels and each can be used separately.

Hi, thanks, it is working perfectly fine now

As for the voltage detection, here's how I was thinking of doing it, please tell me if my concept is flawed

  • Connect the probe to a resistor so that the board can handle it
  • Use an Analog pin to detect the voltage
  • Print the voltage on the screen

Which resistor would work best. I wanted to do a maximum of 20 volts, so I was thinking of doing this 

image.png.b7f18883bc5e3831679cfcd26dfd97a5.png

 

Do you think these value will be suitable and still give a decent accuracy

 

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, RTX 3090 said:

Which resistor would work best. I wanted to do a maximum of 20 volts, so I was thinking of doing this

The pins cannot tolerate 20V, the maximum they can tolerate is 5V and for analog values the maximum is 3.3V. You need a voltage-divider from 20V to 3.3V instead of just a single resistor.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, WereCatf said:

The pins cannot tolerate 20V, the maximum they can tolerate is 5V and for analog values the maximum is 3.3V. You need a voltage-divider from 20V to 3.3V instead of just a single resistor.

This is the voltage divider I was intending on using. Is this the most efficient solution available (as in what are the best two resistors to use to preserver accuracy) image.png.b7f18883bc5e3831679cfcd26dfd97a5.png

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, RTX 3090 said:

This is the voltage divider I was intending on using. Is this the most efficient solution available (as in what are the best two resistors to use to preserver accuracy)

You'd be constantly wasting almost 400mA of power through those resistors with such small resistances. Use much higher resistances. Also, why are you targeting 1.8V? Just go for 3.3V.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WereCatf said:

Also, why are you targeting 1.8V? Just go for 3.3V.

I was trying to avoid a voltage spike killing my STM32 but I think I could put a cap there to fix that

Does this look any better or should I still go much higher

image.png.869c1f90271cd167cac76935edd74597.png

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

15 minutes ago, RTX 3090 said:

I was trying to avoid a voltage spike killing my STM32 but I think I could put a cap there to fix that

So you're not targeting 20V, then? Well, obviously, you should use whatever source-voltage you expect to be seeing. If you expect there to be voltage-spikes, then design accordingly.

15 minutes ago, RTX 3090 said:

Does this look any better or should I still go much higher

I typically use tens or hundreds of kilo-ohms, but sure. It still consumes 3.3mA at all times if the source-voltage is 20V, but it's better than almost 400mA.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, WereCatf said:

I typically use tens or hundreds of kilo-ohms, but sure. It still consumes 3.3mA at all times, but it's better than almost 400mA.

Would 50k and 10k work too ? Does that only use 0.33 mA and how much difference does it make. I have a 5000 pack of resistors so a wide variety of options

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, RTX 3090 said:

Would 50k and 10k work too ?

Yes.

1 minute ago, RTX 3090 said:

Does that only use 0.33 mA and how much difference does it make

3.3mA - 0.33mA ~= 3mA difference.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, WereCatf said:

Yes.

Which analog pin would you recommend me using. 

Does this look correct for the voltage divider 

image.png.ffd2b4e72e914e2c3c4dc57ee6e809a7.png

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×