May 06, 2024, 06:19:22 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Controlling the FC-4+ with an Arduino

Started by robomaster-1, November 03, 2015, 10:12:10 AM

Previous topic - Next topic

robomaster-1

Can the  FC-4+ be controlled with and Arduino Board. I like the features of the FC-4+ and want to us it with and  Arduino Board.
Can this be done?
Tim J. Lewis
Magic and Technology

livinlowe

It sure can. Did you look at the docs for the FC-4? It lists the commands that control it. Just send those commands over a serial line!
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Assuming you have SoftSerial library installed, you might write functions that look like these:

UNTESTED!

void fc4_reset(byte addr)
{
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("X");
}


void fc4_level(byte addr, byte ch, byte level)
{
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("L");
  SoftSerial.write(ch);
  SoftSerial.write(level);
}


void fc4_digital(byte addr, byte ch, byte state)
{
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("D");
  SoftSerial.write(ch);
  SoftSerial.write(state);
}


void fc4_fade(byte addr, byte ch, byte levela, byte levelb, int fadems)
{
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("FH");
  SoftSerial.write(ch);
  SoftSerial.write(levela);
  SoftSerial.write(levelb);
  SoftSerial.write(fadems & 0xFF);
  SoftSerial.write(fadems >> 8);
}
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

Jon,

I thought you said that you did a project where wrote some code for a client if you did can I see what you did?
Tim J. Lewis
Magic and Technology

JonnyMac

I've written code for a friend that I cannot share. What I've written that can be shared is here -- right above your request. That's based on this:

http://www.efx-tek.com/php/smf/index.php?topic=2106

Here's another bit of code I found using Google

/*
* 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

robomaster-1

Since I have an RC-4 board I thought I would try out the RC-4 Demo code to see how it works. I compiled the program and got an error BYTE is no longer supported. Here the line that gave the error. Any thoughts. I would like to this working first before work on the FC-4+ code.

Serial.print(addr, BYTE);   
Tim J. Lewis
Magic and Technology

JonnyMac

January 02, 2016, 08:33:06 AM #6 Last Edit: January 02, 2016, 10:20:46 AM by JonnyMac
Well, I guess that vaunted Arduino community support really isn't what it's cracked up to be.... :)

Please remember that we're not Arduino programmers, so anything we suggest vis-a-vis the Arduino is at your own risk.

Even if community support is lacking, the Arduino has pretty good reference pages (use Help\Reference). I used this one to modify the demo code
-- https://www.arduino.cc/en/Reference/Serial

Here is the updated demo -- it compiles, but I have not run it.

/*
* RC-4 Demo
* Jon Williams, EFX-TEK
* jwilliams@efx-tek.com
* Modified: 02 JAN 2016
*
* 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 addr = B00; addr <= B11; addr++) {               // reset all RC-4s
    setRC4(addr, B0000);
    delay(25);
  }
}

void loop()
{
  int bits, zigzag;

  for (bits = B0000; bits <= B1111; bits++) {               // counter demo
    setRC4(B00, bits);
    delay(100);
  }
  setRC4(B00, B0000);                                       // clear RC-4
  delay(100);

  for (zigzag = 1; zigzag < 6; zigzag++) {                  // run 5x
    for (bits = B0001; bits <= B1000; bits <<= 1) {         // zig
      setRC4(B00, bits);
      delay(50);
    }
    for (bits = B1000; bits >= B0001; bits >>= 1) {         // zag
      setRC4(B00, bits);
      delay(50);
    }
  }
  setRC4(B000, B0000);
  delay(50);
}

void setRC4(int addr, int relays)
{
  Serial.write("!RC4", 4);
  Serial.write(addr);
  Serial.write("S");
  Serial.write(relays);
}
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

Here is the code I am working with and the board is not responding I am not sure what is wrong?


/*
* RC-4 Demo
* Jon Williams, EFX-TEK
* jwilliams@efx-tek.com
* Modified: 02 JAN 2016
*
* Interface for EFX-TEK RC-4 SSR Output Board
* -- http://www.efx-tek.com/topics/rc-4.html
*/
#include <SoftwareSerial.h>

#define RX2   2
#define TX2   3

#define ON    1
#define OFF   0

#define ALL  0xFF                       // global address

SoftwareSerial SoftSerial(RX2, TX2);



void setup()
{
  Serial.begin(38400);                                      // install RC-4 B/R jumper

  for (int addr = B00; addr <= B11; addr++) {               // reset all RC-4s
    setRC4(addr, B0000);
    delay(25);
  }
}

void loop()
{
  int bits, zigzag;

  for (bits = B0000; bits <= B1111; bits++) {               // counter demo
    setRC4(B00, bits);
    delay(100);
  }
  setRC4(B00, B0000);                                       // clear RC-4
  delay(100);

  for (zigzag = 1; zigzag < 6; zigzag++) {                  // run 5x
    for (bits = B0001; bits <= B1000; bits <<= 1) {         // zig
      setRC4(B00, bits);
      delay(50);
    }
    for (bits = B1000; bits >= B0001; bits >>= 1) {         // zag
      setRC4(B00, bits);
      delay(50);
    }
  }
  setRC4(B000, B0000);
  delay(50);
}

void setRC4(int addr, int relays)
{
  Serial.write("!RC4", 4);
  Serial.write(addr);
  Serial.write("S");
  Serial.write(relays);
}
Tim J. Lewis
Magic and Technology

livinlowe

