# position encoder

**URL:** <https://forums.openmv.io/t/position-encoder/851>\
**Category:** OpenMV Boards\
**Created:** [August 6, 2018, 7:40pm UTC](https://forums.openmv.io/t/position-encoder/851 "2018-08-06T19:40:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcls1026](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pcls1026](https://forums.openmv.io/u/pcls1026)\
**Post date:** [August 6, 2018, 7:40pm UTC](https://forums.openmv.io/t/position-encoder/851/1 "2018-08-06T19:40:11Z")

</div>

Do you have a python example to read a simple quadrature encoder with the cam 7?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 7, 2018, 2:34am UTC](https://forums.openmv.io/t/position-encoder/851/2 "2018-08-07T02:34:16Z")

</div>

Hi, the OpenMV Cam would not be good for this type of thing. While you can definitely interrupt it to count the encoder ticks using interrupts you’re not going to capture all ticks due to USB stuff happening at 1KHz.

If you still want to use an encoder see here:

[http://docs.openmv.io/library/pyb.ExtInt.html](http://docs.openmv.io/library/pyb.ExtInt.html)

---

<div class="post-metadata">

**Author:** ![pcls1026](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pcls1026](https://forums.openmv.io/u/pcls1026)\
**Post date:** [August 7, 2018, 7:08pm UTC](https://forums.openmv.io/t/position-encoder/851/3 "2018-08-07T19:08:49Z")

</div>

I understand ithe example Python code would not run well while run as a script. However, would it run OK when it is loaded onto the uProcessor and run with a battery or just a power only USB cable?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 7, 2018, 8:29pm UTC](https://forums.openmv.io/t/position-encoder/851/4 "2018-08-07T20:29:21Z")

</div>

Hi, the camera interrupts the processor per line of data coming in. In general, there are too many interrupts on the system to do a good job like an Arduino monitoring interrupts. If the encoder is a low resolution one and updates slowly then this is okay. However, realistically the processor can’t be trusted to have super real-time performance for anything that doesn’t have hardware pheripals to montitor.

This all said… the timers on the STM32 have the ability to do encoder logic in hardware and can do quadrature encoding. However, I don’t know how to use this from the python interface. But, if you want to figure it out the microcontroller can definitely do it.

---

<div class="post-metadata">

**Author:** ![pcls1026](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pcls1026](https://forums.openmv.io/u/pcls1026)\
**Post date:** [August 9, 2018, 10:16pm UTC](https://forums.openmv.io/t/position-encoder/851/5 "2018-08-09T22:16:25Z")

</div>

The STM processor does use interupts on its QEModule.  
Will I still have interrupt problems if I take a picture; wait until the uP is done processing the image; and then use the QEmodule. I can do this because I will not be moving when I’m using the camera and there won’t be any QEModule interrupts being generated.

---

<div class="post-metadata">

**Author:** ![patrickpoirier51](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@patrickpoirier51](https://forums.openmv.io/u/patrickpoirier51)\
**Post date:** [August 10, 2018, 1:35am UTC](https://forums.openmv.io/t/position-encoder/851/6 "2018-08-10T01:35:12Z")

</div>

Would it be much simpler if you use an arduino to read the encoder and transmit position using I2C or SPI to OpenMV. This is usually what we do with wheel encoder, there are numerous examples on the web and an arduino pro mini is 2$

---

<div class="post-metadata">

**Author:** ![pcls1026](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pcls1026](https://forums.openmv.io/u/pcls1026)\
**Post date:** [August 10, 2018, 9:58pm UTC](https://forums.openmv.io/t/position-encoder/851/7 "2018-08-10T21:58:19Z")

</div>

I like that solution, patrickpoirier51 . What do you think Kwagyeman? I could collect the data, calculate the distance traveled and transmit a 2 byte word to Cam7 every 0.1 second.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 11, 2018, 12:46am UTC](https://forums.openmv.io/t/position-encoder/851/8 "2018-08-11T00:46:33Z")

</div>

Yeah, it’s easier to do. Serial input on the cam is tribal.
