RAK3212 WisDuo LoRaWAN + BLE + WiFi Breakout Board Interface Access Using Arduino
This guide shows how to use Arduino APIs to access the peripherals of RAK3212 Breakout Board. It includesbasic code for digital I/O, analog input, UART, and I2C, as well as pinout information for SPI.
- GPIO33 to GPIO37 are on the stamp modules pins, but with the 16 MB Flash chip, these GPIOs are not available.
- GPIO4 is used internally and not available.
The RAK3212 Breakout Board exposes all available pins of the RAK3112 WisDuo module through four pin headers. For detailed pin assignments and functions, refer to the RAK3212 Breakout Board Datasheet .
Figure 1: RAK3212 Pin HeadersBefore using the examples in this guide, make sure you have completed the hardware setup and Arduino IDE installation described in the RAK3212 Breakout Board Quick Start Guide .
Digital IO Pins
Click to view the example code.
/*
RAK3212 Digital I/O Example
*/
void setup()
{
pinMode(21, OUTPUT); // Change the GPIO21 to any digital pin you want. Also, you can set this to INPUT or OUTPUT
}
void loop()
{
digitalWrite(21,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(21,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
Click to view the example code.
/*
RAK3212 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 Interfaces
The RAK3212 provides UART, I2C, and SPI interfaces for communication with external devices and peripherals.
UART
There is one UART peripheral and one USB peripheral available on the RAK3212.
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("RAK3212 USB TEST!");
Serial0.println("RAK3212 UART TEST!");
delay(1000); // delay for 1 second
}
I2C
The RAK3212 provides two I2C interfaces. 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 Wire.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
}
SPI
The RAK3212 has two SPI interfaces. One is exposed for external peripherals, while the other is used internally to communicate with the LoRa transceiver.
