Oxoscript turns into NanoPy - more infos

Libraries (NanoPy)

IO

The IO library provides the IO object, which simplifies the control of hardware IOs.

Functions:

Use writePin() to set an IO to either 0 (LOW) or 1 (HIGH).

IO.writePin(pinid:byte, value:bool)

Use setSampleRate() to determine the number of samples for averaging ADC measurements (IO06 & IO07).

IO.setSampleRate(newSampleRate:int)

Use readPin() to return the current state (0 or 1) of an IO.

IO.readPin(pinid:byte)->int

Example #1:

import io

def onDraw():
    IO.writePin(C_PIN_01, 1)
    delay(500)
    IO.writePin(C_PIN_01, 0)
    delay(500)

Example #2:

import io

IO.setSampleRate(1000)

def onDraw():
    if IO.readPin(C_PIN_01):
        IO.writePin(C_PIN_04, 1)
    else:
        IO.writePin(C_PIN_04, 0)
    if IO.readPin(C_PIN_06) > 200:
        IO.writePin(C_PIN_05, 1)
    else:
        IO.writePin(C_PIN_05, 0)
    delay(10)

Note:
C_PIN_06 and C_PIN_07 do not return a digital value (1 or 0) with readPin() but an analog value (0 to 4095).

TOF

Only Oxocard-Connect with TOF Cartridge

The TOF library provides the TOF object.

The Time of Flight (TOF) sensor is a distance sensor. It measures the distance to an object in a matrix (8x8 or 4x4) and returns the 64 or 16 values in millimeters.

Functions:

The TOF must be initialized first. Initialization takes about 10 seconds the first time.

TOF.init()

If you don’t want to use 8x8 with 15Hz but 4x4 with 60Hz sampling, you can use the set4x4() function. And to switch back set8x8().

TOF.set4x4()
TOF.set8x8()

Use getData() to read the 64 or 16 values and store them in the TOF.data array.

TOF.getData()

Class variables:

The TOF class contains two variables which are updated when getData() is called.

The TOF.data array contains the measured distances in millimeters.

TOF.data[64]

The TOF.status array contains the status of each measured distance. Here, values 5 and 9 correspond to a valid measurement and all other values correspond to an invalid measurement.

TOF.status[64]

Example:

import tof

TOF.init()
TOF.set4x4()

def onDraw():
    TOF.getData()
    for i in 16:
        print(TOF.data[i] + "mm (" + TOF.status[i] + ")")
    print("")

AIR

Only Oxocard-Connect with AIR Cartridge

The AIR Cartridge includes 3 air quality sensors from Sensirion: - SHT40 Temperature and Humidity sensor. - SCD40 CO2 sensor - SGP41 VOC and NOx sensor

The AIR library provides the AIR object.

Functions:

Returns the current CO2 value in ppm.

AIR.CO2()

Returns the NOx index. This is calculated with “Sensirion’s Gas Index” algorithm and corresponds to a representative value between 1 and 500.

AIR.NOxIndex()

Returns the VOC index. This is calculated with “Sensirion’s Gas Index” algorithm and corresponds to a representative value between 1 and 500.

AIR.VOCIndex()

image

Returns the current temperature in °C.

AIR.temperature()

Returns the current humidity in %RH.

AIR.humidity()

Returns the current absolute humidity in g/m^3. This value indicates the amount of water vapor (humidity) in the air, regardless of temperature.

AIR.humidityAbsolute()

Returns the current IAQ rating. IAQ stands for Indoor Air Quality and usually takes a value between 0 and 5:

AIR.IAQ()

value level State
≤1.99 1 Very good
2.00-2.99 2 Good
3.00-3.99 3 Medium
4.00-4.99 4 Poor
≥5.00 5 Very poor

Example:

import air

setPrecision(3)
textFont(FONT_ROBOTO_24)

def onDraw():
    clear()
    drawText(10, 10, "CO2: " + AIR.CO2() + " ppm")
    drawText(10, 40, "NOxIdx: " + AIR.NOxIndex() + " / 500")
    drawText(10, 70, "VOCIdx: " + AIR.VOCIndex() + " / 500")
    drawText(10, 100, "IAQ: " + AIR.IAQ())
    drawText(10, 130, "temp: " + AIR.temperature() + " °C")
    drawText(10, 160, "humi: " + AIR.humidity() + " %RH")
    drawText(10, 190, "humiAbs: " + AIR.humidityAbsolute() + " g/m3")
    update()
    delay(100)

monitor

The monitor object can be used to simply display system messages on the screen. Three functions are available:

monitor.init()

clears the monitor and initializes everything.

monitor.smallFont() monitor.bigFont()

This can be used to change the font size of the output.

monitor.push(message)

displays a message on the screen. When the screen is full, the oldest message is automatically hidden.

monitor.pushc(message, color)

This can be used to color the messages. The following constants are defined:

MONITOR_RED, MONITOR_GREEN, MONITOR_YELLOW, MONITOR_BLUE

Here is an example:

import monitor
monitor.init()

while true:
    r = random(0,5+1)
    if r == 0:
        monitor.push("Hi!")
    elif r == 1:
        monitor.pushc("It is hot today.", MONITOR_RED)
    elif r == 2:
        monitor.pushc("I am ready.", MONITOR_GREEN)
    elif r == 3:
        monitor.pushc("This is nice.", MONITOR_BLUE)
    elif r == 3:
        monitor.pushc("Let us talk.", MONITOR_YELLOW)
    delay(random(50,300))