I trained a Neural Network in Matlab and used the Matlab Coder to generate C++ Code to include it in my Arduino Yun project.
The Coder generated a main.h and main.cpp file which can be used as a template for the project, I copied all #includes and functions into my Arduino sketch and compiled it without any errors or warnings. But after uploading the Program in my Yun nothing worked. In the serial monitor I can see the number until 2 and then the RX and TX LED on my board are constant on and nothing happens. If I rebuild and upload the same project nothing is shown in she serial monitor, the TX LED is constant on and RX is blinking.
One time I also had the problem that my Yun wasn't recognized by my pc, but after resetting the Linux processor and reconnecting it to my wifi network I could upload the blink example over wifi and some fusebits were changed, afterwards I can use the programming over the COM Port again?!
I have no idea why it's doing these things, is it a problem with my code or with the yun? I once clicked "upload with programmer" is it possbile that it caused a problem with the bootloader or something else?
My sketch:
//Include Files
//#include <FileIO.h>
#include "rt_nonfinite.h"
#include "NeuralNetwork.h"
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "rtwtypes.h"
#include "NeuralNetwork_types.h"
// Function Declarations
static emxArray_real_T *argInit_d7351x5_real_T();
static double argInit_real_T();
void setup() {
// put your setup code here, to run once:
// Initialize the Bridge and the Serial
// Bridge.begin();
Serial.begin(115200);
//while (!SerialUSB); // wait for Serial port to connect.
while (!Serial) ;
Serial.println("test messages:\n");
NeuralNetwork_initialize();
Serial.println("1");
}
void loop() {
emxArray_real_T *data;
double activity_data[10]; //before [7351]!!
int activity_size[1];
double percent;
int i;
Serial.println("2");
// Initialize function 'NeuralNetwork' input arguments.
// Initialize function input argument 'data'.
data = argInit_d7351x5_real_T();
Serial.println("3");
// Call the entry-point 'NeuralNetwork'.
NeuralNetwork(data, activity_data, activity_size, &percent);
Serial.println("3.9");
emxDestroyArray_real_T(data);
Serial.println("4");
Serial.println("NN Output:\n");
for(i=0;i<10;i++){
Serial.println(activity_data[i]);
}
Serial.println("\n \n Prozent: \n"); //Absatz
Serial.println(percent);
delay(50000);
}
// Function Definitions
//
// Arguments : void
// Return Type : emxArray_real_T *
//
static emxArray_real_T *argInit_d7351x5_real_T()
{
emxArray_real_T *result;
static int iv0[2] = { 10, 5 }; //before { 2, 5}
int idx0;
int idx1;
// Set the size of the array.
// Change this size to the value that the application requires.
result = emxCreateND_real_T(2, *(int (*)[2])&iv0[0]);
// Loop over the array to initialize each element.
for (idx0 = 0; idx0 < result->size[0UL]; idx0++) {
for (idx1 = 0; idx1 < 5; idx1++) {
// Set the value of the array element.
// Change this value to the value that the application requires.
result->data[idx0 + result->size[0] * idx1] = argInit_real_T();
}
}
return result;
}
//
// Arguments : void
// Return Type : double
//
static double argInit_real_T()
{
return 0.0;
}
The coder generated so many files that I can't upload them all but the only functions from the code, the board executes are "NeuralNetwork_initialize" which just calls "rt_InitInfAndNaN(8U);" and afterwards the execution stops in "data = argInit_d7351x5_real_T();" .