RAK3112 WisDuo LPWAN+BLE+Wi-Fi Module Interface Access Using Arduino
This guide shows how to use Arduino APIs to access the peripherals of RAK3112 module. It includesbasic code 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 RAK3112 Quick Start Guide .
Digital IO Pins
Here‘s the available Digital IO Pins in RAK3112. Pins with specific functions, such as UART and I2C, are also usable but with limitations. Those dedicated pins have been excluded from this illustration of digital IO pins.
| Pin No. | Name | Type | Description |
|---|---|---|---|
| 11 | GPIO38 | I/O | GPIO |
| 12 | GPIO39 | I/O | GPIO |
| 18 | GPIO41 | I/O | GPIO |
| 19 | GPIO42 | I/O | GPIO |
| 23 | GPIO45 | I/O | GPIO |
| 24 | GPIO0 / Boot | I/O Boot | GPIO Bootloader force |
| 25 | GPIO46 | I/O | GPIO |
| 26 | GPIO1 | I/O | GPIO |
| 27 | GPIO2 | I/O | GPIO |
Click to view the example code.
/*
RAK3112 Digital I/O Example
*/
void setup()
{
pinMode(WB_IO1, OUTPUT); // Change the WB_IO1 (GPIO21) to any digital pin you want. Also, you can set this to INPUT or OUTPUT
}
void loop()
{
digitalWrite(WB_IO1,HIGH); //Change the PA8 to any digital pin you want. Also, you can set this to HIGH or LOW state.
delay(1000); // delay for 1 second
digitalWrite(WB_IO1,LOW); //Change the PA8 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
Here‘s the available Analog input Pins in RAK3112.
| Pin No. | Name | Type | Description |
|---|---|---|---|
| 34 | GPIO14 / AIN1 | I/O Analog In | GPIO / Analog In |
| 41 | GPIO21 / AIN0 | I/O Analog In | GPIO / Analog In |
Click to view the example code.
/*
RAK3112 Analog Input Pins
*/
#define analogPin 21 // Use GPIO21
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
}
Serial Interface Peripherals
The RAK3112 provides UART, I2C, and SPI interfaces for communication with external devices. The following sections describe their pin assignments and demonstrate how to access these interfaces using RUI3 APIs.
UART
There is one UART peripheral and one USB peripheral available on the RAK3112.
| Pin No. | Name | Type | Description |
|---|---|---|---|
| 2 | USB_D- | USB | USB - |
| 3 | USB_D+ | USB | USB + |
| 6 | GPIO44 / UART0_RX | I/O UART | GPIO / UART RX |
| 7 | GPIO43 / UART1_TX | I/O UART | GPIO / UART TX |
Click to view the example code.
void setup()
{
Serial.begin(115200); // By default Serial is using the USB port.
Serial0.begin(115200); // Serial0 is assigned to the UART0 RX/TX pins
}
void loop()
{
Serial.println("RAK3112 USB TEST!");
Serial0.println("RAK3112 UART TEST!");
delay(1000); // delay for 1 second
}
I2C
The RAK3112 provides two I2C ports, I2C1 and I2C2. Here's the available pins for each port.
| Pin No. | Name | Type | Description |
|---|---|---|---|
| 13 | GPIO40 / I2C1_SCL | I/O I2C | GPIO / I2C SCL |
| 28 | GPIO9 / I2C1_SDA | I/O I2C | GPIO / I2C SDA |
| 39 | GPIO18 / I2C2_SCL | I/O I2C | GPIO / I2C SCL |
| 40 | GPIO17 / I2C2_SDA | I/O I2C | GPIO / I2C SDA |
Connect an I2C device to these pins before running the example.
Click to view the example code.
#include <Wire.h>
void setup()
{
Wire.begin(); // Wire is using the I2C2 port on GPIO18 and GPIO17
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.endTransmisstion 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
}
SPI
The RAK3112 has two SPI ports. But only one SPI port is available for peripherals and exposed. The second SPI port is used internally for the connection to the LoRa transceiver.
| Pin No. | Name | Type | Description |
|---|---|---|---|
| 30 | GPIO10 / SPI_MISO | I/O SPI | GPIO / SPI MISO |
| 31 | GPIO11 / SPI_MOSI | I/O SPI | GPIO / SPI MOSI |
| 32 | GPIO12 / SPI_CS | I/O SPI | GPIO / SPI CS |
| 33 | GPIO13 / SPI_SCK | I/O SPI | GPIO / SPI SCK |
