I am utilizing RAK4631 attached to RAK19007 with RAK 12013 attached to the IO-Slot. I am trying to build out a PlatformIO build that can include multiple sensors based on build flags. Each Sensor is a separate library to do the basic INIT and read while the main.h file conditionally includes the reads and writes to the WIS API V2.
I had no problem do this for the 3-axis sensor 1904. When I tried to do this for the IO-Slot sensor RAK12013 I cannot get the sensor to read motion.
The variant.h file defines:
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT
static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT
static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT
static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT
static const uint8_t WB_SPI_CS = 26; // IO_SLOT
static const uint8_t WB_SPI_CLK = 3; // IO_SLOT
static const uint8_t WB_SPI_MISO = 29; // IO_SLOT
static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT
What IO-Slot am I suppose to use? I know I need to turn on the slot and then create loop to detect motion. In the INO example you provide it says WB_IO4 is the slot to turn on and WB_IO3 is the slot I read.
I tried that and only get 0 as motion.
Here is the code I am using in my RAK12013 library:
#include "RAK12013.h"
#include "Wire.h"
#include "SPI.h"
RAK12013* RAK12013::instance = nullptr;
#ifndef MYLOG
#if MY_DEBUG > 0
#define MYLOG(tag, ...) \
do \
{ \
unsigned long currentMillis = millis(); \
PRINTF("[%lu ms] -- ", currentMillis); \
if (tag) \
PRINTF("[%s] ", tag); \
PRINTF(__VA_ARGS__); \
PRINTF("\n"); \
Serial.flush(); \
} while (0)
#else
#define MYLOG(...)
#endif
#endif
#ifndef BLUE_LED
#define BLUE_LED LED_BLUE
#endif
#ifndef GREEN_LED
#define GREEN_LED LED_GREEN
#endif
boolean g_motion_status = false;
int motion_count = 0;
SoftwareTimer motion_read_timer;
uint8_t SENSOR_OUT;
uint8_t SENSOR_EN;
void readNow(TimerHandle_t unused)
{
MYLOG("IO-SLOT", "readNow hit");
int val = digitalRead(SENSOR_OUT);
MYLOG("IO-SLOT", "Value: %u", val);
if (val > 0 && !g_motion_status) {
digitalWrite(BLUE_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
MYLOG("APP", "Motion Detected");
g_motion_status = true;
motion_count++;
} else if (val == 0 && g_motion_status) {
digitalWrite(BLUE_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
MYLOG("APP", "NO Motion");
g_motion_status = false;
}
}
RAK12013::RAK12013()
{
instance = this;
}
void RAK12013::init(uint8_t slot_in, uint8_t slot_out)
{
SENSOR_EN = slot_in;
SENSOR_OUT = slot_out;
pinMode (SENSOR_EN, OUTPUT);
digitalWrite(SENSOR_EN, HIGH);
MYLOG("APP", "Rader 3GHZ is READY!!!");
pinMode (SENSOR_OUT, INPUT);
pinMode (BLUE_LED, OUTPUT);
pinMode (GREEN_LED, OUTPUT);
MYLOG("APP", "Waiting for motion");
motion_read_timer.begin(5000, readNow, NULL, true);
motion_read_timer.start();
}
void RAK12013::read()
{
int val = digitalRead(SENSOR_OUT);
if (val > 0 && !g_motion_status) {
digitalWrite(BLUE_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
MYLOG("APP", "Motion Detected");
g_motion_status = true;
motion_count++;
} else if (val == 0 && g_motion_status) {
digitalWrite(BLUE_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
MYLOG("APP", "NO Motion");
g_motion_status = false;
}
}
int RAK12013::get_motion_count()
{
MYLOG("APP", "Motion Count: %d", motion_count);
return motion_count;
}
void RAK12013::handleInterrupt(TimerHandle_t unused) {
if (instance) {
instance->read();
}
}
Any help would be much appreciated.