0% found this document useful (0 votes)
79 views34 pages

Render

The document provides documentation on the Arduino API for RAKwireless devices. It summarizes various data types and enumerations for serial communication, analog to digital conversion, and pulse width modulation. Methods like begin(), end(), write(), print(), and println() for serial output are also documented.

Uploaded by

diegogachet1618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views34 pages

Render

The document provides documentation on the Arduino API for RAKwireless devices. It summarizes various data types and enumerations for serial communication, analog to digital conversion, and pulse width modulation. Methods like begin(), end(), write(), print(), and println() for serial output are also documented.

Uploaded by

diegogachet1618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Documentation Center

Arduino API
RUI Arduino Data Type
RAK_SERIAL_MODE
c
enum RAK_SERIAL_MODE

Enumerator

RAK_AT_MODE AT command mode.

RAK_API_MODE API mode

RAK_CUSTOM_MODE Custom mode

RAK_DEFAULT_MODE Default mode which depends on platform

RAK_ADC_RESOLUTION
c
enum RAK_ADC_RESOLUTION

Enumerator

RAK_ADC_RESOLUTION_8BIT 8 bit resolution

RAK_ADC_RESOLUTION_10BIT 10 bit resolution

RAK_ADC_RESOLUTION_12BIT 12 bit resolution

RAK_ADC_RESOLUTION_14BIT 14 bit resolution

RAK_ADC_MODE
c
enum RAK_ADC_MODE
Documentation Center

Enumerator

RAK_ADC_MODE_DEFAULT default range which depends on platform

RAK_ADC_MODE_3_0 maximum 3.0V

RAK_ADC_MODE_2_4 maximum 2.4V

RAK_ADC_MODE_1_8 maximum 1.8V

RAK_ADC_MODE_1_2 maximum 1.2V

RAK_PWM_RESOLUTION
c
enum RAK_PWM_RESOLUTION

Enumerator

RAK_PWM_RESOLUTION_8BIT 8 bit resolution

RAK_PWM_RESOLUTION_10BIT 10 bit resolution

RAK_PWM_RESOLUTION_12BIT 12 bit resolution

RAK_PWM_RESOLUTION_14BIT 14 bit resolution

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

Function void begin (uint32_t baud, RAK_SERIAL_MODE mode = RAK_DEFAULT_MODE)

baud - The baudrate to set for the Serial.


mode(optional) - The mode that use UART in different way (if not assigned,
RAK_DEFAULT_MODE is chosen).
List:
Parameters
RAK_AT_MODE
RAK_API_MODE
RAK_CUSTOM_MODE
RAK_DEFAULT_MODE

Returns void

Click to View Example

end()
End connection of the Serial with flushing all data.

c
Serial.end();

Function void end(void)

Returns void

Click to View Example

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

Function void lock(bool locked)

Parameters locked - giving true to lock the device, false to unlock the device

Returns void

Click to View Example

password()
Set up the password to unlock the device when locked.

c
Serial.password(str);

c
Serial.password(new_passwd, len);

Function bool password(char * new_passwd, size_t len)

str - a string to set for unlocking the device


Parameters new_passwd - a char array to set for unlocking the device
len - the length of your password

TRUE - for success


Returns
FALSE - for failure

Click to View Example

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

Function virtual size_t write(const uint8_t* buf, size_t size)

val - a value to send as a single byte


Parameters buf - an array to send as a series of bytes
size - the number of bytes to be sent from the array

Returns number of bytes sent successfully (Type: size_t)

Click to View Example

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.

Function virtual int available(void)

Returns the number of bytes available for reading from the specified serial port (Type: int)

Click to View Example

read()
Reads incoming serial data.

c
Serial.read();

📝 NOTE
Serial.read() inherits from the Stream utility class.

Function virtual int read(void)

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

Click to View Example

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();

Function virtual int peek(void)

Returns The first byte of incoming serial data available (or -1 if no data is available) (Type: int)

Click to View Example

flush()
Waits for the transmission of outgoing serial data to complete.

c
Serial.flush();

Function virtual void flush(void)

Returns void

Click to View Example

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

Function size_t print(long, int=DEC)

Parameters val - the value to print, allows any data type

Returns returns the number of bytes written, though reading that number is optional (Type: size_t)

Click to View Example

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);

Function size_t println(int, int=DEC)

Parameters val - the value to print, allows any data type

Returns returns the number of bytes written, though reading that number is optional (Type: size_t)

Click to View Example

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);

Function size_t printf(const char * val, ...)

Parameters val

Returns returns the number of bytes written, though reading that number is optional (Type: size_t)
Documentation Center

Click to View Example

setTimeout()
This API is used to set the timeout value for read/write/flush API.

