Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 15 Next »

Tinkercad Intro

Tinkercad - https://www.tinkercad.com is an excellent tool that allows you to simulate Arduino-based systems (and a lot more). You can (perhaps you SHOULD) simulate all exercises and even your own designs before trying them on real hardware. It also allows you to do programming using blocks. You can download / copy-paste the generated code later into Arduino IDE to program the real Arduino board, rather than having to write it from scratch.

Create a new personal account on Tinkercad website (you can also use your Google account to log in). Then select Circuits on the left pane, and click Create new Circuit.

Hardware

In Components Basic, you can select Arduino Uno R3.

You can rotate it to portrait mode if you wish, which will allow more space for other components to be added. 

You can add more components and wire them up as desired. Clicking on the lead of a component allows you to start a connecting wire from there. Clicking on a wire allows you to change its color.

Programming and Simulation

To program the Arduino, 

  1. Click on Code
  2. You can choose Blocks or Blocks+Text or Text*. For beginners, it is recommended to use Blocks + Text.
    1. This allows you to see the C++ code generated corresponding to your blocks.
    2. You can copy this code later into Arduino IDE to program the real Arduino, rather than having to write it from scratch.
    3. You can also download the code as an Arduino-compatible .ino file. 
  3. You can code by selecting the blocks and connecting them appropriately.
  4. You can start the simulation by clicking Start Simulation.

*Note : You can go between Blocks and Blocks+Text anytime. You can go from Blocks / Blocks+Text to Text, but you can't go back from Text to either of the other two (converting blocks to text is easy, converting text to blocks is computationally non-trivial).

You have to click Stop Simulation to stop the simulation before you can modify your program and/or hardware connections.

Debugging (Advanced)

More often than not, the code written by a programmer does not work as expected the very first time he/she runs it. We need to find out the logical flaws in our code and fix them before we are able to achieve full functionality. Figuring out flaws usually boil down to inspecting variable values at various points in our code, and comparing it with the expected values at those points based on the program logic and data inputs. The usual way Arduino programmers do it is by printing out the variable values to Serial]] ></ac:plain-text-link-body></ac:link>&nbsp;console. </span></p><p><span style="color: rgb(0,0,0);">Tinkercard allows for debugging without having to print the values you want to inspect through Serial. The example below shows debugging of the <ac:link><ri:page ri:content-title="Ultrasonic Distance Sensor" /></ac:link>&nbsp;example.</span></p><p><ac:image ac:height="400"><ri:attachment ri:filename="image2020-1-20_17-10-32.png" /></ac:image>\</p><ol><li>Press the Debugger button.</li><li>Select the line(s) where you want the execution is to be paused. Such a line where you wish to pause execution is called a <em>breakpoint</em>.</li><li>Click Start Simulation.</li><li>Hover over the variable values you want to inspect, and determine if the values are along the expected lines. If not, there is something wrong, and use your logic to determine what could be wrong.</li><li>You can press the Resume execution button to run until the next breakpoint.</li><li>You can also step line by line by clicking the Step Over Next Function button.</li></ol><h3>Screencast</h3><p><ac:structured-macro ac:name="widget" ac:schema-version="1" ac:macro-id="aa61322c-8883-433c-af2a-d967796ab515"><ac:parameter ac:name="url"><ri:url ri:value="http://youtube.com/watch?v=5bUAFIHhGi8" /></ac:parameter></ac:structured-macro></p><p><br /></p>

  • No labels