RAK13003 WisBlock IO Expansion Module Quick Start Guide
Prerequisite
- Assemble the RAK13003 with a WisBlock Base and WisBlock Core by following the RAK13003 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- Light-emitting diode or LEDs
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Initial Test of the RAK13003 WisBlock Module
NOTE
- This guide uses the RAK4631 WisBlock Core to demonstrate the configuration process. You can also use the RAK11200 or RAK11310 as the WisBlock Core.
- When using the RAK11200, configure the BOOT0 pin correctly before uploading the source code. Otherwise, the upload may fail. For detailed instructions, refer to the RAK11200 Quick Start Guide.
- This example uses the RAK13003 WisBlock IO Expansion Module to power LEDs.
- Install the RAKwireless Arduino BSP's for WisBlock by using the
package_rakwireless_index.jsonboard installation package, the WisBlock Core should now be available on the Arduino IDE. - Use the RAK13003 IO Expansion Module to power ON LEDs using the digitalWrite function.
Figure 1: RAK13003 as Output to LEDs- You need to select first the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core- Next, copy the 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);
}
NOTE
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.
Figure 1: Installing the LibraryNOTE
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.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading code- 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.
Figure 1: Switching between PA and PBNOTE
You can use mcp.digitalWrite(pin_no,state) and mcp.digitalRead(pin_no) to send or read states.
