IoT Programming the Particle Photon.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 6 Digital Inputs
Advertisements

EMS1EP Lecture 8 Pulse Width Modulation (PWM)
Lab7: Introduction to Arduino
ARDUINO FRAMEWORK.
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.
Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay.
Introduction.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
chipKit Sense Switch & Control LED
Microprocessors Tutorial 1: Arduino Basics
Practical Electronics & Programming
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Cascade switching of an LED EAS 199B Winter 2013.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Pulse Width Modulation (PWM). 100% Pulse Width Modulation (PWM) 0% On the chipKIT there are 490 periods per second. Use analogWrite(pin, value) to control.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
Microprocessors Tutorial 1: Arduino Basics
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.
Microcontroller basics Embedded systems for mortals.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Microcontroller basics Embedded systems for mortals.
Lecture 9: Introduction to Arduino Topics: Arduino Fundamentals, Bean Date: Mar 22, 2016.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
Hacking on Arduino George Patterson
Arduino.
Getting Started: Building & Programming
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Introduction to Physical Computing
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
More on LED’s with Arduino
Val Manes Department of Math & Computer Science
Microcontroller basics
Wireless Cue Light Project
Microprocessors Tutorial 1: Arduino Basics
Microcontroller basics
Cascade switching of an LED
Welcome to Arduino A Microcontroller.
Get Your Project Started with Arduino
Lab 1: Arduino Basics Topics: Arduino Fundamentals, First Circuit
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Въведение в Arduino.
Arduino - Introduction
How to avoid catching things on fire.
Introduction to Arduinos
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
Continuing with LED’s and Arduino
using the Arduino to make LEDs flash
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Putting the I in IoT.
Arduino programs Arduino toolchain Cross-compilation Arduino sketches
Programming 2: The Arduino IDE & First Sketches
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
Sensors and actuators Sensors Resistive sensors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Arduino Motor Lab Inspired by NYU ITP project
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to Arduinos
Interrupts.
Presentation transcript:

IoT Programming the Particle Photon

Cloud Service sensor Browser actuator Photon

Pins Input Pin - reads voltage at that point in the circuit Output Pin - allows voltage to flow out from that point in the circuit Can be digital or analog

build.particle.io/ Build: Web IDE Flash Verify Save

Build: Web IDE Code Library Docs Devices Settings

New App: void setup() { } void loop() {

C stuff Define stuff before you use it. Arrays: int[] nums = {1,2,3,4}; Constants: Use “const” (not “final”)

C(++) Strings Photons let you use Strings and some String functions like you’re used to: String message = “message”; You should know that underneath it is an array of characters with a null character at the end.

C Characters char letter = ‘c’; But chars are really ints. int index = ‘c’ - ‘a’; // index is now 2. if (letter >= ‘a’ && letter <= ‘z’) // if lowercase letter

Pointers Every variable has a name, a value, and a memory address. Consider: int x = 3; &x refers to the address of variable x.

Pointers To store the address of a variable, you need a pointer type. Declare variables with a star: int x = 3; int* ptr = &x;

Pointers If you have a pointer variable, you can retrieve the value of the variable it points to. int x = 3; int* ptr = &x; int y = *ptr; // What’s the value of y?

int x = 3; int* ptr = &x; int y = *ptr; ADD NAME TYPE VALUE 1000 x int 2000 ptr int* 3000 y

int x = 3; int* ptr = &x; int y = *ptr; ADD NAME TYPE VALUE 1000 x int 2000 ptr int* 3000 y

int x = 3; int* ptr = &x; int y = *ptr; ADD NAME TYPE VALUE 1000 x int 2000 ptr int* 3000 y

Photon stuff There are constants (ints) named after the pins and also for INPUT, OUTPUT, HIGH, LOW, … Spark.function Spark.variable Be careful with the terminology

Hello World void setup(){ RGB.control(true); } void loop(){ RGB.color(255,0,0); delay(2000); RGB.color(0,255,0); delay(2000); RGB.color(0,0,255); delay(2000); }

Let’s add a light

Controlling the light int ledPin = D7; void setup(){ pinMode(ledPin, OUTPUT); } ... digitalWrite(ledPin, HIGH); // light on delay(1000); // wait one second digitalWrite(ledPin, LOW); // light off

Input: Switches Use a pin as digital input. Can be either a pull-up or pull-down (or neither, technically)

Pull-down Switch sits between the input pin and the voltage source. Switch off = Low voltage to input pin

Pull-down Issue with pull-down: What if circuit is built with pin still in output mode? Can cause a short circuit before the code is flashed.

Pull-up Switch sits between pin and ground. Switch off = High voltage reading We generally use this as it is safer.

I/O!! D7 -> 220R -> LED-> GND D3 -> SWITCH-> GND

Code int ledPin = D7; int switchPin = D3; void setup(){ pinMode(ledPin, OUTPUT); pinMode(switchPin, INPUT_PULLUP); } void loop(){ if(digitalRead(switchPin) == LOW){ // Button is pressed digitalWrite(ledPin,HIGH); else{ digitalWrite(ledPin, LOW); } }

Code Design Write a Morse code flasher. When you press the button the flashing begins. What are the variables? Functions? How will we write it?

Before you go for it... String letters[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // A-I ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", // J-R "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." // S-Z }; Timing: Dot: 200 Dash: 600 Between dots and dashes: 200 Between letters of a word: 400 Between words: 1400 Between messages: 5000

Analog Input The A0-A5 pins can be used for analog input. They give a value from 0 - 4095, telling how much voltage is at that point.

Analog Output Pin DAC (Digital-to-Analog converter) gives true analog output Other A pins (A4 & A5) give “fake” analog output using Pulse Width Modulation Analog outputs are between 0 and 255

Code setup is same as before - tell what is input and what is output. digitalRead becomes analogRead digitalWrite becomes analogWrite

Try a program Set up A5 as an analog output. Connect A5 -> 220 Resistor -> LED -> Ground Set up A0 as an analog input. Connect 3V3 -> Photoresistor -> A0 -> 1K Resistor -> Ground Program: The darker the sensor, the brighter the LED. (Note: Is very sensitive. Try different things. I divided by 500?????)