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
- RAK13004 WisBlock PWM 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 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/Column | Column 1 | Column 2 | Column 3 | Column 4 |
---|---|---|---|---|
Row 1 | CH0 | CH1 | CH14 | CH15 |
Row 2 | CH2 | CH3 | CH12 | CH13 |
Row 3 | CH4 | CH5 | CH10 | CH11 |
Row 4 | CH6 | CH7 | CH8 | CH9 |
Row 5 | GND | VCC | GND | VCC |
For more information about RAK13004, refer to the Datasheet.
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.
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 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
- RAK13004 in RAK11200 WisBlock Core Guide
- RAK13004 in RAK11300 WisBlock Core Guide
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.
- First, you need to select the RAK4631 WisBlock Core.
- 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);
}
}
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.
- Install the required library, as shown in Figure 8.
- Select the correct port and upload your code, as shown in Figure 9 and Figure 10.
- 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.
- First, you need to select the RAK11200 WisBlock Core.
- 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);
}
}
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.
- Install the required library, as shown in Figure 13.
- Select the correct port and upload your code, as shown in Figure 14 and Figure 15.
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.
- 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
- First, you need to select the RAK11300 WisBlock Core, as shown in Figure 16.
- 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);
}
}
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.
- Install the required library, as shown in Figure 17.
- Select the correct port and upload your code, as shown in Figure 18 and Figure 19.
- When you successfully uploaded the example sketch, you can see that the LEDs are fading in and out.