Adalogger SD and I2C on circuit pyton

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
User avatar
lavericklavericklaverick
 
Posts: 20
Joined: Mon May 06, 2019 6:58 pm

Adalogger SD and I2C on circuit pyton

Post by lavericklavericklaverick »

Hi, Im trying to log temperature data using the adalogger m0 and mlx90614. however i get memory errors when i try importing the mlx90614 module

do i just not have enough memory to run the sd card, the onewire and the mlx90614? it all works if i comment out the import mlx...

this is the output from the serial monitor when mlx is imported

Code: Select all

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
Traceback (most recent call last):
  File "main.py", line 10, in <module>
  File "adafruit_ds18x20.py", line 36, in <module>
MemoryError: memory allocation failed, allocating 136 bytes
and my code

Code: Select all

import time

import adafruit_sdcard
import board
import busio
import digitalio
import storage
#import adafruit_mlx90614
from adafruit_onewire.bus import OneWireBus, OneWireAddress
from adafruit_ds18x20 import DS18X20
#

ROM1 = b"('\xa3\xed\r\x00\x00\x94"
ROM2 = b"(\xe37\xed\r\x00\x00\x7f"
ROM3 = b"(\x1c\x8d\xed\r\x00\x00\xdb"
ow_bus = OneWireBus(board.D5)
for device in ow_bus.scan():
    print(device.rom)
    
temp1 = DS18X20(ow_bus, OneWireAddress(ROM1))
temp2 = DS18X20(ow_bus, OneWireAddress(ROM2))
temp3 = DS18X20(ow_bus, OneWireAddress(ROM3))

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

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(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

print("Logging temperature to filesystem")
# append to the file!
while True:
    # open file for append
    with open("/sd/temperature.txt", "a") as f:
        led.value = True  # turn on LED to indicate we're writing to the file
        t1 = temp1.temperature
        t2 = temp2.temperature
        t3 = temp3.temperature
        print("temps", t1, t2, t3)
        f.write("%0.1f,%0.1f,%0.1f\n" % (t1,t2,t3))
        led.value = False  # turn off LED to indicate we're done
    # file is saved
    time.sleep(1)

if anyone has any tips i would love to hear them. could i bring in the mlx module for one read then remove it when im loading the sd card?

Thanks!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adalogger SD and I2C on circuit pyton

Post by mikeysklar »

That is a lot of libraries.

Are you using the libraries in pre-compiled MPY form versus the .py files /lib on your Adalogger? That can save some space.

Are you running CircuitPython 7.x? or 6.x?

Rather than load and unloading modules which is possible, but discouraged it might be necessary to switch to a Feather M4 + Adalogger FeatherWing which would give you 2x the flash and 6x memory.

https://www.adafruit.com/product/3857
https://www.adafruit.com/product/2922

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

Return to “Feather - Adafruit's lightweight platform”