Bonjour, dans le cadre d’un de mes projets, je souhaite réaliser un contrôleur dmx512 (protocole rs485) afin de contrôler mes jeux de lumière (type lyre, spot, stroboscope…)
J’ai donc commencé par acheter des modules qui permettent de convertir du TTL -> RS485 en utilisant le MAX485 (lien du produit en question en dessous de l’article)
Mais malgré plusieurs essais rien ne marchait.
J’ai donc décidé, par peur que mes branchements soit simplement incorrect d’acheter un Shields avec déjà tout ( MAX485, prises XLR…) histoire d’être sûr que les branchements soient corrects . Mais encore une fois, je n’ai pas réussi à créer une trame dmx compréhensible par mes jeux de lumières…
La bibliothèque que j’utilise s’appelle DMXSerial, j’ai également testé d’autres bibliothèques mais elles font globalement toutes la même chose.
J’espère avoir une réponse à ma question, les info sur le dmx/arduino sont très compliqué à trouver, notamment en français. Merci d’avance aux personnes qui m’aideront.
j'ai utilisé un module MAX485 qui ressemble au tien, ainsi que la librairie DMXSerial, et j'ai fait un prog qui marche parfaitement.
// =========================================
// DMX Sender
// Gilles juin 22
// avec MAX485
// =========================================
/* ---
channel 1 = RED
channel 2 = GREEN
channel 3 = BLUE
channel 4 = UV
*/
const int RED = 1;
const int GREEN = 2;
const int BLUE = 3;
const int UV = 4;
const int MAIN = 5;
const int STROB = 6;
const int RED2 = RED;
const int GREEN2 = RED2 + 1;
const int BLUE2 = GREEN2 + 1;
const int UV2 = BLUE2 + 1;
#include "DMXSerial.h"
#include <SoftwareSerial.h>
SoftwareSerial Debug ( 3, 4 );
// ==========================================================
class Color {
public:
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char uv;
Color() { red = green = blue = uv = 0; }
Color ( unsigned char r, unsigned char g, unsigned char b, unsigned char u )
: red(r), green(g), blue(b), uv(u) {}
void SetRGBU ( unsigned char r, unsigned char g, unsigned char b, unsigned char u=0 )
{
red = r; green = g; blue=b; uv=u;
}
void Send ( int offset )
{
DMXSerial.write ( offset + RED, red );
DMXSerial.write ( offset + GREEN, green );
DMXSerial.write ( offset + BLUE, blue );
DMXSerial.write ( offset + UV, uv );
DMXSerial.write ( offset + MAIN, 255 );
DMXSerial.write ( offset + STROB, 0 );
}
void Roll ()
{
if ( red == 0 ) red = 255;
else red -= 1;
if ( green == 255 ) green = 0;
else green += 1;
if ( blue == 255 ) blue = 0;
else blue += 1;
}
void Print ( Stream & stream )
{
stream.print ( red ); stream.print ( " " ); stream.print ( green ); stream.print ( " " );
stream.print ( blue ); stream.print ( " " ); stream.println ( uv );
}
};
// ==========================================================
void setup() {
DMXSerial.init ( DMXController ); // always sending
Debug.begin ( 9600 );
//Serial.begin ( 9600 );
}
// ==========================================================
float def_sign ( float v ) {
if ( v > 0.f ) return 1.f;
else if ( v<0.f) return -1.f;
else return 0.f;
}
// ==========================================================
unsigned long Count = 0;
const int PERIOD = 4;
Color color ( 128, 255, 0, 0 );
Color color2 ( 0, 128, 255, 0 );
const unsigned long RMAX = 0x1000;
// ==========================================================
float new_vitesse ( float v ) {
float s = def_sign ( v );
do {
v = 0.1f * random ( 0, RMAX+1 ) / RMAX;
} while ( v < 0.005 );
return ( -s * v );
}
float vx = new_vitesse ( 1 );
float vy = new_vitesse ( 1 );
float vz = new_vitesse ( 1 );
// ==========================================================
float x=0, y=0, z= 0;
float dt = 0.2f;
// ==========================================================
void new_point ( float &u, float &vu ) {
u = u + vu * dt;
if ( u > 1.f ) {
u = 2.f - u;
vu = new_vitesse ( vu );
} else if ( u < 0.f ) {
u = - u;
vu = new_vitesse ( vu );
}
}
// ==========================================================
void loop() {
new_point ( x, vx );
new_point ( y, vy );
new_point ( z, vz );
unsigned char red = (unsigned char) (x * 255);
unsigned char grn = (unsigned char) (y * 255);
unsigned char blu = (unsigned char) (z * 255);
color.SetRGBU ( red, grn, blu );
color.Send ( 0 );
//color.Print ( Debug );
//Serial.print ( red ); Serial.print ( " " ); Serial.print ( grn ); Serial.print ( " " ); Serial.println ( blu );
delay ( 50 );
}
// ==========================================================
Attention au cablage !
Et note bien que le DMX est monté sur les ports 0 et 1, j'utilise SoftwareSerial sur d'autres broches pour afficher sur le moniteur (grâce à un convertisseur TTL>USB)