Page 2 of 27 FirstFirst 123412 ... LastLast
Results 11 to 20 of 263

Thread: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

  1. #11
    Join Date
    Nov 2014
    Location
    Austin, TX
    Posts
    164
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Quote Originally Posted by outbreak View Post
    That's what I originally thought would happen, however as soon as I start Vixen, data is sent to my Arduino and opens the relays.
    With the code I posted a couple of posts above?
    I guess that what's happening is that when Vixen opens the serial port, the Arduino is reset.
    That is a feature of the arduinos, for easy programming: Every time the arduino ide opens the serial port to program the arduino, the arduino resets and goes to the bootloader automatically.

    That can be disabled in all arduino boards I belive. After you disable that, when you want to program the arduino you will need to press the reset switch on it, but at least you will be able to open and close the port without rebooting the arduino.
    I think there is a jumper that you either open or close to do that.

  2. #12
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,540
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    When I did a test sequence in Vixen3, my USB-TTL serial always showed TX light ON, even thought the sequence was finished. That suggests that Vixen's datastream does not sleep, but keeps transmitting endlessly.
    You may need to come up with a trick to let the Arduino know that the sequence is finished. One thought is to use an extra channel that is off during the sequence and turned on at the end of your sequence and the Arduino sketch would use this channel to determine the sequence active or in-active.

    There may be better ways that I just can't think of right now.

  3. Thanks outbreak thanked for this post
    Likes outbreak liked this post
  4. #13
    Join Date
    Nov 2014
    Location
    Destin, Fl
    Posts
    149
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Quote Originally Posted by victor_pv View Post
    With the code I posted a couple of posts above?
    I guess that what's happening is that when Vixen opens the serial port, the Arduino is reset.
    That is a feature of the arduinos, for easy programming: Every time the arduino ide opens the serial port to program the arduino, the arduino resets and goes to the bootloader automatically.

    That can be disabled in all arduino boards I belive. After you disable that, when you want to program the arduino you will need to press the reset switch on it, but at least you will be able to open and close the port without rebooting the arduino.
    I think there is a jumper that you either open or close to do that.
    I'll look into this and once again, thank you for your help. I really didn't want to ask for help because I don't learn as much as I would figuring it out myself, but at the point I was at - I was LOST!

    Thanks again!
    Jay

  5. #14
    Join Date
    Oct 2014
    Location
    Bracknell, UK
    Posts
    15
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    The Arduino reset is via the DTR pin - so disconnecting that will prevent a reset if DTR is toggled - however that is not what is happening here.

    Vixen outputs a black out condition on all channels as soon as you start it. The simple way to solve this is have an extra channel as suggested but have code in the arduino that says if that channel is 0 then go to random lights. In all your sequences just set level 100% on that channel for the entire squence.

  6. Thanks outbreak thanked for this post
  7. #15
    Join Date
    Nov 2014
    Location
    Austin, TX
    Posts
    164
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Jay,

    Seems like rather than removing the reset you will need to add an extra channel and in the sketch check for it, and as long as that channel is 0, keep all the lights on or whatever you want.
    Keep the part were it checks for no input and if so turns the lights on, so as long as you don't have vixen running the lights are on.

  8. #16
    Join Date
    Nov 2014
    Location
    Destin, Fl
    Posts
    149
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Thanks! I'll see what I can come up with!

  9. #17
    Join Date
    Nov 2014
    Location
    Destin, Fl
    Posts
    149
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Ok, I give up and the wife is mad because I've been on this thing all day. I'm not asking for anybody to fix this, but could you possibly help me out with the direction to go? I've tried if/else and while, but I can't figure it out. I'm thinking this has to go in "void loop()" after receiving the header and reading the CHANNEL_COUNT, but before assigning each output HIGH or LOW - as you can tell, I'm lost.

    I really apologize. I'm not looking for anybody to do this work for me, just looking at a direction to go to.

    Thanks!

  10. #18
    Join Date
    Oct 2014
    Location
    Bracknell, UK
    Posts
    15
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Try replacing your existing loop with this:

    Code:
    void loop() 
    {
    	if (Serial.available() >= (CHANNEL_COUNT + 2)) 
    	{
    		timer_a = millis(); // new line
    		int uno = Serial.read();
    		if (uno == 126) 
    		{
    			int dos = Serial.read();
    			if (dos == 33) 
    			{
    				for (i = 0; i < CHANNEL_COUNT; i++) 
    				{				
    					incomingByte[i] = Serial.read();
    				}
    				if (incomingByte[CHANNEL_COUNT-1] == 0)
    				{
    				    turnLightsOn();
    				}
    				else
    				{
    					for (i = 0; i < CHANNEL_COUNT-1; i++)
    					{
    						if (incomingByte[i] < 127)
    						{
    							digitalWrite(channels[i], (MODE == NOT_INVERTED) ? LOW : HIGH);
    						}
    						else
    						{
    							digitalWrite(channels[i], (MODE == NOT_INVERTED) ? HIGH : LOW);
    						}
    					}
    				}
    			}
    		}
    	}
    	else 
    	{
    		turnLightsOn();
    	}
    }
    Coded blind so might need a compilation fix. You need to increase your channel count by 1 and the last channel is used to force all lights on. If the last channel is 0 (which is what you get from Vixen when nothing is running) all lights come on. In your sequence set this channel to anything other than 0 for the entire sequence.

  11. #19
    Join Date
    Nov 2014
    Location
    Austin, TX
    Posts
    164
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Thanks Simmon, it looks good to me.
    Outbreak, remember that you have to increase your #define CHANNEL_COUNT to 1 more than the channels you use to run the show, to match the extra channel in Vixen.

  12. #20
    Join Date
    Nov 2014
    Location
    Destin, Fl
    Posts
    149
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    PERFECT!!! Thanks all! Yeah, I have increased the channel count by one, and tried a TON of things! I really need to get back into coding. In college I took some Java, Python and Ruby - which definitely helped me out in understand this code, but I clearly forgot a lot.

    I was trying a lot of things, such as using "while" and another if/else, but clearly there was a much easier way to go about this. I was so frustrated yesterday, I went and hung light in the rain and 60 degree weather!

    Thanks again for all of your help everybody...now, do you want to help me finish hanging the rest of the lights? HA!
    Last edited by outbreak; 11-23-2014 at 10:56 AM.

Page 2 of 27 FirstFirst 123412 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •