wireless Control two stepper motors with joystick and 433Mhz RF

Hi,

I have a code to control two stepper motors using joystick and control one servo motor with push button and it works very well.
And now i want to make wireless control by using 433Mhz RF Receiver and Transmitter and two arduino uno boards.

But the code doesn’t work… so any help would be appreciated.
Thanks.

here are the two codes for transmitter and receiver.

// transmitter 
#include <AccelStepper.h>
#include <Bounce2.h>
#include <VirtualWire.h>

int pb = 9;
int button;
const int transm_pin = 12;

// definition of the constants of the Arduino pins
const int ledEnable = 2; // the led on board will show us the activation status of the motors
const int pinSwEnable = 7;  // the button in the joystick module that enables or disables the control
const int pinEnable = 8;  // the pins that control the ENABLE status of the A4988 drivers are connected in series, so only one pin is needed to manage them both
 
unsigned long debounceDelay = 10; // milliseconds for the button debonuce
 
const int jX = A4;  // analog pin reading the values for the Xs
const int stepX = 3;  // digital pin that sends the STEP signals to the X driver
const int dirX = 4; // digital pin that sends the DIRECTION signal to the X driver
long speedX, valX, mapX;  // variables for managing motor movements X
 
const int jY = A5;  //analog pin reading the values for Y
const int stepY = 5;  //digital pin that sends the STEP signals to the Y driver
const int dirY = 6; //digital pin that sends the DIRECTION signal to the Y driver Y
long speedY, valY, mapY;  //Y motor movements management variables

struct package
{
int valX ;
int valY ;
};
 typedef struct package Package;
Package data;

// variables used by the AccelStepper library
const int maxSpeed = 1000;  //according to the library documentation this value can be set up to 4000 for an Arduino UNO
const int minSpeed = 0; //minimum engine speed
const float accelerazione = 50.0; //number of steps per second in acceleration
 
const int treshold = 30;  //the reading of the potentiometers is never 100% reliable, this value helps to determine the point to consider as "Stay still" in the movements
long tresholdUp, tresholdDown;  //service variables to perform the task described above
 
boolean abilitato, muoviX, muoviY, enable;  //movements management variables
 
Bounce btnEnable = Bounce();  //instantiate a button from the Bounce library
 
//instantiate the engines
AccelStepper motoreX(AccelStepper::DRIVER, stepX, dirX);
AccelStepper motoreY(AccelStepper::DRIVER, stepY, dirY);
 
void setup() {
  vw_set_tx_pin(transm_pin);    // Sets pin   as the TX pin         
  vw_set_ptt_inverted(true);   // Required for inverting signal 
  vw_setup(2400);  // Bits per sec   speed of data transfer Kbps
  vw_rx_start();

  pinMode(pb,INPUT_PULLUP);

  //initialize values
  speedX = speedY = 0;
  enable = false;
 
  //definition of the modalities of the pins
  pinMode(ledEnable, OUTPUT);
  pinMode(pinEnable, OUTPUT);
 
  pinMode(pinSwEnable, INPUT_PULLUP); //the input of the switch needs to be set as INPUT_PULLUP
 
  digitalWrite(ledEnable, enable);
  digitalWrite(pinEnable, !enable); //The A4988 drivers disable the motor commands if on the ENABLE pin they receive a HIGH signal for this reason the value is opposite to that of the LED
 
  //configure the joystick button using the Bounce library
  btnEnable.attach(pinSwEnable);
  btnEnable.interval(debounceDelay);
 
  //calculate range values within which to consider the position of the joystick as "Stand still"
  tresholdDown = (maxSpeed / 2) - treshold;
  tresholdUp = (maxSpeed / 2) + treshold;
 
  //configure engine parameters
  motoreX.setMaxSpeed(maxSpeed);
  motoreX.setSpeed(minSpeed);
  motoreX.setAcceleration(accelerazione);
 
  motoreY.setMaxSpeed(maxSpeed);
  motoreY.setSpeed(minSpeed);
  motoreY.setAcceleration(accelerazione);
}
 
void loop() {
 
  //execute check and read function of the button that determines the enabling status
  checkEnable();
 
  digitalWrite(ledEnable, enable);  //show enabling status via LED on pin 13
  digitalWrite(pinEnable, !enable); //set the opposite value on the ENABLE pins of the drivers
  vw_send((uint8_t *)&pinSwEnable,sizeof(pinSwEnable));     // digitaaaaaaaaal
  vw_wait_tx();
 
  //perform analogue reading of the values coming from the joystick potentiometers
  valX = analogRead(jX);
  valY = analogRead(jY);
 
  //map the values read according to the maximum and maximum speed
  mapX = map(valX, 0, 1023, minSpeed, maxSpeed);
  mapY = map(valY, 0, 1023, minSpeed, maxSpeed);
 
  //run engine command function
  pilotaMotori(mapX, mapY);
  
 data.valX = valX;
 data.valY = valY;
 vw_send((uint8_t *)&data, sizeof(data));
 vw_wait_tx(); // Wait until the whole message is gone

 button = digitalRead(pb);
 if(button==0){digitalWrite(12,1);}
 vw_send((uint8_t *)&button,sizeof(button));     // digitaaaaaaaaal
 vw_wait_tx();
}
 
void pilotaMotori(long mapX, long mapY) {
 
  if (mapX <= tresholdDown) {
    //x goes back
    speedX = -map(mapX, tresholdDown, minSpeed,   minSpeed, maxSpeed);
    muoviX = true;
  } else if (mapX >= tresholdUp) {
    //x go forward
    speedX = map(mapX,  maxSpeed, tresholdUp,  maxSpeed, minSpeed);
    muoviX = true;
  } else {
    //x stands still
    speedX = 0;
    muoviX = false;
  }
 
  if (mapY <= tresholdDown) {
    //y goes down
    speedY = -map(mapY, tresholdDown, minSpeed,   minSpeed, maxSpeed);
    muoviY = true;
  } else if (mapY >= tresholdUp) {
    //y goes up
    speedY = map(mapY,  maxSpeed, tresholdUp,  maxSpeed, minSpeed);
    muoviY = true;
  } else {
    //y stands still
    speedY = 0;
    muoviY = false;
  }
 
  if (muoviX) {
    motoreX.setSpeed(speedX);
    motoreX.run();
  } else {
    motoreX.stop();
  }
 
  if (muoviY) {
    motoreY.setSpeed(speedY);
    motoreY.run();
  } else {
    motoreY.stop();
  }
}
  
void checkEnable() {
 
  btnEnable.update();
 
  if (btnEnable.fell()) {
    enable = !enable;
  }
}

receiver.ino (5.4 KB)

Why does the transmitter code have AccelStepper instances defined?

 button = digitalRead(pb);
 if(button==0){digitalWrite(12,1);}
 vw_send((uint8_t *)&button,sizeof(button));     // digitaaaaaaaaal
 vw_wait_tx();

You are using pin 12 as the transmit pin. Why are you f**king with it here?

Why does your receiver code read analog pins to get motor speeds?

You send three different packets, of different sizes. You read one packet, and never use the data that you read. Nor do you concern yourself with the amount of data read.

How can you possibly expect your code to work?