RAK17000 With RAK4631 WisBlock Core Guide
- First, you need to select the RAK4631 WisBlock Core.
Figure 1: Selecting RAK4631 as the WisBlock Core- Next, copy the following sample code into your Arduino IDE. This example code comes from the RAK17000 WisBlock example repository which controls two DC motors.
Click to view the code
/**
@file RAK17000_Motor_Driver_DRV8833.ino
@author rakwireless.com
@brief Control the two motors for forward and reverse rotation from slow to fast and then from fast to slow.
@version 0.1
@date 2021-5-14
@copyright Copyright (c) 2020
**/
#include <Arduino.h>
#define MOTOR_AIN1 SCK
#define MOTOR_AIN2 SS
#define MOTOR_BIN1 WB_IO3
#define MOTOR_BIN2 MOSI
#define MOTOR_SLEEP WB_IO6
void setup()
{
// Enable DRV8833 output.
pinMode(MOTOR_SLEEP, OUTPUT);
digitalWrite(MOTOR_SLEEP, HIGH);
pinMode(MOTOR_AIN1, OUTPUT);
pinMode(MOTOR_AIN2, OUTPUT);
pinMode(MOTOR_BIN1, OUTPUT);
pinMode(MOTOR_BIN2, OUTPUT);
}
void loop()
{
analogWrite(MOTOR_AIN2, 0);
analogWrite(MOTOR_BIN2, 0);
for(uint8_t i = 0 ;i < 255 ;i++ )
{
analogWrite(MOTOR_AIN1, i);
analogWrite(MOTOR_BIN1, i);
delay(50);
}
delay(100);
for(uint8_t i = 255 ;i > 0 ;i-- )
{
analogWrite(MOTOR_AIN1, i);
analogWrite(MOTOR_BIN1, i);
delay(50);
}
analogWrite(MOTOR_AIN1, 0);
analogWrite(MOTOR_BIN1, 0);
for(uint8_t i = 0 ;i < 255 ;i++ )
{
analogWrite(MOTOR_AIN2, i);
analogWrite(MOTOR_BIN2, i);
delay(50);
}
delay(100);
for(uint8_t i = 255 ;i > 0 ;i-- )
{
analogWrite(MOTOR_AIN2, i);
analogWrite(MOTOR_BIN2, i);
delay(50);
}
delay(100);
}
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 RAK17000 Motor Driver Example WisBlock Repository.
The basic example code for stepper motor control can be found on the RAK17000 WisBlock Example Code repository as well.
- Then you can now select the right port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK17000 Sample code- When you successfully uploaded the example sketch, you'll now see that the motor will start spinning and reversing direction repeatedly.
Resources
For WisBlock Core RAK4630:
-
Sample Code: DC Motor Control — RAK17000_Motor_Driver_DRV8833
-
Sample Code: Stepper Motor Control — RAK17000_Stepper_Driver_DRV8833
