2016-04-13 16 views
0

私はarduinoプログラミング(Arduino Pro Mini 3.3vバージョン)を初めて使ったので、以下のようなコードがあります。私は9DOF、OLEDスクリーンとBLEブレイクアウトをarduino pro miniに接続しています。arduinoプログラミング:メモリメッセージが不十分

私はすでにいくつかのメモリ最適化のヒントを行ってきましたが、まだまだ問題があります。次のコードでも、私はダイナミックメモリのために9バイトしか残していません。私がBTLEserial.begin();を有効にすると、メモリが消去されます。ご意見をお待ちしております。

#include <Wire.h> 
#include <SPI.h> 
#include <SparkFunLSM9DS1.h> 
#include "Adafruit_BLE_UART.h" 
#include <Adafruit_GFX.h> 
#include <Adafruit_SSD1306.h> 

#define OLED_RESET 4 
Adafruit_SSD1306 display(OLED_RESET); 



LSM9DS1 imu; 


#define LSM9DS1_M 0x1E // Would be 0x1C if SDO_M is LOW 
#define LSM9DS1_AG 0x6B // Would be 0x6A if SDO_AG is LOW 

#define ADAFRUITBLE_REQ 10 
#define ADAFRUITBLE_RDY 2 
#define ADAFRUITBLE_RST 9 

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST); 



void setup(void) { 

    Serial.begin(9600); 

    display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) 

    display.display(); 
    delay(2000); 


    display.clearDisplay(); 


    display.drawPixel(10, 10, WHITE); 

    display.display(); 
    delay(2000); 
    display.clearDisplay(); 

    imu.settings.device.commInterface = IMU_MODE_I2C; 
    imu.settings.device.mAddress = LSM9DS1_M; 
    imu.settings.device.agAddress = LSM9DS1_AG; 
    if (!imu.begin()) 
    { 
    while (1) 
     ; 
    } 


// BTLEserial.begin(); - if i uncomment this code, i will get a not enough memory error. 

} 


aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED; 

void loop() { 

    displayAllDOF(); 

} 

void displayAllDOF(){ 
    display.setTextSize(1); 
    display.setTextColor(WHITE); 

    imu.readGyro(); 
    display.setCursor(0,0); 
    display.print("G:"); 
    display.print(imu.calcGyro(imu.gx)); 
    display.print(", "); 
    display.print(imu.calcGyro(imu.gy)); 
    display.print(", "); 
    display.print(imu.calcGyro(imu.gz)); 
    display.println(" "); 

    imu.readAccel(); 
    display.print("A:"); 
    display.print(imu.calcAccel(imu.ax)); 
    display.print(", "); 
    display.print(imu.calcAccel(imu.ay)); 
    display.print(", "); 
    display.print(imu.calcAccel(imu.az)); 
    display.println(" "); 

    imu.readMag(); 
    display.print("M:"); 
    display.print(imu.calcMag(imu.mx)); 
    display.print(", "); 
    display.print(imu.calcMag(imu.my)); 
    display.print(", "); 
    display.print(imu.calcMag(imu.mz)); 
    display.println(" "); 

    display.display(); 
    display.clearDisplay(); 

} 

答えて

1

開始するには、RAMがどこに行くのか把握する必要があります - 各ライブラリはどれくらいかかりますか?あなたは本当にそれらをすべて同時に動かす必要がありますか?表示ライブラリと現在の設定でIMUコードを実行できることを知っています - のみがIMUコードを有効にし、データをプルして無効にするものを実装できますか?そしてディスプレイとBTLEコードも同じですか?そのように各ライブラリは、それが必要だ時にRAMを消費し、それは操作が

アップデート1

私は上記のものの例を終了します一度それを解放しています。すべてのライブラリが.end()機能を実装しているかどうかはわかりません。彼らはあなたが使うことができる同様の方法を持っているかもしれません。

// Simple data storage for the .gx and .gy values 
typedef struct { 
    float x, y; 
} GyroData_t; 

GyroData_t getImuData() { 
    GyroData_t data; 
    // Create the IMU class, gather data from it, and then destroy it 
    LSM9DS1 *imu = new LSM9DS1(); 
    imu->begin(); 
    imu->readGyro(); 
    data.x = imu.gx; 
    data.y = imu.gy; 
    imu->end(); 
    // This will reclaim the RAM that was used by the IMU - We no longer need it 
    delete imu; 
    return data; 
} 

void displayAllDOF() { 
    // Gather the IMU data 
    GyroData_t data = getImuData(); 
    // Create the display object, and print the data we received 
    Adafruit_SSD1306 *display = new Adafruit_SSD1306(OLED_RESET); 
    display->print(...); 
    .... 
    display->end(); 
    // Reclaim the display RAM used 
    delete display; 

    // Do any bluetooth operations now 
    doBluetoothStuff(); 
} 

void doBluetoothStuff() { 
    Adafruit_BLE_UART *BTLEserial = new Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST); 
    BTLESerial->begin(); 
    ... 
    BTLESerial->end(); 
    delete BTLESerial; 
} 
+0

これは私が紛失していることです。私はモバイル開発者であり、低レベルのプログラミングを開始しました。私は今考えを得た。ありがとうダニエル。 – triston

+0

こんにちはダニエル、同じ質問をもう一度、私はBTLE、IMU、OLEDディスプレイを一緒に実行する必要がある場合は、任意の提案がありますか?ありがとう – triston

+1

私はあなたができると思います - あなたのコンパイラはあなたが同時に実行するクラスのすべてを持つことができないことを明確に述べています、あなたは単にそれを行うのに十分なRAMがありません。しかし、私はあなたが行う必要があることを行うのに十分なだけ、同時にそれらをすべて実行する必要はないとかなり確信しています。各プロセスを独自の機能に分け、一度に1つずつ処理します。うまくいけばこれをより良く示すいくつかの準擬似コードで私の答えを更新しました –