Module: j5e/mf52a103j3470

Description

A module for measuring temperature using a MF52A103J3470 thermistor.

A thermistor is a type of resistor whose resistance is strongly dependent on temperature, more so than in standard resistors. The word thermistor is a portmanteau of thermal and resistor.Read more on Wikipedia

Requires


Class: MF52A103J3470

The MF52A103J3470 class allows for reading of MF52A103J3470 thermistors°

Constructor

new MF52A103J3470(io)

Parameters

Name
Type
Description
io
(required)
number, string, or object

Description:
Pin identifier or IO Options (See instantiation)

Example

// Use an MF52A103J3470
import MF52A103J3470 from "j5e/tmp36";

const myMF52A103J3470 = await new MF52A103J3470(12);

myMF52A103J3470.on("change", function(data) {
  trace(data.C);
});

Properties

Name
Type
Description
celsius
(read only)
number
Get degrees in celsius
C
(read only)
number
Alias for celsius
fahrenheit
(read only)
number
Get degrees in fahrenheit
F
(read only)
number
Alias for fahrenheit
kelvin
(read only)
number
Get degrees in kelvin
K
(read only)
number
Alias for kelvin
limit
Array.<number>
Limits the output range
threshold
number
The minimum amount of change required to emit a "change" event
interval
number
The interval between readings (in ms)
smoothing
number
The number of samples to take before finding the median
aref
number
The reference voltage
samples
number
The number of samples to take before finding the median
range
(read only)
Array.<number>
The input range of the sensor
raw
(read only)
number
Get the most recent raw ADC reading
median
(read only)
number
Get the most recent median ADC reading
resolution
(read only)
number
The maximum possible ADC reading
scaled
(read only)
number
Get the most recent scaled raw reading
value
(read only)
number

Events

  • event:data
  • event:change

Methods

MF52A103J3470.configure

Note: This method is not part of the public API, and is subject to change.

Configure an MF52A103J3470

mf52a103j3470.configure();

Returns: The instance on which the method was called

Example

// Passing in Cofiguration Options
   import MF52A103J3470 from "j5e/mf52a103j3470";

const thermometer = await new MF52A103J3470({
  pin: 14
});

thermometer.on("change", data => {
  trace(thermometer.celsius);
});

MF52A103J3470.configure

Note: This method is not part of the public API, and is subject to change.

Configure a Thermometer

mf52a103j3470.configure(options);

Returns: The instance on which the method was called

Parameters

Name
Type
Description
options
(required)
object

Description:
Device configuration options

options.aref
number

Description:
Analog reference voltage
Default: 3.3

options.enabled
boolean

Description:
Wether the device is currently performing reads every ms
Default: true

options.interval
number

Description:
Interval between readings in millseconds
Default: 100

options.limit
Array.<number>

Description:
Limit the output range

options.range
Array.<number>

Description:
The input range of the sensor
Default: [0, N]

options.scale
Array.<number>

Description:
The output range for the sensor's value
Default: [0, N]

options.threshold
number

Description:
The minimum amount of change required to emit a "change" event
Default: 1

options.toCelsius
callback

Description:
Function that converts raw value to Celsius

Example

// Passing in Cofiguration Options
   import Thermometer from "j5e/thermometer";

const thermometer = await new Thermometer({
  pin: 14
});

myThermometer.configure({
  toCelsius: function(raw) {
    return raw / 16;
  }
});

thermometer.on("change", data => {
  trace(thermometer.celsius);
});

MF52A103J3470.enable

Enable a disabled sensor.

mf52a103j3470.enable();

Returns: instance

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

sensor.disable();

// Wait 5 seconds and then take readings
timer.setTimeout(function() {
  sensor.enable();
});

MF52A103J3470.disable

Disable an enabled sensor.

mf52a103j3470.disable();

Returns: instance

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

// Take reading for 5 seconds and then stop
timer.setTimeout(function() {
  sensor.disable();
});

MF52A103J3470.read

Synchronous read of a sensor.

mf52a103j3470.read();

