sgall17a / AS5600

AS560 Micropython library for reading this magnetic sensor
30 stars 8 forks source link

confusing #4

Open NowLoadY opened 8 months ago

NowLoadY commented 8 months ago

The file is a bit confusing. The definition of AS5600 in the lib is not consistent with the AS5600 defined in the root directory.🧐Maybe

NowLoadY commented 8 months ago

image and in the lib, i found there's no any definition of value confusing,,, Maybe AS5600 defined in the root directory will work?

dakin80 commented 6 months ago

I concur with NowLoadY that this library is confusing. The code in the subdirectory "library" has a class definition but also some code at the bottom that is presumably a testbed or example code. The function "scan" refers to self.id but this should presumably be AS5600_id. The function also prints out self.CONF which possibly should be just CONF though it's not obvious why this is done. Later the code tries to print out z.MD which doesn't exist and should perhaps be z.md(). In the readwrite function there is a line:

    b = self.i2c.readfrom(register, bytes) #b is a buffer ie array of 8 bit numbers

but the parameter bytes should probably be num_bytes as bytes is not defined and anyway is a function not a variable.

I carried on trying to correct these errors but I couldn't get the code to work.

In desperation I tried the very different code in the as5600.py file in the root directory and managed to get this code to work though it contains some unnecessary imports and some testbed/example code that should be removed.

Looking at :

https://forum.micropython.org/viewtopic.php?t=10843

it looks like the author started with the code currently in the root directory and then rewrote it to produce the code in the "Library" subdirectory but has left it unfinished.

Hope this helps people.

BTW I am using a Raspberry Pico W and managed to get the code to work with a hardware i2c connection without external pullup resistors.

Looking at:

https://matik.org/posts/as5600/

it turns out that if you just want to get the angle and nothing more the code needed is very simple so I have used this as a starting point and produced my own very simple set of functions.