Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Wolfram Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • System Modeler
  • Wolfram Player
  • Finance Platform
  • Wolfram Engine
  • Enterprise Private Cloud
  • Application Server
  • Wolfram|Alpha Notebook Edition
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

WolframConsulting.com

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Wolfram Notebook Assistant + LLM Kit
    • System Modeler
    • Wolfram Player
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Wolfram Engine
    • Enterprise Private Cloud
    • Application Server
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
MicrocontrollerEmbedCode
  • See Also
    • MicrocontrollerCodeData
  • Related Guides
    • Microcontroller Kit
    • Control Systems
    • Signal Processing
    • Connected Devices
  • Tech Notes
    • Microcontroller Kit
    • See Also
      • MicrocontrollerCodeData
    • Related Guides
      • Microcontroller Kit
      • Control Systems
      • Signal Processing
      • Connected Devices
    • Tech Notes
      • Microcontroller Kit

MicrocontrollerEmbedCode[sys,μc,p]

embeds the systems model sys to the microcontroller μc using p.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Digital Output  
Pulse Output  
Analog Output  
Show More Show More
Analog Input  
Digital Input  
Serial (RS-232) Communication  
Serial Peripheral Interface (SPI) Communication  
Inter-Integrated Circuit (I2C) Communication  
External Libraries  
Systems Models  
Targets  
Missing Physical Target  
External Programmer  
Timer  
Properties  
Additional Specifications  
Generalizations & Extensions  
Possible Issues  
See Also
Tech Notes
Related Guides
Related Links
Cite this Page
MICROCONTROLLER KIT SYMBOL
  • See Also
    • MicrocontrollerCodeData
  • Related Guides
    • Microcontroller Kit
    • Control Systems
    • Signal Processing
    • Connected Devices
  • Tech Notes
    • Microcontroller Kit
    • See Also
      • MicrocontrollerCodeData
    • Related Guides
      • Microcontroller Kit
      • Control Systems
      • Signal Processing
      • Connected Devices
    • Tech Notes
      • Microcontroller Kit
MicrocontrollerKit`
MicrocontrollerKit`

MicrocontrollerEmbedCode

MicrocontrollerEmbedCode[sys,μc,p]

embeds the systems model sys to the microcontroller μc using p.

Details and Options

  • MicrocontrollerEmbedCode generates the source code for sys to work with the microcontroller specification μc, compiles it, and embeds the resulting machine code to the μc.
  • In addition a MicrocontrollerCodeData object is generated that can be used to obtain various properties.
  • The systems model sys can be a discrete-time TransferFunctionModel, StateSpaceModel, AffineStateSpaceModel, NonlinearStateSpaceModel, or SystemsConnectionsModel.
  • The microcontroller μc is given as an association with the following primary keys:
  • "Target"target name
    "Inputs"input channels
    "Outputs"output channels
  • Possible input and output channel specifications:
  • cnametypechannel cname configured as type
    cname<|"Type"type|>channel cname configured as type
    cname<|"Type"type,s1v1,…|>additional specifications
    typecname for type is unique
    <|"Type"type,…|> or Automatic-><|"Type"type,…|>cname for type is unique
  • Other possible keys for μc:
  • "ADC"A/D conversion specifications
    "ClockFrequency"frequency of the microcontroller's system clock
    "I2CAddress"I2C address when operating as a I2C slave device
    "Microcontroller"microcontroller to generate code for
    "OperatingVoltage"operating voltage of the microcontroller
    "Serial"serial communication specifications
    "SerialOverUSB"serial over USB specifications
    "SlaveSelect"slave select pin when operating as a SPI slave device
    "Timer"timer or counter number
  • Keys of μc to directly inject code into the source code:
  • "IncludeFiles"files to include
    "Definitions"definition of macros
    "Declarations"function declarations
    "Utilities"utility functions and variables
    "Initializations"program initialization
    "Loop"execute at each sampling instant
    "PreLoop"execute before "Loop"
    "PostLoop"execute after "Loop"
    "UntimedLoop"execute repeatedly whenever the processor is free
  • The programming mechanism p is specified as an association.
  • Possible keys of p include:
  • "BaudRate"baud rate at which to embed the code
    "ConnectionPort"port where external programmer is connected
    "ExternalProgrammer"external programmer to be used
    "ProgrammerName"programmer to be used
    "ProgrammerConfigurationName"programmer configuration to be used
    "ProgrammerConfigurationInstallation"location of the programmer configuration software
    "ProgrammerInstallation"location of the programmer software
  • If p is a string the external programmer is assumed to be connected to the serial port p.
  • MicrocontrollerEmbedCode[sys,μc,p,specs] can be used to give additional specifications.
  • The specifications specs is as association with the following possible keys:
  • "CleanIntermediate"Truewhether temporary files should be deleted
    "CompileOptions"Automaticoptions to pass through to the compiler
    "CompilerInstallation"Automaticlocation of the compiler software
    "CompilerName"Automaticwhich compile command to use
    "CreateBinary"Automaticwhether the machine code should be created
    "I2C"{}external I2C device specifications
    "IncludeDirectories"{}directories to add to the include path
    "Language"Automaticsource code language
    "Libraries"{}libraries to use to build the executable
    "SPI"{}external SPI device specifications
    "WorkingDirectory"Automaticdirectory where temporary files are generated

Examples

open all close all

Basic Examples  (1)

Load the package:

Turn the LED on an Adafruit Trinket 5V at half brightness:

The byte count of the embedded machine code:

The source code that was compiled to generate the machine code:

Scope  (37)

Digital Output  (2)

Turn on the LED connected to pin 13:

A systems model with no input, and a state output that toggles every 2 seconds:

Use it to blink the LED attached to pin 13:

Pulse Output  (2)

Turn pin 13 on for one second during each cycle of 4 seconds:

Specify the sampling period of the pulse to be different from the overall sampling period:

Analog Output  (5)

Turn on the LED connected to pin 3 at half brightness:

Turn it on at a different brightness level:

Analog output only works with pins having pulse-width modulation:

Specify a range, if necessary, to properly scale the output:

Get the LED to glow with maximum brightness:

Half brightness:

Analog signals with positive and negative values need a second pin for direction:

The LED at pin 3 glows with half brightness and the LED at pin 4 is turned on:

The LED at pin 4 is turned off:

The LED at pin 4 is turned on for positive values:

The pin 4 LED is turned off for negative values:

Specify a desired waveform generation mode:

Analog Input  (3)

Read the potentiometer connected to "A0" and use it to adjust the brightness of the LED on pin 3:

Use different voltage references:

Use the voltage of 5V applied at the "AVCC" pin:

Use the internal reference voltage:

Use the voltage of 3.3V applied at the AREF pin:

Specify the prescaler to be used by the input clock of the ADC:

Digital Input  (3)

Turn the LED on pin 3 on and off using a button attached to pin 8:

Turn on the LED using the logic value:

Set the LED brightness using the number of toggles, assumed to be a maximum of 5 every 10 seconds:

Use the number of rising edges:

The number of falling edges:

The number of low counts:

Serial (RS-232) Communication  (2)

Set up the microcontroller to send and receive numerical data:

The serial type can also be directly given, since the serial pins are unique on the Arduino Uno:

Open a serial connection to the device:

Set up a task to read and write data:

Remove the task and close the device after some time:

Compare the sent and received values:

Specify the real-time baudrate to use:

Serial Peripheral Interface (SPI) Communication  (1)

The MAX6675 thermocouple is a SPI sensor whose data can to be read in two bytes: »

The conversion from bytes to obtain the temperature in ° C:

Specify the sensor as a SPI slave device with pin 7 as the slave select pin:

The output is sent over the serial (RS-232) channel:

Embed code to read the sensor and transmit the result:

Open a connection to the Arduino:

Set up a scheduled task to read the data:

Remove the task and close the device after some time:

The temperature plot:

Inter-Integrated Circuit (I2C) Communication  (1)

Measure the temperature using a MPU6050 sensor. The data is in two registers beginning at 0x41: »

The sensor address is 0x68 and its power management register at 0x6B needs to be initialized:

A function to assemble the two bytes that are received:

The systems model to convert it to degrees C:

The model to output a high value if the temperature is over 25° C:

The complete model which reads the temperature and outputs a high or low value:

The embedded code will turn on an LED at pin if the temperature is greater than 25° C:

External Libraries  (1)

Use an external library that is at a known location:

Specify the header file along with the code that needs to be invoked at various stages:

Embed code that utilizes the library:

Systems Models  (6)

Embed a system with two inputs and one output:

Embed a system with two inputs and two outputs:

The serial start, delimiter, and end bytes:

Open a connection to the microcontroller:

Set up a task that sends one input signal and receives two output signals every time period:

A function to parse the actual and reference speed values coming though the serial connection:

Remove the task and close the device after some time:

Plot the outputs:

Specify a state-space model directly as a difference equation:

Embed the system:

Embed a nonlinear model of a simple pendulum:

Discretize the system:

Embed the system:

Embed a SystemsConnectionsModel of a simple pendulum:

The input torque is simulated with a joystick which has an equilibrium value of 2.525:

The complete system:

Embed the system:

Open a serial connection to the target:

A function to parse the data and a variable to store the data:

Set up a scheduled task to read the values every 0.01 seconds:

Remove the task and close the connection after some time:

The simulated result:

Embed a model having bitwise operations:

Targets  (2)

ATmega328P_28PDIP microcontroller with an external 20 MHz clock and pin 15 set as output:

Use an Arduino as the programmer:

Embed code to blink an LED connected to pin 15:

ATmega168A_28PDIP microcontroller with factory settings:

Missing Physical Target  (1)

If no hardware is connected, the code cannot be embedded:

The code is not embedded if the connection port is specified as None:

External Programmer  (1)

Program the microcontroller using an usbasp programmer:

Timer  (1)

Specify which timer the microcontroller should use:

Properties  (1)

Obtain a list of available properties from the MicrocontrollerCodeData object:

Extract a property value:

All property values related to serial communication:

Additional Specifications  (5)

Create a directory to preserve intermediate files:

Deploy the code and preserve the intermediate files:

The intermediate files:

Delete them:

By default, intermediate files are deleted:

Delete the directory:

Specify the path to the compiler:

Specify the compiler's name:

Typically the generated source code is in C:

Use the Wiring language (used by Arduino sketches):

Generate the source code without compiling and embedding it to the target:

Generalizations & Extensions  (1)

A system specified as an expression:

Its equivalent systems model specification:

The data objects:

The generated code is the same in both cases:

Possible Issues  (2)

Only discrete-time systems models can be embedded:

Discretize the system:

Embed the discrete-time system:

In a connections model, all the subsystems must have the same sampling period:

Resample one system to match the other:

Embed the system with subsystems all having the same sampling period:

See Also

MicrocontrollerCodeData

Tech Notes

    ▪
  • Microcontroller Kit

Related Guides

    ▪
  • Microcontroller Kit
  • ▪
  • Control Systems
  • ▪
  • Signal Processing
  • ▪
  • Connected Devices

Related Links

  • ▪ Microcontroller Kit
Wolfram Research (2019), MicrocontrollerEmbedCode, Wolfram Language function, https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html.

Text

Wolfram Research (2019), MicrocontrollerEmbedCode, Wolfram Language function, https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html.

CMS

Wolfram Language. 2019. "MicrocontrollerEmbedCode." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html.

APA

Wolfram Language. (2019). MicrocontrollerEmbedCode. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html

BibTeX

@misc{reference.wolfram_2025_microcontrollerembedcode, author="Wolfram Research", title="{MicrocontrollerEmbedCode}", year="2019", howpublished="\url{https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html}", note=[Accessed: 30-November-2025]}

BibLaTeX

@online{reference.wolfram_2025_microcontrollerembedcode, organization={Wolfram Research}, title={MicrocontrollerEmbedCode}, year={2019}, url={https://reference.wolfram.com/language/MicrocontrollerKit/ref/MicrocontrollerEmbedCode.html}, note=[Accessed: 30-November-2025]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Player
  • Wolfram Engine

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2025 Wolfram
© 2025 Wolfram | Legal & Privacy Policy |
English