January 13, 2016, 12:35:05 PM #8 Last Edit: January 13, 2016, 12:42:39 PM by livinlowe
Can you show a picture of your setup? It's hard to know why its not working by just code. Is the 3 wire connector the same (r,w,b) on both boards?

Edit: Also, do you have to declare which pin your are transmitting serial on? Doh! Nevermind
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Our products use a half-duplex connection over one wire. Most Arduino serial libaries use two (TX and RX).

I did a bit of an Internest search (hint, hint), and came across this post:
-- http://forum.arduino.cc/index.php?topic=114553.0

You might try that library. I'm not an Arduino expert, so I shouldn't post any more code ideas.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Update: I dug around in my box of boards and found a generation 1 RC-4 (which only works at 2400 baud). The half-duplex serial library that I found above will not compile (figures...) so I went back to using the standard SoftSerial library and only connecting to the TX pin.

This code works.

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

#include <SoftwareSerial.h>

#define RX 3    // not used
#define TX 4    // connect to RC-4 Serial.W

SoftwareSerial sio(RX, TX);


void setup()
{
  sio.begin(2400);                                          // start soft serial                               

  for (int addr = B00; addr <= B11; addr++) {               // reset all RC-4s
    setRC4(addr, B0000);
    delay(25);
  }
}

void loop()
{
  int bits, zigzag;

  for (bits = B0000; bits <= B1111; bits++) {               // counter demo
    setRC4(B00, bits);
    delay(100);
  }
  setRC4(B00, B0000);                                       // clear RC-4
  delay(100);

  for (zigzag = 1; zigzag < 6; zigzag++) {                  // run 5x
    for (bits = B0001; bits <= B1000; bits <<= 1) {         // zig
      setRC4(B00, bits);
      delay(50);
    }
    for (bits = B1000; bits >= B0001; bits >>= 1) {         // zag
      setRC4(B00, bits);
      delay(50);
    }
  }
  setRC4(B000, B0000);
  delay(50);
}

void setRC4(int addr, int relays)
{
  sio.write("!");
  sio.write("R");
  sio.write("C");
  sio.write("4");
  sio.write(addr);
  sio.write("S");
  sio.write(relays);
}
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

January 25, 2016, 08:22:27 PM #11 Last Edit: January 25, 2016, 08:24:31 PM by robomaster-1
Using the example of the AP16 board Code , I was able to get some code that compiles of , but when downloaded in my Pro Mini board and hook it to the FC4 nothing is happening. I am at not sure on what is wrong.

Here is the code:


#include <SoftwareSerial.h>

SoftwareSerial SoftSerial(13,4);

void setup() 
{ SoftSerial.begin(2400); // start the object

  int state = 1;
  int addr = 0;
 
  // Reset Board all outputs to off 0%   
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("X");
 
   delay(500);
}

void loop(void)             // run over and over again
{   
   
   // Fade Channel 1 (High Resoultion Timing)
   // Fade up Channel 1  up in 1.25 seconds
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("FH");
  SoftSerial.write(1);
  SoftSerial.write(0);
  SoftSerial.write(255);
  SoftSerial.write(226);
  SoftSerial.write(4);
  delay(500)
 
    // Fade dowm Channel 1  up in 1.25 seconds
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("FH");
  SoftSerial.write(1);
  SoftSerial.write(255);
  SoftSerial.write(0);
  SoftSerial.write(226);
  SoftSerial.write(4);
  delay(500)
}


Tim J. Lewis
Magic and Technology

JonnyMac

Why do you have two WRB wires connected to the FC-4+ Serial connection? On the FC-4+, the Serial pins are tied together.

The code you posted does not compile using Arduino 1.6.6 IDE.

Didn't you tell me you prefer the Arduino because it's "easy"?....   :o

I am traveling this week and do not have an Arduino or FC-4+ with me, so I can't test this code fix, but at least it compiles.

#include <SoftwareSerial.h>

int addr = 0;

SoftwareSerial SoftSerial(13,4);

void setup() 
{
  SoftSerial.begin(2400);
  delay(10);
 
  // Reset Board all outputs to off 0%   
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("X");
  delay(500);
}

void loop(void)

  fade(0, 0, 255, 1250);
  delay(2000);
  fade(0, 255, 0, 1250);
  delay(2000);   
}

void fade(int ch, int startlvl, int stoplvl, int ms)
{
  SoftSerial.write("!FC4");
  SoftSerial.write(addr);
  SoftSerial.write("FH");
  SoftSerial.write(ch);
  SoftSerial.write(startlvl);
  SoftSerial.write(stoplvl);
  SoftSerial.write(ms & 0xff);
  SoftSerial.write(ms >> 8);
}


Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

I want to thank you for your help. I thought this would not be to hard to do but sometimes the most simplest Idea turns out to be a little more complex than you thought. A question the TX& RX pins need to combined in order to do a half duplex mode for the board?     
Tim J. Lewis
Magic and Technology

livinlowe

Quote from: robomaster-1 on January 26, 2016, 08:02:32 AM
I want to thank you for your help. I thought this would not be to hard to do but sometimes the most simplest Idea turns out to be a little more complex than you thought. A question the TX& RX pins need to combined in order to do a half duplex mode for the board?   

No, half duplex ( and someone correct me if I'm wrong) means you just hook the transmit from your Adrinuo to the FC-4. The FC-4 doesn't communicate to the microcontroller.
Shawn
Scaring someone with a prop you built -- priceless!