-
Notifications
You must be signed in to change notification settings - Fork 8
Fixes for SPI class #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@kattni please test this if hasnt yet, and then merge/release! |
Will do! Still needs testing. Added to my list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
If I update both of the following two suggestions to match the rest of the code, it runs perfectly. So please take a look and update either the two lines I suggested, or the rest of the SPI code to match.
adafruit_lsm9ds0.py
Outdated
@@ -397,8 +397,8 @@ class LSM9DS0_SPI(LSM9DS0): | |||
"""Driver for the LSM9DS0 connected over SPI.""" | |||
# pylint: disable=no-member | |||
def __init__(self, spi, xmcs, gcs): | |||
self._gyro_device = spi_device.I2CDevice(spi, gcs) | |||
self._xm_device = spi_device.I2CDevice(spi, xmcs) | |||
self._mag_device = spi_device.SPIDevice(spi, xmcs, baudrate=200000, phase=1, polarity=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the code refers to self._gyro_device
, is this incorrect or is the rest of the code incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below
adafruit_lsm9ds0.py
Outdated
self._gyro_device = spi_device.I2CDevice(spi, gcs) | ||
self._xm_device = spi_device.I2CDevice(spi, xmcs) | ||
self._mag_device = spi_device.SPIDevice(spi, xmcs, baudrate=200000, phase=1, polarity=1) | ||
self._xg_device = spi_device.SPIDevice(spi, gcs, baudrate=200000, phase=1, polarity=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the code refers to self._xm_device
. Same question as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below
Thanks @kattni . Silly copy-pasta error. Didn't have hardware to test so only did like a 2 second copy paste of the fix from LSM9DS1. For some reason, that library uses different variable names for the gyro and mag sensors. Feel stupid for not even doing a visual scan - that should've stuck out like a major thumb of soreness. |
So the fix resulted in the code failing without swapping the two digital pins. When it runs, all of the data is incorrect. Example:
As @caternuson doesn't have hardware to test it with, he's asked that I take over this fix. I'll take a look at it when I finish my current project. |
Thanks @kattni . Ping me if you need help. But yah, doesn't look like a simple copy-paste is all that's needed here. :( |
# csm.direction = Direction.OUTPUT | ||
# csm.value = True | ||
# sensor = adafruit_lsm9ds0.LSM9DS0_SPI(spi, csag, csm) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example copy-pasted from LSM9DS1 is probably all wrong also. For one thing, the CS pins are taken in a different order for the LSM9DS0:
def __init__(self, spi, xmcs, gcs):
here's code, there were a few things wrong! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this on Feather M4, works great! I have a couple of suggestions below.
adafruit_lsm9ds0.py
Outdated
i2c.readinto(buf, end=count) | ||
#print("read from %02x: %s" % (address, [hex(i) for i in buf[:count]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove print
statement. Seems like it's left over from debugging, shouldn't be needed in the final release.
adafruit_lsm9ds0.py
Outdated
@@ -391,26 +385,23 @@ def _write_u8(self, sensor_type, address, val): | |||
self._BUFFER[0] = address & 0xFF | |||
self._BUFFER[1] = val & 0xFF | |||
i2c.write(self._BUFFER, end=2) | |||
#print("write to %02x: %02x" % (address, val)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
adafruit_lsm9ds0.py
Outdated
spi.write(buf, end=1) | ||
spi.readinto(buf, end=count) | ||
#print("read from %02x: %s" % (address, [hex(i) for i in buf[:count]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
adafruit_lsm9ds0.py
Outdated
self._BUFFER[0] = (address & 0x7F) & 0xFF | ||
self._BUFFER[1] = val & 0xFF | ||
spi.write(self._BUFFER, end=2) | ||
#print("write to %02x: %02x" % (address, val)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@ladyada Do you want the |
keep them in, they're not taking up any space :) |
Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS0 to 2.1.0 from 2.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS0#11 from caternuson/iss10
Fix for #10 . But also fixed to work with actual phase/polarity of sensor. Example also updated to show SPI usage.