Hi guys ¡
I have been trying to modify some code to control the arduino dmx dongle from vvvv , I got it to work , but probably not the best way , it is buggy . for testing , i set to control just the first 3 channels . I,m sending the values as an ascii string , it sends the values ok but sometimes interfear in the other 3 channels for a little time and the last dmx channels about the 500 to end are also bothered .
I test the setup with an enttet dongle getting the output from arduino .
possible reasons i humbly think :
the thing is that i dont know how to tell arduino to get the part of the array after a comma , space or any character ?
, so i send the values without logical separation value1value2value3 , the magic is that it mostly work arduino sort of guess where to cut ;D
the other posibility is that arduino is not getting the full data , is there a way of making a tokenizer in arduino ?
or maybe it is better to send a char and convert to int but dont know how to do it i tried some staff without luck .
I need your help , how would you do that ?
//
This is the part i modified
int value[]={0, 1, 2};
// I,m just testing with the first 3 dmx channels
if (Serial.available() > 0){
for ( int count = 0; count<=2; count++) {
value[count] = Serial.read();
shiftDmxOut( sig, value[count]);
}
//---------------------
// Those channels are set to 255
for (int count = 3; count<=512; count++){
shiftDmxOut( sig, 255);
}
Full code :
/*
* DMX fade for arduino 008
* based on the code of Tomek Ness and D. Cuartielles
*
* adapted to arduino 008 by Peter Szakal and Gabor Papp
* http://nextlab.hu
*/
#include "pins_arduino.h"
int sig = 11; // signal
int value[]={0, 1, 2};
/* Sends a DMX byte out on a pin. Assumes a 16 MHz clock.
* Disables interrupts, which will disrupt the millis() function if used
* too frequently. */
void shiftDmxOut(int pin, int theByte)
{
int port_to_output[] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PORTB),
_SFR_IO_ADDR(PORTC),
_SFR_IO_ADDR(PORTD)
};
int portNumber = port_to_output[digitalPinToPort(pin)];
int pinMask = digitalPinToBitMask(pin);
// the first thing we do is to write te pin to high
// it will be the mark between bytes. It may be also
// high from before
_SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;
delayMicroseconds(10);
// disable interrupts, otherwise the timer 0 overflow interrupt that
// tracks milliseconds will make us delay longer than we want.
cli();
// DMX starts with a start-bit that must always be zero
_SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask;
// we need a delay of 4us (then one bit is transfered)
// this seems more stable then using delayMicroseconds
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
for (int i = 0; i < 8; i++)
{
if (theByte & 01)
{
_SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;
}
else
{
_SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask;
}
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
theByte >>= 1;
}
// the last thing we do is to write the pin to high
// it will be the mark between bytes. (this break is have to be between 8 us and 1 sec)
_SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;
// reenable interrupts.
sei();
}
void setup()
{
Serial.begin(115200);
pinMode(sig, OUTPUT);
}
void loop()
{
/***** sending the dmx signal *****/
// sending the break (the break can be between 88us and 1sec)
digitalWrite(sig, LOW);
delay(10);
// sending the start byte
shiftDmxOut(sig, 0);
//------------------
// This is the part i,m modifying
// I,m just testing with the first 3 dmx channels
if (Serial.available() > 0){
for ( int count = 0; count<=2; count++) {
value[count] = Serial.read();
shiftDmxOut( sig, value[count]);
}
//---------------------
// Those channels are set to 255
for (int count = 3; count<=512; count++){
shiftDmxOut( sig, 255);
}
}
}
thanks in advance , i would upload the patch but dont see where to upload ?.
Regards