Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Re: Working library for receiving DMX? on: April 07, 2012, 05:24:10 pm
Okay, some news:
I've tried this mentioned lib on my old duemilanove and it works like a charm!
I'm using the duemilanove's FT232 directly as a DMX interface, so no excursions over RS485. The PWM works perfectly according to the DMX value.

Now I uploaded this sketch to the Mega2560 and nothing happens! The pwm output is stuck to something like a 80% and it's not responding to any DMX which comes directly from the RX input from the duemilanove.
I've changed the UART in the lib from 0 to 1, but neither is working.

The names of the USART registers are the same, so there can't be the problem.

Any clues why the Duemilanove receives the DMX and the Mega2560 won't?

Edit: The library also works perfect on an Uno! So there has to be a smaaaall difference between the controlling of an Uno and a Mega2560...

Thanks!
2  Using Arduino / Project Guidance / Re: Adapt a C library to arduino on: April 07, 2012, 02:57:42 pm
Yeah.. you're right! Sometimes it's too easy  smiley-wink

I've tried to throw both files together and remove recursive includes.
All I get is "F:\Apps\arduino-1.0-windows\arduino-1.0\libraries\dmxrecv/dmx_recv.h:30: error: expected constructor, destructor, or type conversion before '(' token"
Line 30 is "ISR(SIG_USART0_RECV) {"

Okay, maxbe not so easy smiley-wink
I've got some experience in C and some in the Arduino-IDE, but I've never tried to build my own library, so I'm a little stuck.

Code:
/********************************************************************
 * dmx_recv.h
 *
 * AVR GCC / ATtiny2313 (8MHz)
 * DMX512 recieve
 *******************************************************************/

//#include <avr/io.h>
//#include <avr/interrupt.h>

#define DMX_CH_BASE 0
#define DMX_BUF_SIZE 24
#define DMX_SYNC 3 // 3:8MHz, 7:16MHz, 9:20MHz

void wait_dmx ();
unsigned char *init_dmx (int, int);
void set_dmx_channel(int);
static volatile unsigned char dmx_buf[DMX_BUF_SIZE];
static volatile int dmx_ch, dmx_size, dmx_addr;
static volatile char dmx_mode;


// complete receive?
void wait_dmx () {
while (dmx_mode != 4);
dmx_mode = 0;
}

// DMX receive, USART interrupt
ISR(SIG_USART0_RECV) {
    register unsigned char flg, dat;

    flg = UCSRA;
    dat = UDR;

    if (flg & 0x0c) {
        // data over run, parity error

        dmx_mode = 99; // data error
        while (UCSRA & 0x80) { dat = UDR; } // buffer clear
        return;

    } else
    if (flg & 0x10) {
        // Frame error, detect BreakTime

        dmx_mode = 1;
        return;

    }

    if (dmx_mode == 1) {
        // Start Code

        if (dat == 0) {
            // Start Code = 0
            dmx_addr = 0;
            dmx_mode = 2;
        } else {
            // Start Code error
            dmx_mode = 99;
        }

    } else
    if (dmx_mode == 2) {
        // DMX base address

        if (dmx_addr == dmx_ch) {
            dmx_addr = 0;
            dmx_mode = 3;
        } else {
            dmx_addr ++;
        }
    }

    if (dmx_mode == 3) {
        // recieve the data

        dmx_buf[dmx_addr] = dat;
        dmx_addr ++;

        if (dmx_addr >= dmx_size) {
            // complete receive
            dmx_mode = 4;
        }
    }

}

// initialize USART
unsigned char *init_dmx (int ch, int size) {
    int i;

    // buffer clear
    dmx_mode = 0;
    dmx_addr = 0;
dmx_ch = ch;
dmx_size = size;
if (size > DMX_BUF_SIZE) {
dmx_size = DMX_BUF_SIZE;
}
    for (i = 0; i < dmx_size; i ++) {
        dmx_buf[i] = 0;
    }

    // set USART
    UBRRH = 0;
    UBRRL = DMX_SYNC; // 250kbps
    UCSRA = _BV(U2X); // U2X
    UCSRC = _BV(USBS) | _BV(UCSZ1) | _BV(UCSZ0); // stop code 2bitAdata 8bit
    UCSRB = _BV(RXCIE) | _BV(RXEN); // receive, interrupt

    return (unsigned char *)&dmx_buf;
}

