Please help with Firmata and special functions

Hello.

I’m audio and video guy, but not a programmer, so I really need your help. I have arduino uno and Blackmagic Design 3G shield for arduino. I need to modify standard firmata code in this way: when arduino receives code from software to SET HIGH or SET LOW for some pins, do nothing with real physical pins, but perform a code from BMD library. For example:

When PIN3 set to high, perform:
sdiTallyControl.SetCameraTally(
1,
false,
true
);

Probably it’s very simple and stupid question, but my programming knowledge is almost 0 :slight_smile: So thank you for any help!

Welcome,

I'm not familiar with Firmata, I've just looked at some example, so maybe something like this:

void callback(byte pin, int value)
{
  if ( pin == 3 && value == HIGH )
  {
    sdiTallyControl.SetCameraTally( 1, false, true );
  }
}

void setup()
{
  ...
  Firmata.attach(SET_DIGITAL_PIN_VALUE, callback);
  ...

I tried to write code like this, but somewhere is wrong syntax:

/*
* Firmata is a generic protocol for communicating with microcontrollers
* from software on a host computer. It is intended to work with
* any host computer software package.
*
* To download a host software package, please click on the following link
* to open the list of Firmata client libraries in your default browser.
*
* https://github.com/firmata/arduino#firmata-client-libraries
*/

/* Supports as many digital inputs and outputs as possible.
*
* This example code is in the public domain.
*/


#include <BMDSDIControl.h>                                // need to include the library

BMD_SDITallyControl_I2C sdiTallyControl(0x6E);            // define the Tally object using I2C using the default shield address


#include <Firmata.h>

byte previousPIN[TOTAL_PORTS];  // PIN means PORT for input
byte previousPORT[TOTAL_PORTS];

void outputPort(byte portNumber, byte portValue)
{
 // only send the data when it changes, otherwise you get too many messages!
 if (previousPIN[portNumber] != portValue) {
   Firmata.sendDigitalPort(portNumber, portValue);
   previousPIN[portNumber] = portValue;
 }
}

void setPinModeCallback(byte pin, int mode) {
 if (IS_PIN_DIGITAL(pin)) {
   pinMode(PIN_TO_DIGITAL(pin), mode);
 }
}

void digitalWriteCallback(byte port, int value)
{
 byte i;
 byte currentPinValue, previousPinValue;

 if (port < TOTAL_PORTS && value != previousPORT[port]) {
   for (i = 0; i < 8; i++) {
     currentPinValue = (byte) value & (1 << i);
     previousPinValue = previousPORT[port] & (1 << i);
     if (currentPinValue != previousPinValue) {
       digitalWrite(i + (port * 8), currentPinValue);
     }
   }
   previousPORT[port] = value;
 }
}

void setup()
{
 Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
 Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
 Firmata.attach(SET_PIN_MODE, setPinModeCallback);
 Firmata.attach(SET_DIGITAL_PIN_VALUE, callback);
 Firmata.begin(57600);
 
 sdiTallyControl.begin();                                 // initialize tally control
 sdiTallyControl.setOverride(true);                       // enable tally override

}

void callback(byte pin, int value)
{
   if (pin == 2 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   1,                                                     // Camera Number
   false,                                                  // Program Tally
   true                                                  // Preview Tally
 );
 }
 else if (pin == 3 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   1,                                                     // Camera Number
   true,                                                  // Program Tally
   false                                                  // Preview Tally
 );
 }
 else if (pin == 4 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   2,                                                     // Camera Number
   false,                                                  // Program Tally
   true                                                  // Preview Tally
 );
 }
 else if (pin == 5 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   2,                                                     // Camera Number
   true,                                                  // Program Tally
   false                                                  // Preview Tally
 );
 }
 else if (pin == 6 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   3,                                                     // Camera Number
   false,                                                  // Program Tally
   true                                                  // Preview Tally
 );
 }
else if (pin == 7 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   3,                                                     // Camera Number
   true,                                                  // Program Tally
   false                                                  // Preview Tally
 );
 }
 else if (pin == 8 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   4,                                                     // Camera Number
   false,                                                  // Program Tally
   true                                                  // Preview Tally
 );
 }
else if (pin == 9 && value == HIGH){
     sdiTallyControl.setCameraTally(                          // turn tally ON
   4,                                                     // Camera Number
   true,                                                  // Program Tally
   false                                                  // Preview Tally
 );
 }
else {
     sdiTallyControl.setCameraTally(                          // turn tally ON
   1,                                                     // Camera Number
   false,                                                  // Program Tally
   false                                                  // Preview Tally
 );
 }
}
 }

 while (Firmata.available()) {
   Firmata.processInput();
 }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.