I need to receive rf signal, decode it and check if it says spin left or right. I have no idea what's wrong, but the serial window had crazy output.
neither looping nor message ever print
Here is the receiving program
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
/*
2 - rf send
3 - dir
4 - step
5 - y btn
6 - g btn
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
*/
int rfSend = 2;
int stepPin = 4;
int dirPin = 3;
int yBtn = 5; // ccw
int gBtn = 6; // cw
int dirStatus = 3;
char rotateCCW = '1';
char rotateCW = '2';
char spinStop = '3';
int Pin1 = 0;//IN1 is connected to 10
int Pin2 = 4;//IN2 is connected to 11
int Pin3 = 5;//IN3 is connected to 12
int Pin4 = 16;//IN4 is connected to 13
int pole1[] ={0,0,0,0, 0,1,1,1, 0};//pole1, 8 step values
int pole2[] ={0,0,0,1, 1,1,0,0, 0};//pole2, 8 step values
int pole3[] ={0,1,1,1, 0,0,0,0, 0};//pole3, 8 step values
int pole4[] ={1,1,0,0, 0,0,0,1, 0};//pole4, 8 step values
int poleStep = 0;
RH_ASK driver;
void setup()
{
pinMode(Pin1, OUTPUT);//define pin for ULN2003 in1
pinMode(Pin2, OUTPUT);//define pin for ULN2003 in2
pinMode(Pin3, OUTPUT);//define pin for ULN2003 in3
pinMode(Pin4, OUTPUT);//define pin for ULN2003 in4
pinMode(rfSend, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(yBtn,INPUT_PULLUP);
pinMode(gBtn,INPUT_PULLUP);
Serial.begin(115200); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
Serial.println("looping");
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
if('buff' == rotateCCW) {
dirStatus = '1';
}else if('buff' == rotateCW) {
dirStatus = '2';
}else {
dirStatus = '3';
}
if(dirStatus == 1) {
poleStep++;
driveStepper(poleStep);
}else if(dirStatus == 2){
poleStep--;
driveStepper(poleStep);
}else{
driveStepper(8);
}
if(poleStep>7){
poleStep=0;
}
if(poleStep<0){
poleStep=7;
}
}
delay(1);
}
/*
* @brief sends signal to the motor
* @param "c" is integer representing the pol of motor
* @return does not return anything
*
* www.Robojax.com code June 2019
*/
void driveStepper(int c)
{
//Robojax Stepper Motor Code STPB-2
digitalWrite(Pin1, pole1[c]);
digitalWrite(Pin2, pole2[c]);
digitalWrite(Pin3, pole3[c]);
digitalWrite(Pin4, pole4[c]);
}//driveStepper end here