Skip to content

Class Description : Functions and Variables

Mark Miller edited this page Mar 21, 2017 · 13 revisions

Photon Class - Python

On this page you will find a description of the Matlab class file used to access the Particle Photon. For examples on how to use this class see:

Setting Up a Particle Photon

Example 1: Read and Write Pins

Example 2: Servos and PWMs

To download the class file follow this link Photon.m

Constructor

Photon(String name, String access_token)

Arguments

  • String name - Photon ID or Photon name. Requires setup of Particle Photon
  • String access_token - Authorization token retrieved from build.particle.io

Returns

  • A Photon object that knows how to access the following functions and methods.

Functions

analogRead

analogRead(String pin)

Sample the voltage of an analog pin.
Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • A value corresponding to 0-3.33V.

analogWrite

analogWrite(String pin, Int Value)

Writes a voltage value to an analog pin.
Arguments

  • String pin - The name of the pin connected to sample.
  • Int value - The bit value to write. Takes a value between 0-3.33V.

Returns

  • None

attachServo

attachServo(String pin)

Each Photon can support a single servo attachment. Attaches a servo object to the Photon at the given pin.
Arguments

  • String pin - The name of the pin connected to the servo signal input.

Returns

  • None

detachServo

detachServo()

Detaches a servo object, if one is attached.
Arguments

  • None

Returns

  • None

digitalRead

digitalRead(String pin)

Sample the bit value of a digital pin.
Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • The bit value at that pin. Takes value of 0 for LOW and 1 for HIGH.

digitalWrite

digitalWrite(String pin, Int Value)

Writes a bit value to a digital pin.
Arguments

  • String pin - The name of the pin connected to sample.
  • Int value - The bit value to write. Takes a value of 0 or 1 corresponding to HIGH or LOW.

Returns

  • None

fetch

fetch(String variable)

Returns the value associated with the given Particle variable.
Arguments

  • String variable - Name of the variable that you want to query

Returns

  • The value associated with that variable

flash

flash(file=String filepath)

Requires the requests module. Compiles and uploads a local file to the Particle Photon.
Arguments

  • String filepath - File path to the file(s) that you want to flash as the Photon sketch.

Returns

  • None

getConnection

getConnection()

Tells whether the Photon is connected to the internet or not.
Arguments

  • None

Returns

  • Returns True if the device associated with the Photon's name is connected to the internet and False if the device is not.

getDevices

getDevices()

Prints the name and status of every device connected with the Particle account
Arguments

  • None

Returns

  • None

getFunctions

getFunctions()

Prints the list of functions that can be executed by the Photon.
Arguments

  • None

Returns

  • None

getPin

getPin(String pin)

Converts the name of the string to the integer value associated with that pin.
Arguments

  • String pin - The name of the pin connected to get the integer value of.

Returns

  • None

getPinMode

getPinMode(String pin)

Prints whether a pin is an input or output pin
Arguments

  • String pin - The name of the pin connected to get the mode of.

Returns

  • None

getTone

getTone(String pin)

Returns the frequency of a square wave from a given pin, passed by String argument pin
Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • The frequency of the pulsed signal

getVariables

getVariables()

Prints the list of variables currently available for query on the Photon.
Arguments

  • None

Returns

  • None

move

move(Int position)

Moves an attached servo object to the position
Arguments

  • Integer position - Numerical position where the servo will move

Returns

  • If successful returns the new position.

push

push(String functions, String value)

Executes a Photon function and sends it a value
Arguments

  • String functions - Name of the function that you want to execute
  • String value - Value/parameter to send to the function

Returns

  • The value returned by the function

setFreq

setFreq(Int frequency)

Designates the frequency at which analogWrite/PWM outputs a signal Arguments

  • Int frequency - The frequency in Hz that analogWrit will output a signal

Returns

  • 1 if successful, -1 if already designated as an input/output

setInput

setInput(String pin)

Designates a pin to be an input pin
Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • 1 if successful, -1 if already designated as an input/output

setOutput

setOutput(String pin)

Designates a pin to be an output pin
Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • 1 if successful, -1 if already designated as an input/output

mrcylinder

mrcylinder

Requests pressure data for the cylinder from the Particle Photon cloud. Need specific access token for the cylinder photon (provided securely during course of lab). Note that the update time for the function is slower due to the multiplexing of all 18+ inputs.

Arguments

  • none

Returns

  • [pt,pb]: pt corresponds to the pressure along the top side (suction side) of the airfoil. pb likewise corresponds to the pressure along the bottom surface. Note that element 1 of pt is the stagnation pressure tap on the front of the cylinder, then the count increases towards the rear before wrapping around the back side of the cylinder (meaning the last element in pb is the bottom tap closest to the stagnation pressure tap).

mrsairfoil

mrsairfoil

Requests pressure data and current angle of attack from the Particle Photon cloud. Need specific access token for the airfoil photon (provided securely during course of lab). Note that the update time for the function is slower due to the multiplexing of all 30+ inputs.

Arguments

  • none

Returns

  • [pt,pb,aoa] output is the form of three variables: pt, pb, and aoa
    • pt: top pressure taps, note that element 1 of pt is the stangation pressure tap on the front of the airfoil
    • pb: bottom pressure taps, note that tap numbering wraps around the trailing edge of the airfoil, meaning that element 1 of pb is the bottom tap closest to the trailing edge.
    • aoa: a double-precision variable containing the current angle of attack.

Variables

position

position

Current position of the connected servo


frequency

frequency

Frequency of the analogWrite and PWM signals


String

String

String record of the sampled data from every pin. Numerical positions corresponds to integer value of the pins.


String2

String2

String record of which pins are input, output, servo, or undesignated