1 of 40

IT401 Embedded Systems�S7 IT�Module 5��Arduino

2 of 40

Installing IDE

  • Download from Arduino website
  • Unzip to any directory
  • Double click Arduino.exe file

3 of 40

Installing IDE

4 of 40

Arduino IDE

5 of 40

Some common functions

6 of 40

Structure of Arduino sketch

7 of 40

Primitive data types

8 of 40

Arrays

9 of 40

Arrays

10 of 40

Functions

11 of 40

Functions

12 of 40

Returning more than one value using global variable

13 of 40

Returning more than one value using reference variable

14 of 40

Condition testing – if statement

15 of 40

Condition testing – if…else statement

16 of 40

Repeating statements

17 of 40

Variety of actions based on single variable

18 of 40

Operators used in Arduino

19 of 40

Relational Operators

20 of 40

Logical Operators

21 of 40

Bitwise Operators

22 of 40

String Comparison function

  • strcmp() – returns 0 if strings are equal

>0 if first is greater

<0 if second is greater

  • int length = strlen(string);
  • strcpy(destination, source);
  • strncpy(destination, source, 6); // copy up to 6 characters from source to destination
  • strcat(destination, source);

23 of 40

Compound Operators

24 of 40

Functions

  • abs(value);
  • constrain(x, min, max) – ensures value within min-max range
  • min(x,y) – returns minimum value
  • max(x,y)
  • pow(x,y) – x^y
  • sqrt(x)
  • floor(x), ceil(x) – rounding off
  • Trigonometric functions – sin(x), cos(x)
  • random(min,max)

25 of 40

Reading and setting bits

<< - bit shift left

>> - bit shift right

26 of 40

Arduino interaction with Computer and other devices – Serial Communication

27 of 40

Serial Communication

  • Provides an easy and flexible way for Arduino board to interact with computer and other devices
  • Also a handy tool for debugging
  • Arduino IDE provides a Serial Monitor to display serial data received from Arduino

28 of 40

Serial Communication

  • Arduino sketch can use the serial port to indirectly access all the resources that the computer has
  • Computer can also use serial port to interact with sensors or other devices connected to Arduino
  • Serial communication involves hardware and software
  • Hardware provides electrical signaling between the Arduino and the device
  • Software uses hardware to send bytes or bits

29 of 40

Serial hardware

  • Sends and receives data as electrical pulses
  • O volts – bit 0 and 5 volts – bit 1
  • Most Arduino boards have a chip to convert the hardware serial port to USB for connection to the hardware serial port
  • Some Arduino boards uses adapter to convert TTL to USB
  • Standard Arduino has single hardware serial port
  • Arduino Mega has 4 hardware serial ports

30 of 40

Serial hardware

  • Arduino Mega has 4 hardware serial ports

31 of 40

Serial Software

  • Built in libraries available
  • Serial libraries simplifies the use of serial ports by insulating you from hardware complexities
  • If more serial ports than the number of hardware serial ports are needed, we can use additional library that uses software to emulate serial hardware

32 of 40

Serial Message Protocol

  • Hardware and software serial libraries handle sending and receiving information
  • Often consists of group of variables to sent together
  • Receiving side needs to recognize beginning and end of message
  • Communication protocol – formal organization of information in a message and range of appropriate responses to requests
  • Header – one or more special character to identify start of message
  • Footer – one or more special character to identify end of message

33 of 40

Sending debug information from Arduino to computer

34 of 40

Sending debug information from Arduino to computer

35 of 40

Sending formatted text and numeric data from Arduino

36 of 40

Sending formatted text and numeric data from Arduino

37 of 40

Receiving Serial Data in Arduino

38 of 40

Sending Binary data from Arduino

39 of 40

Receiving Binary data from Arduino

40 of 40

Setting up processing on computer to send and receive serial data