c
Serial.setTimeout(timeout);

Function void setTimeout(unsigned long timeout)

Parameters timeout - the timeout value

Returns void

Click to View Example

getTimeout()
This API is used to get the timeout value for read/write/flush API.

c
Serial.getTimeout(timeout);

Function unsigned long getTimeout(void)

Returns The value of timeout (Type: unsigned long)

Click to View Example

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

Function size_t readBytes(char* buffer,size_t length)

buffer - The buffer to store the bytes in.


Parameters
length - The number of bytes to read.

Returns The number of bytes placed in the buffer (Type: size_t )

Click to View Example

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

Function size_t readBytesUntil(char terminator, char* buffer, size_t length)

terminator - The character to search for


Parameters buffer - The buffer to store the bytes in
length - The number of bytes to read

Returns size_t

Click to View Example

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

Function String readString()

Returns A String read from a Stream (Type: String )

Click to View Example

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.

Function String readStringUntil(char terminator)

Returns The entire String read from the serial buffer, up to the terminator character(Type: String ).

Click to View Example

Wire
begin()
Initiate the Wire library and join the I2C bus as a master.

c
Wire.begin();

Function void begin(void)

Returns void

Click to View Example

end()
Documentation Center

End the I2C bus

c
Wire.end();

Function void end(void)

Returns void

Click to View Example

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);

Function void setClock(uint32_t freq)

freq - The value (in Hertz) of desired communication clock. Accepted values are 100000
Parameters
(standard mode) and 400000 (fast mode).

Returns void

Click to View Example

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);

Function void beginTransmission(uint8_t address)

Parameters address - The 7-bit address of the device to transmit to

Returns void
Documentation Center

Click to View Example

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);

Function uint32_t endTransmission(uint8_t sendStop = false)

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

Click to View Example

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);

Function uint8_t requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)

address - The 7-bit address of the device to request bytes from


quantity - The number of bytes to request
sendStop
Parameters
- true will send a stop message after the request, releasing the bus.
- false will continually send a restart after the request, keeping the connection active(default
= false)

Returns The number of bytes returned from the slave device (Type: byte)
Documentation Center

Click to View Example

write()
Writes data to a slave device.

c
Wire.write(value);

c
Wire.write(data, size);

📝 NOTE
In-between calls to beginTransmission() and endTransmission().

Function virtual size_t write(const uint8_t* data, size_t size)

value - A value to send as a single byte


Parameters data - An array of data to send as bytes
size - The number of bytes to transmit

write() will return the number of bytes written, though reading that number is optional
Returns
(Type: byte)

Click to View Example

available()
Returns the number of bytes available for retrieval with read().

c
Wire.available();

Function virtual int available(void)

Returns The number of bytes available for reading

Click to View Example

read()
Documentation Center

Reads a byte that was transmitted from a slave device to a master

c
Wire.read();

Function virtual int read(void)

Returns The next byte received

📝 NOTE
read() inherits from the Stream utility class.

Click to View Example

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()

Function void begin()

Returns void

end()
Disables the SPI bus.

c
SPI.end()

Function void 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

Function uint16_t transfer16 (uint16_t data)

Parameters val16 - the two bytes variable to send out over the bus

Returns the received data

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)

Function void transfer(void* buf, size_t count)

val - the byte to send out over the bus


Parameters
buffer - the array of data to be transferred

Returns the received data

beginTransaction()
Initializes the SPI bus using the defined SPISettings.

c
SPI.beginTransactions(mySetting)

Function void beginTransaction(SPISettings settings)

Parameters mySetting - the chosen settings according to SPISettings

Returns void

endTransaction()
Stops using the SPI bus.

c
SPI.endTransaction()

Function void 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)

Function void setBitOrder(BitOrder order)

Parameters order - either LSBFIRST or MSBFIRST

Returns void

setDataMode()
Sets the SPI data mode: that is, clock polarity and phase.

c
SPI.setDataMode(mode)

Function void setDataMode(uint8_t 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)

Function void setClockDivider(uint32_t uc_div)

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);

Function #define delay udrv_app_delay_ms

Parameters ms - The number of milliseconds to pause

Click to View Example

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);

Function #define delayMicroseconds udrv_app_delay_us

Parameters us - The number of microseconds to pause

Click to View Example

millis
Returns the number of milliseconds passed since the device began running the current program.

c
millis();

Function unsigned long millis()

The number of milliseconds since the device began running the current program (Type:
Returns
unsigned long).
Documentation Center

Click to View Example

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)

Click to View Example

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);

Function void tone(uint8_t pin, uint32_t frequency, uint64_t duration = 0)

pin - The device pin on which to generate the tone


Parameters frequency - The frequency of the tone in hertz
duration(optional) - The duration of the tone in milliseconds (default = no timeout)

