Assist. Prof. Rassim Suliyev - SDU 2017

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

EMS1EP Lecture 7 Program Structure and Serial I/O Dr. Robert Ross.
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Lab7: Introduction to Arduino
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Java Programming Strings Chapter 7.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
How to use Arduino By: Andrew Hoffmaster.
Java Strings in 10 minutes
Lecture 8: Serial Interfaces
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Introduction to Sensor Technology Week Four Adam Taylor
Lab session 3 and 4 Topics to be covered Escape sequences Escape sequences Variables /identifiers Variables /identifiers Constants Constants assignment.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Parallax 4x20 LCD (part number 27979) with Arduino Duemilanove
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
DPNM Lab., POSTECH 1/25 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH
Practical Electronics & Programming
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino.
Code The Arduino Environment.
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Photoresistor resistance changes dramatically with light level living with the lab Using Photoresistors with an Arduino © 2011 LWTL faculty team.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Serial Communication RS-232. In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated.
Microcontroller basics Embedded systems for mortals.
Microcontroller basics Embedded systems for mortals.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
INTERNET OF EVERYTHING SDU 2016 Week 12. Remotely Controlling Devices  interact with almost any device that uses some form of remote control  TVs, audio.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Hacking on Arduino George Patterson
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Arduino.
Embedded Systems Intro to the Arduino
Michael Rahaim, PhD Candidate Multimedia Communications Lab
Lab 7 Basic 1: Game of Memory
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Assist. Prof. Rassim Suliyev - SDU 2017
More on LED’s with Arduino
Manual for Arduino Kit v1.0
Wireless Cue Light Project
Arduino & its hardware interfacing
Arduino Programming Part II
Microcontroller basics
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Lecture 2-2: Arduino Programming
Schedule 8:00-11:00 Workshop: Arduino Fundamentals
Intro to the Arduino Topics: The Arduino Digital IO
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Debugging Debug environments Debug via serial
Arduino Part #3 Variables
Programming 2: The Arduino IDE & First Sketches
C Programming Getting started Variables Basic C operators Conditionals
Appliace Remote Control
Lab #1: Getting Started.
Model Blimp Design Competition Programming Workshop by Youth College (International) / VTC May
Presented By,  Mamata Yadav (BE Elex & Comm.) Vice R&D Coordinator(HW), PCRT  Payal Shah (BE Elex & Comm.)  Ananta Das (BE Elex & Comm.) R&D Team,PCRT.
Presentation transcript:

Assist. Prof. Rassim Suliyev - SDU 2017 Embedded SYstems Week 3 Assist. Prof. Rassim Suliyev - SDU 2017

Communicating with Others Arduino can use same USB cable for programming and to talk with computers Talking to other devices uses the “Serial” commands TX – sending to PC RX – receiving from PC

Serial Communications Sends “Hello world!” to your computer Click on “Serial Monitor” button to see output

Arduino Communications Is just serial communications Arduino doesn’t really do USB It really is “serial”, like old RS-232 serial All microcontrollers can do serial Not many can do USB Serial is easy, USB is hard serial terminal from the old days

Serial Communications “Serial” because data is broken down into bits, each sent one after the other down a single wire. The single ASCII character ‘B’ is sent as: Toggle a pin to send data, just like blinking an LED You could implement sending serial data with digitalWrite() and delay() A single data wire needed to send data. One other to receive.

Arduino & USB-to-serial A standard Arduino has a single hardware serial port But serial communication is also possible using software libraries to emulate additional ports

Arduino Mini Arduino Mini separates the two circuits Arduino Mini USB adapter Arduino Mini

Arduino Mega The Arduino Mega has four hardware serial ports Only one of these has a USB adapter built in

Arduino to Computer USB is totally optional for Arduino, but it makes things easier Original Arduino boards were RS-232 serial, not USB All programs that talk to Arduino (even the Arduino IDE) think that they’re talking via a serial port

Arduino & USB Since Arduino is all about serial, and not USB, Interfacing to things like USB flash drives, USB hard disks, USB webcams, etc. is not possible Also, USB is a host/peripheral protocol. Being a USB “host” means needing a lot of processing power and software, not something for a tiny 8kB microcontroller. It can be a peripheral. In fact, there is an open project called “AVR-USB” that allows AVR chips like used in Arduino to be proper USB peripherals

