May 18, 2024, 11:08:02 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Arduino and AppMod

Started by HackMeister, November 24, 2007, 06:31:10 AM

Previous topic - Next topic

HackMeister

Is it possible for an Arduino controller to send AppMod commands?

Thanks
Jim

JonnyMac

I suppose it is; the Arduino can send serial data, you just have to setup the correct baud rate and ensure that it transmit true (not inverted) data.  What this means is that the TX line idle stat is high and a start bit is low.  Also, I believe the Arduino has dedicated TX and RX lines, so you'd have to tie those together with a resistor if you wanted to get data back from one of the modules (this is not required if just sending commands).
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

I went and looked at the Arduino page, and this is what I came up with -- though I don't have a module to test it on, so you're going to have to write a program and try it.

Since our devices support 38.4K and Arduino can send at that speed, do you serial setup like this:

  Serial.begin(38400);

To send a command you're going to have to mix the serial output functions; this example *should* send the channel levels to an FC-4 at attress %00:

  Serial.print("!FC4");
  Serial.print(0, BYTE);
  Serial.print("S");
  Serial.print(chan1, BYTE);
  Serial.print(chan2, BYTE);
  Serial.print(chan3, BYTE);
  Serial.print(chan4, BYTE);


Of course, your program has to define the variables chan1-chan4.
Jon McPhalen
EFX-TEK Hollywood Office

HackMeister

Thanks Jon,

It works great, I daffed out and did not have the address selected correctly on the board. By the way it was tested with an RC-4 board. I need to order another RC-4 and see if I can daisy chain with Arduino.

Thanks Again
Jim

JonnyMac

November 24, 2007, 10:20:35 AM #4 Last Edit: November 24, 2007, 10:31:52 AM by JonnyMac
Cool!  I just ordered a "bare bones" Ardunio board so I can try it for myself -- we've had other support requests and the only way to do that well is to have the actual hardware.  Please share you complete listing with the group so that other Arduino users can benefit.

By the way, you might want to create a custom function that lets you pass the board address and outputs so that you can simplify your program with multiple boards.

void rc4Out(int addr, int relays) {

  Serial.print("!RC4");
  Serial.print(addr, BYTE);
  Serial.print("S");
  Serial.print(relays, BYTE);

}
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

November 26, 2007, 06:37:59 AM #5 Last Edit: November 26, 2007, 07:17:01 AM by JonnyMac
Here's a completed program that works -- and does work with multiple boards (I now have an Arduino and did test it).

/*
* RC-4 Demo
* Jon Williams, EFX-TEK
* jwilliams@efx-tek.com
*
* Interface for EFX-TEK RC-4 SSR Output Board
* -- http://www.efx-tek.com/topics/rc-4.html
*/

void setup()
{
  Serial.begin(38400);                          // install RC-4 B/R jumper 
 
  for (int idx = 0; idx < 4; idx++) {
    setRC4(idx, 0);
  }
}

void loop()
{
  int idx, zigzag;
 
  for (idx = 0; idx <= 15; idx++) {             // counter demo
    setRC4(0, idx);
    delay(100);
  } 
  setRC4(0, 0);
   
  for (zigzag = 1; zigzag < 6; zigzag++) {      // zig
    for (idx = 1; idx <= 8; idx *= 2) {
      setRC4(1, idx);
      delay(50);
    }
    for (idx = 8; idx >= 1; idx /= 2) {         // zag
      setRC4(1, idx);
      delay(50);
    }
  }
  setRC4(1, 0);
}

void setRC4(int addr, int relays)
{
  Serial.print("!RC4");
  Serial.print(addr, BYTE);
  Serial.print("S");
  Serial.print(relays, BYTE); 
}

Jon McPhalen
EFX-TEK Hollywood Office

Bottle

Jon

I have now managed to get an Arduino Diecimila board as well, and am very pleased with it!!

Just wondered if anyone had managed to get the Serial.In structure to work for extracting the Version and Status information from the attached RC-4s?

I've currently got 4 x RC-4 boards hanging off the Serial.TX line (which works great, BTW), and what I'd like to do is be able to extract Status and Version info from each board. Is there an easy way of implementing it at all?

Thanks in advance, Ian



PS: Here is my first stab at it!!


/*
* RC-4 Demo + Serial Message extensions
* Jon Williams, EFX-TEK + Ian Sherlock
* jwilliams@efx-tek.com, ian@thehides.org
*
* Interface for EFX-TEK RC-4 SSR Output Board
* -- http://www.efx-tek.com/topics/rc-4.html
*/

void setup()
{
  Serial.begin(38400);                          // install RC-4 B/R jumper
 
  for (int idx = 0; idx < 4; idx++) {
    vers_RC4(idx);                                  // V-command (get version)
  }

  for (int idx = 0; idx < 4; idx++) {
    all_off_RC4(idx);                               // X-command (all off)
  }
}

void loop()
{
  int idx, zigzag;

  for (idx = 0; idx <= 15; idx++) {             // counter demo
    set_RC4(0, idx);
    delay(800);
  }
  set_RC4(0, 0);
   
  for (zigzag = 1; zigzag < 6; zigzag++) {      // zig
    for (idx = 1; idx <= 8; idx *= 2) {
      set_RC4(1, idx);
      delay(300);
    }
    for (idx = 8; idx >= 1; idx /= 2) {         // zag
      set_RC4(1, idx);
      delay(300);
    }
  }
  setRC4(1, 0);
}

void vers_RC4(int addr)
{
 
   
  Serial.print("!RC4");
  Serial.print(addr, BYTE);
  Serial.print("V");
 
  // receive data:
if (Serial.available() > 0) {
        int bufferByte = 0;
                int incomingByte = 0;
 
                bufferByte = Serial.available()
               //while (bufferByte > 0) {  //need to think about this line
                // read the contents of the buffer and display one byte at-a-time
                incomingByte = Serial.read();    // serial input string
                bufferByte++;     
                }
       }
Serial.flush()
}

void all_off_RC4(int addr)
{
  Serial.print("!RC4");
  Serial.print(addr, BYTE);
  Serial.print("X");



void set_RC4(int addr, int relays)
{
  Serial.print("!RC4");
  Serial.print(addr, BYTE);
  Serial.print("S");
  Serial.print(relays, BYTE);
}
"Follow the White Rabbit"
"Hang on to your hat, 'cos Kansas is going bye-bye!"

JonnyMac

February 19, 2008, 08:54:55 AM #7 Last Edit: February 19, 2008, 08:57:21 AM by JonnyMac
Since the Arduino uses a hardware UART I think the best thing to do is put a 1K0 to 4K7 resistor between RX and TX.  Connect the serial line to the RX pin.  Since the Arduino buffers serial you'll have to filter your own commands out of the buffer but that shouldn't be too hard.  With the Version request you can hunt through the receive buffer until you hit the "V"; the next three bytes will be the version string.
Jon McPhalen
EFX-TEK Hollywood Office

Bottle

Sweet!!  :D

I'll give that a go and report back. Many thanks for the info.

Ta, Ian
"Follow the White Rabbit"
"Hang on to your hat, 'cos Kansas is going bye-bye!"