Returns: sensor value

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

let myValue = sensor.read();

MF52A103J3470.scale

scale/scaleTo Set a value scaling range

mf52a103j3470.scale(low, high, low, high);

Returns: instance

Parameters

Name
Type
Description
low
(required)
Number

Description:
Lowerbound

high
(required)
Number

Description:
Upperbound

low, high
Array

Description:
Lowerbound

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

// Scale all future values to 8-bit range
sensor.scale([0, 255]);

MF52A103J3470.scaleTo

scaleTo Scales value to integer representation

mf52a103j3470.scaleTo(low, low, high);

Returns: The scaled value

Parameters

Name
Type
Description
low
(required)
Number

Description:
An array containing a lower and upper bound

low
(required)
Number

Description:
A number to use as a lower bound

high
(required)
Number

Description:
A number to use as an upper bound

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

// Scale the returned value to 8-bit range
sensor.scaleTo([0, 255]);

MF52A103J3470.fscaleTo

fscaleTo Scales value to single precision float representation

mf52a103j3470.fscaleTo(low, low, high);

Returns: The scaled value

Parameters

Name
Type
Description
low
(required)
Number

Description:
An array containing a lower and upper bound

low
(required)
Number

Description:
A number to use as a lower bound

high
(required)
Number

Description:
A number to use as an upper bound

Example

import Sensor from "j5e/sensor";

const sensor = await new Sensor(12);

// Scale the returned value to float between 0 and 1
sensor.fscaleTo([0, 1]);

MF52A103J3470.within

Fire a callback when the value is within a certain range

mf52a103j3470.within(range, unit, callback);

Parameters

Name
Type
Description
range
(required)
Array.<number>

Description:
The upper and lower ends of the range to watch

unit
(required)
string

Description:
The property to test

callback
(required)
function

Description:
A callback to run when the event is fired.


MF52A103J3470.on

Create an event listener

mf52a103j3470.on(event, listener);

Parameters

Name
Type
Description
event
(required)
string

Description:
The name of the event to listen for

listener
(required)
function

Description:
A callback to run when the event is fired.


MF52A103J3470.removeListener

Remove an event listener

mf52a103j3470.removeListener(event, listener);

Parameters

Name
Type
Description
event
(required)
string

Description:
The name of the event that we are removing a listener from

listener
(required)
function

Description:
The callback that we are removing


MF52A103J3470.emit

Note: This method is not part of the public API, and is subject to change.

Emit an event

mf52a103j3470.emit(event);

Parameters

Name
Type
Description
event
(required)
string

Description:
The name of the event to emit


MF52A103J3470.once

Create an event listener that will only fire one time.

mf52a103j3470.once(event, listener);

Parameters

Name
Type
Description
event
(required)
string

Description:
The name of the event to listen for

listener
(required)
function

Description:
A callback to run when the event is fired.


MF52A103J3470.configure

Configure a Thermometer

mf52a103j3470.configure(options);

Returns: The instance on which the method was called

Parameters

Name
Type
Description
options
(required)
object

Description:
Device configuration options

options.aref
number

Description:
Analog reference voltage
Default: 3.3

options.enabled
boolean

Description:
Wether the device is currently performing reads every ms
Default: true

options.interval
number

Description:
Interval between readings in millseconds
Default: 100

options.limit
Array.<number>

Description:
Limit the output range

options.range
Array.<number>

Description:
The input range of the sensor
Default: [0, N]

options.scale
Array.<number>

Description:
The output range for the sensor's value
Default: [0, N]

options.threshold
number

Description:
The minimum amount of change required to emit a "change" event
Default: 1

options.toCelsius
callback

Description:
Function that converts raw value to Celsius

Example

// Passing in Cofiguration Options
   import Thermometer from "j5e/thermometer";

const thermometer = await new Thermometer({
  pin: 14
});

myThermometer.configure({
  toCelsius: function(raw) {
    return raw / 16;
  }
});

thermometer.on("change", data => {
  trace(thermometer.celsius);
});