Comparing received rf signal

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

if('buff' == rotateCCW) {

Oops. Pretty sure you didn't compile that successfully, did you?

It might compile since both sides of the == are chars, but 'buff' is four chars, and your directions are only one char. They'll NEVER match. Read up on data types. You might want to look at the contents and not the name.

It's a good point, it does technically compile, come to it. Throws warnings, but new users never have that level enabled, and wouldn't know what to do with them anyway. That's a big flaw in the Arduino environment, as far as I'm concerned.
That's twice today I've been fooled by newish constructs in C(new since 1984...). That would have been a compile error then, for sure. I presume(not gonna look it up) this is now tolerated in order to accommodate greater than 1 character character sets.

Thanks, Mark.

@joortiz22 If you never see "looping", since it's the first line in loop() you're not getting out of setup(), and that pretty much means either driver.init() failed, or you've got the context of the call wrong, and are failing it despite it passing.

1 Like

I know nothing of this radio head stuff..

the above is using the default construct..


RH_ASK (uint16_t speed=2000, uint8_t rxPin=11, uint8_t txPin=12, uint8_t pttPin=10, bool pttInverted=false)

do you have your device hooked up to the default pins??

sorry.. ~q

You haven't shown us the program for the Transmit end.

Did you get the RH library's examples working with your hardware before trying your own program?

Hello joortiz22

Do the transmitter and receiver speak the same 'language', such as modulation type, frequency, data protocol, etc.? ?

Hi,
We need to know;

  1. What RF modules you are using.
  2. What model Arduino you are using?
  3. A schematic of Tx and Rx circuits.
    An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
  4. Complete Tx and Rx code.
  5. What is your application for this project?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

The compiled perfectly fine

Well, it's perfectly compiled nonsense. The 'if' statement in question doesn't even use the data received in the buffer.

i just get a warning, but i believe the intent is more like

       if (buf [0] == rotateCCW) {

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.