void set_dmx_channel(int ch)
{ dmx_ch=ch;
  dmx_mode=0;
}

3  Using Arduino / Project Guidance / Adapt a C library to arduino on: April 07, 2012, 02:29:24 pm
Hi!
For an earlier project I've written a library for receiving DMX with an AVR. Unfortunately it's written in C.
Is there any chance of adapting those code snippets for the use with an Arduino? They are working well and it would be great to use them with my Arduino!

 
Code:
/********************************************************************
 * dmx_recv.h
 *
 * AVR GCC / ATtiny2313 (8MHz)
 * DMX512 receive
 *******************************************************************/

#include <avr/io.h>
#include <avr/interrupt.h>

#define DMX_CH_BASE 0
#define DMX_BUF_SIZE 24
#define DMX_SYNC 3 // 3:8MHz, 7:16MHz, 9:20MHz

void wait_dmx ();
unsigned char *init_dmx (int, int);
void set_dmx_channel(int);

Code:
/********************************************************************
 * dmx_recv.c
 *
 * AVR GCC / ATtiny2313 (8MHz)
 * DMX512 Receive
 *******************************************************************/

#include "dmx_recv.h"

static volatile unsigned char dmx_buf[DMX_BUF_SIZE];
static volatile int dmx_ch, dmx_size, dmx_addr;
static volatile char dmx_mode;


// complete receive?
void wait_dmx () {
while (dmx_mode != 4);
dmx_mode = 0;
}

// DMX receive, USART interrupt
ISR(SIG_USART0_RECV) {
    register unsigned char flg, dat;

    flg = UCSRA;
    dat = UDR;

    if (flg & 0x0c) {
        // data over run, parity error

        dmx_mode = 99; // data error
        while (UCSRA & 0x80) { dat = UDR; } // buffer clear
        return;

    } else
    if (flg & 0x10) {
        // Frame error, detect BreakTime

        dmx_mode = 1;
        return;

    }

    if (dmx_mode == 1) {
        // Start Code

        if (dat == 0) {
            // Start Code = 0
            dmx_addr = 0;
            dmx_mode = 2;
        } else {
            // Start Code error
            dmx_mode = 99;
        }

    } else
    if (dmx_mode == 2) {
        // DMX base address

        if (dmx_addr == dmx_ch) {
            dmx_addr = 0;
            dmx_mode = 3;
        } else {
            dmx_addr ++;
        }
    }

    if (dmx_mode == 3) {
        // recieve the data

        dmx_buf[dmx_addr] = dat;
        dmx_addr ++;

        if (dmx_addr >= dmx_size) {
            // complete receive
            dmx_mode = 4;
        }
    }

}

// initialize USART
unsigned char *init_dmx (int ch, int size) {
    int i;

    // buffer clear
    dmx_mode = 0;
    dmx_addr = 0;
dmx_ch = ch;
dmx_size = size;
if (size > DMX_BUF_SIZE) {
dmx_size = DMX_BUF_SIZE;
}
    for (i = 0; i < dmx_size; i ++) {
        dmx_buf[i] = 0;
    }

    // set USART
    UBRRH = 0;
    UBRRL = DMX_SYNC; // 250kbps
    UCSRA = _BV(U2X); // U2X
    UCSRC = _BV(USBS) | _BV(UCSZ1) | _BV(UCSZ0); // stop code 2bitAdata 8bit
    UCSRB = _BV(RXCIE) | _BV(RXEN); // receive, interrupt

    return (unsigned char *)&dmx_buf;
}

void set_dmx_channel(int ch)
{ dmx_ch=ch;
  dmx_mode=0;
}

4  Using Arduino / Networking, Protocols, and Devices / Working library for receiving DMX? (Solved) on: April 06, 2012, 10:52:06 am
I've searched the forum and nearly all the other Internet but with no result.
There are a lot of libraries and code examples when it comes to send DMX, but I'd like to receive it and control my Arduino with it.

