setSPIReadBufferIndex(int index)
Sets the internal readBufferIndex to the desired value.
This allows a previously read value to be read again.
getSPILong()->long
Returns a long previously read with readSPI().
The internal readBufferIndex is increased by 4.
getSPIInt()->int
Returns an integer previously read with readSPI().
The internal readBufferIndex is increased by 2.
getSPIByte()->byte
Returns a byte previously read with readSPI().
The internal readBufferIndex is increased by 1.
transferSPI(int size, byte[] txData)
Transfers and reads any number of bytes (size) and saves them in the internal SPI read buffer.
The read data can then be returned using the getSPI functions.
txData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
transferSPI(7, txData)
myByte = getSPIByte()
myInt = getSPIInt()
myLong = getSPILong()
readSPI(int size)
Reads any number of bytes (size) and saves them in the internal SPI read buffer.
The read data can then be returned using the getSPI functions.
readSPI(7)
myByte = getSPIByte()
myInt = getSPIInt()
myLong = getSPILong()
writeSPI(int size, byte[] data)
Writes any number of bytes (size).
data = [0x11, 0x22, 0x33]
writeSPI(3, data)
initSPI(byte mode, long speed)
Initializes the SPI interface.
Available modes:
C_SPI_MODE_0 // CPOL=0; CPHA=0
C_SPI_MODE_1 // CPOL=0; CPHA=1
C_SPI_MODE_2 // CPOL=1; CPHA=0
C_SPI_MODE_3 // CPOL=1; CPHA=1
Example:
initSPI(C_SPI_MODE_3, 1000000)
initGPIO(C_PIN_01, OUTPUT)
writeGPIO(C_PIN_01, 1) # resetCS
def onDraw():
len = 2
txData = [0x00, 0x00]
writeGPIO(C_PIN_01, 0) # setCS
writeSPI(len, txData)
readSPI(1)
writeGPIO(C_PIN_01, 1) # resetCS
rxData = getSPIByte()
print(rxData)
delay(1000)
if getButton():
if returnToMenu():
return
writeLineUART(byte[] data)
Write a string and append ‘\n’ at the end.
writeUART(int size, byte[] data)
Writes any number of bytes (size).
data = [0x11, 0x22, 0x33]
writeUART(3, data)
readLineUART()->byte[256]
Reads an entire line (up to ‘\n’) and returns it as a byte array.
Note:
A maximum of 256 bytes can be returned per function call.
readUART(int size)->byte[256]
Reads a defined length in bytes and returns it as a byte array.
Note:
A maximum of 256 bytes can be returned per function call.
getUARTDataLength()->int
Returns the received data length.
configUART(byte dataBits, byte parity, byte stopBits)
Optional UART configurations.
Available dataBits:
C_UART_DATA_BITS_5
C_UART_DATA_BITS_6
C_UART_DATA_BITS_7
C_UART_DATA_BITS_8 // default
Available parity options:
C_UART_PARITY_DISABLE // default
C_UART_PARITY_EVEN
C_UART_PARITY_ODD
Available stopBits:
C_UART_STOP_BITS_1 // default
C_UART_STOP_BITS_1_5
C_UART_STOP_BITS_2
initUART(byte pinNrTx, byte pinNrRx, long baudrate)
Initializes the UART interface.
Example:
# UART echo example
initUART(C_PIN_04, C_PIN_05, 115200) # TX, RX, BAUDRATE
#configUART(C_UART_DATA_BITS_8, C_UART_PARITY_DISABLE, C_UART_STOP_BITS_1)
def onDraw():
len = getUARTDataLength()
if len > 0:
data = readLineUART()
#data = readUART(len)
writeLineUART(data) # send the same data back
#writeUART(len, data)
clear()
drawText(10, 10, data)
update()
print(data)
delay(10)
if getButton():
if returnToMenu():
return
applyDigitalLeds()
Outputs the color values previously defined with setDigitalLed() on the pin selected with initDigitalLeds().
applyDigitalLeds()
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(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()->byte
Returns the data type size of the byteAddr used at the moment.
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(slaveAddr:byte)->bool
Returns true if a device with defined slaveAddr was found and false otherwise.
setPWMDutyCycleResolution(res:byte)
Sets the used PWM resolution: 0… 20bit (Default: 12bit)
setPWMDutyCycleResolution(12)
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(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(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(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()->long
Returns a long previously read with readI2C().
The internal readBufferIndex is incremented by 4.
getI2CInt()->int
Returns an integer previously read with readI2C().
The internal readBufferIndex is incremented by 2.
getI2CByte()->byte
Returns a byte previously read with readI2C().
The internal readBufferIndex is incremented by 1.
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(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(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(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(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(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(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(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(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(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(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(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*)