Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Implementing a remote controlled "STOP" via an interrupt? on: January 11, 2013, 04:18:03 pm
Ah!  I get it now. Thanks guys for that example!

Ok... that means that I have a lot of reconfiguring of the code to do, but I get it.  I looked over the blinking without delay example and understand the concept. I'll have to look for an example of a similar non-blocking code that has some more inputs and outputs so I can better understand how to translate my code into that.  I'll dig around.  If anyone has any good examples of this type of thing, please let me know.
2  Using Arduino / Project Guidance / Re: Implementing a remote controlled "STOP" via an interrupt? on: January 11, 2013, 11:26:59 am
Thanks guys- I have tried the encoder/decoder chips, but I wanted to eliminate them and just use VirtualWire and an Arduino on both ends, which works to send the messages... just not sure how to react to those messages.

PeterH- thank you for the reply. I'm very intrigued into how to do this. Can you tell me what code I would need to continue to handle incoming messages while it is carrying out the action sequence?  Or point me in the direction of any example of this?

Thanks again!

3  Using Arduino / Project Guidance / Re: Implementing a remote controlled "STOP" via an interrupt? on: January 10, 2013, 11:36:32 pm
Thanks Boffin1- I should clarify that I only want the "loop" to run through once, at which point it is basically done (and wait to be reset.  My code probably doesn't make that at all clear.

The "MainRoutine", as I've poorly called it, will run some servos and will likely last 10-15 seconds. During that time, I'm basically looking for an emergency stop capability via an RF signal from my transmitter.  Since I'm really looking for the ability to stop at any point during a single 10-15 sec run of the "loop", I thought that I needed to use an interrupt function. 

Having clarified that, do you have any additional advice?
4  Using Arduino / Project Guidance / Implementing a remote controlled "STOP" via an interrupt? on: January 10, 2013, 10:25:08 pm
Hello-
I'm fairly new the Arduino and looking for a small amount of code help to get me over this stumbing block- Please!

Here's what I'm trying to make:
1.An RF transmitter circuit with a START and STOP button to remote control a receiver
2.An RF receiver circuit that runs some servos, starting when it receives the RF "start" message and stopping via an interrupt whenever it receives an RF "stop" command.

The part I'm struggling with is the "stop" command. I don't know how to implement it in my code. Right now I've tried a while loop, but realized it only checks for that "stop" message at the beginning of the main routine.

Here is my RECEIVER code:

Code:
#include <VirtualWire.h>

int startLEDPin = 11;
int stopLEDPin= 12;
int runLEDPin = 4;

void setup()
{
  // initialize input and output remote pins
  pinMode(startLEDPin, OUTPUT);
  pinMode(stopLEDPin, OUTPUT);
  pinMode(runLEDPin, OUTPUT);
  digitalWrite(startLEDPin, LOW);
  digitalWrite(stopLEDPin, LOW);
  digitalWrite(runLEDPin, LOW);

  Serial.begin(9600); // Debugging only
  Serial.println("setup");

  vw_setup(1000); // Bits per sec- can go up to 2400
  vw_set_rx_pin(2);
  vw_rx_start();       // Start the receiver PLL running
}

void MainRoutine()
{
  digitalWrite(runLEDPin, LOW);
  delay(5000);  // this represents the main routine (motor) stuff
}

void ShutDown()
{
  digitalWrite(startLEDPin, LOW);
  digitalWrite(runLEDPin, LOW);
  digitalWrite(stopLEDPin, HIGH);
  delay(2000) // this represents the motor shutdown stuff
    digitalWrite(stopLEDPin, LOW);
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  // beginning of RF check
  while (vw_get_message(buf, &buflen) && buf[0] != '1') {
  }
  // while msg is avail (good checksum or not) copy it to buffer and do nothing else

  while (vw_get_message(buf, &buflen) && buf[0] != '2')
  {
    // now that "1" was received (for START) do this stuff...
    digitalWrite(13, true); // Flash a light to show received good message
    // Message with a good checksum received, dump it.
    delay(500);
    digitalWrite(13, false);
    Serial.print("Got: ");  // take this out later
    Serial.print(buf[0]); // print the content of the msg recvd
    Serial.println("");

    MainRoutine();
  }

  // once "2" (for STOP) is received go into shutdown mode
  ShutDown();

  // then start over at the top waiting for another start button press
}


For reference, here is the TRANSMITTER code w/debounce check. It seems to be working o.k.:

Code:
#include <VirtualWire.h>

int startPin = 5;
int stopPin = 6;
int startLEDPin = 11;
int stopLEDPin= 12;
boolean lastStartButton = LOW;
boolean currentStartButton = LOW;
boolean lastStopButton = LOW;
boolean currentStopButton = LOW;

void setup()
{
  Serial.begin(9600);  // Debugging only
  Serial.println("setup");
  vw_setup(1000); // Bits per sec- can go up to 2400
  vw_set_tx_pin(3);


  // initialize input and output remote pins
  pinMode(startPin, INPUT);
  pinMode(stopPin, INPUT);
  pinMode(startLEDPin, OUTPUT);
  pinMode(stopLEDPin, OUTPUT);

  digitalWrite(startLEDPin, LOW);
  digitalWrite(stopLEDPin, LOW);
}

boolean debounceStart(boolean lastStart)
{
  boolean currentStart = digitalRead(startPin);   // determine the current value of the START switch
  if (lastStart != currentStart)                        // if switch changed states, delay by 5 ms so switch can stop debouncing
  {
    delay(5);
    currentStart = digitalRead(startPin);         // read it again after 5 ms
  }
  return currentStart;                             // return the value of the switch read after the 5 ms delay
}

boolean debounceStop(boolean lastStop)
{
  boolean currentStop = digitalRead(stopPin);   // determine the current value of the STOP switch
  if (lastStop != currentStop)                        // if switch changed states, delay by 5 ms so switch can stop debouncing
  {
    delay(5);
    currentStop = digitalRead(stopPin);         // read it again after 5 ms
  }
  return currentStop;                             // return the value of the switch read after the 5 ms delay
}

void loop()
{
  char *msg;

  lastStartButton = LOW;   // reseting if this isn't the first loop
  currentStartButton = LOW;   // reseting if this isn't the first loop
  lastStopButton = LOW;   // reseting if this isn't the first loop
  currentStopButton = LOW;   // reseting if this isn't the first loop

  // START of routine for transmitting message
  currentStartButton = debounceStart(lastStartButton); // run debounce function, pass it LastButton
  if(lastStartButton == LOW && currentStartButton == HIGH) // if START button actually changed, do stuff below
  {
    char *msg = "1";    // a message sent of "1" means START
    lastStartButton = currentStartButton;  // resetting the last stop back to the current state
    digitalWrite(startLEDPin, HIGH);
    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false); // Turn off light after transmission
    digitalWrite(startLEDPin, LOW);
  }

  currentStopButton = debounceStop(lastStopButton);  
  if(lastStopButton == LOW && currentStopButton == HIGH)  // if STOP button actually changed, do stuff below
  {
    char *msg = "2";  // a message sent of "2" means STOP
    lastStopButton = currentStopButton;  // resetting the last stop back to the current state
    digitalWrite(stopLEDPin, HIGH);
    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false); // Turn off light after transmission
    digitalWrite(stopLEDPin, LOW);
  }

  // END of routine for transmitting message

}


