RAK3172-SiP WisDuo LPWAN SiP Interface Access Using RUI3
This guide shows how to use RUI3 APIs to access the pinouts of RAK3172-SiP. It includes code examples for digital I/O, analog input, UART, and I2C, as well as pinout information for SPI.
Before using the examples in this guide, make sure you have completed the hardware setup and Arduino IDE installation described in the RAK3172-SiP Quick Start Guide.
Digital I/O Pins
The available digital I/O pins are highlighted in purple.
Figure 1: Available Digital I/O pins in RAK3172-SiP moduleYou can use any of the pins below as Digital Pin.
| Port Name | Alternative Pin Usage |
|---|---|
| PA4 | SPI1_NSS |
| PA5 | SPI1_CLK |
| PA6 | SPI1_MISO |
| PA7 | SPI1_MOSI |
| PA8 | - |
| PA9 | I2C_SCL |
| PA10 | I2C_SDA / PIN_A4 |
| PA15 | PIN_A3 |
| PB1 | - |
| PB2 | PIN_A2 |
| PB3 | PIN_A0 |
| PB4 | PIN_A1 |
| PB5 | - |
| PB6 | UART1_TX |
| PB7 | UART1_RX |
| PB8 | - |
| PB9 | - |
| PB10 | - |
| PB11 | - |
| PB12 | - |
| PB13 | - |
| PB14 | - |
| PB15 | - |
| PC0 | - |
| PC1 | - |
| PC2 | - |
| PC3 | - |
| PC4 | - |
| PC5 | - |
| PC6 | - |
| PC13 | - |
The pins listed below must not be used.
| Port Name | Pin Usage | Pin Number |
|---|---|---|
| PA2 | UART2_TX | 29 |
| PA3 | UART2_RX | 30 |
| PA13 | SWDIO | 1 |
| PA14 | SWCLK | 2 |
The RUI3 Arduino API provides the following functions for digital I/O:
-
pinMode(): Configures a GPIO pin as an input or output. -
digitalRead(): Reads the logic level of a digital input pin (HIGHorLOW). -
digitalWrite(): Sets a digital output pin toHIGHorLOW.
The GPIO pin name is the one to be used on the digitalRead and digitalWrite and NOT the pin numbers.
Click to view the code.
void setup()
{
pinMode(PA15, OUTPUT); //Change the P0_04 to any digital pin you want. Also, you can set this to INPUT or OUTPUT
}
void loop()
{
digitalWrite(PA15,HIGH); //Change the PA15 to any digital pin you want. Also, you can set this to HIGH or LOW state.
delay(1000); // delay for 1 second
digitalWrite(PA15,LOW); //Change the PA15 to any digital pin you want. Also, you can set this to HIGH or LOW state.
delay(1000); // delay for 1 second
}
Analog Input Pins
The available Analog pins are highlighted in purple.
Figure 1: Available Analog pins in RAK3172-SiP Module| Port Name | ADC | Pin Number |
|---|---|---|
| PB3 | PIN_A0 | 14 |
| PB4 | PIN_A1 | 15 |
| PB2 | PIN_A2 | 57 |
| PA10 | PIN_A3 | 62 |
| PA15 | PIN_A4 | 8 |
Use Arduino analogRead to read the value from the specified Analog Input pin.
Click to view the code.
#define analogPin PB3
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(115200);
}
void loop()
{
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
delay(100);
}
Serial Interfaces
The RAK3172 provides UART, I2C, and SPI interfaces for communication with external devices.
UART
There are two UART peripherals available on the RAK3172-SiP module. There are also different Serial Operating Modes possible in RUI3, namely Binary Mode, AT Mode, and Custom Mode.
Figure 1: Available UART pins in RAK3172-SiP Module| Port Name | Serial Port | Serial Instance Assignment | Default Mode | Pin Number |
|---|---|---|---|---|
| PB6 | UART1_RX | Serial1 | Custom Mode | 17 |
| PB7 | UART1_TX | Serial1 | Custom Mode | 18 |
| PA3 | UART2_RX | Serial | AT Command | 30 |
| PA2 | UART2_TX | Serial | AT Command | 29 |
Click to view the code.
void setup()
{
Serial1.begin(115200); // use Serial1 for UART1 and Serial for UART2
// you can designate separate baudrate for each.
Serial.begin(115200);
}
void loop()
{
Serial1.println("RAK3172-SiP UART1 TEST!");
Serial.println("RAK3172-SiP UART2 TEST!");
delay(1000); // delay for 1 second
}
I2C
There is one I2C peripheral available on RAK3172-SiP Module. Make sure you have an I2C device connected to specified I2C pins to run the I2C scanner code.
Figure 1: Available I2C pins in RAK3172-SiP Module| Port Name | I2C Pin Name | Pin Number |
|---|---|---|
| PA9 | I2C_SCL | 50 |
| PA10 | I2C_SDA | 62 |
Use Arduino Wire library to communicate with I2C devices.
Click to view the code.
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmission to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
The Arduino Serial Monitor shows the I2C device found.
17:29:15.690 -> Scanning...
17:29:15.738 -> I2C device found at address 0x28 !
17:29:15.831 -> done
17:29:15.831 ->
17:29:20.686 -> Scanning...
17:29:20.733 -> I2C device found at address 0x28 !
17:29:20.814 -> done
17:29:20.814 ->
SPI
Figure 1: Available SPI pins in RAK3172-SiP ModuleIf your RUI3 project uses SPI, then PA4 to PA7 pins are reserved for RUI3 SPI interface.
| Port Name | SPI Pin Name | Pin Number |
|---|---|---|
| PA4 | SPI1_CS | 31 |
| PA5 | SPI1_CLK | 32 |
| PA6 | SPI1_MISO | 33 |
| PA7 | SPI1_MOSI | 34 |
