Sorry But I am stuck!

Hello.

I am looking for a nudge in the right direction on a project. I built a rig using a stepper motor to rotate (pan) a camera. I had it hard wired (10m of cable) to two buttons one for clockwise and one for anticlockwise rotation. All works well.

I wanted to lose the wire so bought a 4 channel remote controller. my problem is that the controller "pulses" from High to Low, so now my stepper motor is very jerky as there is no longer a continuous HIGH while the button is pushed.

I tried to use a Do While loop so that the motor would start to run and keep going until the opposite button is pressed (i.e. if I press clockwise button once the motor should keep going until anti clockwise button is pressed), but although motor runs it does not stop.

How can I set it up so that when the clockwise button is pushed and the input pin goes high for the first time (remember it pulses) the motor runs until the anticlockwise button is pressed?

what strategy should I adopt, I have looked hard for a solution including Switch Case, Do While, etc but I think I may have the wrong approach.

Cheers, Peter.

Does it work properly if you put the cable and switches back? Why do you believe the 4 channel remote control is not causing the problem? Are we supposed to guess at what your code is doing? Best strategy is to supply enough information to allow help!

Paul

The time for the Tx/Rx response will cause the problem.

Direct wiring has no delay so will run smooth.

Weedpharma

weedpharma: The time for the Tx/Rx response will cause the problem.

Direct wiring has no delay so will run smooth.

Weedpharma

True, but will only delay one time, unless the "4 channel remote control" is not working like he thinks it should.

Paul

Is the remote set for toggle or hold while button is pressed?

You need the latter so the output remains on as long as the remote button is pressed.

Weedpharma

It sounds like Naff is 'sending, sending, sending ...', each step of his motor. But as Paul implied, he's shown no code, nor even a description of it, only the hardware. Could be anything.

Naffusername: How can I set it up so that when the clockwise button is pushed and the input pin goes high for the first time (remember it pulses) the motor runs until the anticlockwise button is pressed?

You need a variable that records the most recent signal sent from the transmitter - for example 'F' for forward and 'R' for reverse and 'S' for stop.

Then the code to move the motor should make decisions based on that variable - not directly from the transmitter signal.

...R

Thanks everyone, I did not show any code because its the approach I am struggling with.

the remote is http://www.aliexpress.com/item/Higher-Quality-4-Channel-RF-Wireless-Remote-Control-Module-2262-2272-Four-Ways-Wireless-Remote-Controler/32303499552.html

and is similar to an IR remote, in that when the button is held down it sends pulses not a constant signal (which the Sketch gets from a wired connection) so wired, an input pin sees HIGH until the button is released, whereas with the remote it gets HIGH LOW HIGH LOW ,etc.

So the stepper is starting and stopping then starting and stopping while the button is held.

I was trying to think of a way to latch (not sure if thats the right word) on the first HIGH, and keep the Rotation going until it gets a HIGH from the button that would send it the other way, sort of using the opposite direction button to cancel the rotation. But that seems complicated.

as weedpharma said, if I could set the remote to just stay HIGH while button is pressed, all would be good.

Thanks all for looking,

Paul I could post some code but might not help much cos my approach is looking wrong? I don't know how to handle that pulsed input.

Hi,
Can you draw us a block diagram of how you are configuring the 4ch remote, the arduino, and the stepper please?
A hand drawn diagram in jpg, png will be fine.

A picture is worth thousand words.

Thanks… Tom… :slight_smile:

Thanks Robin2 I think I understand that, I will see if I can do it.

sorry could not post this earlier as I had exceeded number of posts in 5 mins.

Cheers.

Naffusername: Thanks Robin2 I think I understand that, I will see if I can do it.

What I suggested is the equivalent of the "latch" concept you mentioned in Reply #7

...R

A link to the Tx/Rx would be good.

Weedpharma

Ok here is the code that works with the hard wired switches

I’m not sure I need the two condition checks on the If statements, was just hedging bets in case both switches were accidentally pressed at once.

when using the radio I just used the radio’s HIGH instead of the Hardwired HIGH.

Peter (please don’t laugh at my code lol, I’m very new to coding).

#include <stepperMotor.h>

/*
project aims to run a stepper motor clockwise or anti clockwise depending on which button is pressed.
NOTE: buttons are HIGH when pressed.
*/

