RAK13003 WisBlock IO Expansion Module Quick Start Guide
Prerequisite
What Do You Need?
Before going through each and every step on using RAK13003 WisBlock module, make sure to prepare the necessary items listed below:
Hardware
- RAK13003 IO Expansion Module
- Your choice of WisBlock Base
- Your choice of WisBlock Core
- Light-emitting diode or LEDs
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Software
Arduino
- Download and install Arduino IDE.
- To add the RAKwireless Core boards on your Arduino Boards Manager, install the RAKwireless Arduino BSP.
Product Configuration
Hardware Setup
The RAK13003 is an IO expansion module that can be mounted to the IO slot of the WisBlock Baseboard. It offers 16 bidirectional I/O ports by using MCP23017 IC from Microchip. The configuration of this module is via the I2C interface, and it supports both standard and fast I2C modes.
Row/Column | Column 1 | Column 2 | Column 3 | Column 4 |
---|---|---|---|---|
Row 1 | PA0 | PA1 | PB6 | PB7 |
Row 2 | PA2 | PA3 | PB4 | PB5 |
Row 3 | PA4 | PA5 | PB2 | PB3 |
Row 4 | PA6 | PA7 | PB0 | PB1 |
Row 5 | GND | VCC | GND | VCC |
For more information about RAK13003, refer to the Datasheet.
Assembling and Disassembling of WisBlock Modules
Assembling Procedure
The RAK13003 module can be mounted on the IO slot of the WisBlock Base board, as shown in Figure 2. Also, always secure the connection of the WisBlock module by using the compatible screws.
Disassembling Procedure
The procedure in disassembling any type of WisBlock modules is the same.
- First, remove the screws.
- Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
- Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts.
Software Configuration and Example
In the following example, you will be using the RAK13003 WisBlock IO Expansion Module to power LEDs.
Initial Test of the RAK13003 WisBlock Module
-
Install the RAKwireless Arduino BSP's for WisBlock by using the
package_rakwireless_index.json
board installation package, the WisBlock Core should now be available on the Arduino IDE. -
Shown in Figure 6 is the illustration on how to use the RAK13003 IO Expansion Module to power ON LEDs using digitalWrite function.
- You need to select first the WisBlock Core you have, as shown in Figure 7 to Figure 9.
- Next, copy the following sample code into your Arduino IDE.
Click to view the code
/**
@file RAK13003_GPIO_Expander_IO_MCP32.ino
@author rakwireless.com
@brief Use IIC to expand 16 GPIO.
Configure PA input PB output, or PA output PB input.Serial port print GPIO status.
@version 0.2
@date 2022-5-11
@copyright Copyright (c) 2022
**/
#include <Wire.h>
#include "Adafruit_MCP23X17.h" //http://librarymanager/All#Adafruit_MCP23017
#define PAIN_PBOUT //PB is set as output here and PA as input.
//#define PAOUT_PBIN
Adafruit_MCP23X17 mcp;
void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, 1);
// Reset device
pinMode(WB_IO4, OUTPUT);
digitalWrite(WB_IO4, 1);
delay(10);
digitalWrite(WB_IO4, 0);
delay(10);
digitalWrite(WB_IO4, 1);
delay(10);
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("MCP23017 GPIO Input Output Test.");
mcp.begin_I2C(); // use default address 0.
#ifdef PAIN_PBOUT
for(int i=0 ;i < 8 ;i++)
{
mcp.pinMode(i, INPUT); // PA input.
}
for(int j=8 ;j < 16 ;j++)
{
mcp.pinMode(j, OUTPUT); // PB output.
}
mcp.digitalWrite(8, LOW); // The output state of the PB port can be changed to high or low level.
mcp.digitalWrite(9, HIGH); //PIN PB1
mcp.digitalWrite(10, LOW); //PIN PB2
mcp.digitalWrite(11, LOW); //PIN PB3
mcp.digitalWrite(12, LOW); //PIN PB4
mcp.digitalWrite(13, LOW); //PIN PB5
mcp.digitalWrite(14, LOW); //PIN PB6
mcp.digitalWrite(15, HIGH);//PIN PB7
Serial.println();
for(int i=0; i < 8; i++ )
{
if(mcp.digitalRead(i) == 1)
Serial.printf("GPIO A %d Read High\r\n",i);
else
Serial.printf("GPIO A %d Read Low\r\n",i);
}
#endif
#ifdef PAOUT_PBIN
for(int i=0 ;i < 8 ;i++)
{
mcp.pinMode(i, OUTPUT); // PA output.
}
for(int j=8 ;j < 16 ;j++)
{
mcp.pinMode(j, INPUT); // PB input.
}
mcp.digitalWrite(0, LOW); // The output state of the PA port can be changed to high or low level.
mcp.digitalWrite(1, HIGH); // PA1
mcp.digitalWrite(2, LOW); // PA2
mcp.digitalWrite(3, HIGH); // PA3
mcp.digitalWrite(4, LOW); // PA4
mcp.digitalWrite(5, HIGH); // PA5
mcp.digitalWrite(6, LOW); // PA6
mcp.digitalWrite(7, HIGH); //PA7
Serial.println();
for(int i=8; i < 16; i++ )
{
if(mcp.digitalRead(i) == 1)
Serial.printf("GPIO B %d Read High\r\n",i-8);
else
Serial.printf("GPIO B %d Read Low\r\n",i-8);
}
#endif
}
void loop()
{
mcp.digitalWrite(8, HIGH); //PIN PB0
delay(1000);
mcp.digitalWrite(8, LOW); //PIN PB0
delay(1000);
}
If you experience any error in compiling the example sketch, check the updated code for the all WisBlock Core Module that can be found on the RAK13003 WisBlock Example Code Repository. Other examples like interrupt and pooling can be found in the github repository as well.
- Install the required library, as shown in Figure 10.
The library version required must be at least ver 2.1.0 to compile the example code successfully.
- Select the correct port and upload your code, as shown in Figure 11 and Figure 12.
If you're using the RAK11200 as your WisBlock Core, the RAK11200 requires the Boot0 pin to be configured properly first before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.
- When you have successfully uploaded the example sketch, you can see that the LEDs are powered ON and PB0 will have LED blinking output. You can also switch PB as INPUT and PA as OUTPUT by changing this line of code shown in Figure 13.
You can use mcp.digitalWrite(pin_no,state)
and mcp.digitalRead(pin_no)
to send or read states.