Problems with DMX output from SparkFun ESP32 Thing Plus DMX to LED Shield without the ESP32 board

Hello! I am trying to use the Sparkfun DMX shield with my arduino mega 2560 board. I am trying to get the example code to work. However, the example code is for ESP32 which I don't have. From my understanding the shield should work with a standard Arduino too. I am struggling with editing the code to work with Arduino. I want to use the serial1 (ports 18 and 19) for communication between arduino and the DMX shield. There is something wrong with line 28.

Here is the schematic of my connections etc.

Here is the code I am working with, which I need help with:

/*
  Writes DMX data to channel 1

  By: Dryw Wade
  SparkFun Electronics
  Date: 10/3/2023
  License: GNU. See license file for more information but you can
  basically do whatever you want with this code.
  This example runs two servos and a number of LED's off of 5 DMX channels
  
  Feel like supporting open source hardware?
  Buy a board from SparkFun! https://www.sparkfun.com/products/15110
  
  Hardware Connections:
  Connect a Thing Plus board to the SparkFun DMX Shield, and connect a DMX XLR-3
  cable between the shield and another device that outputs DMX data. You can use
  a second board and shield running Example 2!
*/

// Inlcude DMX library
#include <SparkFunDMX.h>

// Create DMX object
SparkFunDMX dmx;

// Create serial port to be used for DMX interface. Exact implementation depends
// on platform, this example is for the ESP32
HardwareSerial dmxSerial(2);

// Enable pin for DMX shield (Free pin on Thing Plus or Feather pinout)
uint8_t enPin = 21;

// Number of DMX channels, can be up tp 512
uint16_t numChannels = 100;

// Create a counter as example data
uint8_t counter = 0;

void setup()
{
    Serial.begin(115200);
    Serial.println("SparkFun DMX Example 1 - Output");

    // Begin DMX serial port
    dmxSerial.begin(DMX_BAUD, DMX_FORMAT);

    // Begin DMX driver
    dmx.begin(dmxSerial, enPin, numChannels);

    // Set communicaiton direction, which can be changed on the fly as needed
    dmx.setComDir(DMX_WRITE_DIR);

    Serial.println("DMX initialized!");
}

void loop()
{
    // Write counter to channel 1
    dmx.writeByte(counter, 1);

    // Once all data has been written, update() must be called to actually send it
    dmx.update();

    Serial.print("DMX: sent value to channel 1: ");
    Serial.println(counter);

    // Increment counter (overflows back to 0 after 255)
    counter++;

    // Slow down communication for this example
    delay(100);
}

Trying to verify the code, i get the following error
C:\Users\5600X\AppData\Local\Temp.arduinoIDE-unsaved20231114-10440-3358x2.k6mkj\Example1-DMXOutput\Example1-DMXOutput.ino:28:27: error: no matching function for call to 'HardwareSerial::HardwareSerial(int)'
HardwareSerial dmxSerial(2);
^
In file included from C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:233:0,
from C:\Users\5600X\AppData\Local\Temp\arduino\sketches\B60D227A5F3B3AC660AB77868C086975\sketch\Example1-DMXOutput.ino.cpp:1:
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:117:12: note: candidate: HardwareSerial::HardwareSerial(volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*)
inline HardwareSerial(
^~~~~~~~~~~~~~
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:117:12: note: candidate expects 6 arguments, 1 provided
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:93:7: note: candidate: constexpr HardwareSerial::HardwareSerial(const HardwareSerial&)
class HardwareSerial : public Stream
^~~~~~~~~~~~~~
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:93:7: note: no known conversion for argument 1 from 'int' to 'const HardwareSerial&'
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:93:7: note: candidate: constexpr HardwareSerial::HardwareSerial(HardwareSerial&&)
C:\Users\5600X\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/HardwareSerial.h:93:7: note: no known conversion for argument 1 from 'int' to 'HardwareSerial&&'

exit status 1

Compilation error: no matching function for call to 'HardwareSerial::HardwareSerial(int)'

The architecture of the ESP32 and the Mega are so different that i suggest you use a different library.
For DMX transmission on an AVR i use Conceptinetics.h and if you want to use Serial1, you need to go into the .h file and

//#define USE_DMX_SERIAL_0  // comment this line
#define USE_DMX_SERIAL_1   // and uncomment this one.
//#define USE_DMX_SERIAL_2
//#define USE_DMX_SERIAL_3

I do suspect that you will need to connect also the 485EN pin which probably is connected to DE & !RE and can be specified also in the conceptinetics examples. (if you provide a schematic of the shield i can have a proper look, the direction of the transceiver does always have to be set, but it may be done with pullups i don't know)

1 Like

Thanks for the reply!
Here is the schematic of the DMX shield. I will try the conceptinetics with my code as soon as possible. At least that one seems to be compiling normally!

The shield has a few Opto-couplers for the 3.3v to 5v conversion, this complicates the connections a bit. I think, but i am not 100% sure there, that you would be best of connecting the 3.3v on the shield to 5v as well. That will be the best for the opto-couplers and the data signal, there is also a TX80104 connected to 3.3v though for use with some kind of leds on the board, and applying 5v to it will be outside of it's range, which will probably cause it to break. So actually hmm looking at the Opto-couplers again, maybe the safest would be to connect 3.3v on the shield to 3.3v on the mega, The 6N137 should according to the datasheet be able to take the 1.7v reverse voltage that may occur.

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