Hi,
I'm getting back to you (I know it has been a bit long but I could't work on that sooner) because I'm still having trouble ! :(
I tried two methods and got two different result both not correct.
Just to remember, I'm trying to use an "Adafruit RFM9X LoRa Packet Radio Breakout" and an "Adafruit lsm9ds1 accelerometer plus gyro plus magnetometer 9 dof breakout" simultaneously on a Raspberry pi 3.
So I tried the link you gave me :
https://learn.adafruit.com/circuitpytho ... rs-devices
As it's written I tried to use the "second" SPI Port. I edited the /boot/config.txt file and I changed my code to :
Code: Select all
CS = digitalio.DigitalInOut(board.D24)
RESET = digitalio.DigitalInOut(board.D23)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
spi2 = busio.SPI(board.SCK_1, MOSI=board.MOSI_1, MISO=board.MISO_1)
csag = DigitalInOut(board.D16)
csag.direction = Direction.OUTPUT
csag.value = True
csm = DigitalInOut(board.D17)
csm.direction = Direction.OUTPUT
csm.value = True
sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi2,csag,csm)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
My wirings : What I call physical is the number of the pin from 1 to 40 (
https://pinout.xyz/pinout)
LoRa board :
Vin physical 17(shared with a breadboard) - GND physical 25 - SCK physical 23 - MISO physical 21 - MOSI physical 19 - CS physical 18 - Reset physical 16
Lsm9ds1 Board :
Vin physical 17 (shared with a breadboard) - GND physical 9 - SCL (replacing SCK) physical 40 - SDA (replacing MOSI) physical 38 -SDOAG and SDOM (replacing MISO and both on the same pin thanks to a breadboard) physical 35 - CSM physical 11 - CSAG physical 36
I rebooted and run the code, but I have the following error :
Code: Select all
Traceback (most recent call last):
File "main_capteur.py", line 39, in <module>
sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi2,csag,csm)
File "/home/pi/.local/lib/python3.5/site-packages/adafruit_lsm9ds1.py", line 411, in __init__
super().__init__()
File "/home/pi/.local/lib/python3.5/site-packages/adafruit_lsm9ds1.py", line 158, in __init__
self._write_u8(_XGTYPE, _LSM9DS1_REGISTER_CTRL_REG8, 0x05)
File "/home/pi/.local/lib/python3.5/site-packages/adafruit_lsm9ds1.py", line 442, in _write_u8
spi.write(self._BUFFER, end=2)
File "/home/pi/.local/lib/python3.5/site-packages/busio.py", line 118, in write
return self._spi.write(buf, start, end)
File "/home/pi/.local/lib/python3.5/site-packages/adafruit_blinka/microcontroller/raspi_23/spi.py", line 47, in write
self._spi.writebytes([x for x in buf[start:end]])
File "/home/pi/.local/lib/python3.5/site-packages/adafruit_blinka/microcontroller/raspi_23/spi.py", line 47, in <listcomp>
self._spi.writebytes([x for x in buf[start:end]])
OSError: [Errno 22] Invalid argument
So I tried another way which didn't work either :
I tried to use the same MISO, MOSI, SCK and change only the CS as suggested, so for the code part I have :
Code: Select all
CS = digitalio.DigitalInOut(board.D24)
RESET = digitalio.DigitalInOut(board.D23)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
spi2 = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
csag = DigitalInOut(board.D16)
csag.direction = Direction.OUTPUT
csag.value = True
csm = DigitalInOut(board.D17)
csm.direction = Direction.OUTPUT
csm.value = True
sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi2,csag,csm)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
And for the wiring :
LoRa board :
Vin physical 17(shared with a breadboard) - GND physical 25 - SCK physical 23 ( shared) - MISO physical 21 ( shared) -- MOSI physical 19 ( shared) -- CS physical 18 - Reset physical 16
Lsm9ds1 Board :
Vin physical 17 (shared with a breadboard) - GND physical 9 - SCL (replacing SCK - shared with a breadboard) physical 23 - SDA (replacing MOSI) physical 19 -SDOAG and SDOM (replacing MISO and both on the same pin thanks to a breadboard) physical 21 - CSM physical 37 - CSAG physical 36
For this solution, I didn't have any error HOWEVER values returned by the lsm9ds1 were completed wrong (knowing that i managed to have correct value with i2c) when the rfm9x was used, but correct as soon as the rfm9x.receive() method was descativated. Seems to be an interference between the two spi.
Raspadafruit.