Maker.io main logo

I made a rotation input device using parts of a broken mouse

2024-03-06 | By M5Stack

License: General Public License Bluetooth / BLE Wifi Arduino

* Thanks for the source code and project information provided by @qinfu

1

2

 

Story

 

Development material

2

System configuration

3

Configuring M5Stack

  • M5Stack Gray (Core)
  • UIFlow_Fire v1.7.5
  • UIFlow-Desktop-IDE v1.7.4 (select "Fire" for Device)

*Without this configuration, "BLE UART" cannot be used with M5Stack Gray.

Rotation detection and chattering support

The program uses Python. If I follow the reference site, I am able to detect the rotation relatively easily, but when the rotation becomes fast, chattering occurs and the values ​​become unstable...This is the most difficult point to solve.

Finally, temporarily assign the rotation direction value (1, -1) to the list. When the number of elements reached three, we determined whether the total value of the array was positive or negative and determined the final value, and the numbers became quite stable. Increasing the number of elements increases accuracy, but the problem is that the response becomes slower. (In my environment, the number of elements = 3 was appropriate.)

Script (excerpt)

Copy Code
pLastPinA = 1
pLastPinB = 1

pCounter = 0
pValList = []
pLastWay = 0

#ホイール検知処理
def dfRotationAct(p):
global pLastPinA,pLastPinB
global pCounter,pLastWay,pValList

xListLength = 3 #要素数

xStateA = pin1.value()
xStateB = pin2.value()

if xStateA == 1 and pLastPinA == 0:

#回転方向値を一時的にリストに入れる
if pLastPinB == 0 or xStateB == 0:
pValList.append(1)
elif pLastPinB == 1 and xStateB == 1:
pValList.append(-1)

pLastPinB = xStateB

#リストの合計値で最終方向を設定
if len(pValList) == xListLength:
pLastWay = 1
if sum(pValList) < 0:
pLastWay = -1

pValList.clear()
pCounter = pCounter + pLastWay

pLastPinA = xStateA
pass


# 入力ピン設定 #########################
pin1 = machine.Pin(19, mode=machine.Pin.IN, pull=machine.Pin.PULL_UP)
pin2 = machine.Pin(22, mode=machine.Pin.IN, pull=machine.Pin.PULL_UP)

pin1.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING,handler=dfRotationAct)
pin2.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING,handler=dfRotationAct)

Creation of crank parts

I don't have a convenient material or 3D printer that would fit into the hexagonal hole of the encoder, so I tried using 1.5mm diameter aluminum wire. Aluminum wire can be easily crushed with pliers, making it easy to adjust the thickness of the connection. Now I have a crank that I can use for now.

Background

The crank function of " Playdate " seemed very interesting, so I wondered if it would be possible to create a crank-type rotation input device using a rotary encoder. So, I pulled the parts out of the broken mouse and started working!

The chattering countermeasures were more difficult than expected and I couldn't finish it in time for the year-end hackathon, but I managed to complete it during the New Year's holiday.

Since I used M5Stack, I was able to implement BLE communication, so I plan to use it for various contents from now on!

制造商零件编号 K001-V27
ESP32 BASIC CORE IOT DEVELOPMENT
M5Stack Technology Co., Ltd.
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum