Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Similar documents
Arduino Uno Microcontroller Overview

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

SECOND EDITION. Arduino Cookbook. Michael Margolis O'REILLY- Tokyo. Farnham Koln Sebastopol. Cambridge. Beijing

Course Outline Introduction to C-Programming

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Arduino Prof. Dr. Magdy M. Abdelhameed

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Energia MSP-430!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1

UNIT- 3 Introduction to C++

The Arduino Briefing. The Arduino Briefing

Arduino provides a standard form factor that breaks the functions of the micro-controller into a more accessible package.

Computers Programming Course 6. Iulian Năstac

Introduction to Arduino. Wilson Wingston Sharon

Some Basic Concepts EL6483. Spring EL6483 Some Basic Concepts Spring / 22

Programming, numerics and optimization

Arduino Cookbook O'REILLY* Michael Margolis. Tokyo. Cambridge. Beijing. Farnham Koln Sebastopol

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Why embedded systems?

If you note any errors, typos, etc. with this manual or our software libraries, let us know at

Quick Reference Guide

TANGIBLE MEDIA & PHYSICAL COMPUTING INTRODUCTION TO ARDUINO

A flow chart is a graphical or symbolic representation of a process.

Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

C Language Programming

Arduino notes IDE. Serial commands. Arduino C language. Program structure. Arduino web site:

CS313D: ADVANCED PROGRAMMING LANGUAGE

EL6483: Brief Overview of C Programming Language

Fundamentals of Programming

IME-100 Interdisciplinary Design and Manufacturing

Variables and literals

Quick Reference Guide

6.096 Introduction to C++ January (IAP) 2009

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

PROGRAMMING AND CUSTOMIZING

Introduction to Programming. Writing an Arduino Program

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

INTRODUCTION 1 AND REVIEW

Procedure: Determine the polarity of the LED. Use the following image to help:

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Intel Galileo gen 2 Board

BASIC ELEMENTS OF A COMPUTER PROGRAM

Programming (1.0hour)

BITG 1233: Introduction to C++

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Computer Components. Software{ User Programs. Operating System. Hardware

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

ME 461 C review Session Fall 2009 S. Keres

SOME ASSEMBLY REQUIRED

Fundamental of Programming (C)

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Special Topics for Embedded Programming

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Chapter 2: Basic Elements of C++

micro:bit Lesson 1. Using the Built-in Sensors

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Maciej Sobieraj. Lecture 1

Programming in C++ 5. Integral data types

3. Java - Language Constructs I

Reserved Words and Identifiers

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

CS16 Exam #1 7/17/ Minutes 100 Points total

GUIDE TO SP STARTER SHIELD (V3.0)

DEPARTMENT OF MATHS, MJ COLLEGE

COMP 202 Java in one week

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

The Design of C: A Rational Reconstruction

<Table of content> <Parts and description> <Circuit board Guide> <Pins> <Basics of Coding> <Intro to Arduino> <Intro> <Downloading Arduino IDO>

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

PHPoC vs PHP > Overview. Overview

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

The Design of C: A Rational Reconstruction"

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

Fundamental of C programming. - Ompal Singh

Language Fundamentals Summary

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

Memo on development of the car-rangefinder device/data logger for crosswalk study

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum: Homepage:

Computers Programming Course 5. Iulian Năstac

RoboSpecies Technologies Pvt. Ltd.

EL2310 Scientific Programming

MICROPROCESSORS A (17.383) Fall Lecture Outline

JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course

Short introduction to C for AVR

Programming. C++ Basics

Lecture 03 Bits, Bytes and Data Types

Work relative to other classes

A Fast Review of C Essentials Part I

Sten-SLATE ESP Kit. Description and Programming

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Arduino Part 3. Introductory Medical Device Prototyping

Transcription:

Introductory Medical Device Prototyping Arduino Part 1, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Arduino Uno Power & Interface Reset Button USB Interface 7 to 12 VDC Input Debug LED Digital I/O Pins ICSP Connector ATMega Microcontroller Power & Auxiliary Pins Analog to - Digital Converter Pins 1

USB Connection to Computer Example Modules Sensors Ultrasonic Sensor HC SR04 IR Sensor 2Y0A21 Sharp Digital Distance Sensor MAX6675 Module + K Type Thermocouple Temperature Sensor Diymall Bme280 Pressure Temperature Sensor Module with IIC I2c SunFounder Accelerometer ADXL335 9-Axis Absolute Orientation Sensor Sensor fusion combines the following measurements Absolute Orientation (Euler Vector, 100Hz) Three axis orientation data based on a 360 sphere. Absolute Orientation (Quaterion, 100Hz) Four point quaternion output for more accurate data manipulation. Angular Velocity Vector (100Hz) Three axis of 'rotation speed' in rad/s. Acceleration Vector (100Hz) Three axis of acceleration (gravity + linear motion) in m/s^2. Magnetic Field Strength Vector (20Hz) Three axis of magnetic field sensing in micro Tesla (ut). Linear Acceleration Vector (100Hz) Three axis of linear acceleration data (acceleration minus gravity) in m/s^2. Gravity Vector (100Hz) Three axis of gravitational acceleration (minus any movement) in m/s^2. Temperature (1Hz) Ambient temperature in degrees celsius. Courtesy of Adafruit 2

Actuators Standard Size High Torque Metal Gear Servo Stepper Motor DC Motor with Gear 2 Channel 5 V Solid State Relay Module User Interface Diymall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module 7 Segment Serial Display Red Adafruit 1.8 Color TFT LCD Display with MicroSD Card Breakout ST77 35R1.8" Color TFT LCD display with MicroSD Card Breakout ST7735R Mini ISD2548 Digital Voice Recorder Consider this Device Concept Task: Make a digital thermometer consisting of an enclosure, microcontroller board, thermocouple sensor, digital display, sound alert, slide switch, pushbutton and battery. http://store-usa.arduino http://www.thermometricscorp.com http://www.globalsources.com 3

Formulate an Algorithm 1. When the pushbutton is pressed Measure the temperature, Beep when the reading is good, Display the value for ten seconds, and finally Save the value to memory. 2. Start all over again. 3. Now flowchart this Flowchart the Algorithm Start Monitor for Button Press Button Pressed? No Yes Read Temperature Store Value Valid Reading? No Yes Stop Clear Display Delay 10 Sec. Display Temperature & Beep Software & Programming 1. Software is the smart in your smart device. 2. An algorithm displayed as a flowchart, transforms your problem into various input, processing, decision and output steps 3. Lines of code are written to implement your algorithm. 4. Code may be written in assembly language and/or higher level languages such as C, C++, and C#. 5. A compiler converts your code into machine language that the microcontroller understands. 6. The compiled code is then uploaded into a board containing the microcontroller, memory and various interface circuits. 7. Errors are then fixed by debugging. 8. You may write your own code and/or incorporate code that has been written by others ( sketches ). 4

Integrated Development Environment (IDE) Editor To write your code in C (.c) and/or assembly (.a) language. A finished program is called a sketch. Compiler Turns your code into machine readable instructions or object files (.o). A Linker combines this code with the standard Arduino Libraries, producing a single hex file (.h). Means to Upload Transferring the hex file to the Arduino board program memory. This is done via the USB or serial connection with the aid of the bootloader. Means to Run Executing the Program Means to Debug Finding & Correcting Errors Programs are Written in C and/or Assembly Language Arduino Bootloader & Firmware Bootloader is resident code that runs when the board is powered on or reset. It is programmed via the ICSP with a programmer. This code configures the board and USB port for your subsequent use and programming directly from your computer. You can instead remove the bootloader to save memory and program directly through the ICSP header. 5

Arduino Programming Components 1. Structures A. Setup & loop B. Control statements C. Syntax D. Arithmetic operators E. Comparison operators F. Bitwise operators G. Compound operators 2. Variables A. Constants B. Data Types C. Variable Scope D. Qualifiers E. Conversion F. Utilities Items in blue will be covered in this lecture, items in red in Arduino Part 2, and green in Arduino Part 3. 3. Functions A. Digital I/O B. Analog I/O C. Due & Zero only D. Advanced I/O E. Time F. Math G. Trigonometry H. Characters I. Random numbers J. Bits and bytes K. External interrupts L. Interrupts M. Communication N. USB 1. Structures: Setup() Example 1) Initialize variables 2) Assign pins 3) Runs once, after powerup or reset. int buttonpin = 3; void setup() Serial.begin(9600) ; //serial baud rate pinmode(buttonpin), INPUT); //assign pin 3 to be an input void loop() Loop() Example 1. Occurs after setup. 2. Loops consecutively 3. Initialize variables 4. Assign pins 5. Runs once, after powerup or reset. 6. Variations: if, ifelse; if-else-if int buttonpin = 3; void setup() Serial.begin(9600) ; //serial baud rate pinmode(buttonpin), INPUT); //assign 3 to be an input void loop() if(digitalread(buttonpin) == HIGH) Serial.write( H ); else serial.write( L ); delay(1000); 6

Control Statements Loop Statements For While Do-While Decision Statements Break and Continue If If-Else, if-else-if Switch-Case Directional Goto Return Arrays 1. The first element is indexed with zero, e.g. a[3] has 3 elements, a[0], a[1], and a[2]. 2. Declare as usual, e.g. int a[3], float a[3], and char a[3]. 3. Initialize: int a[3] = 2, 6, 1. 4. Ok to initialize using a for loop. 5. If number of elements is not stated, the initialization will determine it, e.g. int a[ ] = 2, 6, 1 elements will be three. 6. Arrays may be multidimensional, e.g. a[3, 5]. 7. Two dimensional (rows and columns) can also be written, e.g. int M[4] [5] (remember there is a zero row and column). 8. Number of elements may be determined by a variable in which case range check first. For Statement (a Loop) Statement Format Example Code for (initialization; condition; increment) program statement(s); Example What is the value of the a[49] element? int a[100]; for (int n = 0; n < 100; n = n + 1) a[n] = n * 2; 7

While Statement (a Loop) while (expression a boolean that is true or false) program statement(s); Example What is the value of a[30] element? int a[100]; int n = 0; while (n < 100) a[n] = n * 3; n = n + 1; // Could also use ++n Do-while Statement (a Loop) do program statement(s) while (test condition); Example What is the value of a[75] element? int a[100]; int n = 0; do a[n] = n * 4; n = n + 1; while n < 100; If Statement (a Decision) if (expression) program statement(s); Example What is the value of n? int a = 4, n = 0; if a <= 5 n = n + 50; 8

If-Else Statement (a Decision) if (expression) program statement(s); else program statement(s); Example What is the value of n? int a = 10, n = 0; if a <= 5 n = n + 50; else n = n + 25; Switch Case Statement (a Decision) switch (expression) case label1: program statements; break; case label2: program statements; break; default: program statements; break; For example: int a; Bool buy; a = 2; switch (a) case 1: // if a =1 buy = true; break; case 2: // if a =2 buy = false; break; Syntax ; Used to end a statement Enclose statements, keep balanced // Start comment until end of line /* */ Multi-line comment #define #include Assigning a value to a constant name Follows C rules and no semicolon afterwards Use const type variable = value (e.g. const float pi = 3.14) when able instead. To include outside libraries 9

Arithmetic & Boolean Operators = assignment operator + addition - subtraction * multiplication / division % modulo && and or! not Comparison & Pointer Operators == equal to!= not equal to < less than > greater than <= less than or equal to >= greater than or equal to * dereference & reference Bitwise & Compound Operators & bitwise and bitwise or ^ bitwise xor ~ bitwise not << bit shift left >> bit shift right ++ increment -- decrement += compound addition -= compound subtraction *= compound multiplication /= compound division %= compound modulo &= compound bitwise and = compound bitwise or 10

2. Variables: Constants 1. true false (typed in lower case) 1. false is defined as zero 2. true is defined as one, or any boolean test of an integer that is non-zero. 2. Integer constants: Decimal 123 Binary B11110000 (leading B) Octal 0173 (leading zero) Hexadecimal 0x7B (leading 0x) 4. By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with a: 'u' or 'U' to force the constant into an unsigned data format. Example: 33u 'l' or 'L' to force the constant into a long data format. Example: 100000L ul or 'UL' to force the constant into an unsigned long constant. Example: 32767ul 5. Floating point constants: Constant Evaluates to Also 10.0 10 2.34E5 2.34 * 10^5 234000 67e-5 67.0 * 10^-5.00067 11

Data Types 1. boolean (8 bit) - simple logical true/false (1 byte = 8 bits) 2. byte (8 bit) - unsigned number from 0-255 3. char (8 bit) - signed number from -128 to 127. The compiler will attempt to interpret this data type as a character in some circumstances, which may yield unexpected results 4. unsigned char (8 bit) - same as byte ; if this is what you re after, you should use byte instead, for reasons of clarity 5. word (16 bit) - unsigned number from 0-65535 (1 word = 2 bytes) 6. unsigned int (16 bit)- the same as word. Use word instead for clarity and brevity. https://learn.sparkfun.com/tutorials/data-types-in-arduino 7. int (16 bit) - signed number from -32768 to 32767. This is most commonly what you see used for general purpose variables in Arduino example code provided with the IDE. 8. unsigned long (32 bit) - unsigned number from 0-4,294,967,295. The most common usage of this is to store the result of the millis() function, which returns the number of milliseconds the current code has been running. 9. long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647 10. float (32 bit) or double- signed number from -3.4028235E38 to 3.4028235E38. Floating point on the Arduino is not native; the compiler has to jump through hoops to make it work. If you can avoid it, you should. https://learn.sparkfun.com/tutorials/data-types-in-arduino Conversion char() - Converts a value to the char data type. byte() - Converts a value to the byte data type. int() - Converts a value to the int data type. word() - Converts a value to the word data type or creates a word from two bytes. long() - Converts a value to the long data type. float() - Converts a value to the float data type. 12

Variable Scope & Qualifiers 1. A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a global variable. For loop variables are local. 2. Static - the static keyword is used to create variables that are visible to only one function. 3. Volatile - a keyword known as a variable qualifier, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable. e.g. volatile int state = LOW; Specifically, it directs the compiler to load the variable from RAM and not from a storage register. A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine. Summary Arduino Uno, sensors and actuator examples. Using an IDE, programs are typically written in C and assembly language, compiled, linked with libraries and uploaded onto the Arduino board memory as hexadecimal code. Structures, variables and functions comprise an embedded program. 13