I am using an Arduino Mega and the DMXSerial include file to convert DMX data from a 256 channel NJD Merlin to access various programs and modes within my project.
I checked the DMX signal firstly using a Max485 board and the DmxSerialRecv sketch.
The DMX values were correct when I checked the serial Monitor to verify this.
When I transpose the relevant code into my sketch, I am getting spurious '0’s along with the DMX data
i.e 0,0,0,0,0,120,120,0,0,0,0,120,120,120,120,0,0,0,0,0,0,0,0,0,0,120,120 etc
I have had to write in a workaround by ignoring the '0’s, but this is not an ideal fix.
The DMXSerial.cpp file has been modified to allow data into the Rx1 pin as I am also using Rx0 serial.begin(9600).
I am using additional hardware such as I2C LCD display, nRF24L01 transceiver module,microphone board, Neopixels as well as EEProm for saving settings such as DMX address,RF frequency, Standalone, mic gain.
The program works fine, apart from this DMX receive issue.
When I also read DMX address +1 data, it seems to corrupt the first DMX address data.
I have only been using the Arduino C language for around 6 months, so I am still a newbie so any help would be much appreciated. Not too sure if there is some conflict using some of the other include files or timing sync issues.
My include files are as follows:-
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#include <EEPROM.h>
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DMXSerial.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <math.h>
LiquidCrystal_I2C lcd(0x27,16,2); // i2c address 0x3F (20 or 27 only)
RF24 radio(22, 24); // CE, CSN
const byte address[6] = "00001";
boolean buttonState = 0;
//******************************************************************************************************
//******************************** Set Receive Protocol Variables *************************************
//*************************************** within DataStruct ********************************************
//******************************************************************************************************
struct dataStruct {
uint8_t rxData0; // **** Program Number 1-15 *********
bool rxData1; // **** Magic Button Pressed 1-on 0- off *******
uint8_t rxData2; // **** Check for interactive programs 0=passive 1=Single Shot 2=Continuous *******
uint8_t rxData3; // ****
uint8_t rxData4; // ****
uint8_t rxData5; // ****
uint8_t rxData6; // **** Sync Mode Number
} myData;
//******************************************************************************************************
//******************************** Set Transmit Protocol Variables ************************************
//************************************* within DataStructTx ********************************************
//******************************************************************************************************
struct dataStructtx {
uint8_t txData0; // **** Program Number 1-15 *********
bool txData1; // **** Magic Button Pressed 1-on 0- off *******
uint8_t txData2; // **** Check for interactive programs 0=passive 1=Single Shot 2=Continuous *******
uint8_t txData3; // ****
uint8_t txData4; // ****
uint8_t txData5; // ****
uint8_t txData6; // **** Sync Mode Number
} myDatatx;
my DMX receive code which is called from within each sub-program:-
//******************************************************************************
//******************* Check for DMX program receving ***************************
//******************************************************************************
void tubeDmxReceive(){
//*************** Check DMX for program number **********************
tubeDmxVal = DMXSerial.read(tubeDmxAddress);//Read DMX program value from DMX address
modeValTemp = DMXSerial.read(tubeDmxAddress+1);//Read DMX mode value from DMX address +1
//Serial.println(tubeDmxVal);
//Serial.println(DMXSerial.read(1));
unsigned long lastPacket = DMXSerial.noDataSince();//Time since no DMX packet was received.
if (lastPacket < 500){//Check for DMX packet within 0.5 secs
tube_Dmx_On = HIGH;
// Turn on DMX LED
// digitalWrite(dmxLed,HIGH);
if (tubeDmxVal >0 && tubeDmxVal <= 255 ){//Stop program from reading 0
dmxProgTemp = map (tubeDmxVal ,0 ,255 ,1 ,12);
}
if (modeValTemp >0 && modeValTemp <=255){//Stop mode from reading 0
tube_Dmx_On = HIGH;
if (tubeProg == 4){tubeDmxModeVal = map(modeValTemp ,0 ,255 ,150 ,1);}
if (tubeProg == 6){tubeDmxModeVal = map(modeValTemp ,0 ,255 ,0 ,6);}
if (tubeProg == 7){tubeDmxModeVal = map(modeValTemp ,0 ,255 ,1 ,5);}
}
}
if (lastPacket >= 2000) {//Check for no DMX received for 2 secs
tube_Dmx_On = LOW;
// Turn off DMX Receiving LED
// digitalWrite(dmxLed,LOW);
}
// Serial.println(tube_Dmx_On);
// Serial.println(lastPacket);
}
I have tried just the DMXSerial.read(1) without calling the DMX read routine, but still get random '0’s along with the DMX value.
The program is 2500 lines of code, so didn’t think it would be advisable to paste it on here, but hopefully someone with more experience can point me in the right direction.
Thanks in advance…