{"id":198217,"date":"2026-04-01T08:18:07","date_gmt":"2026-04-01T08:18:07","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/knowledge\/?post_type=topic&#038;p=198217"},"modified":"2026-04-01T08:35:47","modified_gmt":"2026-04-01T08:35:47","slug":"integrating-scade-one-generated-code-with-the-raspberry-pi-pico-a-model-based-design-tutorial-for-robotics","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/knowledge\/forums\/topic\/integrating-scade-one-generated-code-with-the-raspberry-pi-pico-a-model-based-design-tutorial-for-robotics\/","title":{"rendered":"Integrating Scade One Generated Code with the Raspberry Pi Pico: A Model-Based Design Tutorial for Robotics"},"content":{"rendered":"<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-banner.jpeg\" style=\"max-height: 700px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p><a href=\"https:\/\/www.ansys.com\/products\/embedded-software\/ansys-scade-suite\">SCADE Model-Based Design<\/a> has become a reference methodology for developing safety-critical embedded software, where reliability, verification, and traceability are essential. By enabling engineers to specify software behavior at a high level and automatically generate implementation code, it helps reduce development errors and maintain strong consistency between models and deployed software.<\/p>\n<p>At the same time, Model-Based Design is not limited to highly regulated domains. Modern tools such as Scade One make the approach accessible for a wide range of embedded platforms, including lightweight microcontrollers used in less critical applications, like the Raspberry Pi Pico. Developers can design software behavior graphically and automatically generate production-quality C code and accelerating implementation.<\/p>\n<p>This tutorial demonstrates how to integrate C code generated by Scade One into a simple embedded application running on the Adeept&#8217;s robot <strong>4WD Mecanum Wheel Smart Car<\/strong>, based on the Raspberry Pi Pico. The example application combines two functions:<\/p>\n<ul>\n<li>A blinking LED using the Pico&#8217;s onboard LED<\/li>\n<li>Moving the robot&#8217;s head using a Pulse-Width Modulation-controlled servomotor. In our robot, the head is a servo-mounted ultrasonic sensor, that can be used to scan the environment.<\/li>\n<\/ul>\n<p>While these two functions are simple and don&#8217;t leverage all capabilities of the robot, they allow us to demonstrate key concepts while keeping a reasonable article length.<\/p>\n<p>This tutorial article walks through the hardware setup, PWM configuration, and set-up of the Visual Studio Code environment to compile and build the integrated code.<\/p>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-pico-board.jpg\" style=\"max-height: 500px !important\" \/><br \/>\n    <em>Hardware setup overview<\/em>\n<\/p>\n<h4  id=\"WHAT-IS-THE-RASPBERRY-PI-PICO\">What is the Raspberry Pi Pico?<\/h4>\n<p>The <a href=\"https:\/\/www.raspberrypi.com\/products\/raspberry-pi-pico\/\">Raspberry Pi Pico<\/a> is a low-cost microcontroller board designed for embedded systems development and education. It is based on the <a href=\"https:\/\/pip-assets.raspberrypi.com\/categories\/814-rp2040\/documents\/RP-008371-DS-1-rp2040-datasheet.pdf?disposition=inline\">RP2040 microcontroller<\/a>, which features:<\/p>\n<ul>\n<li>Dual-core ARM Cortex-M0+ processors<\/li>\n<li>Up to 133 MHz clock frequency<\/li>\n<li>264 KB SRAM<\/li>\n<li>Flexible peripherals including GPIO, PWM, SPI, I2C, UART, and timers<\/li>\n<\/ul>\n<p>The Pico is widely used in <strong>robotics<\/strong>, control systems, and educational projects because it offers a powerful microcontroller with a simple development workflow. The official SDK allows developers to program the device in <strong>C or C++<\/strong>, and firmware is typically flashed using a <a href=\"https:\/\/github.com\/microsoft\/uf2\">.uf2<\/a> file copied directly to the device via USB.<\/p>\n<p>For embedded control applications such as robotics, two features are particularly important:<\/p>\n<ul>\n<li><strong>GPIO (General Purpose Input\/Output)<\/strong> for digital control signals<\/li>\n<li><strong>PWM (Pulse Width Modulation)<\/strong> for driving devices such as motors and servos<\/li>\n<\/ul>\n<h4  id=\"WHY-USE-SCADE-ONE\">Why use Scade One?<\/h4>\n<p><a href=\"https:\/\/innovationspace.ansys.com\/knowledge\/forums\/topic\/scade-one-a-visual-coding-experience\/\">Scade One<\/a> is a model-based engineering and code generation environment used for developing embedded software.<\/p>\n<p>Instead of writing control algorithms directly in C, engineers <strong>design<\/strong> the software using <strong>graphical models<\/strong>. These models represent software behavior, signal flows, and operation modes.<\/p>\n<p>Once the software is validated through on-host model execution, debugging and analysis, Scade One can <strong>automatically generate C code<\/strong> suitable for embedded deployment.<\/p>\n<p>Key Scade One Characteristics:<\/p>\n<ul>\n<li>Graphical and textual modeling language<\/li>\n<li>Deterministic execution semantics<\/li>\n<li>Automatic generation of structured-safe C code<\/li>\n<\/ul>\n<p>Scade-based approach is widely used in industries such as aerospace, automotive, and industrial control.<\/p>\n<p>In recent years, SCADE has also been <a href=\"https:\/\/www.ansys.com\/fr-fr\/blog\/ansys-scade-architect-complex-systems\">increasingly adopted in universities<\/a> to teach embedded software and Model-Based Design. The tool helps students understand how high-level software models can be transformed into executable software.<\/p>\n<h4  id=\"WHAT-IS-MODEL-BASED-DESIGN\">What is Model-Based Design?<\/h4>\n<p>Model-Based Design (MBD) is a development methodology where the <strong>software model is the central artifact<\/strong> in the design process.<\/p>\n<p>Instead of implementing algorithms directly in source code, developers first create a <strong>formal model<\/strong> describing the software behavior.<\/p>\n<p>A typical Model-Based Design workflow includes:<\/p>\n<ul>\n<li>Software modeling<\/li>\n<li>Simulation and verification<\/li>\n<li>Automatic code generation<\/li>\n<li>Code integration on target <\/li>\n<\/ul>\n<p>Benefits include:<\/p>\n<ul>\n<li>Improved traceability between requirements and implementation<\/li>\n<li>Faster development cycles<\/li>\n<li>Early verification through simulation<\/li>\n<li>Reduced implementation errors<\/li>\n<\/ul>\n<p>Scade One MBD makes it possible to maintain a consistent workflow from software modeling to deployed code, all with a high level of confidence given the level of qualification of the tool.<\/p>\n<h3  id=\"APPLICATION-OVERVIEW\">Application Overview<\/h3>\n<p>The demonstration application combines two simple embedded functions: Led blinking and Servo control.<\/p>\n<p>In the Adeept Robot, the LED is connected to the Pico&#8217;s <strong>GPIO 25<\/strong>, while the servo controlling the robot head is connected to <strong>GPIO 7<\/strong>.<\/p>\n<p>The servo receives a <strong>PWM signal<\/strong>, where the pulse width determines the servo position.<\/p>\n<h4  id=\"HOW-PWM-CONTROLS-A-SERVO\">How PWM Controls a Servo<\/h4>\n<p>The servomotors in the robot operate using a <strong>50 Hz PWM signal<\/strong>, which corresponds to a <strong>20 ms period<\/strong>. Within each 20 ms period, the <strong>high-pulse duration (width) determines the servo angle<\/strong>.<\/p>\n<p>Control values are:<\/p>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-pwm-diagram.svg\" style=\"max-height: 600px !important\" \/><br \/>\n    <em>Pulse Width Modulation values and resulting servo angles<\/em>\n<\/p>\n<p>The PWM configuration in this project is designed so that &#8220;<strong>PWM counts&#8221; directly represent microseconds<\/strong>, making it straightforward to send values produced by the Scade One model. The next section describes how to achieve that.<\/p>\n<h4  id=\"PWM-ARCHITECTURE-IN-THE-RP2040\">PWM Architecture in the RP2040<\/h4>\n<p>The RP2040 microcontroller implements PWM using <strong>independent PWM slices<\/strong>.<\/p>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-pwm-architecture.png\" style=\"max-height: 300px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p>To generate a 50 Hz signal:<\/p>\n<ul>\n<li>The <strong>system clock<\/strong> (125 MHz) is divided<\/li>\n<li>A <strong>counter <\/strong>increments at the resulting clock rate<\/li>\n<li>When the counter reaches the <strong>wrap value<\/strong>, it resets<\/li>\n<\/ul>\n<p>In this project:<\/p>\n<ul>\n<li>Clock divider = <strong>125<\/strong><\/li>\n<li>Effective PWM tick = <strong>1 MHz (1 \u00b5s resolution)<\/strong><\/li>\n<li>Wrap value = <strong>19999<\/strong><\/li>\n<\/ul>\n<p>This produces: 1 MHz \/ 20000 counts = 50 Hz<\/p>\n<p>Because each PWM tick represents <strong>1 \u00b5s<\/strong>, the PWM duty cycle can be set directly using microsecond values. In this way:<\/p>\n<ul>\n<li>The hardware generates the PWM signal automatically every 20 ms, with width resolution of 1 \u00b5s<\/li>\n<li>The application code can update the duty cycle at any time (e.g., every control loop iteration), that is, comand the position of the head by providing a pulse width. <\/li>\n<\/ul>\n<h4  id=\"SCADE-ONE-MODEL\">Scade One Model<\/h4>\n<p>The model implements two simple behaviors: LED blinking and servo motion. <\/p>\n<p>When designing software with Scade One, interaction with external software components is supported (e.g. PICO SDK functions), but these components must remain outside the (application) model in a way that preserves simulation capability. Simulation requires generating, compiling, and executing code on the host platform. Consequently, any external components must be compatible with the host (PC) architecture, which is not true for the SDK components that are meant for the PICO architecture.<\/p>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-integration-overview.svg\" style=\"max-height: 250px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p>The behavior is described using two independent state machines, running in parallel. <\/p>\n<h5  id=\"INTERFACE\">Interface<\/h5>\n<p>The LED blinks at a frequency set by the <code>LED_delay<\/code> input, while the robot head moves from left to right at a frequency set by the <code>SERV_delay<\/code> input.<\/p>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-robot-operator-definition.png\" style=\"max-height: 150px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p>The model provides two outputs:<\/p>\n<ul>\n<li><code>led<\/code>: a Boolean signal that controls the LED state (true = ON, false = OFF)<\/li>\n<li><code>us<\/code>: a pulse width value (in microseconds) used to generate the PWM signal, which defines the position of the robot head. This value range is between 1000 and 2000 us, corresponding to an angle range of [-90 .. 90]\u00b0.<\/li>\n<\/ul>\n<h5  id=\"LED-CONTROL\">LED control<\/h5>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-led-control-state-machine.png\" style=\"max-height: 300px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p>The <code>LED_SSM<\/code> state-machine with two states (<code>LED<\/code>_<code>off<\/code>_<code>st<\/code> and <code>LED<\/code>_<code>on<\/code>_<code>st<\/code>) toggles the <strong>led<\/strong> output between <em>false<\/em> and <em>true<\/em>. In each state, a <code>CountCycles<\/code> counter increments every cycle. When <code>countL<\/code> = <code>LED<\/code>_<code>delay<\/code>, the machine transitions to the other state, producing a periodic LED blink.<\/p>\n<h5  id=\"HEAD-CONTROL\">Head control<\/h5>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-head-control-state-machine.png\" style=\"max-height: 350px !important\" \/><br \/>\n    <em><\/em>\n<\/p>\n<p>The <code>SERVO<\/code>_<code>SSM<\/code> state machine with two states (<code>HEAD<\/code>_<code>left<\/code>_<code>st<\/code> and <code>HEAD<\/code>_<code>right<\/code>_<code>st<\/code>) alternates the servo angle between \u221290\u00b0 and +90\u00b0. In each state, <code>Servo<\/code>_<code>Deg2Us<\/code> converts the fixed angle to a PWM value (<code>us<\/code>), while a <code>CountCycles<\/code> counter increments; when <code>count<\/code> = <code>SERV<\/code>_<code>delay<\/code>, the machine transitions to the other state, producing periodic left-right motion.<\/p>\n<h5  id=\"SIMULATION\">Simulation<\/h5>\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-robot-debug.png\" style=\"max-height: 700px !important\" \/><br \/>\n    <em>Live debug of the Robot operator in Scade One. Active state machine states are highlighted.<\/em>\n<\/p>\n<p>Before deployment, it is better to analyze the behavior of the model. To do this, we launch our model in debug mode on a host laptop.<\/p>\n<p>The simulation was launched and executed several steps; at this point the LED is OFF and waiting for its counter to reach 6 before switching ON. The servo is positioned to the right (+90\u00b0) and is waiting for its counter to reach 4 before switching to the left position.<\/p>\n<h4  id=\"CODE-GENERATION-AND-INTEGRATION\">Code generation and integration<\/h4>\n<p>We are now ready to integrate our model onto the embedded target. When launching code generation from Scade One, the code generator produces the files below. For details on how to generate the code, see <a href=\"https:\/\/www.youtube.com\/watch?v=ww5-sx8U0lc\">Scade One Student Quick Getting Started<\/a>:<\/p>\n<ul>\n<li><strong>Robot_blinker.c:<\/strong> implementation of the SCADE model logic <\/li>\n<li><strong>Robot_blinker.h<\/strong>: public interface of the model <\/li>\n<li><strong>swan_consts.c<\/strong>: definitions of global constants used by the generated code<\/li>\n<li><strong>swan_consts.h<\/strong>: declarations of those constants.<\/li>\n<li><strong>swan_sensors.h<\/strong>: interface for external inputs <\/li>\n<li><strong>swan_types.c<\/strong>: implementation of custom data types (if required by the model)<\/li>\n<li><strong>swan_types.h<\/strong>: definitions of all data types used by the generated code <\/li>\n<\/ul>\n<p>The user should create an integration file (e.g. picoBlink.c) including the <strong>Robot_blinker.h<\/strong> file.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow:auto;width:auto;background:none;border:none;padding:.2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\"><span><\/span><span style=\"color: #998;font-style: italic\">\/\/ === PICO SDK  ===<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&quot;pico\/stdlib.h&quot;<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&lt;stdbool.h&gt;<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&lt;stdint.h&gt;<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&lt;stdio.h&gt;<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&quot;hardware\/pwm.h&quot;<\/span>\r\n\r\n<span style=\"color: #998;font-style: italic\">\/\/ === SCADE API  ===<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#include<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">&quot;Robot_blinker.h&quot;  \/\/ in SCADE_DIR<\/span>\r\n\r\n<span style=\"color: #998;font-style: italic\">\/\/ === Hardware pins ===<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#define LED_PIN 25   <\/span><span style=\"color: #998;font-style: italic\">\/\/ Onboard LED on Raspberry Pi Pico<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#define SERVO_PIN 7   <\/span><span style=\"color: #998;font-style: italic\">\/\/ Adeept board X11 &quot;SIG&quot; -&gt; GP0<\/span>\r\n<span style=\"color: #999;font-weight: bold\">#define PIN_PWM_SLICE 3 <\/span><span style=\"color: #998;font-style: italic\">\/\/ RP2040 slice hardcoded for pin 7<\/span>\r\n<\/pre>\n<\/div>\n<h4  id=\"INITIALIZATION\">Initialization<\/h4>\n<p>The <code>init_Robot<\/code> function initializes the hardware and the SCADE-generated code for the robot. It first sets up standard I\/Os, configures the LED pin as a digital output, and assigns the servo pin to the PWM function. It then initializes the PWM peripheral using the Pico SDK: the clock divider is set to obtain a 1 MHz PWM tick rate, and the wrap value is configured to 19,999, resulting in a 20 ms period (50 Hz), which is suitable for servo control. The PWM slice corresponding to the servo pin is started with this configuration. Finally, the function calls Robot_init_blinker to initialize the internal state and outputs of the generated SCADE model.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow:auto;width:auto;background:none;border:none;padding:.2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\"><span><\/span><span style=\"color: #998;font-style: italic\">\/\/ === Robot init fuction ===<\/span>\r\n<span style=\"font-weight: bold\">static<\/span><span style=\"color: #BBB\"> <\/span><span style=\"font-weight: bold\">inline<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #458;font-weight: bold\">void<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #900;font-weight: bold\">init_Robot<\/span>(<span style=\"color: #458;font-weight: bold\">void<\/span>)<span style=\"color: #BBB\"> <\/span>{\r\n<span style=\"color: #BBB\">    <\/span>stdio_init_all();\r\n<span style=\"color: #BBB\">    <\/span>gpio_init(LED_PIN);\r\n<span style=\"color: #BBB\">    <\/span>gpio_set_dir(LED_PIN,<span style=\"color: #BBB\"> <\/span>GPIO_OUT);\r\n<span style=\"color: #BBB\">    <\/span>gpio_set_function(SERVO_PIN,<span style=\"color: #BBB\"> <\/span>GPIO_FUNC_PWM);\r\n\r\n<span style=\"color: #BBB\">    <\/span><span style=\"color: #998;font-style: italic\">\/\/ 125 MHz \/ 125 = 1 MHz tick =&gt; wrap 19999 gives 50 Hz (20 ms period)\t<\/span>\r\n<span style=\"color: #BBB\">    <\/span>pwm_config<span style=\"color: #BBB\"> <\/span>cfg<span style=\"color: #BBB\"> <\/span><span style=\"font-weight: bold\">=<\/span><span style=\"color: #BBB\"> <\/span>pwm_get_default_config();<span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">\/\/ PICO SDK pwm configuration<\/span>\r\n<span style=\"color: #BBB\">    <\/span>pwm_config_set_clkdiv(<span style=\"font-weight: bold\">&amp;<\/span>cfg,<span style=\"color: #BBB\"> <\/span><span style=\"color: #099\">125.0f<\/span>);<span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">\/\/ to achieve 1M PWM ticks per second <\/span>\r\n<span style=\"color: #BBB\">    <\/span>pwm_config_set_wrap(<span style=\"font-weight: bold\">&amp;<\/span>cfg,<span style=\"color: #BBB\"> <\/span><span style=\"color: #099\">19999<\/span>);<span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">\/\/ a period of 20K (50hz) ticks per PWM pulse<\/span>\r\n<span style=\"color: #BBB\">    <\/span>pwm_init(PIN_PWM_SLICE,<span style=\"color: #BBB\"> <\/span><span style=\"font-weight: bold\">&amp;<\/span>cfg,<span style=\"color: #BBB\"> <\/span><span style=\"color: #999\">true<\/span>);<span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">\/\/ the RP2040 slice is hardcoded for pin 7 <\/span>\r\n<span style=\"color: #BBB\">\t<\/span>\r\n<span style=\"color: #BBB\">    <\/span><span style=\"color: #998;font-style: italic\">\/\/ init the memories and outputs of the SCADE-generated code<\/span>\r\n<span style=\"color: #BBB\">    <\/span>Robot_init_blinker(<span style=\"font-weight: bold\">&amp;<\/span>outC);<span style=\"color: #BBB\"> <\/span>\r\n}\r\n<\/pre>\n<\/div>\n<h4  id=\"MAIN-FUNCTION\">Main function<\/h4>\n<p>The main function calls the initialization function and continuously executes the control loop driven by the SCADE-generated code. <\/p>\n<p>After calling <code>init_Robot()<\/code> and waiting briefly for stabilization, it enters an infinite loop where the <code>Robot_blinker<\/code> function is invoked with fixed delay parameters to compute the current outputs. These outputs are then applied to the hardware: the LED state (<code>outC.led<\/code>) is set using a GPIO write, and the servo position is controlled by updating the PWM pulse width (<code>outC.us<\/code>). The loop runs periodically with a 100 ms delay (\u224810 Hz), defining the execution rate of the model.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow:auto;width:auto;background:none;border:none;padding:.2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\"><span><\/span><span style=\"color: #458;font-weight: bold\">int<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #900;font-weight: bold\">main<\/span>(<span style=\"color: #458;font-weight: bold\">void<\/span>)<span style=\"color: #BBB\"> <\/span>{\r\n\r\n<span style=\"color: #BBB\">    <\/span>init_Robot();\r\n<span style=\"color: #BBB\">       <\/span>\r\n<span style=\"color: #BBB\">    <\/span><span style=\"font-weight: bold\">while<\/span><span style=\"color: #BBB\"> <\/span>(<span style=\"color: #999\">true<\/span>)<span style=\"color: #BBB\"> <\/span>{<span style=\"color: #BBB\"> <\/span>\r\n<span style=\"color: #BBB\">        <\/span><span style=\"color: #998;font-style: italic\">\/\/ --- Call SCADE-generated logic ---<\/span>\r\n<span style=\"color: #BBB\">        <\/span>Robot_blinker(SERVO_FREQ,<span style=\"color: #BBB\"> <\/span>LED_FREQ,<span style=\"color: #BBB\"> <\/span><span style=\"font-weight: bold\">&amp;<\/span>outC);\r\n<span style=\"color: #BBB\">        <\/span>\r\n<span style=\"color: #BBB\">        <\/span><span style=\"color: #998;font-style: italic\">\/\/ --- Drive the pin with SCADE output ---<\/span>\r\n<span style=\"color: #BBB\">        <\/span>gpio_put(LED_PIN,<span style=\"color: #BBB\"> <\/span>outC.led);\r\n<span style=\"color: #BBB\">        <\/span>pwm_set_gpio_level(SERVO_PIN,<span style=\"color: #BBB\"> <\/span>outC.us);\r\n<span style=\"color: #BBB\">            <\/span>\r\n<span style=\"color: #BBB\">        <\/span><span style=\"color: #998;font-style: italic\">\/\/ Model tick period (adjust to your design\u2019s sampling time)<\/span>\r\n<span style=\"color: #BBB\">        <\/span>sleep_ms(<span style=\"color: #099\">100<\/span>);<span style=\"color: #BBB\"> <\/span><span style=\"color: #998;font-style: italic\">\/\/ main loop at ~100 Hz; tweak as needed   <\/span>\r\n<span style=\"color: #BBB\">    <\/span>}\r\n}\r\n<\/pre>\n<\/div>\n<h3  id=\"COMPILE-AND-BUILD-USING-VISUAL-STUDIO-CODE-AND-PICO-SDK\">Compile and Build using Visual Studio Code and PICO SDK<\/h3>\n<p>The build is demonstrated using Visual Studio Code together with the <a href=\"https:\/\/www.raspberrypi.com\/documentation\/pico-sdk\/\">Pico C SDK<\/a>.<\/p>\n<h4  id=\"PREREQUISITES\">Prerequisites<\/h4>\n<p>Before creating a Pico Project, first Install:<\/p>\n<ul>\n<li>Visual Studio Code<\/li>\n<li>Raspberry Pi Pico C SDK<\/li>\n<li>Raspberry Pi Pico VS Code extension<\/li>\n<li>Microsoft CMake Tools extension<\/li>\n<\/ul>\n<h4  id=\"STEP-1-CREATE-A-NEW-PICO-PROJECT\">Step 1: Create a New Pico Project<\/h4>\n<ul>\n<li>Open Visual Studio Code<\/li>\n<li>Press <strong>Ctrl+Shift+P<\/strong><\/li>\n<li>Select:<\/li>\n<\/ul>\n<p><code>Raspberry Pi Pico: New Pico Project<\/code><\/p>\n<ul>\n<li>Choose a folder such as:<\/li>\n<\/ul>\n<p><code>C:\\PicoProjects\\line_follower<\/code><\/p>\n<ul>\n<li>Select <strong>C<\/strong> as the language.<\/li>\n<\/ul>\n<p>The extension creates a project containing:<\/p>\n<ul>\n<li>main.c<\/li>\n<li>CMakeLists.txt<\/li>\n<li>. vscode configuration files<\/li>\n<\/ul>\n<h4  id=\"STEP-2-CONFIGURE-THE-PROJECT\">Step 2: Configure the Project<\/h4>\n<p>Press <strong>Ctrl+Shift+P<\/strong> and run:<\/p>\n<p><code>Raspberry Pi Pico: Configure CMake<\/code><\/p>\n<p>The terminal should show a successful configuration and select <strong>Ninja<\/strong> as the generator.<\/p>\n<h4  id=\"STEP-3-BUILD-THE-PROJECT\">Step 3: Build the Project<\/h4>\n<p>Run:<\/p>\n<p><code>Raspberry Pi Pico: Compile Pico Project<\/code><\/p>\n<p>The build produces a <code>.uf2<\/code> firmware file inside the build directory.<\/p>\n<h4  id=\"STEP-4-FLASH-THE-PICO\">Step 4: Flash the Pico<\/h4>\n<ul>\n<li>Hold <strong>BOOTSEL<\/strong> on the Pico.<\/li>\n<li>Connect the Pico to the computer via USB.<\/li>\n<li>Release the button.<\/li>\n<\/ul>\n<p>The device appears as a <strong>USB storage drive<\/strong>.<\/p>\n<p>Then run:<\/p>\n<p><code>Raspberry Pi Pico: Flash Pico Project (USB)<\/code><\/p>\n<p>The <code>.uf2<\/code> file is copied to the Pico and the program starts automatically.<\/p>\n<p>And there you have it! Our robot is happily blinking its light and moving its head from side to side:<\/p>\n<p><p style=\"text-align: center\"><iframe loading=\"lazy\" class=\"vidyard_iframe\" src=\"https:\/\/play.vidyard.com\/FyTrxnEqmCS2ABzk7kmat1\" width=\"740\" height=\"460\" frameborder=\"0\" allowfullscreen referrerpolicy=\"no-referrer-when-downgrade\"><\/iframe><\/p>\n<\/p>\n<h3  id=\"CONCLUSION\">Conclusion<\/h3>\n<p>This tutorial demonstrated how Model-Based Design using Scade One can be combined with the Raspberry Pi Pico to implement a simple embedded robotics application.<\/p>\n<p>By generating C code from a Scade One model and integrating it into a Pico project, developers can bridge the gap between <strong>high-level software models and real hardware execution<\/strong>.<\/p>\n<p>Even a simple example such as a blinking LED and a servo-driven robot head illustrates the core workflow:<\/p>\n<ul>\n<li>Model software behavior in Scade One<\/li>\n<li>Generate deterministic embedded C code<\/li>\n<li>Integrate the generated code with hardware drivers<\/li>\n<li>Deploy the application to an embedded target<\/li>\n<\/ul>\n<p>This workflow highlights the practical benefits of Model-Based Design: faster design, improved reliability, and a clear connection between software design models and the embedded code. You can use Scade One for your academic projects! Get it from <a href=\"https:\/\/www.ansys.com\/academic\/students\/ansys-scade-student\">Ansys SCADE Student Free Software Download | Ansys<\/a>.<\/p>\n<h3  id=\"ABOUT-THE-AUTHOR\">About the author<\/h3>\n<table style=\"max-width: 1000px;border: none !important\">\n<tr>\n<td style=\"padding: 0px 10px;min-width: 150px;border: none !important\">\n<p style=\"text-align: center\">\n    <img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/knowledge\/wp-content\/uploads\/sites\/4\/2026\/04\/scade-061-author.png\" style=\"max-height: 150px !important\" \/><br \/>\n                <em><\/em>\n<\/p>\n<\/td>\n<td style=\"padding: 0px 10px;min-width: 150px;border: none !important\">\n<p><strong>Dr. Jair Gonzalez<\/strong> (<a href=\"https:\/\/www.linkedin.com\/in\/dr-jair-gonzalez\/\">LinkedIn<\/a>) has extensive experience in Model-Based Development (MBD) for embedded systems, spanning teaching, research, and business leadership. Currently serves as Sr. Principal Engineer at Ansys, where he promotes the adoption of SCADE MBD approach across diverse industries, including Railway, Energy, Robotics.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"template":"","class_list":["post-198217","topic","type-topic","status-publish","hentry","topic-tag-pico","topic-tag-raspberry-pi","topic-tag-robotics","topic-tag-scade-one"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_edit_lock":["1775811764:1769"],"_edit_last":["1769"],"_aioseo_title":[null],"_aioseo_description":[null],"_aioseo_keywords":["a:0:{}"],"_aioseo_og_title":[null],"_aioseo_og_description":[null],"_aioseo_og_article_section":[""],"_aioseo_og_article_tags":["a:0:{}"],"_aioseo_twitter_title":[null],"_aioseo_twitter_description":[null],"filter_by_optics_product":["Lumerical"],"_filter_by_optics_product":["field_64fb192ba3121"],"application_name":[""],"_application_name":["field_64a80903c8e15"],"family":[""],"_family":["field_64a809229a857"],"siebel_km_number":[""],"_siebel_km_number":["field_63ecbffce60db"],"salesforce_km_number":[""],"_salesforce_km_number":["field_63ecc018e60dc"],"km_published_date":[""],"_km_published_date":["field_64c77704499dd"],"product_version":[""],"_product_version":["field_64c776cb4fd2e"],"_bbp_forum_id":["27825"],"_bbp_topic_id":["198217"],"_bbp_author_ip":["87.190.19.71"],"_bbp_last_reply_id":["0"],"_bbp_last_active_id":["198218"],"_bbp_last_active_time":["2026-04-01 08:18:07"],"_bbp_reply_count":["0"],"_bbp_reply_count_hidden":["0"],"_bbp_voice_count":["0"],"_btv_view_count":["169"],"_bbp_likes_count":["4"]},"test":"solution"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/topics\/198217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":5,"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/topics\/198217\/revisions"}],"predecessor-version":[{"id":198225,"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/topics\/198217\/revisions\/198225"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/knowledge\/wp-json\/wp\/v2\/media?parent=198217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}