Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Memory Error Lora_Device with BME280
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Memory Error Lora_Device with BME280

by lawrence01073 on Fri Jun 05, 2020 4:06 pm

"""
lora_device.py

CircuitPython LoRa Device w/BME280
"""
import time
import busio
import digitalio
import board

# Import LoRa Library
import adafruit_rfm9x

# Import BME280 Sensor Library
import adafruit_bme280

# Device ID
FEATHER_ID = 0x01

# Delay between sending radio data, in minutes.
SENSOR_SEND_DELAY = 1

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# Define radio frequency, MUST match gateway frequency.
RADIO_FREQ_MHZ = 905.5

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
# pylint: disable=c-extension-no-member
CS = digitalio.DigitalInOut(board.RFM9X_CS)
# pylint: disable=c-extension-no-member
RESET = digitalio.DigitalInOut(board.RFM9X_RST)

# Define the onboard LED
LED = digitalio.DigitalInOut(board.D13)
LED.direction = digitalio.Direction.OUTPUT

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialze RFM radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)

# Set transmit power to max
rfm9x.tx_power = 23

# sensor data
bme280_data = bytearray(8)

while True:
# Get sensor readings
temp_val = int(bme280.temperature * 100)
print("\nTemperature: %0.1f C" % bme280.temperature)
humid_val = int(bme280.humidity * 100)
print("Humidity: %0.1f %%" % bme280.humidity)
pres_val = int(bme280.pressure * 100)
print("Pressure: %0.1f hPa" % bme280.pressure)

# Build packet with float data and headers

# packet header with feather node ID
bme280_data[0] = FEATHER_ID
# Temperature data
bme280_data[1] = (temp_val >> 8) & 0xff
bme280_data[2] = temp_val & 0xff

# Humid data
bme280_data[3] = (humid_val >> 8) & 0xff
bme280_data[4] = humid_val & 0xff

# Pressure data
bme280_data[5] = (pres_val >> 16) & 0xff
bme280_data[6] = (pres_val >> 8) & 0xff
bme280_data[7] = pres_val & 0xff
--------------------------------------------------------------------------------------------------------
File "code.py", line 15, in <module>
File "adafruit_bme280.py", line 499, in <module>
File "adafruit_bme280.py", line 517, in Adafruit_BME280_SPI
MemoryError:

I am new at this. I have tried examples and both the RFM9x MO Feather is working and the BME280 independently. When I try to use code from the Weather Monitoring Project I continue to get a Memory Error. Please help...

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by brubell on Mon Jun 08, 2020 11:42 am

Hi,

The RFM9x M0 Feather has less memory available than a Feather M4.
File "adafruit_bme280.py", line 499, in <module>
File "adafruit_bme280.py", line 517, in Adafruit_BME280_SPI


It seems that you have .py library files on your CIRCUITPY drive. .MPY files take up less space on your CIRCUITPY drive.

You may want to delete your /lib/ folder and download the .mpy bundle to free up some space. You can download the latest version of the library bundle here, unzip it, and select which libraries you need: https://circuitpython.org/libraries

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Mon Jun 08, 2020 12:33 pm

Looks like I bricked the RFM9x board after trying every conceivable method to download this program. I wish the non-Arduino method to program the RFM9x board was more concise and all in 1 place especially for this 76 year old newbie (though a retired Electrical Engineer). I will order another board when they are available and try what you recommend. Thanks,
Art

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by brubell on Mon Jun 08, 2020 12:38 pm

lawrence01073 wrote:Looks like I bricked the RFM9x board after trying every conceivable method to download this program. I wish the non-Arduino method to program the RFM9x board was more concise and all in 1 place especially for this 76 year old newbie (though a retired Electrical Engineer). I will order another board when they are available and try what you recommend. Thanks,
Art


How did you brick it? Does it mount as FEATHER when you double-tap the reset button?

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Mon Jun 08, 2020 12:50 pm

It does come up as a FEATHERBOOT and the LED pulses. The board never Resets and turn to CIRCUIT... Art

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Tue Jun 09, 2020 1:17 pm

I am now able to use CIRCUITPY on my RFM95 LoRa Radio board. The board is not bricked like thought in a previous post. I am still seeing the same (original) Memory Error as follows:
File "code.py", line 15, in <module>
File "adafruit_bme280.py", line 499, in <module>
File "adafruit_bme280.py", line 517, in Adafruit_BME280_SPI
MemoryError:

I am using adafruit_bme280.mpy, not sure why the above is showing adafruit_bme280.py? I am using the latest libraries.