Moderator edit: [code] [/code] tags added.
5  Using Arduino / Networking, Protocols, and Devices / Re: Remote application w/RF modules using only ONE arduino possible?- newbie here on: January 05, 2013, 06:19:57 pm
Thanks for the response. I looked through the HT12-E spec quite a bit to try and figure out some clues on how to do this, but ended up at a dead end. Here is the HT-12e spec:
http://www.rentron.com/Files/ht-12e.pdf

Based on that, can you give me some more guidance, examples, bits of code on how I would do this?
6  Using Arduino / Networking, Protocols, and Devices / Remote application w/RF modules using only ONE arduino possible?- newbie here on: January 05, 2013, 04:35:22 pm
Hello-
I'll preface this post by saying I'm a newbie to Arduino.  I'm trying to incorporate cheap remote control capabilities into an Arduino (Uno or Nano) application to receive a two bit RF signal. I'm using the TWS-434 and RWS-434 modules from Reynolds electronics.
http://www.rentron.com/remote_control/TWS-434.htm
http://www.rentron.com/remote_control/RWS-434.htm

I'm wondering if it is possible to use only an Arduino on the receiver end (not on the transmitter side) along with the RF module and eliminate the decorder IC?  On the transmitter side it would only have the TWS-434 module, HT-12E encoder IC, and two buttons (for the two bit inputs) but no arduino. Everything I've looked at online related to RF with Arduino (such as VirtualWire) seems to require an Arduino on each end (but does get rid of the encoder and decoder IC). My main goal here is low price as I'm considering possibly turning this into a product to sell... so I'm open to rethinking things.  I need the Arduino on the reciever end to do a few other motor control things, but will likely replace it with an ATTiny at some point.

I've played with this configuration a little bit but I'm lost when it comes to the transmitted word, baud rate, synching, etc. Any help is much appreciated!!!
Pages: [1]