Oxoscript turns into NanoPy - more infos

IO functions

applyDigitalLeds

  applyDigitalLeds()

Outputs the color values previously defined with setDigitalLed() on the pin selected with initDigitalLeds().

applyDigitalLeds()

setDigitalLed

  setDigitalLed(ledNr:byte, r:byte, g:byte, b:byte)

Sets the color value (RGB) of the selected digital LED.

setDigitalLed(0, 50, 255, 10)

initDigitalLeds

  initDigitalLeds(pinNr:byte, ledsCount:byte, ledType:byte)

Initializes the selected pin so that a defined number of digital LEDs (e.g. NeoPixels) of the desired type can be set.

LED types:

C_LED_TYPE_WS2812
C_LED_TYPE_WS2812B
C_LED_TYPE_WS2812B_MINI
C_LED_TYPE_WS2813
C_LED_TYPE_WS2814
C_LED_TYPE_SK6812

initDigitalLeds(C_PIN_01, 12, C_LED_TYPE_WS2812B)

getI2CByteAddrSize

  getI2CByteAddrSize()->byte

Returns the data type size of the byteAddr used at the moment.

setI2CByteAddrSize

  setI2CByteAddrSize(size:byte)

Sets the data type size of the byteAddr used for I2C functions. This is mostly 1 (0… 255), but can also be 2 (0… 65535) for certain devices.

checkI2CAddress

  checkI2CAddress(slaveAddr:byte)->bool

Returns true if a device with defined slaveAddr was found and false otherwise.

setPWMDutyCycleResolution

  setPWMDutyCycleResolution(res:byte)

Sets the used PWM resolution: 0… 20bit (Default: 12bit)

setPWMDutyCycleResolution(12)

setPWMFrequency

  setPWMFrequency(freq:long)

Sets the PWM frequency used: 10… 9765 Hz (13bit) or 19… 19531 Hz (12bit) or 38… 39062 Hz (11bit) etc. (Default: 500Hz)

setPWMFrequency(1000)

writePWM

  writePWM(pinNr:byte, dutyCycleValue:long)

Outputs a PWM signal with 500Hz and defined dutyCycle value from 0 (0%) to 4096 (100% at 12bit) on the selected GPIO.

writePWM(C_PIN_01, 2048) # 50%

writeDAC

  writeDAC(pinNr:byte, value:byte)

Only Oxocard Connect

Outputs an analog voltage signal between 0 (0) and 3.3V (255) on the selected GPIO (C_PIN_02 or C_PIN_03).

writeDAC(C_PIN_02, 127)

setI2CReadBufferIndex

  setI2CReadBufferIndex(index:int)

Sets the internal readBufferIndex to the desired value.
This allows a previously read value to be read again.

readI2C(0x4C, 0x0D, 6) # accel raw X, Y & Z axis
xRaw = getI2CInt()
setI2CReadBufferIndex(0)
xRaw = getI2CInt()
yRaw = getI2CInt()
zRaw = getI2CInt()

getI2CLong

  getI2CLong()->long

Returns a long previously read with readI2C().

The internal readBufferIndex is incremented by 4.

getI2CInt

  getI2CInt()->int

Returns an integer previously read with readI2C().

The internal readBufferIndex is incremented by 2.

getI2CByte

  getI2CByte()->byte

Returns a byte previously read with readI2C().

The internal readBufferIndex is incremented by 1.

readI2C

  readI2C(slaveAddr:byte, byteAddr:int, size:int)

Reads an arbitrary number of bytes (size) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

If byteAddr is -1, the data is read directly after transfering the slaveAddr.

With the getI2C functions the read data can be returned afterwards.

readI2C(0x4C, 0x0D, 6) # accel raw X, Y & Z axis
xRaw = getI2CInt()
yRaw = getI2CInt()
zRaw = getI2CInt()

readI2CLong

  readI2CLong(slaveAddr:byte, byteAddr:int)->long

Reads a long (4 bytes) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

If byteAddr is -1, the data is read directly after transfering the slaveAddr.

ir = readI2CLong(0x52, 0x0A) # IR value (3 bytes + 1 unused)
ir = ir & 0x00FFFF # masking of the first 3 bytes

readI2CInt

  readI2CInt(slaveAddr:byte, byteAddr:int)->int

Reads an integer (2 bytes) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

If byteAddr is -1, the data is read directly after transfering the slaveAddr.

readI2CInt(0x4C, 0x0D) # accel raw X axis (16bit)

readI2CByte

  readI2CByte(slaveAddr:byte, byteAddr:int)->byte

Reads a byte of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

If byteAddr is -1, the data is read directly after transfering the slaveAddr.

readI2CByte(0x4C, 0x18) # accel ID => 164

writeI2C

  writeI2C(slaveAddr:byte, byteAddr:int, size:int, data:byte[])

Writes an arbitrary number of bytes (size) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

data = [0x11, 0x22, 0x33]
writeI2C(0x2C, 0x05, 3, data)

writeI2CLong

  writeI2CLong(slaveAddr:byte, byteAddr:int, data:long)

Writes a long (4 bytes) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

writeI2CLong(0x2C, 0x05, 0x42133742)

writeI2CInt

  writeI2CInt(slaveAddr:byte, byteAddr:int, data:int)

Writes an integer (2 bytes) of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

writeI2CInt(0x2C, 0x05, 0x1337)

writeI2CByte

  writeI2CByte(slaveAddr:byte, byteAddr:int, data:byte)

Writes a byte of a defined I2C slave (7bit slaveAddr) and register (byteAddr).

writeI2CByte(0x4C, 0x08, 0x13) # accel sample rate = 100Hz

readADC

  readADC(pinNr:byte, nSamples:long)->int

Reads the analog value of either pinNr 32 or 33 multiple times (nSamples) and averages it.
The set reference voltage is ~2600mV (11dB attenuation).
The returned value ranges between 0 and 4095 (12bit).

readADC(32, 100)
readADC(33, 1000)

readGPIO

  readGPIO(pinNr:byte)->bool

Reads the state of a GPIO previously initialized as INPUT(_PULLUP/DOWN).

initGPIO(32, INPUT_PULLDOWN)
readGPIO(32) # false (0)
readGPIO(32) # true (1) if connected to 3.3V

writeGPIO

  writeGPIO(pinNr:byte, state:bool)

Sets the state of a GPIO previously initialized as OUTPUT.

initGPIO(32, OUTPUT)
writeGPIO(32, 1) # HIGH
writeGPIO(32, 0) # LOW

initGPIO

  initGPIO(pinNr:byte, mode:byte)

Initializes the selected GPIO (analog pinMode) with one of the following modes:

OUTPUT
INPUT
INPUT_PULLUP
INPUT_PULLDOWN

Available pinNr constants:

C_PIN_01 (20*)
C_PIN_02 (25*)
C_PIN_03 (26*)
C_PIN_04 (32)
C_PIN_05 (33)
C_PIN_06 (34*)
C_PIN_07 (35*)
C_PIN_MISO (8)
C_PIN_MOSI (5)
C_PIN_SCK (7)
C_PIN_SDA (21*)
C_PIN_SCL (22*)