I am at wits end and getting very frustrated that I cannot get this code working on the board. Any and all help would be appreciated!!!!
Art

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Tue Jun 09, 2020 3:24 pm

When I add gc (import gc and gc.collect()), I get the following:

code.py output:
Traceback (most recent call last):
File "code.py", line 17, in <module>
File "adafruit_bme280.py", line 134, in <module>
File "adafruit_bme280.py", line 439, in Adafruit_BME280
MemoryError: memory allocation failed, allocating 232 bytes

Memory Error is now an allocation issue. I need this code to run:
Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN project. I am using the exact same Feather RFM95 MO board used in the project write-up.
Art

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by brubell on Tue Jun 09, 2020 3:35 pm

I am using adafruit_bme280.mpy, not sure why the above is showing adafruit_bme280.py? I am using the latest libraries.


Could you please take and attach a screenshot of the CIRCUITPY's lib folder?

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Re: Memory Error Lora_Device with BME280

by jerryn on Tue Jun 09, 2020 4:58 pm

The tracebacks always show .py -- even for a .mpy file.

jerryn
 
Posts: 1251
Joined: Sat Sep 14, 2013 9:05 am

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Tue Jun 09, 2020 5:11 pm

Lib 6-9-2020.jpg
Lib file for CIRCUITPY
Lib 6-9-2020.jpg (106.95 KiB) Viewed 73 times

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Tue Jun 09, 2020 5:24 pm

bme280 program.jpg
bme280 screenshot
bme280 program.jpg (170.44 KiB) Viewed 72 times


I am able to run the BME280 through the Feather RFM95 MO board without any problems. Here is the screenshot of the MU:

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by jerryn on Wed Jun 10, 2020 7:42 am

I am not surprised that you cannot load both the rfm9x library and the bme280 library on a feather_m0_rfm9x -- it just does not have enough RAM...

I don't represent Adafruit -- just sharing my experiences with it. There is not enough RAM on the M0_rfm9x to do much at all with CircuitPython if the rfm9x library is loaded.

You might have better luck with the tinylora library on the m0_rfm9x board.

jerryn
 
Posts: 1251
Joined: Sat Sep 14, 2013 9:05 am

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Wed Jun 10, 2020 8:33 am

Thank You for your reply. I am a bit confused that the project listed below specially called out the Feather MO that you also see below. I would have thought AdaFruit would have checked out and tested the Feather MO before they released this project to the public. If you call out just about any LoRA board and click Technical, you see this project listed. I believe I tried the TinyLoRa library but with similar results. I will try again. I am hoping someone in AdaFruit would tell me specially that the board does not have enough RAM so I could move on and hopefully get a refund... Art

Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN

Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz
PRODUCT ID: 3178
This is the Adafruit Feather M0 RFM95 LoRa Radio (900MHz). We call these RadioFruits, our take on an microcontroller with a.

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by lawrence01073 on Thu Jun 11, 2020 2:03 pm

code.py output:
Bytes before import rfm9x lib: 20240.0
Bytes after import rfm9x lib: 10832.0
Traceback (most recent call last):
File "code.py", line 20, in <module>
File "adafruit_bme280.py", line 134, in <module>
File "adafruit_bme280.py", line 439, in Adafruit_BME280
MemoryError: memory allocation failed, allocating 232 bytes

I ran the above with gc to determine how much memory I had before the adafruit_rfm9x library was loaded and after the library was loaded. I then see that when adafruit_BME280 library is loaded, there is a 232 byte allocation memory error. This, I believe, shows the Feather MO with RFM95 LoRa Radio DOES NOT have enough memory to run the program published for the "Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN" project.

Why does the project state the Feather MO with RFM95 LoRa Radio is to be used (the project says buy 2 Feather MO with RFM95 LoRa Radios at $34.95 a pop. Glad I only bought 1 board)????

How do you get an Adafruit Representative to look at this issue??? Getting very frustrated with this project and would like some answers from Adafruit as to why this project has been published (looks like without any testing with the above board
and how would I get my money back for the board?????

lawrence01073
 
Posts: 15
Joined: Thu Jul 04, 2013 2:53 pm

Re: Memory Error Lora_Device with BME280

by jerryn on Sat Jun 13, 2020 9:12 am

FWIW --when the guide was first published, the demo did work on this board. Since then, both the CircuitPython core and the rfm9x (and bme2800) library have grown. That may not be any great consolation for you, but I wanted to let you know the history.

It would be great to get this working again but it is still a "work in progress" and I'm not sure how it will play out.

I do hope you hear directly from Adafruit Support soon.

jerryn
 
Posts: 1251
Joined: Sat Sep 14, 2013 9:05 am

Please be positive and constructive with your questions and comments.