I found just one library from mathertel.de, but I have no success using it. My oscilloscope shows that my DMX sender and the MAX485 are working, but neither the example code of this library nor some own lines are working.
The example from the Playground won't compile. (core.a(HardwareSerial.cpp.o): In function `__vector_25':
F:\Apps\arduino-1.0-windows\arduino-1.0\hardware\arduino\cores\arduino/HardwareSerial.cpp:102: multiple definition of `__vector_25'
Blink.cpp.o:C:\Users\SEBAST~1\AppData\Local\Temp\build5591305470023210670.tmp/Blink.cpp:33: first defined here)

Do you have any suggestions of (working) DMX receiving libraries?

Thanks in advance!
5  Using Arduino / Programming Questions / Re: random() won't stay within its boundaries on: April 04, 2012, 02:41:11 pm
As I said: Just a small problem  smiley-wink

Yep, added a clear() and everything is fine..

Thanks for the quick help!
6  Using Arduino / Programming Questions / Re: random() won't stay within its boundaries on: April 04, 2012, 02:33:08 pm
okay, it's nothing big, just the LCD example with random numbers:

Code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
long randNumber;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {

  lcd.setCursor(0, 1);
  randNumber = random(0, 160);
  lcd.print(randNumber);
  delay(1000);
}


7  Using Arduino / Programming Questions / random() won't stay within its boundaries on: April 04, 2012, 02:27:32 pm
Hello, World!

Just a quick problem:
random(0,160) returns in my case a lot of random numbers greater than 159 (up to 999), but random (10,20), random (100, 160) and/or random(0,100) are working just fine (It's the same when using RandomSeed()).
I'm using the Ardu Mega2560 Rev.3 and I'd like to know if you can reproduce my problem and maybe tell me what sort of wizardry is going on here  smiley-small

Greets from Germany,
Sebastian
8  Forum 2005-2010 (read only) / Troubleshooting / [m by=mellis destboard=programming dest=1266266877]: If-Statement should be false but seems to be true on: February 15, 2010, 05:18:16 pm
[moved] [link=http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266266877/0]Syntax & Programs[/link] [move by] mellis.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: If-Statement should be false but seems to be true on: February 17, 2010, 02:45:41 am
Wow, thank you guys.
But I don't think, I'll go that far with this project.

I have found this circuit wirh CMOS ICs: http://www.zen22142.zen.co.uk/Circuits/Misc/quiz.htm

Maybe I just but this between the buttons and the Arduino. Then, the Arduino can control the LEDs (the delay doesn't matter this way) and I can use some serial commands to control a selfmade audio-player, that should stop, when somebody has hit his button.

But nevertheless, it's an interesting challenge to make something like this as fair as possible by using just a µC.
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: If-Statement should be false but seems to be true on: February 16, 2010, 02:52:13 am
I changed the buttons and the delay was on the other button.
I removed the push buttons and tested it without them - It works.
Then, I put them back and everything was just fine.

If I find some small bushbuttons, I'll build a button board on some stripboard. Then, a lot of wires and potential mistakes should disappear. And I can switch to 4 buttons.

Of course, the system isn't really fair, and for 4 players it becomes even more unfair, but I think, this is ok. At least I have no other ideas how to solve this.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: If-Statement should be false but seems to be true on: February 15, 2010, 05:18:16 pm
Okay, no problem.

I'm using Pin 2 and 3 for the buttons.
Both pins are pulled down by 10k resistors.
The push buttons are connected to an input and +5V.
None of the pins is floating.

I can plug the pin direct to 5V and the delay is still there.
And to the first code I have just added a reset button.

Here are two images (not very usefull, chaos):
http://img687.imageshack.us/img687/1027/quiz004.jpg
http://img684.imageshack.us/img684/1961/quiz002.jpg
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: If-Statement should be false but seems to be true on: February 15, 2010, 04:52:51 pm
No I have tidied up the code and removed nearly all debugging infos:
Code:
 Serial.println("Ready.");
  
  while(winner == 0) {
    if (digitalRead(button1) == HIGH) {  
      winner = 1;
    }
    
    if (digitalRead(button2) == HIGH) {
      winner = 2;
    }
  }

When I press button 1, it takes about a second until it is recognized. Button 2 works immediately. Both push buttons are wired the same. 10k pull-down and to +5V  :-?
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: If-Statement should be false but seems to be true on: February 15, 2010, 03:59:12 pm
Argh!
Thank you very much. I know that it could be just a little mistake. On my protoshield I've wired the buttons correctly to 2 and 3, but I haven't changed the software.

Works perfekt!  smiley
14  Forum 2005-2010 (read only) / Syntax & Programs / If-Statement should be false but seems to be true on: February 15, 2010, 03:47:57 pm
Hi!
I'm working on a small project. A classical quiz bowl buzzer. Nothing big, just 2 pushbuttons and 2 LEDs at the moment (should be expanded to 4 lateron).

Concept:
- parameter 'winner' = 0
- While (winner == 0) checks, if button 1 or button 2 has been pressed.
- If so, 'winner' is set to 1 or 2 and the while loop stops

Ive got a lot of debugging information and so I can say, that there's a problem with the button2-checking If statement. It becomes true, also the button isn't pressed and the state is LOW.

Code:
const int button1 = 2;
const int button2 = 1;
const int led1 =  13;
const int led2 =  12;

int winner = 0;

void setup() {
  pinMode(led1, OUTPUT);    
  pinMode(led2, OUTPUT);    
  pinMode(button1, INPUT);    
  pinMode(button2, INPUT);
  Serial.begin(9600);
  Serial.print("Init done, 'winner' set to: ");
  Serial.println(winner);
  delay(1000);
}

void loop(){
  Serial.print("Button 1 state: ");
  Serial.println(digitalRead(button1));
  Serial.print("Button 2 state: ");
  Serial.println(digitalRead(button2));
  delay(1000);
  Serial.println("Begin of while()");
  delay(1000);
  
  while(winner == 0) {
    if (digitalRead(button1) == HIGH) {  
      Serial.print("Button 1 state ");
      Serial.println(digitalRead(button1));  
      winner = 1;
      Serial.print("Winner now set to: ");
      Serial.println(winner);  
    }
    
    if (digitalRead(button2) == HIGH) {
      Serial.print("Button 2 state ");
      Serial.println(digitalRead(button2));
      winner = 2;
      Serial.print("'winner' now set to: ");
      Serial.println(winner);    
    }
  }
  
  Serial.println("While finished");
  delay(1000);
  
  if (winner == 1) {
    Serial.println("Winner = 1; LED 1 high");
    delay(1000);
    digitalWrite(led1, HIGH);
  }
  
  if (winner == 2) {
    Serial.println("Winner = 2; LED 2 high");
    delay(1000);
    digitalWrite(led2, HIGH);
  }
  
  Serial.println("All done. Going to do nothing");
  while (winner != 0) {
    Serial.print("Waiting for reset, winner is now: ");
    Serial.println(winner);
    delay(2000);
  }
}

And all I get is:
Quote
Init done, 'winner' set to: 0
Button 1 state: 0
Button 2 state: 0
Begin of while()
Button 2 state 0
'winner' now set to: 2
While finished
Winner = 2; LED 2 high
All done. Going to do nothing
Waiting for reset, winner is now: 2
[...]

So winner is set to 2, but the button wasn't pressed at all.

Thank you in advance  smiley-wink
15  Forum 2005-2010 (read only) / Deutsch / Re: 4 Relais auf Lochraster on: April 03, 2010, 03:45:53 pm
Na und?
Streifenraster anstatt Punktraster und nen Transistor anstatt Treiber...
Und du wirst die Schaltung ja n mal nebeneinander aufbauen können.. notfalls kopier ichs dir in Paint nebeneinander  :o

Also ich sehe das Problem nicht... Es ist nicht genau das, was du wolltest, aber es erfüllt den gleichen Zweck. Beispielschaltungen für den ULN2803 gibt es notfalls genug. Die lassen sich zu 99% vom Blatt aufs Punktraster übertragen, ohne groß nachzudenken.
Pages: [1] 2 3