Skip to main content

ST Spin Family Interface

A Python library for interfacing with ST Spin Family devices, specifically the ST Micro L6470, L6472, L6474, and L6480 ICs. Can be used nearly without modification with similar ICs.

If you do not specify your own spi_transfer function when creating a SpinChain, this project relies on spidev's SPI transfer function.

Python 3.6 or greater recommended.

Getting Started

pip install st-spin pip install spidev (if you intend to use /dev/spi and spidev's spi transfer function)

Add imports

import time  # Used in our example

from stspin import (
    SpinChain,
    SpinDevice,
    Constant as StConstant,
    Register as StRegister,
    utility,
)

Create a device chain

stChain = SpinChain(
    total_devices=2,
    spi_select=(0, 0),
)

This assumes the spi device is at 0, 0.

Create devices

motorMain = stChain.create(1)
motorAux = stChain.create(0)

# Unless you absolutely need holding current,
# it is good practice to disable the power bridges
motorMain.hiZHard()
motorAux.hiZHard()

Run basic commands

motorMain.setRegister(StRegister.SpeedMax, 0x22)

motorMain.run(100)
time.sleep(3)
motorMain.hiZSoft()
time.sleep(1)

# {{{ Set some registers
motorMain.setRegister(StRegister.Acc, 0x5)
motorMain.setRegister(StRegister.Dec, 0x10)
motorAux.setRegister(StRegister.Acc, 0x20)
# }}}

# {{{ Go n steps with both motors
motorMain.move(steps=420000)
motorAux.move(steps=420000)
while motorMain.isBusy():
    time.sleep(0.2)
# }}}

# {{{ Head back
motorMain.setDirection(StConstant.DirReverse)
motorMain.move(steps=420000)
while motorMain.isBusy():
    time.sleep(0.2)
# }}}

# Release holding current
motorAux.hiZHard()
motorMain.hiZHard()

More details

For details on the SPI setup, see create() in spin_chain.py. See example.py.

Creating your own spi_transfer function You may use your own spi transfer function in place of spidev's xfer2.

def custom_spi_transfer(buffer: List[int]) -> List[int]:
    # TODO: Implement me
    pass

stChain = SpinChain(
    total_devices=2,
    spi_transfer=custom_spi_transfer,
)

custom_spi_transfer() must take a list of bytes as int, and return a same-length list of bytes as int from the MISO pin.

It should handle latching using the Chip Select pin, and transfer data with MSB first in SPI Mode 3 (sample on rising edge, shift out on falling edge).

On these devices, Chip Select is active low.

Troubleshooting

getStatus() is your friend. Feel free to use getPrettyStatus() under utility.py. The manual is also your friend.

Q: Why is my motor stalling, loud, or both? Most likely the Back-EMF compensation is not configured properly. The correction parameters depend heavily on your motor's ke value (V/Hz), inductance, and phase resistance.

After calculating the parameters using the manufacturer's tool, set KvalAcc, SpeedInt, SlpSt, etc. using setRegister().

Metadata

Release files for st-spin 0.0.22.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for st-spin 0.0.22.4
File Size Uploaded
st_spin-0.0.22.4.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for st-spin 0.0.22.4
File Interpreter ABI Platform
st_spin-0.0.22.4-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / st_spin-0.0.22.4.tar.gz

Download URL st_spin-0.0.22.4.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
696373d6ab5a3df8f6859ae84ef53784d233483e0a235073ac53ded9d0106faf
BLAKE2b-256 checksum
How to use checksums
d3e256cff23150a354dc2888b91c9bc85166f5378119004368b48857052a205b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.2

Release files / st_spin-0.0.22.4-py3-none-any.whl

Download URL st_spin-0.0.22.4-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea4763b288c8e2f1614c5117830b1aadfae558858a44252115b33163b1bd2ccd
BLAKE2b-256 checksum
How to use checksums
29185e362088084d293589ce3ab45ea3d1079523fde3fc17606a764b1810d0f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.22.4 This release

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page