1 / 20

Intro to Arduino Programming and Lab Basics

Intro to Arduino Programming and Lab Basics. Mike Robinson. Part 1 - Words to the wise. Keep your code organized!. A quick demonstration. A quick word about reading and writing code. Keep your circuits organized!. A quick demonstration. 330 Ohm. From Arduino. 330 Ohm. From Arduino.

warren
Download Presentation

Intro to Arduino Programming and Lab Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to Arduino Programming and Lab Basics Mike Robinson

  2. Part 1 - Words to the wise

  3. Keep your code organized! • A quick demonstration

  4. A quick word about reading and writing code

  5. Keep your circuits organized! • A quick demonstration 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm From Arduino

  6. Keep separate pieces of code once you get each part of your lab or project working Balancing Arduino Robot Read Accelerometer/ Gyroscope Measure motor rotation Estimate angle of robot Set motor voltage

  7. Part 2 – Arduino Basics

  8. First things first Make sure you can upload the code blink from examples/basic. If it worked, there should be a light slowly blinking on your Arduino

  9. Void setup() and void loop() Your code must have only one function called setup and one called loop but They can be empty If you only want a piece of code to run once, where should you put it?

  10. If statements can be use to make basic decisions in your code Syntax if(conditional statement) { Your code goes here } Example if(testVal == number) if(testVal < number) if(testVal > number1 && testVal < number2 )

  11. Else if and else Syntax if(conditional statement) { } else if(conditional statement) { } else { }

  12. Later on you may want to be able to turn a section of code on and off for debugging. Here is a trick to make that easier Syntax if(1) { Code you want to turn on and off } To deactivate this code, change the one to a zero if(0) { Now any code in between the brackets won’t do anything }

  13. The serial monitor is going to be your best friend when it comes to debugging your code The serial monitor lets you print information from your code If your code is doing something strange, try printing out different values and see if they make sense Click here

  14. You will (hopefully not) make this mistake! The serial lines are connected to digital pins 0 and 1 on the Arduino. You usually don’t want to connect anything else to these lines.

  15. Anatomy of a for loop in Arduino Serial monitor output The variable i here is our counter You need to declare the variable with “int” Example: for(inti = 0; i<10 ; i++) { Serial.println(i); } This section says to run the loop while the counter i is less than 10 This section says to add 1 to our counter each time through the for loop This code will now run 10 times

  16. Functions Also sometimes called subroutines Functions are a great way to organize your code. They allow you to break your code in small pieces and they help you troubleshoot. The two main types of functions we will use are void and int, but you can also use other data types if needed.

  17. Functions example: int add(int a, int b) { int c = a + b; return c; } To call “add” in your code: sum = add(num1,num2);

  18. Functions help make your code much more readable

  19. Part 3 – Project Advice

  20. Consider using the “V Model” of mechatronic design when working on your project System Design System Test Subsystem Design Subsystem Test Single Part Design Single Part Test Code Vasić, Vasilije S., and Mihailo P. Lazarević. "Standard industrial guideline for mechatronic product design." FME Transactions 36.3 (2008): 103-108.

More Related