Serial Message Protocol Where each message begins and ends? Sides must agree how information is organized in the message (communications protocol) Header - one or more special characters that identify the start of message Footer - one or more special characters that identify the end of message

Sending Debug Information from Arduino to Your Computer This sketch prints sequential numbers on the Serial Monitor: void setup(){ Serial.begin(9600); // send and receive at 9600 baud } int number = 0; void loop(){ Serial.print("The number is "); Serial.println(number); // print the number delay(500); // delay half second between numbers number++; // to the next number Output is: The number is 0 The number is 1 The number is 2

Baud rate First call the Serial.begin() The function takes a single parameter: the desired communication speed (baud). You must use the same speed for the sending side and the receiving side. baud is a measure of the number of bits transmitted per second

Sending information You can display text using the Serial.print()or Serial.println() function println() – prints the data followed by a carriage return character and a newline character These commands can take many forms Numbers are printed using an ASCII character for each digit Floats are similarly printed as ASCII digits, defaulting to two decimal places Bytes are sent as a single character Characters and strings are sent as is

Strings String message = "This string"; //C++ type strings message.length() //provides thenumber of characters) in the string message.concat(anotherMessage) //appends the contents of anotheMessage to message (also + operator) message.substring(s, e); //returns a substring starting from s till e You can use the indexOf and lastIndexOf functions to find an instance of a particular character in a string char message[8] = "Arduino"; //C type string int length = strlen(message); // return the number of characters in the string strcpy(destination, source); // copy string source to destination strcat(destination, source); // append source string to the end of the destination string if(strcmp(str, "Arduino") == 0) // do something if the variable str is equal to "Arduino"

Comparing C type Strings char str1[ ] = "left"; char str2[ ] = "right"; if(strcmp(str1, str2) == 0) Serial.print("strings are equal) strcmp("left", "leftcenter") == 0) // this will evaluate to false strncmp("left", "leftcenter", 4) == 0) // this will evaluate to true

String Object charAt(n) or [n] - Access a particular character of the String concat(parameter) or + - Appends the parameter to a String endsWith(string2) - Tests whether or not a String ends with string2 equals(string2) or == - Compares two strings for equality (case sensitive) indexOf(val, [strt]) – locates val in a String by searching forward starting from strt index. To search backward use lastIndexOf(val,[strt]) length() - Returns the length of the String, in characters remove(index,[count]) – remove all characters (or count caracters if given) from a String starting from index replace(substring1, substring2) – Replace all instances of substring1 in a String to substring2 setCharAt(index, c) - Sets a character to c at index of the String startsWith(string2) - Tests whether or not a String starts with the string2 substring(from, [to]) - Get a substring of a String, from - inclusive, to – exclusive toInt() or toFloat() - Converts a valid String to an integer or float toLowerCase() or toUpperCase() - Get a lower-case or upper-case version of a String trim() - Get a version of the String with any leading and trailing whitespace removed

Mathematical Operators

Comparing Character and Numeric Values

Logical and Bitwise operators Logical operators Bitwise operators

Combining Operations and Assignment

Advanced Mathematical Operators

Other Useful Operators

Functions type functionName(parameters) { statements; } Functions are declared by first declaring the function type. This is the type of value to be returned by the function such as 'int' for an integer type function. If no value is to be returned the function type would be void. After type, declare the name given to the function and in parenthesis any parameters being passed to the function. int delayVal() { int v; // create temporary variable 'v' v = analogRead(pot); // read potentiometer value v /= 4; // converts 0-1023 to 0-255 return v; // return final value }

Receiving Serial Data in Arduino Serial.available() - Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes) Serial.read() - Reads incoming serial data Serial.readBytes(buffer, length) - reads characters from the serial port into a buffer. The function terminates if the determined length has been read, or it times out

Controlling Arduino int ledPin = 13; // choose a pin for LED int val = 0; // variable to store the data received via Serial port void setup() { pinMode(ledPin,OUTPUT); // make ledPin an output Serial.begin(9600); // initialize the Serial port } void loop () { // Serial.available() – is a method to see whether something is // received or not via Serial port without pausing the main program if( Serial.available() ) { val = Serial.read(); // read the value received via Serial port if( val == 'H' ) { // if ‘H’, then blink digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW);