Skip to main content

RAK13004 Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using RAK13004 WisBlock module, make sure to prepare the necessary items listed below:

Hardware

Software

Arduino

Product Configuration

Hardware Setup

The RAK13004 is a PWM expansion module that can be mounted to the IO slot of WisBlock Base board. It can control 16-channel PWM output, and the module uses PCA9685 from NXP which can be interfaced via I2C. RAK13004 power source can be controlled by the WisBlock Core via IO2 pin or WB_IO2 in code. This feature can be utilized for applications requiring low power requirements.

Row/ColumnColumn 1Column 2Column 3Column 4
Row 1CH0CH1CH14CH15
Row 2CH2CH3CH12CH13
Row 3CH4CH5CH10CH11
Row 4CH6CH7CH8CH9
Row 5GNDVCCGNDVCC

For more information about RAK13004, refer to the Datasheet.

Figure 3042: RAK13004 Connection to WisBlock Base module

Assembling and Disassembling of WisBlock Modules

Assembling Procedure

The RAK13004 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.

Figure 3043: RAK13004 mounting connection to WisBlock Base module
Disassembling Procedure

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 3044: Removing screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 3045: Detaching silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 3046: Applying even forces on the proper location of a WisBlock module
NOTE

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 RAK13004 WisBlock PWM Expansion Module to set up fading in and out LEDs.

These are the quick links that go directly to the software guide for the specific WisBlock Core module you use:

RAK13004 in RAK4631 WisBlock Core Guide

Arduino Setup

Shown in Figure 6 is the illustration on how to use the RAK13004 PWM Expansion Module to produce PWM Output. In this example, you can use LEDs for demonstration.

Figure 3047: RAK13004 Sending PWM Output to LEDs
  1. First, you need to select the RAK4631 WisBlock Core.
Figure 3048: Selecting RAK4631 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
Click to view the code
/**
@file RAK13004_PWM_Expander_PCA9685.ino
@author rakwireless.com
@brief Use IIC to expand 16 PWM.
Control PCA9685 channels 0~15 to output PWM with different duty cycles and time delays.
The frequency can be adjusted supports 24HZ to 1526HZ.
@version 0.1
@date 2021-3-2
@copyright Copyright (c) 2021
**/

#include <Arduino.h>
#include <PCA9685.h> //Click the link to get the library: http://librarymanager/All#PCA9685

PCA9685 PCA9685;

void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, 1);

PCA9685.setupSingleDevice(Wire,0x40);// Library using 0x40(0100 0000) i2c address, and default Wire @400kHz.

PCA9685.setupOutputEnablePin(WB_IO6);// WB_IO6 active LOW output enable.
PCA9685.enableOutputs(WB_IO6);

PCA9685.setOutputsNotInverted();

PCA9685.setToFrequency(500); // Set PWM freq to 500Hz (supports 24Hz to 1526Hz)

// Set the PWM output of channel 0 .
// PWM duty cycle = 50 % (LED on time = 50 %; LED off time = 50 %).
// Delay time = 0 % .
PCA9685.setChannelDutyCycle(0, 50, 0);
PCA9685.setChannelDutyCycle(1, 50, 25);
PCA9685.setChannelDutyCycle(2, 50, 50);
PCA9685.setChannelDutyCycle(3, 10, 10);
PCA9685.setChannelDutyCycle(4, 20, 20);
PCA9685.setChannelDutyCycle(5, 30, 30);
PCA9685.setChannelDutyCycle(6, 40, 40);
PCA9685.setChannelDutyCycle(7, 50, 50);
PCA9685.setChannelDutyCycle(8, 60, 60);
PCA9685.setChannelDutyCycle(9, 70, 70);
PCA9685.setChannelDutyCycle(10, 80, 80);
PCA9685.setChannelDutyCycle(11, 90, 90);
PCA9685.setChannelDutyCycle(12, 100, 0);
}

void loop()
{
// Use channels 13, 14, 15 to make a simple breathing light example.
for(uint8_t i=0 ;i < 100; i+=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
for(uint8_t i=100 ;i >0; i-=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK4631 WisBlock Core Module that can be found on the RAK13004 WisBlock Example Code Repository.

  1. Install the required library, as shown in Figure 8.
Figure 3049: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 9 and Figure 10.
Figure 3050: Selecting the correct Serial Port
Figure 3051: Uploading code
  1. When you successfully uploaded the example sketch, you can see that the LEDs are fading in and out.

RAK13004 in RAK11200 WisBlock Core Guide

Arduino Setup

Shown in Figure 11 is the illustration on how to use the RAK13004 PWM Expansion Module to produce PWM Output. In this example, you can use LEDs for demonstration.

Figure 3052: RAK13004 Sending PWM Output to LEDs
  1. First, you need to select the RAK11200 WisBlock Core.
Figure 3053: Selecting RAK11200 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
Click to view the code
/**
@file RAK13004_PWM_Expander_PCA9685.ino
@author rakwireless.com
@brief Use IIC to expand 16 PWM.
Control PCA9685 channels 0~15 to output PWM with different duty cycles and time delays.
The frequency can be adjusted supports 24HZ to 1526HZ.
@version 0.1
@date 2021-3-2
@copyright Copyright (c) 2021
**/

#include <Arduino.h>
#include <PCA9685.h> //Click the link to get the library: http://librarymanager/All#PCA9685

PCA9685 PCA9685;

void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, 1);

PCA9685.setupSingleDevice(Wire,0x40);// Library using 0x40(0100 0000) i2c address, and default Wire @400kHz.

PCA9685.setupOutputEnablePin(WB_IO6);// WB_IO6 active LOW output enable.
PCA9685.enableOutputs(WB_IO6);

PCA9685.setOutputsNotInverted();

PCA9685.setToFrequency(500); // Set PWM freq to 500Hz (supports 24Hz to 1526Hz)

// Set the PWM output of channel 0 .
// PWM duty cycle = 50 % (LED on time = 50 %; LED off time = 50 %).
// Delay time = 0 % .
PCA9685.setChannelDutyCycle(0, 50, 0);
PCA9685.setChannelDutyCycle(1, 50, 25);
PCA9685.setChannelDutyCycle(2, 50, 50);
PCA9685.setChannelDutyCycle(3, 10, 10);
PCA9685.setChannelDutyCycle(4, 20, 20);
PCA9685.setChannelDutyCycle(5, 30, 30);
PCA9685.setChannelDutyCycle(6, 40, 40);
PCA9685.setChannelDutyCycle(7, 50, 50);
PCA9685.setChannelDutyCycle(8, 60, 60);
PCA9685.setChannelDutyCycle(9, 70, 70);
PCA9685.setChannelDutyCycle(10, 80, 80);
PCA9685.setChannelDutyCycle(11, 90, 90);
PCA9685.setChannelDutyCycle(12, 100, 0);
}

void loop()
{
// Use channels 13, 14, 15 to make a simple breathing light example.
for(uint8_t i=0 ;i < 100; i+=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
for(uint8_t i=100 ;i >0; i-=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK11200 WisBlock Core Module that can be found on the RAK13004 WisBlock Example Code Repository.

  1. Install the required library, as shown in Figure 13.
Figure 3054: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 14 and Figure 15.
Figure 3055: Selecting the correct Serial Port
Figure 3056: Uploading code
NOTE

RAK11200 requires the BOOT0 pin to be configured properly before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.

  1. When you successfully uploaded the example sketch, you can see that the LEDs are fading in and out.

RAK13004 in RAK11300 WisBlock Core Guide

Arduino Setup
  1. First, you need to select the RAK11300 WisBlock Core, as shown in Figure 16.
Figure 3057: Selecting RAK11300 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE:
Click to view the code
/**
@file RAK13004_PWM_Expander_PCA9685.ino
@author rakwireless.com
@brief Use IIC to expand 16 PWM.
Control PCA9685 channels 0~15 to output PWM with different duty cycles and time delays.
The frequency can be adjusted supports 24HZ to 1526HZ.
@version 0.1
@date 2021-3-2
@copyright Copyright (c) 2021
**/

#include <Arduino.h>
#include <PCA9685.h> //Click the link to get the library: http://librarymanager/All#PCA9685

PCA9685 PCA9685;

void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, 1);

PCA9685.setupSingleDevice(Wire,0x40);// Library using 0x40(0100 0000) i2c address, and default Wire @400kHz.

PCA9685.setupOutputEnablePin(WB_IO6);// WB_IO6 active LOW output enable.
PCA9685.enableOutputs(WB_IO6);

PCA9685.setOutputsNotInverted();

PCA9685.setToFrequency(500); // Set PWM freq to 500Hz (supports 24Hz to 1526Hz)

// Set the PWM output of channel 0 .
// PWM duty cycle = 50 % (LED on time = 50 %; LED off time = 50 %).
// Delay time = 0 % .
PCA9685.setChannelDutyCycle(0, 50, 0);
PCA9685.setChannelDutyCycle(1, 50, 25);
PCA9685.setChannelDutyCycle(2, 50, 50);
PCA9685.setChannelDutyCycle(3, 10, 10);
PCA9685.setChannelDutyCycle(4, 20, 20);
PCA9685.setChannelDutyCycle(5, 30, 30);
PCA9685.setChannelDutyCycle(6, 40, 40);
PCA9685.setChannelDutyCycle(7, 50, 50);
PCA9685.setChannelDutyCycle(8, 60, 60);
PCA9685.setChannelDutyCycle(9, 70, 70);
PCA9685.setChannelDutyCycle(10, 80, 80);
PCA9685.setChannelDutyCycle(11, 90, 90);
PCA9685.setChannelDutyCycle(12, 100, 0);
}

void loop()
{
// Use channels 13, 14, 15 to make a simple breathing light example.
for(uint8_t i=0 ;i < 100; i+=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
for(uint8_t i=100 ;i >0; i-=1)
{
PCA9685.setChannelDutyCycle(13, i,0);
PCA9685.setChannelDutyCycle(14, 100-i,0);
PCA9685.setChannelDutyCycle(15, i,0);
delay(20);
}
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK11300 WisBlock Core Module that can be found on the RAK13004 WisBlock Example Code Repository.

  1. Install the required library, as shown in Figure 17.
Figure 3058: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 18 and Figure 19.
Figure 3059: Selecting the correct Serial Port
Figure 3060: Uploading the code
  1. When you successfully uploaded the example sketch, you can see that the LEDs are fading in and out.