-->
Page 1 of 1

ESP8266 based dmx receiver and sender

PostPosted: Sat Apr 25, 2020 10:02 am
by Martmh
Hi,

So I have a esp with two max485 shields to receive (alter) and send dmx data. However, first off i'd like to just receive and pass through the DMX signal so when i get that to work, i can start doing my if's and elses.

However, reading the dmx just doesn't seem to start working with my kind of experience. I based the sending (which actually already works) on the espdmx library found here:

The code i'm currently running:
Code: Select all#include <ESP8266WiFi.h>

#include <Ticker.h>  //Ticker Library
#include "espDMX2/espDMX.h"

#define NUMBER_OF_CHANNELS 512
unsigned int dmxaddress = 1;

#define DEpinTX D5
#define DEpinRX D6
#define btnPin 7

DMXESPSerial dmx;


#define RX_PIN 3   // serial receive pin, which takes the incoming data from the MAX485.
#define TX_PIN 2   // serial transmission pin


/******************************* DMX variable declarations ********************************/

volatile byte i = 0;              //dummy variable for dmxvalue[]
volatile byte dmxreceived = 0;    //the latest received value
volatile unsigned int dmxcurrent = 0;     //counter variable that is incremented every time we receive a value.
volatile int currentBit = 0;
volatile byte dmxvalue[NUMBER_OF_CHANNELS];
volatile int zeroCounter = 0;
volatile int dmxnewvalue = 0;


void setup() {
  //pinMode(RX_PIN, FUNCTION_3);
  WiFi.mode( WIFI_OFF );
  WiFi.forceSleepBegin();
  /******************************* Max485 configuration ***********************************/
  Serial.begin(250000);
  pinMode(DEpinTX, OUTPUT);
  pinMode(DEpinRX, OUTPUT);
  digitalWrite(DEpinRX, LOW);
  digitalWrite(DEpinTX, HIGH);
  dmx.init(512);

  pinMode(RX_PIN, INPUT);  //sets serial pin to receive data
  pinMode(TX_PIN, OUTPUT);
  timer1_attachInterrupt(onTimerISR); //function to call at 4us
  timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP); // 80 Mhz / 16 = 5 Mhz, 5 ticks / us -> 20 ticks = 4us,
  timer1_write(20); //4 us
  delay(2000);

}  //end setup()

void loop()  {
  // the processor gets parked here while the ISRs are doing their thing.
  if (dmxnewvalue == 1) {    //when a new set of values are received, jump to action loop...
    for (int y = 0; y < NUMBER_OF_CHANNELS; y++) {
      dmx.write(y, interestingBytes[y]);
    }
    dmx.update();
    dmxnewvalue = 0;
    zeroCounter = 0;      //and then when finished reset variables and enable timer2 interrupt
    i = 0;
   
  }

} //end loop()

void onTimerISR() {
 

  if (digitalRead(RX_PIN)) {
    zeroCounter = 0;
  } else {
    zeroCounter++;
    if (zeroCounter == 20) {
      //80 us break (20 zero's in a row)
      attachInterrupt(digitalPinToInterrupt(RX_PIN), receptionISR, CHANGE);
    }
  }
}


void receptionISR() {
  dmxreceived = Serial.read();
  dmxcurrent++;                        //increment address counter
  if (dmxcurrent > dmxaddress) {        //check if the current address is the one we want.
    dmxvalue[i] = dmxreceived;
    i++;
    if (i == NUMBER_OF_CHANNELS) {
      detachInterrupt(digitalPinToInterrupt(RX_PIN));
      dmxnewvalue = 1;                        //set newvalue, so that the main code can be executed.
    }
  }
}




I know somewhere i'm messing up RX pins, serial and the attachinterrupt, however i'm not very capable of sorting out what to do after days of desperate trial and error.

source: https://github.com/Rickgg/ESP-Dmx

Re: ESP8266 based dmx receiver and sender

PostPosted: Sat Jun 06, 2020 8:28 am
by Cide
Hi, did you find an answer to your problem? I'm interested in your project. I'm also trying to use the rick's dmx library but it works with SERIAL1 and my ESP doesn't have a RX1. Only the TX1. I'm looking for a solution or another library to use the ESP as a DMX receiver.

Re: ESP8266 based dmx receiver and sender

PostPosted: Sat Jun 06, 2020 9:32 am
by Cide
Hey! Sorry I don't have any answer but did you find a solution? I'm alse looking at this library for a project who looks like yours.
My problem is that that library is using Serial 1 and I need to use Serial 0 or 2 because I don't have the Rx1 pin on my ESP. Does anybody can tell me if it's possible to change the Serial in the library and if yes, how?
I already tried that library
https://github.com/claudeheintz/LXESP8266DMX
It works but the lamp turn off or on randomly sometimes.