RAK11161 Breakout Board Interface Access Using RUI3
This guide shows how to use RUI3 APIs to access the pinouts of RAK11161 Breakout Board. 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 RAK11161 Breakout Board Quick Start Guide.
Digital IO Pins
Here's the available Digital IO Pins in RAK11161 (with notes on pins with Analog capability):
| ST_GPIO Header # - Pin # | GPIO |
|---|---|
| 1-5 | ST_PA8 |
| 2-6 | ST_PA9 |
| 2-7 | ST_PB2 / Analog(A2) |
| 2-8 | ST_PB12 |
| 1-6 | ST_PA10 / Analog(A3) |
| 2-2 | ST_PA15 / Analog(A4) |
| 2-5 | ST_PB3 / Analog(A0) |
| 2-4 | ST_PB4 / Analog(A1) |
| 2-1 | ST_PB5 |
The GPIO pins of the ESP8684 cannot be controlled by the STM32WLE5 directly.
Any of the pins listed in the table above can be used. 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.
Click to view the example code.
/*
RAK11161 Digital I/O Example
You can use any of the following as Digital I/O:
ST_PA8 PA8
ST_PA9 PA9
ST_PB2 PB2
ST_PA10 PA10
ST_PB12 PB12
ST_PB3 PB3
ST_PB4 PB4
ST_PB5 PB5
ST_PA1 PA1
ST_PA15 PA15
*/
void setup()
{
pinMode(PA8, OUTPUT); //Change the PA8 to any digital pin you want. Also, you can set this to INPUT or OUTPUT
}
void loop()
{
digitalWrite(PA8,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(PA8,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 RAK11161 Breakout Board:
| ST_GPIO Header # - Pin # | Analog in |
|---|---|
| 2-5 | PB3 |
| 2-4 | PB4 |
| 2-7 | PB2 |
| 1-6 | PA10 |
| 2-2 | PA15 |
Click to view the example code.
/*
RAK11161 Analog Input Pins
ST_PB5 PB5
ST_PA10 PA10
ST_PB3 PA3
ST_PB4 PB4
*/
#define analogPin PB5 // or you can use PB5
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 RAK11161 Breakout Board provides UART, I2C, and SPI interfaces for communication with external devices and peripherals.
UART
There is one UART peripheral available on the RAK11161 Breakout Board. There are also different Serial Operating Modes possible in RUI3, namely AT Mode, and Custom Mode.
| Serial Port | Serial Instance Assignment | Default Mode |
|---|---|---|
| UART2 (PA3)/(PA2) | Serial | AT Command |
Click to view the example code.
void setup()
{
Serial.begin(115200); // By default Serial is used for FW update and AT command.
}
void loop()
{
Serial1.println("RAK11161 TEST!");
delay(1000); // delay for 1 second
}
I2C
Make sure you have an I2C device connected to the specified I2C pins to run the example code.
| I2C | ST_GPIO Header # - Pin # | GPIO |
|---|---|---|
| SDA | 1-7 | PA11 |
| SCL | 1-8 | PA12 |
Click to view the example 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.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 RAK11161 provides an SPI interface through ST_GPIO Header 1. The interface uses PA4 for NSS, PA5 for SCK, PA6 for MISO, and PA7 for MOSI.
| SPI | ST_GPIO Header # - Pin # | GPIO |
|---|---|---|
| NSS | 1-1 | PA4 |
| SCK | 1-2 | PA5 |
| MISO | 1-3 | PA6 |
| MOSI | 1-4 | PA7 |
