{"id":13802337,"url":"https://github.com/sgall17a/AS5600","last_synced_at":"2025-05-13T13:30:40.902Z","repository":{"id":50660786,"uuid":"386567996","full_name":"sgall17a/AS5600","owner":"sgall17a","description":"AS560 Micropython library for reading this magnetic sensor","archived":false,"fork":false,"pushed_at":"2023-03-03T09:58:28.000Z","size":93,"stargazers_count":23,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-22T12:35:12.796Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgall17a.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-07-16T08:36:59.000Z","updated_at":"2024-04-07T06:41:05.000Z","dependencies_parsed_at":"2024-01-07T21:53:30.894Z","dependency_job_id":"a239c926-ca00-41a6-98ee-f7c67231a595","html_url":"https://github.com/sgall17a/AS5600","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgall17a%2FAS5600","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgall17a%2FAS5600/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgall17a%2FAS5600/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgall17a%2FAS5600/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgall17a","download_url":"https://codeload.github.com/sgall17a/AS5600/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225218014,"owners_count":17439712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:42.281Z","updated_at":"2025-05-13T13:30:40.893Z","avatar_url":"https://github.com/sgall17a.png","language":"Python","readme":"# Micropython library for AS5600\n\n# PLEASE NOTE - There has been a rewrite.  See comments below.  The old file is in old_as5600.py\n\nThe AS5600 is an angle sensor, based on detecting  the rotation of a magnet by the Hall effect.  The resolution is 12 bits thus it can divide a complete rotation into 2^12 or 4096 parts. The device is configured and read by I2C.  This library can read all registers on the AS5600 and can write to the writable registers.  (This is a complete rewrite of the library which simplifies the Descriptors used in the previous version)\n\nThe device is  configured and read through I2C but can also be used in a standalone mode in \nwhich the angle is converted either to a voltage between 0 and 3.3V or to a PWM output.  \n\n## Overview.\nNotes:  \n    1. Relevant register names in brackets.  \n    2. The registers can be READ/WRITE (for configuration), READONLY(status and readout) or WRITE ONLY (for BURN). \n    3. This is a brief overview and the datasheet will need to be consulted for for further information.\n\n### Configuration registers (READ/WRITE)   \n1.  Setting a minimum and maximum angle. (ZPOS,MPOS,MANG)\n2.  Setting an output type, either an analog voltage or duty cycle on a PWM output.  This is mainly for a standalone mode in which the device can be used without a microprocessor. (OUTS)\n4.  Set PWM frequency. (PWMF)\n3.  Set direction (either clockwise or anti-clockwise). (Pin)\n4.  Set power mode to use less current and a watchdog setting.( PM, WD)\n5.  Filtering output to reduce jitter, either fast or slow (SF,FTH)\n6.  Setting some hysteresis in order to stabilise sensors outputs. (HYST)\n\n### Status registers (Read only):\n1.  Magnet strength (MD,ML,MH)\n2.  Automatic gain control (adusted automatically bring readings to useable levels) (AGC)\n\n### Reading sensor values (Read only)\nOutput can be analog, PWM or the register values ANGLE and RAWANGLE.\n\n### Burning configuration.\nConfiguration can be permanently burnt into the device to enable it to operate in a standalone fashion.\nThis is down by writing to a burn register. (BURN).\nMaximum and minimal angles can only be burnt three times and the burn count is stored in ZMCO.  (See datasheet!)  \n\n## Library\nThe library provides a class AS5600 in a file called ‘as5600.py’ and is initialised by passing in an I2C object from machine library.   \n\n**Class A5600**\n\nThis class is instantiated with an I2C object from the micropython machine library.\nAn optional device id can be supplied (default 0x36),  say if you had multiple devices and were using a I2C bus multiplexer \n\n### General notes\n\nEach register is assigned a method with the same name as  the datasheet  except that it is in lower case rather upper case.\n\nIf the method is called with no parameter it returns the value of the register\n\nIf the method is called with a parameter then the register is set to the value of the parameter and the passed parameter is returned.\n\nIf you try to write to a non-writeable register an error will be thrown\n\n\n# AS5600 rewrite. \n\nI have rewritten the AS5600p.py.  This is a work in progress because I am learning (slowly) to use Github! \nRegister attributes should work the same.  The internal mechanism has changes. \n\nThe scan() utility has been dropped. Just call scan on the I2C object\n\nThe method magnet_status has been dropped.  Just use the magnet status attributes.\n\nBurn angle and burn setting have changed a bit.  I did not want to put these as normal attributes to\nlimit the likelihood of being used inadvertently.\n\nNOTE-I have never actually used BURN  because I dont want to brick my device for programming.\n\n## Notes on internal changes.\nDescriptor classes are supported by Micropython.  I think these are more neater and more conventional.  I whas just learing\nabout descriptors when I wrote the first version.\n\nI dropped the namedtuple.  I think does not actually provide any benefit in conciseness or readability.\n\nVarious other simplifications.\n\nI dropped register cacheing.  This was done mainly to limit bitfield extraction from CONF but considering this will only a few times \n(at most) it is not the worth the effort or complication.\n\n### Testing.\nI have run a few tests.  These consist of testing reading and writing attributes  with a range of values which seems to work.\nInterestingly writing to a register seems to persist through a power cycle (as it should).\n\nReading values by moving a magnet around and reading from angle and rawangle gives plausible values but I have not made a rig to test the accuracy of results.  Angle results are reasonable.  Rawangle seems too unstable, at least in this setup, to be useable.\n\n### Checking against datasheet.\nThis is a moderately complex device with both magnetics and electronics.  \nThis library is not sufficient for documentation of the device and the datasheet should be kept for reference.\n\nThe name of the attributes are capitalised versions of the register names in the data sheet.  \n\nI have added a field to the data descriptor classes (R or W) to indicate read and write registers.\n\nThere is a chart in the datasheet showing the registers and their bitfields.  My library is derived from this chart.\n\nThe smaller bit address and the larger bit address for each bitfield is passed to the descriptor.  The descriptor either reads the bitfields or sets the bitfields and writes the whole adjusted register back to the device.\n\n\n\n\n\n\n\n### Example.\n\n\n``` python\nfrom as5600 import AS5600\n#THIS HAS BEEN CHANGED TO CURRENT USAGE\nz = AS5600(i2c)\n#Read the ZPOS register:\nvalue = z.ZPOS\n#Write to the ZPOS register\nz.ZPOS = value\n```\n\n# All register methods\n\n## Set Angles\n\n``` python \n\ndef zpos(self,*args)\n    Zero value, to set that the minimum readout  value\n    \ndef mpos(self,*args)\n    Maximum position in devices units or 360/4096.  Setting this clear the maximum angle\n\ndef mang(self,*args)\n    Set the maximum position in degrees.  Setting this clears the mpos value\n```\n\n## Configuration (Read / Write)\n\n\n``` python\nz = AS5600(I2C)\nz.PM\n    \"\"\"Power Mode.  There are 4 modes to reduce device current at the expense of increasing polling time\n    00 = NOM, \n    01 = LPM1 \n    10 = LPM2 \n    11 = LPM3\"\"\"\n    \nz.HYST\n    \"\"\"Hysteresis.  Set 4 hysteresis modes to reduce output jitter\n    00 = OFF,\n    01 = 1 LSB, \n    10 = 2 LSBs, \n    11 = 3 LSBs\"\"\"\n    \nz.OUTS\n    \"\"\"Output stage PWM or analog\n    00 = analog (full range from 0% to 100% between GND and VDD,\n    01 = analog (reduced range from 10% to 90% between GND and VDD, \n    10 = digital PWM\"\"\"\n\nz.PMWF\n\n    \"\"\"PWM frequency   \n    00 = 115 Hz; \n    01 = 230 Hz; \n    10 = 460 Hz; \n    11 = 920 Hz\"\"\"\n\nz.SF \n    \"\"\"Slow filter to reduce jitter or noise.\n     00 = 16x (1); \n     01 = 8x; \n     10 = 4x; \n     11 = 2x\"\"\"\n\nz.FTH\n    \"\"\"Fast filter to reduce jitter or noise\n    000 = slow filter only, \n    001 = 6 LSBs, \n    010 = 7 LSBs,\n    011 = 9 LSBs,\n    100 = 18 LSBs, \n    101 = 21 LSBs, \n    110 = 24 LSBs, \n    111 = 10 LSBs\"\"\"\n\nz.WD\n   \"\"\" Watchdog.  Drop into LPM3 after about 1 minute of inactivity\n    0 = OFF, \n    1 = ON   \"\"\"      \n\n```\n## Status (Read only )\n\n```python\n\nz.MD\n    #Magnet detected\n\nz.ML\n    #Magnet too weak\n    \nz.MH   \n    # Magnet too strong\n    \nz.AGC\n    #Automatic Gain control (0-255)\n    \n```\n\n## Actual angles read only\n\n``` python\nz.RAWANGLE\n    #Raw angle\n    \nz.ANGLE\n    #Angle - same as rawangle() but filters and hysteresis applied\n```\n\n\n# Comments.\n\nThe library was tested and developed on a Raspberry Pi Pico with Micropython 19.1.1.\n\nStandard micropython is used and this should run on other boards and micropython versions.\n\nI have had trouble using hardware I2C on the Pi Pico but SoftI2C was fine.\n\nNot tested on Circuitypython but I would expect that some fixes and changes may be required. \n\n\n\n","funding_links":[],"categories":["Libraries"],"sub_categories":["IO"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgall17a%2FAS5600","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgall17a%2FAS5600","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgall17a%2FAS5600/lists"}