Adalogger and LSM303

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
phi_fibonacci
 
Posts: 23
Joined: Wed Jun 04, 2014 9:15 pm

Adalogger and LSM303

Post by phi_fibonacci »

I'm trying to log LSM303 acceleration values using the Adalogger and CircuitPython. I have code and verified that I can write to the SD card. Check! I have also testing reading data from the LSM303 via I2C and printing to the terminal via serial. Check! So they both work. But when I attempt to write the values to the SD card (by combining my python scripts) I get a pin conflict.

ValueError: Pin PA12 in use

I believe the issue is I2C and SPI are trying to use the same pin but I don't know how to move it. From what I've read it's possible. Can someone point me in the right direction?

Code that generates the error below.

Code: Select all

import adafruit_sdcard
import microcontroller
import busio
import digitalio
import board
import storage
import os
import time
import sd_mountlib
import adafruit_lsm303

# Use any pin that is not taken by SPI
SD_CS = board.D0

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Connect to the card and mount the filesystem.
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
# Use the filesystem as normal! Our files are under /sd

# Set up the accelerometer
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm303.LSM303(i2c)

x = 0
while x < 200:
    # open file for append
    with open("/sd/accellog.txt", "a") as f:
        led.value = True   # turn on LED to indicate we're writing to the file
        accel_x, accel_y, accel_z = sensor.acceleration
        print('{0:10.3f}, {1:10.3f}, {2:10.3f}'.format(accel_x, accel_y, accel_z))
        f.write('{0:10.3f}, {1:10.3f}, {2:10.3f}'.format(accel_x, accel_y, accel_z))
        led.value = False   # turn off LED to indicate we're done

    # file is saved
    time.sleep(1)
    x+=1

while True:
    led.value = True
    time.sleep(.2)
    led.value = False
    time.sleep(.2)
    led.value = True
    time.sleep(.2)
    led.value = False
    time.sleep(.2)
    led.value = True
    time.sleep(.2)
    led.value = False
    time.sleep(4)

phi_fibonacci
 
Posts: 23
Joined: Wed Jun 04, 2014 9:15 pm

Re: Adalogger and LSM303

Post by phi_fibonacci »

Meant to include the full error.

main.py output:
Traceback (most recent call last):
File "main.py", line 19, in <module>
ValueError: Pin PA12 in use

Note, Line 19 is the line that reads,
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)

phi_fibonacci
 
Posts: 23
Joined: Wed Jun 04, 2014 9:15 pm

Re: Adalogger and LSM303

Post by phi_fibonacci »

Stand down. The problem was I was accidentally trying to mount the File System twice. Once in main.py and once in sd_mountlib.py. As soon as I removed the duplicate lines from my main.py everything started working. : )

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adalogger and LSM303

Post by adafruit_support_mike »

Glad to hear you got things working!

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”