Microcontroller basics Embedded systems for mortals.

Slides:



Advertisements
Similar presentations
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Advertisements

How to use Arduino By: Andrew Hoffmaster.
SPI Serial Peripheral Interface. SPI Serial Peripheral Interface is communication between two devices, one bit at a time sequential one bit at time over.
Lecture 8: Serial Interfaces
Intro to the Arduino Topics: The Arduino Digital IO Analog IO Serial Communication.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
Serial Communication Buses: I 2 C and SPI By Brody Dunn.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Robotics Research Laboratory Louisiana State University.
Parallax 4x20 LCD (part number 27979) with Arduino Duemilanove
Little arduino microcontrollers Meghan Jimenez 12 February 2014.
Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.
Intro to the Arduino Topics: The Arduino Digital IO
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
Ballooning Bundle. What is a Microcontroller? Small computer with a processor core, memory and programmable input/output Continuously repeats software.
4.0 rtos implementation part II
Input/Output mechanisms
7/23 Inter-chip Serial Communication: SPI and I 2 C Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee.
EE 446 Project Assignment Top Design Sensor Components Pin Assignment and Configuration Completed Physical Setup Project Tasks.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Lecture 20: Communications Lecturers: Professor John Devlin Mr Robert Ross.
INTERFACING WEB SERVER WITH A ROBOT
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK
Autonomous Helicopter James LydenEE 496Harris Okazaki.
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
智慧電子應用設計導論(1/3) Arduino MEGA 2560
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.
HMC5883L TYWu.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
BMP085 Barometric Digital Pressure Sensor Module TYWu.
Department of Electronic & Electrical Engineering Serial interfaces Serial Interfaces allow communication between devices sending one bit at a time. In.
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.
Youn-Hee Han, In-Seok Kang {yhhan, Laboratory of Intelligent Networks Advanced Technology Research Center Korea University of Technology.
Microcontroller basics Embedded systems for mortals.
Embedded Communication Protocols Don Heer 10/18/10 1.
Serial Communication RS-232. In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated.
AAPT workshop W03 July 26, 2014 Saint Cloud State University, MN, USA
Microcontroller basics Embedded systems for mortals.
Networked Embedded Systems Sachin Katti & Pengyu Zhang EE107 Spring 2016 Lecture 9 Serial Buses – SPI, I2C.
Microcontroller basics
Electronic instrumentation Digitization of Analog Signal in TD
1 of 20 How to use the Compass A. Compass. 2 Compass: - Provides heading relative to Magnetic North, not true North HMC5883L V input - I2C (not.
Microcontroller basics Embedded systems for mortals.
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.
Arduino.
Lab 7 Basic 1: Game of Memory
Assist. Prof. Rassim Suliyev - SDU 2017
Serial Communication Originally created by Anurag Dwidedi and Rudra Pratap Suman.
Assist. Prof. Rassim Suliyev - SDU 2017
Serial Communication Buses: I2C and SPI
Microcontroller basics
Manual for Arduino Kit v1.0
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
Microcontroller basics
Arduino Part 1 Topics: Microcontrollers Programming Basics
Chapter D – Serial Connections to the RPi and Analog-to-Digital Converters
Communication Lines Fundamentals.
Week 5: Microcontrollers
BJ Furman ME 106 Fundamentals of Mechatronics 15NOV2012
Asynchronous Serial Communications
Debugging Debug environments Debug via serial
Arduino : Introduction & Programming
Programming 2: The Arduino IDE & First Sketches
Introduction to Arduino
UNIT 12 SERIAL INTERFACE.
UNIT 12 COMMUNICATIONS.
Presentation transcript:

Microcontroller basics Embedded systems for mortals

Lesson 3 Serial communication (Devices) I2C communication SPI communication Using a heatsensor

Serial communication Point-to-point communication between two devices Requires two wires minimum (RX and TX) Also recommended to connect the ground wires of the devices together TTL (transistor-transistor-logic) and RS232 voltage levels are different!

Serial communication

Adjustable parameters: Baud rate - Communication speed Data bits - Number of actual data bits in one byte Stop bit - Length of the stop after each sent byte Parity - Used for error checking

Serial communication with Teensy Provides two hardware serial communication methods Serial communication over USB Serial over RX and TX pins (2 & 3) – Works using Serial1 -class in Arduino IDE

Example 8 - Schematic Using hardware serial with Teensy

Example 8 – Breadboard setup Using hardware serial with Teensy

Example 8 - Code byte rxPin = 2; void setup() { pinMode(rxPin, INPUT_PULLUP); Serial.begin(9600); Serial1.begin(9600); } void loop() { if(Serial.available()) //If you recieve data over the USB serial { Serial1.write(Serial.read()); //Send it to hardware serial } if(Serial1.available()) //If you recieve data over hardware serial { Serial.write(Serial1.read()); //Send it to USB serial } Using hardware serial with Teensy

Arduino C – More Serial functions Serial.available() Serial.write() Returns the number of bytes available in the serial input buffer. Write a single byte into the serial port MORE INFO: Serial.read() Read a single byte from the input buffer

I2C communication Bus type communication (one transmits, multiple receives) All the devices in the bus have a specific 7-bit address Requires 2 wires (SDA & SCL) SDA = Serial Data Line SCL = Serial Clock Line

I2C wiring

I2C communication with Teensy Works using the Wire -library in Arduino IDE Not easily understandable library

Example 9 - Schematic Using I2C with Teensy

Example 9 – Breadboard setup Using I2C with Teensy The ADXL345 in the picture is not the one you have! Check the wiring, you have to do your own.

Example 9 - Code #define ADXL345_I2CADD 0x53 #include void setup() { Wire.begin(); //Start up the Wire librarys I2C Serial.begin(9600); } void loop() { //Wire writing Wire.beginTransmission(ADXL345_I2CADD); // starts communication to address (0x53) Wire.write(0x00); // sets register pointer to the command register (0x00) Wire.endTransmission(); //Wire reading Wire.beginTransmission(ADXL345_I2CADD); // starts communication to address (0x53) Wire.requestFrom(ADXL345_I2CADD, 1); // requestFrom(address, quantity) while(Wire.available()) { Serial.println(Wire.receive(), BIN); //show the } Wire.endTransmission(); delay(200); } Using I2C with Teensy

Example 10 1/2 #define ADXL345_I2CADD 0x53 #include byte accelData[2]; //make a vector with a lenght of 2 void setup() { Wire.begin(); Serial.begin(9600); Wire.beginTransmission(ADXL345_I2CADD); //start transmission to device Wire.write(0x2D); // 0x2D is the Power Control register of the ADXL345 Wire.write(0x08); // send value to write (0x08 = 8), so it goes to Measure mode (datasheet) Wire.endTransmission(); //end transmission } Read acceleration value of X-axis with I2C

Example 10 2/2 void loop() { Wire.beginTransmission(ADXL345_I2CADD); Wire.write(0x32); // Go to place in memory where the data acceleration values start, first // two are x-axis. (It needs two bytes for reading 13 bit resolution data) Wire.endTransmission(); Wire.beginTransmission(ADXL345_I2CADD); //begin transmission to 0x53 address Wire.requestFrom(ADXL345_I2CADD, 2); //get two bytes from the adress 0x53 int i = 0; while(Wire.available()) { accelData[i] = Wire.receive(); //write the x-axis acceleration value to the vector i++; } Wire.endTransmission(); i = (int)accelData[1]<<8 | accelData[0]; //left-Bit shifting and bitwise OR two add these //bytes together Serial.println(i); //print the value delay(100); } Read acceleration value of X-axis with I2C

SPI communication Bus type communication The desired recipient is select individually with dedicated wire Requires 2 or 3 wires for the communication +1 wire for each device in the bus Slaves send data to master at the same time when master is sending data to them Our example is the 3 wire spi (MISO, MOSI, SCLK pins) Works using the SPI -library in Arduino IDE

SPI wiring

Example 11: DYI TMP36 Tmp36 is a heatsensor It gives you an analog input signal How can you connect it and read values for it?

Example 11: Wiring

Example 11: Code int sensorPin = 38; //the analog pin the TMP36's Vout (sense) pin is connected to //the resolution is 10 mV / degree centigrade with a //500 mV offset to allow for negative temperatures void setup(){ Serial.begin(9600); //Start the serial connection } void loop() { int reading = analogRead(sensorPin); //getting the voltage reading from the temperature sensor float voltage = reading * 5.0; // converting that reading to voltage voltage /= ; Serial.print(voltage); Serial.println(" volts"); // print out the voltage float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset //to degrees ((voltage - 500mV) times 100) Serial.print(temperatureC); Serial.println(" degrees C"); // now print out the temperature (Celsius) delay(1000); //waiting a second }

Feedback Answer to the short survey about the µC exercises Bonus reading: accelerometer-breakout-board.html ADXL345 accelerometer project for Arduino

In next lesson Advanced components in embedded systems PWM and servo motors Stepper motor