#include <StepperMotor.h> //pulls in stepper library
StepperMotor motor(9, 10, 11, 12); //These are the pins for the stepper motor controller outputs

int cwPin = 2; //sets Pin for clockwise switch
int ccwPin = 3; //sets Pin for counter clockwise switch

void setup() {
// put your setup code here, to run once:

Serial.begin(9600); // So I can see whats going on

pinMode (cwPin, INPUT); //Clockwise switch input
pinMode (ccwPin, INPUT); // Counter Clockwise switch input
motor.setStepDuration(1); //needs setting dont know why yet
}

void loop() {
// put your main code here, to run repeatedly:

Serial.print("Read switch input: ");
Serial.print("CW Pin = “);
Serial.print(digitalRead(cwPin)); // Read the clockwise pin and display the value
Serial.print(” CCW Pin = ");
Serial.println(digitalRead(ccwPin)); // Read the anti clockwise pin and display the value

if (digitalRead(cwPin) == LOW && digitalRead(ccwPin) == HIGH) // test to see if clockwise button is pressed, and if so turns motor clockwise.

{
motor.step(100);//turns motor clockwise
}

if (digitalRead(cwPin) == HIGH && digitalRead(ccwPin) == LOW) // test to see if counter clockwise button is pressed, and if so turns motor counter clockwise.

{
motor.step(-100);//turns motor counter clockwise
}

}

Hi,

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you post a picture or a diagram of how you have the Rx connected to the controller please?

Thanks.. Tom... :)

Thanks Tom,

Pictures attached (should be ok I did them from memory as not near my arduino at the moment, I left out the obvious VCC in and GND etc.)

#include <stepperMotor.h>

/*
  project aims to run a stepper motor clockwise or anto clockwise depending on which button is pressed.
  NOTE: buttons are HIGH when not pressed.
*/

#include <StepperMotor.h> //pulls in stepper library
StepperMotor motor(9, 10, 11, 12); //These are the pins for the stepper motor controller outputs

int cwPin = 2; //sets Pin for clockwise switch
int ccwPin = 3; //sets Pin for counter clockwise switch


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600); // So I can see whats going on

  pinMode (cwPin, INPUT); //Clockwise switch input
  pinMode (ccwPin, INPUT); // Counter Clockwise switch input
  motor.setStepDuration(1); //needs setting dont know why yet
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("Read switch input: ");
  Serial.print("CW Pin = ");
  Serial.print(digitalRead(cwPin));    // Read the clockwise pin and display the value
  Serial.print(" CCW Pin = ");
  Serial.println(digitalRead(ccwPin));   // Read the anti clockwise pin and display the value

  if (digitalRead(cwPin) == LOW && digitalRead(ccwPin) == HIGH) // test to see if clockwise button is pressed, and if so turns motor clockwise.

  {
    motor.step(100);//turns motor clockwise
  }

  if (digitalRead(cwPin) == HIGH && digitalRead(ccwPin) == LOW) // test to see if counter clockwise button is pressed, and if so turns motor counter clockwise.

  {
    motor.step(-100);//turns motor counter clockwise
  }

}

Hi, Have you got the gnd of the Rx connected to the gnd of the arduino? It is needed so the input has a reference for the 5V control from the Rx.

Tom... :)

Hi Tom yes I have the RX to GND on the Arduino.

Robin2: You need a variable that records the most recent signal sent from the transmitter - for example 'F' for forward and 'R' for reverse and 'S' for stop.

Then the code to move the motor should make decisions based on that variable - not directly from the transmitter signal.

...R

Was thinking about this (possibly overthinking it), If I press the button it will go HIGH which I can store in say R, but as soon as I take my finger off it will go LOW so that would then get written into R? and motor would stop?

Have I got that right,

I kinda need a toggle, off to google I go!

Peter.

Please take a look at the StateChangeDetection example in the 02.Digital examples which come with the IDE. It will teach you how to detect when a button has become pressed, rather than stays pressed.

Naffusername: If I press the button it will go HIGH which I can store in say R, but as soon as I take my finger off it will go LOW

Only if that is what your code is written to do - and why would you do that?

You need something like this pseudo code

void loop() {
  checkReceiver();
  if signal == X
      motorCommand = 'F'
  else if signal == Y
      motorCommand = 'R'
  etc

With this code if no signal is received nothing changes.

...R