Returns void

Click to View Example

noTone()
Documentation Center

Stops the generation of a square wave triggered by tone().

c
noTone(pin);

Function void noTone(uint8_t pin)

Parameters pin - The device pin on which to stop generating the tone

Returns void

Click to View Example

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);

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t


Function
val)

dataPin - The pin on which to output each bit


clockPin - The pin to toggle once the dataPin has been set to the correct value
Parameters
bitOrder - Which order to shift out the bits, either MSBFIRST or LSBFIRST
val - The data to shift out

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

Function uint32_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)

dataPin - The pin on which to output each bit


Parameters clockPin - The pin to toggle once the dataPin has been set to the correct value
bitOrder - Which order to shift out the bits, either MSBFIRST or LSBFIRST

Returns The value read(Type: byte);

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);

unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout =


Function
1000000L)

pin - The pin on which you want to read a pulse


state - Type of pulse to read: either HIGH or LOW
Parameters
timeout(optional) - The number of microseconds to wait for the pulse to start; default is
one second

The length of the pulse (in microseconds) or 0 if no pulse started before the timeout(Type:
Returns
unsigned long)

Click to View Example

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

unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout =


Function
1000000L)

pin - The pin on which you want to read a pulse


state - Type of pulse to read: either HIGH or LOW
Parameters
timeout(optional) - The number of microseconds to wait for the pulse to start; default is
one second.

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);

