3.1 Serial Communication Part 1

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Introduction to Sensor Technology Week Four Adam Taylor
Electrical and Computer Engineering iLights Nick Wittemen, EE Chris Merola, EE José Figueroa, EE Matt Ryder, EE Comprehensive Design Review.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Basic Circuits – Lab 2 Arduino and Sensors
Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.
Ballooning Bundle. What is a Microcontroller? Small computer with a processor core, memory and programmable input/output Continuously repeats software.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
Code The Arduino Environment.
Robootika lahenduste esitlus Raul Liinev Martin Ligema Siim Suu Martin Tõnne.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011.
Basic Circuits – Lab 5 Wireless Networking Xmedia Spring 2011.
Rebecca Bruce and Susan Reiser, May 2015 Analog Input and Output.
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.
Serial Communication RS-232. In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated.
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?
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Using a SparkFun™ serial LCD with an Arduino
Having fun with code, using Arduino in a middle school CS classroom
Michael Rahaim, PhD Candidate Multimedia Communications Lab
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Assist. Prof. Rassim Suliyev - SDU 2017
Assist. Prof. Rassim Suliyev - SDU 2017
Prototyping with Microcontrollers and Sensors
Microcontroller basics
More on LED’s with Arduino
Val Manes Department of Math & Computer Science
Manual for Arduino Kit v1.0
Wireless Cue Light Project
Microprocessors Tutorial 1: Arduino Basics
Raspberry Pi <--> Arduino
Arduino Programming Part II
Microcontroller basics
UTA010 : Engineering Design – II
calibration of conductivity sensors
Principles of Information Technology
Tele-presence – Connecting Two Processing Platforms via Internet
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
Arduino - Introduction
Control the color and brightness of an RGB LED with a Potentiometer
Control a motors angular position with a flex sensor
Introduction to Arduino Microcontrollers
3.2 Serial Communication Part 2
Data Encoding Characters.
Roller Coaster Design Project
What is an Arduino ? Open Source electronic prototyping platform based on flexible easy to use hardware and software.
IoT Programming the Particle Photon.
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Last of the LED’s and Arduino
Arduino : Introduction & Programming
Programming 2: The Arduino IDE & First Sketches
Appliace Remote Control
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to Arduinos
Arduino UMBC IEEE Sekar Kulandaivel
CTY SAR FCPS Alexander Velikanov
Presentation transcript:

3.1 Serial Communication Part 1 Using the Serial Port to communicate with an external application.

3.1 Serial Communication Send data from a Potentiometer and a Photoresistor through the Serial Port and utilize the data in Processing software.

3.1 Learning Objectives Receiving and Transmitting data over Serial Using Processing to Receive Information Save Information on an external file

3.1 Functions - Arduino mySerial.available(); Start Serial Monitor mySerial.begin(); Start Serial Communication mySerial.write(); Write data to the port mySerial.read(); Read Data mySerial.listen() Choose which port to listen to

3.1 Connecting to Applications Arduino has no built in interface This is why we use serial communication to send our data to an external Application Arduino > Serial Port; Processing xCode Visual Studios Unity Etc.

3.1 Connecting to Applications Arduino also cannot save data This data has to be sent to an application that has the ability to save to a file to your computer Example Arduino > Serial Port > Processing > .csv File

3.1 Bits and Bytes Group of binary digits or bits operated on as a unit. Byte is a unit of memory size One byte = Eight bits One byte can hold an integer between 0 and 255.

3.1 Byte to Char A Character on your keyboard can be represented as one byte. An ASCII Table is an encoding that represents letters as a byte. Example: 01000001(byte) = 65(int) = A(char)

3.1 Sending and Receiving Bytes Serial communication allows us to only send one byte of data at a time. For example if were trying to send three different bytes of data, we cannot send them all at once over the serial port. We have to send them one at a time.

3.1 Sending and Receiving Bytes Therefore its hard to obtain these bytes in proper order in our external application. To overcome this issue we send and receive these bytes through an Array to keep our data nice and organized when it’s being sent through the serial port.

3.1 Photoresistor A photoresistor is a light-controlled variable resistor The more light the less resistance is provided We are able to get an analog reading from this sensor

3.1 Breadboard Diagram Hardware: Potentiometer Photoresistor 330 Ohm Resistor

3.1 Variable Initialization - Arduino Initialize the variables at the top of the program #include <SoftwareSerial.h> SoftwareSerial mySerial(0,1); // Initialize location (Pin Hole) for the Temperature sensor int xValue; int yValue; int zValue; int myByte[3] = {0, 0, 0}; int potValue; int photoValue; int POT_PIN = A0; int PHOTO_PIN = A1; CODE

3.1 Loop Function - Arduino Start reading our analog values from our sensors and map them to 0- 255 to be sent through the serial port. void loop() { potValue = analogRead(POT_PIN); potValue = map(potValue, 0, 1023, 0, 255); photoValue = analogRead(PHOTO_PIN); photoValue = map(photoValue, 0, 1023, 0, 255); xValue = potValue; yValue = photoValue; zValue = 30; … CODE

3.1 Variable Initialization - Arduino Initialize our variables to 0 in our setup void setup() { // Start our software serial communication mySerial.begin(9600); xValue = 0; yValue = 0; zValue = 0; potValue = 0; photoValue = 0; } CODE

3.1 Loop Function - Arduino Loop function will run on the Arduino infinite times till reset or power is disabled. … // Going to write the byte in order in a for loop we initialize the values into our loop. myByte[0] = xValue; myByte[1] = yValue; myByte[2] = zValue; for (int i = 0; i < 3; i++) { mySerial.write(myByte[i]); } delay(100); CODE

3.1 Variable Initialization - Processing Now we launch our application Processing to receive all our variables import processing.serial.*; String PORT = “COM3”; Serial mySerial; PrintWriter mLogger; int xValue; int yValue; int zValue; int myByte[3] = {0, 0, 0}; float mValue; float mInterpolate; float time; CODE

3.1 Void Setup - Processing In our setup we establish our connection by selecting which port we are going to connect void setup() { // Establish connection through our port mySerial = new Serial(this, PORT, 9600); if (mySerial.available() == 0) { println("Port connection established..."); } delay(2000); mValue = 0; mInterpolate = 0; ... CODE

3.1 Void Setup - Processing ... xValue = 0; yValue = 0; zValue = 0; mLogger = createWriter("DataOutput.csv"); mLogger.println("Time" + "," + "x" + "," + "y" + "," + "z" + "," + "mVal" + "," + "mInter"); size(500, 500); } CODE

3.1 Void Draw - Processing After initialization the variables, we then assign specific functions in order to program. void draw() { println("x:", xValue, "y:", yValue, "z:", zValue, "mVal: ", radians(mValue), "mInter: ", radians(mInterpolate)); mLogger.println(time + "," + xValue + "," + yValue + "," + zValue + "," + radians(mValue) + "," + radians(mInterpolate)); ... CODE

3.1 Void Draw - Processing After initialization the variables, we then assign specific functions in order to program. ... while (mySerial.available() > 3) { for (int i = 0; i < 3; i++) { myByte[i] = mySerial.read(); } // After all the values are stored align them properly in each variable to be used later on. xValue = myByte[0]; yValue = myByte[1]; zValue = myByte[2]; CODE