Cross-Compile and import

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
jwissing
Posts: 29
Joined: Thu Jun 19, 2014 12:23 pm
Location: Germany

Cross-Compile and import

Post by jwissing » Sun May 08, 2016 9:36 am

I have come to the same memory error just by using the BME280 module.
viewtopic.php?f=14&t=1315
I have tried to get around this by precompiling the module using the cross-compiler as suggested by pythoncoder.
http://forum.micropython.org/viewtopic. ... 876#p10542
This is what i have done:
cd into mpy-cross
running make in this directory
running the resulting ./mpy-cross binary to compile the BME280.py module to BME280.mpy
I have gotten it downloaded to flash as BME280.mpy
When i now get this error when i try to import it:

Code: Select all

PYB: soft reboot
could not open file 'main.py' for reading
MicroPython v1.8-21-g9e47c14-dirty on 2016-05-08; ESP module with ESP8266
Type "help()" for more information.
>>> ls()
['boot.py', 'port_config.py', 'BME280.mpy', 'util.py', 'wlanconnect.py', 'file', 'BMP1801.py', 'test.py', 'testget.py']
>>> import BME280
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'BME280'
Any hints what i'm doing wrong?

Update:
This approach does not seem to work by now.
I increased heap size and the import worked.
The board with BME280 sensor is deployed in the basement and is reporting the measurements via mqtt to my openhab server.
The measurement are collected into a mongodb collection for later analysis.
Last edited by jwissing on Sun May 08, 2016 5:59 pm, edited 1 time in total.

User avatar
jwissing
Posts: 29
Joined: Thu Jun 19, 2014 12:23 pm
Location: Germany

Re: Cross-Compile and import

Post by jwissing » Sun May 08, 2016 12:37 pm

I got it to work with increased heap size and small modifications to BME280:

Code: Select all

>>> import BME280
>>> b=BME280.BME280(i2c=i2c)
>>> dir(b)
['read_pressure', 'read_humidity', '_load_calibration', '__init__', '__qualname__', 'read_raw_humidity', 'read_temperature', 'humidity', 'read_raw_pressure', 'temperature', '__module__', 'pressure', 'read_raw_temp', 'dig_P6', 'dig_P7', 'dig_P8', 'dig_P9', 'dig_H2', 'dig_H3', 'dig_H1', 'dig_H6', 'dig_H4', 'dig_H5', '_mode', '_device', 'dig_T2', 'dig_T3', 'dig_T1', 't_fine', 'dig_P1', 'dig_P2', 'dig_P3', 'dig_P4', 'dig_P5']
>>> b.temperature
'29.19C'
>>> b.humidity
'28.53%'
>>> b.pressure
'998.03hPa'
>>>
main.c:

Code: Select all

STATIC char heap[40 * 1024];

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cross-Compile and import

Post by Roberthh » Sun May 08, 2016 3:25 pm

@pfalcon : Is there a way to enable cross -compiled byte code?
Best regards

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: Cross-Compile and import

Post by slzatz » Sun May 08, 2016 4:20 pm

I have a font file of the structure:

Code: Select all

cols = 5
rows = 8
bytes = [
    0x00, 0x00, 0x00, 0x00, 0x00,
    ...
    0x20, 0x54, 0x54, 0x78, 0x40,
    0x38, 0x44, 0x44, 0x28, 0x7F,
    0x3C, 0x26, 0x23, 0x26, 0x3C]
 
It appears to successfully compile to a .mpy file but when I transfer it to flash and import I get module not found. I have created a very small version of the file and cross-compiled it with the same result. Is there something about that file structure that won't compile to an .mpy that can be successfully imported?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cross-Compile and import

Post by Roberthh » Sun May 08, 2016 7:17 pm

Cross-compiled files seem not to be imported yet. That's why I asked whether there is a build option to achieve that, lile it is possible on WiPy.

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: Cross-Compile and import

Post by slzatz » Sun May 08, 2016 8:50 pm

Since @jwissing seems to have made it work on the esp, it seems like it's possible today. Would be great to understand how it's done and whether the .mpy has to be compiled with the firmware or can be copied to the esp flash file system.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cross-Compile and import

Post by Roberthh » Mon May 09, 2016 5:02 am

As far as I understand the posts of @jwissing, he increased the heap and then the .py version of his script worked.
The pre-compiled versions will still not be accepted as python scripts.

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: Cross-Compile and import

Post by slzatz » Mon May 09, 2016 10:33 am

@Roberthh - thanks - I had misinterpreted what had worked. Am in the same position, I can get things to work with the font.py module I have but would very much like to turn it into frozen bytecode -- will stay tuned to see if/when that is possible via the esp port.

Post Reply