Function boolean isAlphaNumeric(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is alphanumeric


Returns
FALSE: The character is not alphanumeric

Click to View Example

isAlpha()
Analyze if a char is alpha (that is a letter). Returns true if thisChar contains a letter.

c
isAlpha(thisChar);

Function boolean isAlpha(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is a letter


Returns
FALSE : The character is not a letter

Click to View Example


Documentation Center

isAscii()
Analyze if a char is Ascii. Returns true if thisChar contains an Ascii character.

c
isAscii(thisChar);

Function boolean isAscii(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is Ascii


Returns
FALSE : The character is not Ascii

Click to View Example

isWhitespace
Analyze if a char is a space character. Returns true if the argument is a space or horizontal tab ('').

c
isWhitespace(thisChar);

Function boolean isWhitespace(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is a space or tab


Returns
FALSE: The character is not a space or tab

Click to View Example

isControl()
Analyze if a char is a control character. Returns true if thisChar is a control character.

c
isControl(thisChar);
Documentation Center

Function boolean isControl(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is a control character


Returns
FALSE: The character is not a control character

Click to View Example

isDigit()
Analyze if a char is a digit (that is a number). Returns true if thisChar is a number.

c
isDigit(thisChar);

Function boolean isDigit(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is a number


Returns
FALSE: The character is not a number

Click to View Example

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);

Function boolean isGraph(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is printable


Returns
FALSE: The character is not printable

Click to View Example


Documentation Center

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);

Function boolean isLowerCase(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is lower case


Returns
FALSE: The character is not lower case

Click to View Example

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);

Function boolean isPrintable(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is printable


Returns
FALSE: The character is not printable

Click to View Example

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

Function boolean isPunct(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is a punctuation


Returns
FALSE: The character is not a punctuation

Click to View Example

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);

Function boolean isSpace(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is white-space


Returns
FALSE: The character is not white-space

Click to View Example

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);

Function boolean isUpperCase(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is upper case


Returns
FALSE: The character is not upper case

Click to View Example


Documentation Center

isHexadecimalDigit()
Analyze if a char is an hexadecimal digit (A-F, 0-9). Returns true if thisChar contains an hexadecimal digit.

c
isHexadecimalDigit(thisChar);

Function boolean isHexadecimalDigit(int thisChar)

Parameters thisChar variable(Type: char)

TRUE: The character is an hexadecimal digit


Returns
FALSE: The character is not an hexadecimal digit

Click to View Example

Bit and Byte


bitRead
Reads a bit of a number.

c
bitRead(value, bit);

Function #define bitRead(value, bit)(((value) >> (bit)) & 0x01)

value - The number from which to read


Parameters
bit - Which bit to read, starting at 0 for the least-significant (rightmost) bit

Returns The value of the bit (0 or 1)

Click to View Example

bitSet
Sets (writes a 1 to) a bit of a numeric variable.

c
bitSet(value, bit);
Documentation Center

Function #define bitSet(value, bit)((value) | = (1UL << (bit)))

value - The numeric variable whose bit to set


Parameters
bit - Which bit to set, starting at 0 for the least-significant (rightmost) bit

Returns void

Click to View Example

bitClear
Clears (writes a 0 to) a bit of a numeric variable.

c
bitClear(value, bit);

Function #define bitClear(value, bit)((value) &= ~(1UL << (bit)))

value - The numeric variable whose bit to clear


Parameters
bit - Which bit to clear, starting at 0 for the least-significant (rightmost) bit

Returns The value of the numeric variable after the bit at position n is cleared

Click to View Example

bitWrite
Writes a bit of a numeric variable.

c
bitWrite(value, bit, bitvalue);

#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) :


Function
bitClear(value, bit))

value - The numeric variable to which to write


Parameters bit - Which bit of the number to write, starting at 0 for the least-significant (rightmost) bit
bitvalue - The value to write to the bit (0 or 1)

Returns void

Click to View Example


Documentation Center

bit
Computes the value of the specified bit. (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.)

c
bit(b);

Function #define bit(b)(1UL << (b))

Parameters b - The bit whose value to compute

Returns The value of the bit

Click to View Example

lowByte
Extracts the low-order (rightmost) byte of a variable (e.g. a word).

c
lowByte(w);

Function #define lowByte(w)((uint8_t) ((w) & 0xff))

Parameters w - A value of any type

Returns byte

Click to View Example

highByte
Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).

c
highByte(w);

Function #define highByte(w)((uint8_t)((w) >> 8))

Parameters w - A value of any type

Returns byte
Documentation Center

Click to View Example

DigitalIO
pinMode()
Configures the specified pin to behave either as an input or an output.

c
pinMode(pin, mode);

Function void pinMode(uint8_t pin, uint8_t mode)

pin - The pin which you want to set


Parameters
mode - INPUT , OUTPUT , or INPUT_PULLUP

Returns void

Click to View Example

digitalWrite()
Writes a HIGH or a LOW value to a digital pin.

c
digitalWrite(pin, value);

Function void digitalWrite(uint8_t pin, uint8_t value)

pin - The pin which you want to write


Parameters
value - HIGH or LOW

Returns void

Click to View Example

digitalRead()
Reads the value from a specified digital pin, either HIGH or LOW.

c
digitalRead(pin);
Documentation Center

Function int digitalRead (uint8_t pin)

Parameters pin - The pin which you want to read

Returns HIGH or LOW(Type: int)

Click to View Example

AnalogIO
analogRead()
Reads the value from the specified analog pin.

c
analogRead(pin);

Function int analogRead(uint8_t pin)

Parameters pin - The name of the analog input pin to read from

Returns The analog reading on the pin(Type: int)

analogReference()
Configures the reference voltage used for analog input.

c
analogReference(type);

Function void analogReference(uint8_t type)

type - Which type of reference to use:


UDRV_ADC_MODE_DEFAULT
UDRV_ADC_MODE_3_3
Parameters (Interval Vref RAK4630) UDRV_ADC_MODE_3_0
UDRV_ADC_MODE_2_4
UDRV_ADC_MODE_1_8
UDRV_ADC_MODE_1_2

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);

Function void analogWrite(uint8_t pin, int value)

pin - The pin which you want to read


Parameters
value - The duty cycle: between 0 (always off) and 255 (always on)

Returns void

Click to View Example

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);

Function void analogReadResolution(uint8_t 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

Function void analogWriteResolution(uint8_t bits)

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();

Function void interrupts(void)

Returns void

Click to View Example

noInterrupts()
Disables interrupts. You can re-enable them with interrupts() .

c
noInterrupts();

Function void noInterrupts(void)

Returns void

Click to View Example

attachInterrupt()
Digital Pins With Interrupts. See also AttachInterrupt

c
attachInterrupt(pin, ISR, mode);
Documentation Center

Function void attachInterrupt(uint32_t pin, void(*)(void) userFunc, int mode)

pin - The number of the interrupt


ISR - The ISR to call when the interrupt occurs; this function must take no parameters and
Parameters return nothing. This function is sometimes referred to as an interrupt service routine.
mode - Defines when the interrupt should be triggered (LOW, CHANGE, RISING,
FALLING).

Returns void

Click to View Example

detachInterrupt()
Turns off the given interrupt.

c
detachInterrupt(pin);

Function void detachInterrupt(uint32_t pin)

Parameters pin - The number of the interrupt to disable

Returns void

Click to View Example

RandomNumber
random
The random function generates pseudo-random numbers.

c
random(max);

c
random(min, max);
Documentation Center

Function long random(long min, long max)

min(optional) - Lower bound of the random value, inclusive(default = 0)


Parameters
max - Upper bound of the random value, exclusive

Returns A random number between min and max-1(Type: long)

Click to View Example

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);

Function void randomSeed (unsigned long seed)

Parameters seed number to initialize the pseudo-random sequence

Returns void

Click to View Example

Last Updated: 8/5/2022, 7:20:53 AM

You might also like