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
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)
Thanks!