Render
Render
Arduino API
RUI Arduino Data Type
RAK_SERIAL_MODE
c
enum RAK_SERIAL_MODE
Enumerator
RAK_ADC_RESOLUTION
c
enum RAK_ADC_RESOLUTION
Enumerator
RAK_ADC_MODE
c
enum RAK_ADC_MODE
Documentation Center
Enumerator
RAK_PWM_RESOLUTION
c
enum RAK_PWM_RESOLUTION
Enumerator
Serial
begin()
Sets the data rate in bits per second (baud) for serial data transmission
c
Serial.begin(baud);
c
Serial.begin(baud, mode);
Documentation Center
Returns void
end()
End connection of the Serial with flushing all data.
c
Serial.end();
Returns void
lock()
To lock the Serial port of the device.
📝 NOTE
1. If you never set a password successfully, the default password will be 00000000 .
2. Serial.lock can only lock the Serial which is in AT Command mode.
3. Serial.lock will lock all Serial that is on AT Command mode.
4. Due that Serial lock and unlock is system-wise operation for all Serial ports in AT Command mode, the
Serial could be unlocked from either one or more Serial ports which are in AT Command mode.
c
Serial.lock(locked);
Documentation Center
Parameters locked - giving true to lock the device, false to unlock the device
Returns void
password()
Set up the password to unlock the device when locked.
c
Serial.password(str);
c
Serial.password(new_passwd, len);
write()
Writes a byte sequence to a specified serial port.
c
Serial.write(val);
c
Serial.write(buf, size);
📝 NOTE
This function is a virtual function that declared in Print.h .
Documentation Center
available()
Gets the number of bytes available for reading from the specified serial port.
c
Serial.available();
📝 NOTE
Serial.available() inherits from the Stream utility class.
Returns the number of bytes available for reading from the specified serial port (Type: int)
read()
Reads incoming serial data.
c
Serial.read();
📝 NOTE
Serial.read() inherits from the Stream utility class.
Returns The first byte of incoming serial data available (Type: int32_t)
Return Values -1 Read fail, get nothing from the specified serial port
Documentation Center
peek()
Returns the next byte (character) of incoming serial data without removing it from the internal serial buffer. That is,
successive calls to peek() will return the same character, as will the next call to read().
c
Serial.peek();
Returns The first byte of incoming serial data available (or -1 if no data is available) (Type: int)
flush()
Waits for the transmission of outgoing serial data to complete.
c
Serial.flush();
Returns void
print()
Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are
printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two
decimal places. Bytes are sent as a single character. Characters and strings are sent as is.
c
Serial.print(val);
c
Serial.print(val,format);
Documentation Center
Returns returns the number of bytes written, though reading that number is optional (Type: size_t)
println()
Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '')
and a newline character (ASCII 10, or ''). This command takes the same form as Serial.print() .
c
Serial.print(val);
c
Serial.print(val,format);
Returns returns the number of bytes written, though reading that number is optional (Type: size_t)
printf()
To output formatted text over Serial without the need to create a char array first, fill it with snprintf() and then send
it with Serial.println .
c
Serial.printf(val);
Parameters val
Returns returns the number of bytes written, though reading that number is optional (Type: size_t)
Documentation Center
setTimeout()
This API is used to set the timeout value for read/write/flush API.
c
Serial.setTimeout(timeout);
Returns void
getTimeout()
This API is used to get the timeout value for read/write/flush API.
c
Serial.getTimeout(timeout);
readBytes()
Read characters from Stream into buffer terminates if length characters have been read, or timeout (see
setTimeout).
c
Serial.readBytes(buffer, length);
📝 NOTE
Serial.readBytes() inherits from the Stream utility class.
Documentation Center
readBytesUntil()
As readBytes with terminator character Terminates if length characters have been read, timeout, or if the
terminator character detected.
c
Serial.readBytesUntil(terminator, buffer, length);
📝 NOTE
Serial.readBytesUntil() inherits from the Stream utility class
Returns size_t
readString
Reads characters from a Stream into a String The function terminates if it times out (see setTimeout()).
c
Serial.readString();
📝 NOTE
Serial.readString() inherits from the Stream utility class.
Documentation Center
readStringUntil()
Reads characters from the serial buffer into a String. The function terminates if it times out (see setTimeout()).
c
Serial.readStringUntil(terminator);
📝 NOTE
Serial.readStringUntil() inherits from the Stream utility class.
Returns The entire String read from the serial buffer, up to the terminator character(Type: String ).
Wire
begin()
Initiate the Wire library and join the I2C bus as a master.
c
Wire.begin();
Returns void
end()
Documentation Center
c
Wire.end();
Returns void
setClock()
This function modifies the clock frequency for I2C communication. I2C slave devices have no minimum working
clock frequency, however 100 kHz is usually the baseline.
c
Wire.setClock(freq);
freq - The value (in Hertz) of desired communication clock. Accepted values are 100000
Parameters
(standard mode) and 400000 (fast mode).
Returns void
beginTransmission()
Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission
with the write() function and transmit them by calling endTransmission().
c
Wire.beginTransmission(address);
Returns void
Documentation Center
endTransmission()
Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were
queued by write() .
c
Wire.endTransmission();
c
Wire.endTransmission(sendStop);
sendStop(optional)
Parameters - true will send a stop message, releasing the bus after transmission.
- false will send a restart, keeping the connection active (default = false).
0 - success
Returns
1- fail
requestFrom()
Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available() and
read() functions.
c
Wire.requestFrom(address, quantity);
c
Wire.requestFrom(address, quantity, sendStop);
Returns The number of bytes returned from the slave device (Type: byte)
Documentation Center
write()
Writes data to a slave device.
c
Wire.write(value);
c
Wire.write(data, size);
📝 NOTE
In-between calls to beginTransmission() and endTransmission().
write() will return the number of bytes written, though reading that number is optional
Returns
(Type: byte)
available()
Returns the number of bytes available for retrieval with read().
c
Wire.available();
read()
Documentation Center
c
Wire.read();
📝 NOTE
read() inherits from the Stream utility class.
SPI
begin()
Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
c
SPI.begin()
Returns void
end()
Disables the SPI bus.
c
SPI.end()
Returns void
transfer16()
SPI transfer is based on a simultaneous send and receive: the received data is returned in receivedVal16.
c
receivedVal16 = SPI.transfer16(val16)
Documentation Center
Parameters val16 - the two bytes variable to send out over the bus
transfer()
SPI transfer is based on a simultaneous send and receive: the received data is returned in receivedVal. In case of
buffer transfers the received data is stored in the buffer in-place.
c
receivedVal = SPI.transfer(val)
c
SPI.transfer(buffer, size)
beginTransaction()
Initializes the SPI bus using the defined SPISettings.
c
SPI.beginTransactions(mySetting)
Returns void
endTransaction()
Stops using the SPI bus.
c
SPI.endTransaction()
Returns void
Documentation Center
setBitOrder()
Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or
MSBFIRST (most-significant bit first).
c
SPI.setBitOrder(order)
Returns void
setDataMode()
Sets the SPI data mode: that is, clock polarity and phase.
c
SPI.setDataMode(mode)
mode - SPI_MODE0
SPI_MODE1
Parameters
SPI_MODE2
SPI_MODE3
Returns void
setClockDivider()
Sets the SPI clock divider relative to the system clock.
c
SPI.setClockDivider(divider)
divider - SPI_CLOCK_DIV2
SPI_CLOCK_DIV4
SPI_CLOCK_DIV8
Parameters SPI_CLOCK_DIV16
SPI_CLOCK_DIV32
SPI_CLOCK_DIV64
SPI_CLOCK_DIV128 SPI_CLOCK_DIV256
Returns void
Documentation Center
Time
delay
Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds
in a second.)
c
delay(ms);
delayMicroseconds
Pauses the program for the amount of time (in microseconds) specified by the parameter. There are a thousand
microseconds in a millisecond and a million microseconds in a second.
c
delayMicroSeconds(us);
millis
Returns the number of milliseconds passed since the device began running the current program.
c
millis();
The number of milliseconds since the device began running the current program (Type:
Returns
unsigned long).
Documentation Center
micros
Returns the number of microseconds since the device began running the current program.
c
unsigned long micros()
Function micros();
Number of microseconds since the device began running the current program (Type: unsigned
Returns
long)
AdvancedIO
tone()
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified,
otherwise the wave continues until a call to noTone(). Only one tone can be generated at a time. If a tone is
already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the
call will set its frequency.
c
tone(pin, frequency);
c
tone(pin, frequency, duration);
Returns void
noTone()
Documentation Center
c
noTone(pin);
Parameters pin - The device pin on which to stop generating the tone
Returns void
shiftOut()
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost)
significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed (taken high, then low) to
indicate that the bit is available.
c
shiftOut(dataPin, clockPin, bitOrder, val);
Returns void
shiftIn()
Shifts in a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant
bit. For each bit, the clock pin is pulled high, the next bit is read from the data line, and then the clock pin is taken
low.
c
byte incoming = shiftIn(dataPin, clockPin, bitOrder);
Documentation Center
pulseIn()
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go from
LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in
microseconds or gives up and returns 0 if no complete pulse was received within the timeout.
c
pulseIn(pin, state);
c
pulseIn(pin, state, timeout);
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout(Type:
Returns
unsigned long)
pulseInLong()
pulseInLong() is an alternative to pulseIn() which is better at handling long pulse and interrupt affected
scenarios
c
pulseInLong(pin, state);
c
pulseInLong(pin, state, timeout);
Documentation Center
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout(Type:
Returns
unsigned long).
Characters
isAlphaNumeric()
Analyze if a char is alphanumeric (that is a letter or a numbers). Returns true if thisChar contains either a number
or a letter.
c
isAlphaNumeric(thisChar);
isAlpha()
Analyze if a char is alpha (that is a letter). Returns true if thisChar contains a letter.
c
isAlpha(thisChar);
isAscii()
Analyze if a char is Ascii. Returns true if thisChar contains an Ascii character.
c
isAscii(thisChar);
isWhitespace
Analyze if a char is a space character. Returns true if the argument is a space or horizontal tab ('').
c
isWhitespace(thisChar);
isControl()
Analyze if a char is a control character. Returns true if thisChar is a control character.
c
isControl(thisChar);
Documentation Center
isDigit()
Analyze if a char is a digit (that is a number). Returns true if thisChar is a number.
c
isDigit(thisChar);
isGraph()
Analyze if a char is printable with some content (space is printable but has no content). Returns true if thisChar is
printable.
c
isGraph(thisChar);
isLowerCase()
Analyze if a char is lower case (that is a letter in lower case). Returns true if thisChar contains a letter in lower
case.
c
isLowerCase(thisChar);
isPrintable()
Analyze if a char is printable (that is any character that produces an output, even a blank space). Returns true if
thisChar is printable
c
isPrintable(thisChar);
isPunct()
Analyze if a char is punctuation (that is a comma, a semicolon, an exclamation mark and so on). Returns true if
thisChar is punctuation.
c
isPunct(thisChar);
Documentation Center
isSpace()
Analyze if a char is a white-space character. Returns true if the argument is a space, form feed (''), newline (''),
carriage return (''), horizontal tab (''), or vertical tab ('').
c
isSpace(thisChar);
isUpperCase()
Analyze if a char is upper case (that is, a letter in upper case). Returns true if thisChar is upper case.
c
isUpperCase(thisChar);
isHexadecimalDigit()
Analyze if a char is an hexadecimal digit (A-F, 0-9). Returns true if thisChar contains an hexadecimal digit.
c
isHexadecimalDigit(thisChar);
c
bitRead(value, bit);
bitSet
Sets (writes a 1 to) a bit of a numeric variable.
c
bitSet(value, bit);
Documentation Center
Returns void
bitClear
Clears (writes a 0 to) a bit of a numeric variable.
c
bitClear(value, bit);
Returns The value of the numeric variable after the bit at position n is cleared
bitWrite
Writes a bit of a numeric variable.
c
bitWrite(value, bit, bitvalue);
Returns void
bit
Computes the value of the specified bit. (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.)
c
bit(b);
lowByte
Extracts the low-order (rightmost) byte of a variable (e.g. a word).
c
lowByte(w);
Returns byte
highByte
Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).
c
highByte(w);
Returns byte
Documentation Center
DigitalIO
pinMode()
Configures the specified pin to behave either as an input or an output.
c
pinMode(pin, mode);
Returns void
digitalWrite()
Writes a HIGH or a LOW value to a digital pin.
c
digitalWrite(pin, value);
Returns void
digitalRead()
Reads the value from a specified digital pin, either HIGH or LOW.
c
digitalRead(pin);
Documentation Center
AnalogIO
analogRead()
Reads the value from the specified analog pin.
c
analogRead(pin);
Parameters pin - The name of the analog input pin to read from
analogReference()
Configures the reference voltage used for analog input.
c
analogReference(type);
Returns void
⚠ WARNING
ADC voltage reference for RAK3172 and RAK3172-SiP is fixed to VDD voltage.
Documentation Center
analogWrite()
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor
at various speeds. After a call to analogWrite() , the pin will generate a steady rectangular wave of the specified
duty cycle until the next call to analogWrite() .
c
analogWrite(pin, value);
Returns void
analogReadResolution()
analogReadResolution() is an extension of the Analog API for the Zero, Due, MKR family, Nano 33 (BLE and
IoT), and Portenta.
Sets the size (in bits) of the value returned by analogRead() . It defaults to 10 bits (returns values between 0-
1023) for backward compatibility with AVR based boards.
c
analogReadResolution(bits);
bits - Determines the resolution (in bits) of the value returned by the analogRead()
function. You can set this between 1 and 32. You can also set the resolutions higher than
Parameters
the supported 12 or 16 bits, but values returned by analogRead() will suffer
approximation.
Returns void
analogWriteResolution()
analogWriteResolution() is an extension of the Analog API for the Arduino Due. It sets the resolution of the
analogWrite() function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based
boards.
c
analogWriteResolution(bits);
Documentation Center
bits - Determines the resolution (in bits) of the values used in the analogWrite()
function. The value can range from 1 to 32. If you choose a resolution higher or lower than
Parameters
your board’s hardware capabilities, the value used in analogWrite() will be either
truncated if it’s too high or padded with zeros if it’s too low.
Returns void
Interrupts
interrupts()
Re-enables interrupts after they’ve been disabled by noInterrupts() .
c
interrupts();
Returns void
noInterrupts()
Disables interrupts. You can re-enable them with interrupts() .
c
noInterrupts();
Returns void
attachInterrupt()
Digital Pins With Interrupts. See also AttachInterrupt
c
attachInterrupt(pin, ISR, mode);
Documentation Center
Returns void
detachInterrupt()
Turns off the given interrupt.
c
detachInterrupt(pin);
Returns void
RandomNumber
random
The random function generates pseudo-random numbers.
c
random(max);
c
random(min, max);
Documentation Center
randomSeed()
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its
random sequence. This sequence, while very long, and random, is always the same. If it is important for a
sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed()
to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected
pin.
c
randomSeed(seed);
Returns void