Arduino 2 (Receiver)
Arduino Uno + TB6600 + Nema23 Stepper motor + NRF24L01
The aim of the project is to get the NRF24L01 connected to the Nano Every board to communicate with the NRF24L01 on the Arduino Uno board and move the stepper motor either clockwise or anticlockwise based on which momentary switch on transmitter (Nano Every) is held down.
After lots of serial monitor analysis I can see that the NRF24L01's are communicating with each other and is registering the button presses however the stepper motor is not moving.
I tried some test code with the NEMA23 stepper motor with the same connection setup and it works.
As a result I'm at a loss and have tried for 2 days to get this to work but to no avail. Please see the code below:
how often do you send the button pressed message from the sender?
please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)
When you read the button states from on the transmitter side, it could be done much easier:
int state;
void loop()
{
state = (digitalRead(button2) << 1) | digitalRead(button1);
//State == 0: both down
//State == 1: 1 down
//State == 2: 2 down
//State == 3: None down
//if ((state == 0) || (state==3)) state ^= 3; //Invert 3 to 0 or 0 to 3
//Transmit
}
On the receiver side, you only handle the stepper when something is received. You should consider to use the Stepper library to handle the stepper instead.
Now we see that the emitter is sending the button Status once per second
So on the receiving side, you would issue steppers orders only every second since those orders are within the “if I got a message” part. Your stepper won’t move fast…(even worse if you are configured for micro steps)
You should re Architect the code so that messages say start stepping forward or backward or stop. That will define the state on the receiver and it will keep on going until a new state is sent