Delving into the Generated Code

(PackageLink[MicrocontrollerEmbedCode, paclet:MicrocontrollerKit/ref/MicrocontrollerEmbedCode, MicrocontrollerKit Package Symbol]) returns a (PackageLink[MicrocontrollerCodeData, paclet:MicrocontrollerKit/ref/MicrocontrollerCodeData, MicrocontrollerKit Package Symbol]) object that can be used to inspect the generated source code and probe other properties of the generated code.

Load the package.

Needs["MicrocontrollerKit`"]

(PackageLink[MicrocontrollerEmbedCode, paclet:MicrocontrollerKit/ref/MicrocontrollerEmbedCode, MicrocontrollerKit Package Symbol]) returns a (PackageLink[MicrocontrollerCodeData, paclet:MicrocontrollerKit/ref/MicrocontrollerCodeData, MicrocontrollerKit Package Symbol]) object .

ℳ1=MicrocontrollerEmbedCode[(StateSpaceModelFull[1, 1, , ]),<|"Target"->"ArduinoUno","Inputs"->"A0"->"Analog","Outputs"->"3"->"Analog"|>,"/dev/tty.usbmodem14101"]

Use the "SourceCode" property to get the source code that was generated.

The source code.

Framed[StringTrim[ℳ1["SourceCode"]],Background->Lighter[LightGreen,0.4]]

Alternatively the source code can be sent to a specific working directory.

Create a temporary directory to put the source code.

wdir=CreateDirectory[];

ℳ2=MicrocontrollerEmbedCode[(StateSpaceModelFull[1, 1, , ]),<|"Target"->"ArduinoUno","Inputs"->"Serial","Outputs"->"Serial"|>,"/dev/tty.usbmodem14101",<|"WorkingDirectory"->wdir,"CleanIntermediate"->False|>]

The directory has the source code as well as other intermediate files.

FileNames["*",wdir]

While the source code provides the most complete information about all the generated code, you will also have to cross reference the microcontroller's datasheet to understand what the the specific settings of the microcontroller's registers mean.

Some of this information can be obtained upfront by using the properties.

The settings for serial communication.

Dataset[ℳ2["Serial"]]

Some other properties are specifications of the microcontroller for which the code was generated.

General microcontroller specifications.

Table[{p,ℳ1[p]},{p,{"Target","Microcontroller","OperatingVoltage","ClockFrequency"}}];

Grid[%,Background->{None,{{LightBlue,White}}},Frame->True]

Other properties provide diagnostic information.

Data sent to standard error by the programmer.

Framed[StringTrim[ℳ1["StandardError"]],Background->Lighter[LightGray,0.8]]

The exit code.

ℳ1["ExitCode"]

The file sizes.

Table[{p,ℳ1[p]},{p,{"SourceCodeByteCount","MachineCodeByteCount"}}];

Grid[%,Background->{None,{{Lighter[Brown,0.7],White}}},Frame->True]

All the available properties can be seen using the properties data.

All available properties.

ℳ2["Properties"];

Grid[Partition[%,4],Frame->All,Background->{None,{{LightYellow,White}}}]

Not all properties are available in every case.

ℳ1["Serial"]