# Read a potentiometer continuously? on STM32 and analogRead()

**URL:** <https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214>\
**Category:** hardware support\
**Created:** [December 15, 2023, 5:31pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214 "2023-12-15T17:31:18Z")\
**Posts on this page:** 13\
**Page:** 8

<div class="post-metadata">

**Author:** ![Candas1](https://community.simplefoc.com/user_avatar/community.simplefoc.com/candas1/32/5296_2.png) [@Candas1](https://community.simplefoc.com/u/Candas1)\
**Post date:** [March 7, 2024, 7:51pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/141 "2024-03-07T19:51:33Z")

</div>

![IMG_20240307_205102](https://community.simplefoc.com/uploads/default/original/2X/0/03277cf015a896b05445bb69ac35033fdd6d0930.jpeg)

---

<div class="post-metadata">

**Author:** ![DHK](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/d/f475e1/32.png) [@DHK](https://community.simplefoc.com/u/DHK)\
**Post date:** [March 8, 2024, 9:02am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/142 "2024-03-08T09:02:00Z")

</div>

Thanks! One shunt is pretty close to the encoder chip.  
I wonder if the magnet will affect the shunt measurement.  
Overall, routing is not bad. Decoupling caps are close to the pins and on the same layer, short traces.  
Better than original dual motor Odrive 3.6 in my opinion.

---

<div class="post-metadata">

**Author:** ![Candas1](https://community.simplefoc.com/user_avatar/community.simplefoc.com/candas1/32/5296_2.png) [@Candas1](https://community.simplefoc.com/u/Candas1)\
**Post date:** [March 8, 2024, 9:30am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/143 "2024-03-08T09:30:21Z")

</div>

It can have some small impact I imagine, it would be worse with hall current sensors.

The 4th half bridge is for dumping energy in a braking resistor, that’s a good board to experiment this for SimpleFOC.

I am still wondering how it’s so cheap although it was a STM32F405, DRV8301 and AS5047P. Are they cutting costs on the mosfets ?  
[EDIT]  
I am biased by the price of the [ODESC](https://fr.aliexpress.com/item/1005005763345874.html?spm=a2g0o.productlist.main.2.7527uRscuRscyb&algo_pvid=d7175129-d691-4435-89b2-6537667d1292&aem_p4p_detail=20240308013348923882459677970002599289&algo_exp_id=d7175129-d691-4435-89b2-6537667d1292-1&pdp_npi=4%40dis%21EUR%2145.16%2145.16%21%21%2148.29%2148.29%21%40211b612517098904283358957e1ccf%2112000034265535547%21sea%21FR%214100544%21&curPageLogUid=nWUczTA5BnWF&utparam-url=scene%3Asearch%7Cquery_from%3A&search_p4p_id=20240308013348923882459677970002599289_2%C2%A8) (63e for the 56V version)  
And the [Xdrive-S](https://fr.aliexpress.com/item/1005006329082241.html?spm=a2g0o.detail.pcDetailBottomMoreOtherSeller.1.22d77c601xUFjF&gps-id=pcDetailBottomMoreOtherSeller&scm=1007.40000.326746.0&scm_id=1007.40000.326746.0&scm-url=1007.40000.326746.0&pvid=306c794e-5484-4254-9da1-c3c56fabb8e0&_t=gps-id:pcDetailBottomMoreOtherSeller,scm-url:1007.40000.326746.0,pvid:306c794e-5484-4254-9da1-c3c56fabb8e0,tpp_buckets:668%232846%238116%23934&pdp_npi=4%40dis%21EUR%2162.53%2162.53%21%21%21481.39%21481.39%21%40211b617b17098906565456045e269e%2112000036781799950%21rec%21FR%214100544%21&utparam-url=scene%3ApcDetailBottomMoreOtherSeller%7Cquery_from%3A) (62.5e 56V)

By the way it’s out of stock again lol.

---

<div class="post-metadata">

**Author:** ![DHK](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/d/f475e1/32.png) [@DHK](https://community.simplefoc.com/u/DHK)\
**Post date:** [March 8, 2024, 9:55am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/144 "2024-03-08T09:55:25Z")

</div>

And the original STM not a GD clone. Mosfets are also looks original ON Semi.  
I have bought it for $30 with shipping to my country.

Looked up current minimum prices @10k order:  
stm32f405rgt6 $7.5  
8301 $2.4  
AS5047 $4.4  
NTMFS5C628NL $0.5x8 $4  
So, $19 for only this parts alone.

---

<div class="post-metadata">

**Author:** ![Pablo9026](https://community.simplefoc.com/user_avatar/community.simplefoc.com/pablo9026/32/6723_2.png) [@Pablo9026](https://community.simplefoc.com/u/Pablo9026)\
**Post date:** [May 20, 2024, 5:36pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/145 "2024-05-20T17:36:47Z")

</div>

@multisystem when working with the ODESC v4.1, did you make the USB port work for communication? What did you use to flash the STM32? ST-Link?

---

<div class="post-metadata">

**Author:** ![multisystem](https://community.simplefoc.com/user_avatar/community.simplefoc.com/multisystem/32/5114_2.png) [@multisystem](https://community.simplefoc.com/u/multisystem)\
**Post date:** [May 20, 2024, 9:00pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/146 "2024-05-20T21:00:04Z")

</div>

@Pablo9026  
No, the available USB port is not in use at the moment.  
I transfer the firmware with ST-LINK  
And I communicate via Serial1 & Commander to drive the “MKS DRIVE MINI” with an M5StickC  
It’s the M5StickC that sends commands to “MKS DRIVE MINI”.

---

<div class="post-metadata">

**Author:** ![Pablo9026](https://community.simplefoc.com/user_avatar/community.simplefoc.com/pablo9026/32/6723_2.png) [@Pablo9026](https://community.simplefoc.com/u/Pablo9026)\
**Post date:** [May 21, 2024, 9:40am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/147 "2024-05-21T09:40:51Z")

</div>

@multisystem Did you do a gtihub repository with all your code? If yes please share the link, i would like to see it.  
If its not too much to ask, can you upload the simpleFOC library that you created? (So, all the header and .c files that the library uses)

---

<div class="post-metadata">

**Author:** ![multisystem](https://community.simplefoc.com/user_avatar/community.simplefoc.com/multisystem/32/5114_2.png) [@multisystem](https://community.simplefoc.com/u/multisystem)\
**Post date:** [May 21, 2024, 7:15pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/148 "2024-05-21T19:15:30Z")

</div>

look above and you’ll find the link to download the test code in the video on sourceforge …

SimpleFOC\_MKS\_DRIVE\_MINI\_V2.zip

> **[openhardware - Browse /SimpleFOC\_MKS\_DRIVE\_MINI at SourceForge.net](https://sourceforge.net/projects/openhardware-eu/files/SimpleFOC_MKS_DRIVE_MINI/)**
>
> Partage de projets openhardwares

---

<div class="post-metadata">

**Author:** ![MostHated](https://community.simplefoc.com/user_avatar/community.simplefoc.com/mosthated/32/6804_2.png) [@MostHated](https://community.simplefoc.com/u/MostHated)\
**Post date:** [June 12, 2024, 12:59am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/149 "2024-06-12T00:59:47Z")

</div>

I just got one of these today. ([FlipSky ODESC v4.2](https://www.amazon.com/dp/B0CB64MVHC)). Is the ST-Link V2 still necessary for this device?

I didn’t realize I needed one since it had a USB port and all the pins, etc. I should have looked into it a bit more first.

* * *

Update: I had asked this to the seller on Amazon, and the AI generated answer before I submitted the question said:

“No, it does not require an ST-Link v2. The ODESC V4.2 uses an STM32F405RGT6 microprocessor that can be programmed via USB without needing an external programmer like the ST-Link v2.”

Not sure if this is true, or if it comes into play. I was initially using an ESP32-S3 devkit-m with simplefoc-mini, and was going to just replace the foc-mini with this and thought this was just a higher powered driver, and didn’t even realize it was a whole controller on it’s own.

---

<div class="post-metadata">

**Author:** ![multisystem](https://community.simplefoc.com/user_avatar/community.simplefoc.com/multisystem/32/5114_2.png) [@multisystem](https://community.simplefoc.com/u/multisystem)\
**Post date:** [June 12, 2024, 6:56am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/150 "2024-06-12T06:56:30Z")

</div>

Hi  
@MostHated, if you’re using Odrive3.6, you don’t need st-link to program it.  
However, USB programming is not currently supported by SimpleFOC for this model.  
If you’re using SimpleFOC, you’ll need to use a st-link for the time being.

---

<div class="post-metadata">

**Author:** ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)\
**Post date:** [June 12, 2024, 7:27am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/151 "2024-06-12T07:27:52Z")

</div>

> [@multisystem](#):
>
> However, USB programming is not currently supported by SimpleFOC for this model.

SimpleFOC has no requirement for any particular programming protocol… it’s just a library, and is compiled into your firmware binary. What tool and protocol you use to program the firmware onto the board is totally outside the scope of the library, and purely a topic of your development environment.

So you can use USB, JTAG, SWD, Serial or any other protocol to program, it just has to be supported by your board.

---

<div class="post-metadata">

**Author:** ![Ashemah\_Harrison](https://community.simplefoc.com/user_avatar/community.simplefoc.com/ashemah_harrison/32/426_2.png) [@Ashemah\_Harrison](https://community.simplefoc.com/u/Ashemah_Harrison)\
**Post date:** [July 19, 2024, 9:08am UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/152 "2024-07-19T09:08:31Z")

</div>

Big thanks to everyone in this thread for the info. I have finally gotten around to building a new robot and will use 2 of the MakerBase ODRIVE MINI boards. They are cheap and all over aliexpress and seem to be of good quality with encoder and heatsink even. Nice to have a cheap alternative to the 150 AUD boards I have been using (Tinymovr etc - Great boards but I too expensive for me all up with accessories and i prefer SimpleFOC). The info in this thread should help a lot to get started.

---

<div class="post-metadata">

**Author:** ![John\_Dowson](https://community.simplefoc.com/user_avatar/community.simplefoc.com/john_dowson/32/7460_2.png) [@John\_Dowson](https://community.simplefoc.com/u/John_Dowson)\
**Post date:** [September 12, 2024, 4:47pm UTC](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214/153 "2024-09-12T16:47:33Z")

</div>

what would you use for a communication bus? is the onboard can bus still working?

[Previous page](https://community.simplefoc.com/t/read-a-potentiometer-continuously-on-stm32-and-analogread/4214.md?page=7)
