Skip to content

JavaScript Core API

Overview

Category Description
GPS Access GPS lock data
I2C Read/Write I2C Registers
Pin Control digital pin output
ADC Take ADC measurements
SYS Access system status
Basic Functions Log(), DelayMs(), etc

GPS API

GPS API Description

// Time values (UTC)
gps.GetYear()               // a number, eg 2025
gps.GetMonth()              // a number, eg 1
gps.GetDay()                // a number, eg 2
gps.GetHour()               // a number, eg 19
gps.GetMinute()             // a number, eg 42
gps.GetSecond()             // a number, eg 1
gps.GetMillisecond()        // a number, eg 25

// Latitude values - broken out by degrees, minutes, seconds
gps.GetLatDeg()             // a number, eg 40
gps.GetLatMin()             // a number, eg 44
gps.GetLatSec()             // a number, eg 30

// Latitude values - degrees only
gps.GetLatDegMillionths()   // a number, eg 40741668

// Longitude values - broken out by degrees, minutes, seconds
gps.GetLngDeg()             // a number, eg -74
gps.GetLngMin()             // a number, eg 1
gps.GetLngSec()             // a number, eg 59

// Longitude values - degrees only
gps.GetLngDegMillionths()   // a number, eg -74032986

// Grid values
gps.GetGrid6()              // a string, eg "FN20XR"

// Altitude values
gps.GetAltitudeFeet()       // a number, eg 426
gps.GetAltitudeMeters()     // a number, eg 130

// Speed values
gps.GetSpeedMPH()           // a number, eg 22
gps.GetSpeedKPH()           // a number, eg 35

// Course values
gps.GetCourseDegrees()      // a number, eg 206

These values are available during testing

As you develop your code, the tracker will simulate a genuine GPS lock using the values listed in the API description above.

This helps you work with real values in a repeatable way as you enhance your code.

I2C API

I2C API Description

// Create a new I2C interface
let sensor = new I2C(0x77)

// Detect if the I2C device is operational
sensor.IsAlive()

// Read a 1-byte (8-bit) value from a register
let reg = 0x10
let u8  = sensor.ReadReg8(reg)

// Read a 2-byte (16-bit) value from a register
let reg = 0x10
let u16 = sensor.ReadReg16(reg)

// Write a 1-byte (8-bit) value to a register
let reg = 0x10
let u8  = 0b10010011
sensor.WriteReg8(reg, u8)

// Write a 2-byte (16-bit) value to a register
let reg = 0x10
let u16 = 0x03F2
sensor.WriteReg16(reg, u16)

Example I2C usage

// Create a new I2C interface
let sensor = new I2C(0x77)

// Detect if the sensor is operational
if (sensor.IsAlive()) {
    // Do something
    // ...
} else {
    // Do something else
    // ...
}

I2C HW Details

The I2C bus is operated at 400 Kbit.

SDA = GPIO14.
SCL = GPIO15.

Pullups are enabled on both pins.

Pin API

Suitable for switching on/off sensors via transistor, or powering directly via the GPIO pin.

Pin API Description

1
2
3
4
5
6
7
8
// Create a new Pin interface
let p = new Pin(12)

// Turn the pin on (HIGH output)
p.On()

// Turn the pin off (LOW output)
p.Off()

Example Pin usage

// Create a new Pin interface
let pSensorEnable = new Pin(12)

// Turn on sensor
pSensorEnable.On()

// Wait for sensor to come alive
DelayMs(1)

// Do stuff
// ...

// Turn off sensor
pSensorEnable.Off()

Only some pins are made available for GPIO control

Status GPIO Pin List
Available 10, 11, 12, 13, 20, 21
Unavailable Everything else

GPIO pins can supply a very limited amount of current

The datasheet indicates a maximum of 50mA sink/source total for all GPIO pins.

The output pins are defaulted to 2mA output drive strength each.

You probably don't need to turn your sensor on/off

How much power are you really saving?

But controlling a switch to drop leaflets over North Korea, that's a different question.

ADC API

ADC API Description

1
2
3
4
5
6
7
8
9
// Create new ADC instance
let adc = new ADC(26);

// Read the calculated voltage value assuming 3.3v reference
adc.ReadVolts();

// Read the raw ADC 12-bit value
// (ie a value in the range 0 - 4095)
adc.ReadRaw();

Only some pins can serve as an ADC source

You have access to two ADC GPIO pins -- 26 and 27.

The spec notes there are 4 ADC GPIO pins. This is how they're allocated.

ADC GPIO Allocation
26 Available to use
27 Available to use
28 Not available (used by tracker to switch SI5351 on/off)
29 Not available (used by tracker to measure source voltage -- access via SYS API)

ADC values are multi-sampled and averaged automatically

Each ADC read function will take 100 ADC samples and return the average.

It's instantaneous, don't worry about it.

SYS API

SYS API Description

1
2
3
sys.GetTemperatureFahrenheit()  // eg 55.8
sys.GetTemperatureCelsius()     // eg 13.2
sys.GetInputVoltageVolts()      // eg 3.3

Basic Functions API

Basic Functions API Description

// Print to the screen strings, values, etc, to help debug your program.
Log(output)

// Pause execution of the program for a while, such as after enabling
// a sensor, to give it time to become active.
//
// Delay times are in milliseconds (ms), ie 1,000 ms per second.
//
// A common delay time to let a sensor wake up is less than 5ms.
//
// Note -- There is a STRICT time limit imposed on the execution time of
// a script, after which it will be canceled and the message NOT sent.
// Do NOT delay execution for long periods of time.
//
DelayMS(ms)

Example Basic Functions - Log usage

Log(3)          // this will have "3" appear on screen

let x = 3
Log(x)          // this will have "3" appear on screen

Log("x")        // this will have "x" appear on screen
Log("hi mom")   // this will have "hi mom" appear on screen

// You can embed values into the output when you put them inside the `${}`
// Notice that the quotation marks are not normal, they're `backticks`,
// which are the key left of the `1` key in the USA.
let x = 3
Log(`x = ${x}`) // this will have "x = 3" appear on screen