Page 1 of 6 123 ... LastLast
Results 1 to 10 of 54

Thread: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

  1. #1
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    974
    Post Thanks / Like

    Default Success Modifying VictorPV and ZParticle Sketches to Accept Renard Protocol

    I have succeded in modifying the sketch by VictorPV, that has become a staple of this forum, to accept Renard protocol. "Why would I do that" you ask? So that I can use an ESpixelstick to provide a datastream to my Arduino MEGA controller with AC/DC single light elements. The ESPixelstick has an option to provide the Renard protocol as an output even though it is receiving the data via E1.31. Now I can export my Vixen sequence to FPP running on a Pi and have the Pi communicate with the ESPixelsticks over wifi. I used Bill Porter's Arduino Renard library to make it work.


    Kevin

    EDIT - I am adding here in the first post of this thread that I have also modified the sketch by ZParticle to accept Renard protocol (code is posted in post #4 below).



    MODIFIED VICTOR_PV SKETCH
    Code:
    // WORKING VERSION WITH RENARD PROTOCOL USING SERIAL3 (PINS 14 TO FTDI RX AND 15 TO FTDI TX)
    
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
     // KG add for renard. Include the Arduino Renard library by Bill Porter
     #include <Arduino-Renard.h>
     
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
     #define CHANNEL_COUNT 48
    
     Renard renard; //KG add for renard
    
     byte incomingByte[CHANNEL_COUNT];  //KG add for renard
     
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     #define VIXEN_COM_SPEED 57600
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE NOT_INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 A0
     #define CH02 A1
     #define CH03 A2
     #define CH04 A3
     #define CH05 A4
     #define CH06 A5
     #define CH07 A6
     #define CH08 A7
     #define CH09 A8
     #define CH10 A9
     #define CH11 A10
     #define CH12 A11
     #define CH13 A12
     #define CH14 A13
     #define CH15 A14
     #define CH16 A15
     #define CH17 38
     #define CH18 39
    // Up to here for Arduino uno.
     #define CH19 40
     #define CH20 41
     #define CH21 42
     #define CH22 43
     #define CH23 44
     #define CH24 45
     #define CH25 30
     #define CH26 31
     #define CH27 32
     #define CH28 33
     #define CH29 34
     #define CH30 35
     #define CH31 36
     #define CH32 37
     #define CH33 22
     #define CH34 23
     #define CH35 24
     #define CH36 25
     #define CH37 26
     #define CH38 27
     #define CH39 28
     #define CH40 29
     #define CH41 13
     #define CH42 12
     #define CH43 11
     #define CH44 10
     #define CH45 9
     #define CH46 8
     #define CH47 7
     #define CH48 6
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
     CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,CH20,CH21,CH22,
     CH23,CH24,CH25,CH26,CH27,CH28,CH29,CH30,CH31,CH32,CH33,CH34,CH35,
     CH36,CH37,CH38,CH39,CH40,CH41,CH42,CH43,CH44,CH45,CH46,CH47,CH48};
    
     // KG subtract for renard - int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
    renard.begin((uint8_t*)&incomingByte, CHANNEL_COUNT, &Serial3, 57600); //KG add for renard
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      //sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop(){
      
       if (renard.receive()) {   //KG modified from VictorPV original
         wdt_reset(); // resets the watchdog
         timer_a = millis (); // new line
         int uno = Serial.read();
         //KG if (uno == 126){
           
         //KG  int dos = Serial.read();
         //KG  if (dos == 33){
       
         //KG    for (i=0; i < CHANNEL_COUNT; i++) {
         //KG        // read each byte
         //KG     incomingByte[i] = Serial.read();
         //KG    }
         if (MODE == NOT_INVERTED) {
          for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value <= 127) {
            digitalWrite(channels[i], LOW);
          }
          else {
            digitalWrite(channels[i], HIGH);
          }
          }
         }
         else {
         for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value < 127) {
            digitalWrite(channels[i], HIGH);
          }
          else {
            digitalWrite(channels[i], LOW);
          }
          }
         }
    
          //KG  }
         //KG }
       }
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
           timer_a = millis ();
           int random_a = 0;
           for (i=0; i < CHANNEL_COUNT; i++){
             random_a = random(0, 2);
             if (random_a == 0) {
               digitalWrite(channels[i], LOW);
             }
             else {
               digitalWrite(channels[i], HIGH);
             }
           }
         }
       }
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       //kg delay (500);
      //kg digitalWrite(channels[i], HIGH);
       }
     }
    }
    Last edited by kev; 12-18-2019 at 03:07 AM. Reason: add code
    Kevin

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

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Good work kev.

    How do you connect the ESpixelstick to the MEGA board? I haven't looked into the wifi stuff yet. Is it like a "shield" for the MEGA?

  3. #3
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    974
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Quote Originally Posted by LightUp View Post
    Good work kev.

    How do you connect the ESpixelstick to the MEGA board? I haven't looked into the wifi stuff yet. Is it like a "shield" for the MEGA?
    So far I have just been testing to a bare MEGA with three LEDs stuck in the output pins and the output of the ESPixelstick wired to Serial 3 pins. My shield will have to be modified to accept the ESPixelstick output. I have not done that yet. I was thinking of incorporating the ESP-01 module into a new shield design, but that will probably have to wait for next year. I wasn't sure if I would be using the MEGA based system until I got this RENARD/ESPixelstick stuff figured out. Next up I will be trying to modify ZParticle sketch to accept RENARD protocol so that I can continue to dim the props connected to the MEGA based system.
    Kevin

  4. #4
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    974
    Post Thanks / Like

    Default Am I a Criminal? Succes modifying ZParticle Sketch

    Am I a criminal? I feel like I did a drive by, smash and grab, slash and burn, or whatever cliche you want to add. I have 'modified' a piece of art found here on the forum to meet my needs. I am talking about ZParticle's 32 channel Arduino MEGA sketch. Yes, I have been successful in adapting it to accept the RENARD protocol. I have tested it by sending data from FPP running on a Pi-3 via wifi to a ESPixelstick comfigured for RENARD out (8 channels so far).

    I think that I will slink away for awhile now.

    MODIFIED ZParticle SKETCH
    Code:
    // WORKING RENARD PROTOCOL VERSION
    // REDUCED NUMBER OF DIMMING STEPS FROM 256 TO 64
    // REMOVED RANDOM LIGHTS SECTION
    // REVERSED ISR LOGIC AND COUNTER ACTION FROM ++ TO -=4
    // REMOVED A LOT OF EXTRA COMMENTS - REFER TO ORIGINAL FOR REFERENCE
    // 
    
    /************************************************************************************************ 
    *  This is a derivitave of the Version 2 Christmas Light Controller by Scott Shaver (ZParticle).
    *  It has been modified to accept the Renard protocol rather than generic serial. 
    *  Modifications by Kevin Graff during August 2017
    *************************************************************************************************  
    */
    /********************************************************
     * 
     * This is the code for Version 2 of the Christmas Lights 
     * Controller.
     *
     * This code is targetting - 32 channels with 256 dimming 
     * levels and a 50ms frame rate from Vixen.
     *
     * - Copyright Scott Shaver 2013
     * 
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     * 
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     * 
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     * 
     ********************************************************/
    
    #include <avr/power.h>
    
    #include <Arduino-Renard.h>  //kg add
    
    // comment this out if AC is 50Hz, uncomment if AC is 60Hz
    #define HERTZ60 true             
    
    #define CHANNEL_COUNT 32         // 32 channels to read from vixen
    #define CHANNEL_PIN_START 22     // 32 channels, assuming all are in order, start at what pin
    
    Renard renard; //kg add
    
    #define DIMMING_LEVELS 64  //kg changed from 256  // the number of levels of dimming we will get from Vixen 0-255
    
    // Ticks Per Half AC Cycle
    #ifdef HERTZ60
    #define TICK_HALF_CYCLE 133333
    #else
    #define TICK_HALF_CYCLE 160000
    #endif
    
    // This is the number of clock cycles the timer will cause an interrupt at.
    #define TIMER_CYCLE_COUNT (int)((float)(TICK_HALF_CYCLE)/(float)(DIMMING_LEVELS-1))
    
    #define ZCD_INT 0 // use interrupt 0 for zero cross detection
    #define ZCD_PIN 2 // interrupt 0 is on pin 2
    
    #define VIXEN_COM_SPEED 57600
    
    #define PC_COM_SPEED 57600
    
    //#define PC_COM_ON true // comment this out for "production" execution. ////////////////////
    
    // this just lets us know if we are switching from random mode to vixen mode
    boolean startingVixenMode = true;
    
    
    volatile unsigned int tickCounter = 0;             // track number of clock interrupts since last ZC detection, this needs to be pretty accurate, keep as volatile
    volatile byte channelValue[CHANNEL_COUNT];         // channel values 0-255 vixen values stored here - TODO: try this as non-volatile
    
    
    //byte channelPins[CHANNEL_COUNT];      // channel pins on the Arduino - changed this to #defines below so the macros produce the fastest code
    #define CHANNEL_PIN_1 CHANNEL_PIN_START
    #define CHANNEL_PIN_2 CHANNEL_PIN_START+1
    #define CHANNEL_PIN_3 CHANNEL_PIN_START+2
    #define CHANNEL_PIN_4 CHANNEL_PIN_START+3
    #define CHANNEL_PIN_5 CHANNEL_PIN_START+4
    #define CHANNEL_PIN_6 CHANNEL_PIN_START+5
    #define CHANNEL_PIN_7 CHANNEL_PIN_START+6
    #define CHANNEL_PIN_8 CHANNEL_PIN_START+7
    #define CHANNEL_PIN_9 CHANNEL_PIN_START+8
    #define CHANNEL_PIN_10 CHANNEL_PIN_START+9
    #define CHANNEL_PIN_11 CHANNEL_PIN_START+10
    #define CHANNEL_PIN_12 CHANNEL_PIN_START+11
    #define CHANNEL_PIN_13 CHANNEL_PIN_START+12
    #define CHANNEL_PIN_14 CHANNEL_PIN_START+13
    #define CHANNEL_PIN_15 CHANNEL_PIN_START+14
    #define CHANNEL_PIN_16 CHANNEL_PIN_START+15
    #define CHANNEL_PIN_17 CHANNEL_PIN_START+16
    #define CHANNEL_PIN_18 CHANNEL_PIN_START+17
    #define CHANNEL_PIN_19 CHANNEL_PIN_START+18
    #define CHANNEL_PIN_20 CHANNEL_PIN_START+19
    #define CHANNEL_PIN_21 CHANNEL_PIN_START+20
    #define CHANNEL_PIN_22 CHANNEL_PIN_START+21
    #define CHANNEL_PIN_23 CHANNEL_PIN_START+22
    #define CHANNEL_PIN_24 CHANNEL_PIN_START+23
    #define CHANNEL_PIN_25 CHANNEL_PIN_START+24 // or A0
    #define CHANNEL_PIN_26 CHANNEL_PIN_START+25 // or A1
    #define CHANNEL_PIN_27 CHANNEL_PIN_START+26 // or A2
    #define CHANNEL_PIN_28 CHANNEL_PIN_START+27 // or A3
    #define CHANNEL_PIN_29 CHANNEL_PIN_START+28 // or A4
    #define CHANNEL_PIN_30 CHANNEL_PIN_START+29 // or A5
    #define CHANNEL_PIN_31 CHANNEL_PIN_START+30 // or A6
    #define CHANNEL_PIN_32 CHANNEL_PIN_START+31 // or A7
    
    unsigned long time;  // used for timing during serial reads from Vixen
    int index = 0;
    int inByte = 0;     // used to read bytes in from Vixen
    
    /********************************************************
     * START OF FASTER DIGITAL WRITE LIBARY CODE
     *******************************************************/
    
    // Arduino Mega Pins
    #define digitalPinToPortReg(P) \
    (((P) >= 22 && (P) <= 29) ? &PORTA : \
    ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
    (((P) >= 30 && (P) <= 37) ? &PORTC : \
    ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
    ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
    (((P) >= 54 && (P) <= 61) ? &PORTF : \
    ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
    ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
    (((P) == 14 || (P) == 15) ? &PORTJ : \
    (((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))
    
    #define digitalPinToDDRReg(P) \
    (((P) >= 22 && (P) <= 29) ? &DDRA : \
    ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
    (((P) >= 30 && (P) <= 37) ? &DDRC : \
    ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
    ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
    (((P) >= 54 && (P) <= 61) ? &DDRF : \
    ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
    ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
    (((P) == 14 || (P) == 15) ? &DDRJ : \
    (((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))
    
    #define digitalPinToPINReg(P) \
    (((P) >= 22 && (P) <= 29) ? &PINA : \
    ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
    (((P) >= 30 && (P) <= 37) ? &PINC : \
    ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
    ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
    (((P) >= 54 && (P) <= 61) ? &PINF : \
    ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
    ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
    (((P) == 14 || (P) == 15) ? &PINJ : \
    (((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))
    
    #define __digitalPinToBit(P) \
    (((P) >=  7 && (P) <=  9) ? (P) - 3 : \
    (((P) >= 10 && (P) <= 13) ? (P) - 6 : \
    (((P) >= 22 && (P) <= 29) ? (P) - 22 : \
    (((P) >= 30 && (P) <= 37) ? 37 - (P) : \
    (((P) >= 39 && (P) <= 41) ? 41 - (P) : \
    (((P) >= 42 && (P) <= 49) ? 49 - (P) : \
    (((P) >= 50 && (P) <= 53) ? 53 - (P) : \
    (((P) >= 54 && (P) <= 61) ? (P) - 54 : \
    (((P) >= 62 && (P) <= 69) ? (P) - 62 : \
    (((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
    (((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
    (((P) == 19) ? 2 : \
    (((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
    (((P) == 2) ? 4 : \
    (((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))
    
    // 15 PWM
    #define __digitalPinToTimer(P) \
    (((P) == 13 || (P) ==  4) ? &TCCR0A : \
    (((P) == 11 || (P) == 12) ? &TCCR1A : \
    (((P) == 10 || (P) ==  9) ? &TCCR2A : \
    (((P) ==  5 || (P) ==  2 || (P) ==  3) ? &TCCR3A : \
    (((P) ==  6 || (P) ==  7 || (P) ==  8) ? &TCCR4A : \
    (((P) == 46 || (P) == 45 || (P) == 44) ? &TCCR5A : 0))))))
    
    #define __digitalPinToTimerBit(P) \
    (((P) == 13) ? COM0A1 : (((P) ==  4) ? COM0B1 : \
    (((P) == 11) ? COM1A1 : (((P) == 12) ? COM1B1 : \
    (((P) == 10) ? COM2A1 : (((P) ==  9) ? COM2B1 : \
    (((P) ==  5) ? COM3A1 : (((P) ==  2) ? COM3B1 : (((P) ==  3) ? COM3C1 : \
    (((P) ==  6) ? COM4A1 : (((P) ==  7) ? COM4B1 : (((P) ==  8) ? COM4C1 : \
    (((P) == 46) ? COM5A1 : (((P) == 45) ? COM5B1 : COM5C1))))))))))))))
    
    #define __atomicWrite__(A,P,V) \
    if ( (int)(A) < 0x40) { \
      bitWrite(*((volatile uint8_t*)A), __digitalPinToBit(P), (V) ); \
    } \
    else {   \
      uint8_t register saveSreg = SREG;   \
      cli();   \
      bitWrite(*((volatile uint8_t*)A), __digitalPinToBit(P), (V) );   \
      SREG=saveSreg;   \
    } 
    
    #define customDigitalWrite(P, V) \
    do {   \
      if (__builtin_constant_p(P) && __builtin_constant_p(V))   __atomicWrite__((uint8_t*) digitalPinToPortReg(P),P,V) \
    else  digitalWrite((P), (V));   \
    }while (0)
    
    #define customPinMode(P, V) \
    do { \
      if (__builtin_constant_p(P) && __builtin_constant_p(V)) __atomicWrite__((uint8_t*) digitalPinToDDRReg(P),P,V) \
      else pinMode((P), (V));   \
    } while (0)
    
    #define customDigitalRead(P) ( (int) _digitalReadFast2_((P)) )
    #define _digitalReadFast2_(P ) \
    (__builtin_constant_p(P) ) ? ( \
    ( bitRead(*digitalPinToPINReg(P), __digitalPinToBit(P))) ) : \
    digitalRead((P))
    
    /********************************************************
     * END OF FASTER DIGITAL WRITE LIBARY CODE
     ********************************************************/
    
    
    void setup()
    {
    
    renard.begin((uint8_t*)&channelValue, CHANNEL_COUNT, &Serial3, 57600); //KG add for renard
    
    #ifdef PC_COM_ON
      Serial.begin(PC_COM_SPEED);
    #endif
    
    
    
      for(int c=0;c<CHANNEL_COUNT;c++)
      {
        pinMode(CHANNEL_PIN_START + c, OUTPUT); // set the channel pin to output mode
        channelValue[c] = 0; // currently off  kg changed value from 255 to 0
      }
    
      turnAllLightsOff(); // set the channels to off
    
      powerOnSelfTest(); // do a quick test of the channels
    
      setupVixenMode();
    
    #ifdef PC_COM_ON
          Serial.println("end of setup");
    #endif
    }
    
    /*********************************************************/
    
    void loop()
    {   
    #ifdef PC_COM_ON
          Serial.println("void loop");
         
    #endif
    
        if(renard.receive()) //kg
        {
    #ifdef PC_COM_ON
          Serial.println("read");
         
    #endif
        }
      
    }
    
    /******************************************************/
    void setupVixenMode()
    {
    #ifdef PC_COM_ON
      Serial.println("Setting up Vixen mode.");
    #endif
      // make sure we can read from Vixen COM port
     //kg Serial1.begin(VIXEN_COM_SPEED);  done by renard library now
    
      /* Disable all of the unused peripherals. Some of these
       * peripherals may generate interrupts and slow us down.
       */
      power_adc_disable();     //Disable the Analog to Digital Converter module.
      power_spi_disable();     //Disable the Serial Peripheral Interface module.
    //  power_timer0_disable();  //Disable the Timer 0 module. This kills the delay() and millis() methods
      power_timer2_disable();  //Disable the Timer 2 module.
      power_timer3_disable();  //Disable the Timer 3 module.
      power_timer4_disable();  //Disable the Timer 4 module.
      power_timer5_disable();  //Disable the Timer 5 module.
      power_twi_disable();     //Disable the Two Wire Interface module.
      power_usart2_disable();  //Disable the USART 2 module.
    //kg  power_usart3_disable();  //Disable the USART 3 module.
    
      turnAllLightsOff();
      noInterrupts(); // turn the interrupts off while we are setting everything up
    
      // attach the ISR for getting zero cross signals
      attachInterrupt(ZCD_INT, ZeroCrossDetected, CHANGE);
    
      TCCR1A = 0;
    
      TCCR1B = _BV(WGM12) | _BV(CS10); 
    
      TCNT1 = 0; 
    
      OCR1A = TIMER_CYCLE_COUNT;
    
      // enable timer/counter 1 Output Compare A Match interrupt
      TIMSK1 = _BV(OCIE1A);
    
      interrupts(); // okay, turn the interrupts on, let's go
    }
    
    /*****************************************************/
    void powerOnSelfTest()
    {
    #ifdef PC_COM_ON
      Serial.println("Power on self test running.");
    #endif
    
    #ifdef PC_COM_ON
        Serial.print("Channel: ");
    #endif
    
      for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
         #ifdef PC_COM_ON
             Serial.print(channelIndex+1,DEC); // print channel number not pin number
             Serial.print(" "); // print channel number not pin number
         #endif
       digitalWrite(channelIndex+CHANNEL_PIN_START, HIGH); // turn on one channel at a time
       delay(250); // wait .25 seconds
       digitalWrite(channelIndex+CHANNEL_PIN_START, LOW); // turn it back off
      }
    
    #ifdef PC_COM_ON
        Serial.println("\nPOST Done.");
        delay(2000); 
    #endif
    
    #ifdef PC_COM_ON
          Serial.print("TIMER_CYCLE_COUNT = ");
          Serial.println(TIMER_CYCLE_COUNT);
          delay(5000); 
    #endif
    
      turnAllLightsOff();
    }
    
    /***************************************************/
    void turnAllLightsOff()
    {
      for(int c=0;c<CHANNEL_COUNT;c++)
      {
        digitalWrite(c+CHANNEL_PIN_START,LOW);
        channelValue[c] = 255; // currently off
      }
    
    #ifdef PC_COM_ON
          Serial.println("turn all lights off");
    #endif
    }
    
    /****************************************************/
    void ZeroCrossDetected()
    {
      
      // reset the tick counter to zero/256 at the start of the half AC cycle
      tickCounter = 255; //kg changed from 0   try 256 with -=4 and TIMER_CYCLE_COUNT 2088
    
      // turn channels off immediately after zero cross here
      customDigitalWrite(CHANNEL_PIN_1, LOW);
      customDigitalWrite(CHANNEL_PIN_2, LOW);
      customDigitalWrite(CHANNEL_PIN_3, LOW);
      customDigitalWrite(CHANNEL_PIN_4, LOW);
      customDigitalWrite(CHANNEL_PIN_5, LOW);
      customDigitalWrite(CHANNEL_PIN_6, LOW);
      customDigitalWrite(CHANNEL_PIN_7, LOW);
      customDigitalWrite(CHANNEL_PIN_8, LOW);
      customDigitalWrite(CHANNEL_PIN_9, LOW);
      customDigitalWrite(CHANNEL_PIN_10, LOW);
      customDigitalWrite(CHANNEL_PIN_11, LOW);
      customDigitalWrite(CHANNEL_PIN_12, LOW);
      customDigitalWrite(CHANNEL_PIN_13, LOW);
      customDigitalWrite(CHANNEL_PIN_14, LOW);
      customDigitalWrite(CHANNEL_PIN_15, LOW);
      customDigitalWrite(CHANNEL_PIN_16, LOW);
      customDigitalWrite(CHANNEL_PIN_17, LOW);
      customDigitalWrite(CHANNEL_PIN_18, LOW);
      customDigitalWrite(CHANNEL_PIN_19, LOW);
      customDigitalWrite(CHANNEL_PIN_20, LOW);
      customDigitalWrite(CHANNEL_PIN_21, LOW);
      customDigitalWrite(CHANNEL_PIN_22, LOW);
      customDigitalWrite(CHANNEL_PIN_23, LOW);
      customDigitalWrite(CHANNEL_PIN_24, LOW);
      customDigitalWrite(CHANNEL_PIN_25, LOW);
      customDigitalWrite(CHANNEL_PIN_26, LOW);
      customDigitalWrite(CHANNEL_PIN_27, LOW);
      customDigitalWrite(CHANNEL_PIN_28, LOW);
      customDigitalWrite(CHANNEL_PIN_29, LOW);
      customDigitalWrite(CHANNEL_PIN_30, LOW);
      customDigitalWrite(CHANNEL_PIN_31, LOW);
      customDigitalWrite(CHANNEL_PIN_32, LOW);
    }
    
    /****************************************************/
    ISR(TIMER1_COMPA_vect)
    {
      register uint16_t tick = tickCounter;
      
      // the higher the channel value the faster we want to turn the channel on.
      // if the channel value is 255 (full bright) and this is the first interrupt (tick=0) after 
      // the ZC we want the channel on now (kg - this has been reversed from original ZParticle sketch)
      
      if(channelValue[0] >= tick) customDigitalWrite(CHANNEL_PIN_1, HIGH); // turn the channel on here 
      if(channelValue[1] >= tick) customDigitalWrite(CHANNEL_PIN_2, HIGH); // turn the channel on here
      if(channelValue[2] >= tick) customDigitalWrite(CHANNEL_PIN_3, HIGH); // turn the channel on here
      if(channelValue[3] >= tick) customDigitalWrite(CHANNEL_PIN_4, HIGH); // turn the channel on here
      if(channelValue[4] >= tick) customDigitalWrite(CHANNEL_PIN_5, HIGH); // turn the channel on here
      if(channelValue[5] >= tick) customDigitalWrite(CHANNEL_PIN_6, HIGH); // turn the channel on here
      if(channelValue[6] >= tick) customDigitalWrite(CHANNEL_PIN_7, HIGH); // turn the channel on here
      if(channelValue[7] >= tick) customDigitalWrite(CHANNEL_PIN_8, HIGH); // turn the channel on here
      if(channelValue[8] >= tick) customDigitalWrite(CHANNEL_PIN_9, HIGH); // turn the channel on here
      if(channelValue[9] >= tick) customDigitalWrite(CHANNEL_PIN_10, HIGH); // turn the channel on here
      if(channelValue[10] >= tick) customDigitalWrite(CHANNEL_PIN_11, HIGH); // turn the channel on here
      if(channelValue[11] >= tick) customDigitalWrite(CHANNEL_PIN_12, HIGH); // turn the channel on here
      if(channelValue[12] >= tick) customDigitalWrite(CHANNEL_PIN_13, HIGH); // turn the channel on here
      if(channelValue[13] >= tick) customDigitalWrite(CHANNEL_PIN_14, HIGH); // turn the channel on here
      if(channelValue[14] >= tick) customDigitalWrite(CHANNEL_PIN_15, HIGH); // turn the channel on here
      if(channelValue[15] >= tick) customDigitalWrite(CHANNEL_PIN_16, HIGH); // turn the channel on here
      if(channelValue[16] >= tick) customDigitalWrite(CHANNEL_PIN_17, HIGH); // turn the channel on here
      if(channelValue[17] >= tick) customDigitalWrite(CHANNEL_PIN_18, HIGH); // turn the channel on here
      if(channelValue[18] >= tick) customDigitalWrite(CHANNEL_PIN_19, HIGH); // turn the channel on here
      if(channelValue[19] >= tick) customDigitalWrite(CHANNEL_PIN_20, HIGH); // turn the channel on here
      if(channelValue[20] >= tick) customDigitalWrite(CHANNEL_PIN_21, HIGH); // turn the channel on here
      if(channelValue[21] >= tick) customDigitalWrite(CHANNEL_PIN_22, HIGH); // turn the channel on here
      if(channelValue[22] >= tick) customDigitalWrite(CHANNEL_PIN_23, HIGH); // turn the channel on here
      if(channelValue[23] >= tick) customDigitalWrite(CHANNEL_PIN_24, HIGH); // turn the channel on here
      if(channelValue[24] >= tick) customDigitalWrite(CHANNEL_PIN_25, HIGH); // turn the channel on here
      if(channelValue[25] >= tick) customDigitalWrite(CHANNEL_PIN_26, HIGH); // turn the channel on here
      if(channelValue[26] >= tick) customDigitalWrite(CHANNEL_PIN_27, HIGH); // turn the channel on here
      if(channelValue[27] >= tick) customDigitalWrite(CHANNEL_PIN_28, HIGH); // turn the channel on here
      if(channelValue[28] >= tick) customDigitalWrite(CHANNEL_PIN_29, HIGH); // turn the channel on here
      if(channelValue[29] >= tick) customDigitalWrite(CHANNEL_PIN_30, HIGH); // turn the channel on here
      if(channelValue[30] >= tick) customDigitalWrite(CHANNEL_PIN_31, HIGH); // turn the channel on here
      if(channelValue[31] >= tick) customDigitalWrite(CHANNEL_PIN_32, HIGH); // turn the channel on here
    
      // decrease/increase tick counter by one/4
      tickCounter-=4;   //kg changed from ++ and change DIMMING_LEVELS to 64
    
     
    }
    Last edited by kev; 12-18-2019 at 03:06 AM.
    Kevin

  5. #5
    Join Date
    Mar 2012
    Location
    Lebanon, Illinois, USA
    Posts
    2,926
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Criminal? Well that is between you, your victim, and the authorities. As far as taking something and making it work in a "different than designed way"... that is what DIY is all about.
    Live, Laugh, Love.

  6. #6
    Join Date
    Aug 2017
    Posts
    6
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    I need some help! This is what I'm trying but its not working.


    Code:
    WORKING VERSION WITH RENARD PROTOCOL USING SERIAL3 (PINS 14 TO FTDI RX AND 15 TO FTDI TX)
    
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
     // KG add for renard. Include the Arduino Renard library by Bill Porter
     #include <Arduino-Renard.h>
     
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
     #define CHANNEL_COUNT 8
    
     Renard renard; //KG add for renard
    
     byte incomingByte[CHANNEL_COUNT];  //KG add for renard
     
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     #define VIXEN_COM_SPEED 57600
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE NOT_INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 2
     #define CH02 3
     #define CH03 4
     #define CH04 5
     #define CH05 6
     #define CH06 7
     #define CH07 8
     #define CH08 9
    // Up to here for Arduino uno.
    
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08};
    
     // KG subtract for renard - int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
    renard.begin((uint8_t*)&incomingByte, CHANNEL_COUNT, &Serial3, 57600); //KG add for renard
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      //sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop(){
      
       if (renard.receive()) {   //KG modified from VictorPV original
         wdt_reset(); // resets the watchdog
         timer_a = millis (); // new line
         int uno = Serial.read();
         //KG if (uno == 126){
           
         //KG  int dos = Serial.read();
         //KG  if (dos == 33){
       
         //KG    for (i=0; i < CHANNEL_COUNT; i++) {
         //KG        // read each byte
         //KG     incomingByte[i] = Serial.read();
         //KG    }
         if (MODE == NOT_INVERTED) {
          for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value <= 127) {
            digitalWrite(channels[i], LOW);
          }
          else {
            digitalWrite(channels[i], HIGH);
          }
          }
         }
         else {
         for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value < 127) {
            digitalWrite(channels[i], HIGH);
          }
          else {
            digitalWrite(channels[i], LOW);
          }
          }
         }
    
          //KG  }
         //KG }
       }
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
           timer_a = millis ();
           int random_a = 0;
           for (i=0; i < CHANNEL_COUNT; i++){
             random_a = random(0, 2);
             if (random_a == 0) {
               digitalWrite(channels[i], LOW);
             }
             else {
               digitalWrite(channels[i], HIGH);
             }
           }
         }
       }
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       //kg delay (500);
      //kg digitalWrite(channels[i], HIGH);
       }
     }
    }
    And I'm getting this error messege
    Arduino: 1.8.1 (Mac OS X), Board: "Arduino/Genuino Uno"

    In file included from /Users/Brandon/Documents/Arduino/Renard_ESPIXEL/Renard_ESPIXEL.ino:10:0:
    /Users/Brandon/Documents/Arduino/libraries/Arduino-Renard-master/Arduino-Renard.h:25:16: warning: extra tokens at end of #ifndef directive
    #ifndef Arduino-Renard_h
    ^
    /Users/Brandon/Documents/Arduino/libraries/Arduino-Renard-master/Arduino-Renard.h:26:16: warning: ISO C99 requires whitespace after the macro name
    #define Arduino-Renard_h
    ^
    Renard_ESPIXEL:1: error: 'WORKING' does not name a type
    WORKING VERSION WITH RENARD PROTOCOL USING SERIAL3 (PINS 14 TO FTDI RX AND 15 TO FTDI TX)
    ^
    /Users/Brandon/Documents/Arduino/Renard_ESPIXEL/Renard_ESPIXEL.ino: In function 'void setup()':
    Renard_ESPIXEL:53: error: 'Serial3' was not declared in this scope
    renard.begin((uint8_t*)&incomingByte, CHANNEL_COUNT, &Serial3, 57600); //KG add for renard
    ^
    Renard_ESPIXEL:56: error: 'wdt_enable' was not declared in this scope
    wdt_enable(WDTO_1S);
    ^
    exit status 1
    'WORKING' does not name a type

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    Any suggestions?

  7. #7
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    974
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Oops!! Sorry. Forgot to comment out "WORKING VERSION WITH RENARD PROTOCOL USING SERIAL3 (PINS 14 TO FTDI RX AND 15 TO FTDI TX)" at the top of the code. Add two slashes "//" in front of the first line.
    Kevin

  8. #8
    Join Date
    Aug 2017
    Posts
    6
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Doh! Just needed an extra set of eyes on it. Thanks, I'll try that out soon.

    Sent from my SM-J700T using Tapatalk

  9. #9
    Join Date
    Aug 2017
    Posts
    6
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Quote Originally Posted by kev View Post
    Oops!! Sorry. Forgot to comment out "WORKING VERSION WITH RENARD PROTOCOL USING SERIAL3 (PINS 14 TO FTDI RX AND 15 TO FTDI TX)" at the top of the code. Add two slashes "//" in front of the first line.
    Back to my computer, felt like an idiot missing that one. I'm new to coding and don't understand the debugging messages all that well, after looking back at it with a fresh brain I slapped myself. I just updated that with slashes and looked back over the code and couldn't find out why I was getting this though.

    It looks like you also have to change "Serial3" to "Serial" for the UNO
    Code:
    renard.begin((uint8_t*)&incomingByte, CHANNEL_COUNT, &Serial, 57600); //KG add for renard

  10. Likes kev liked this post
  11. #10
    Join Date
    Aug 2017
    Posts
    6
    Post Thanks / Like

    Default Re: Success Modifying VictorPV Sketch to Accept Renard Protocol from ESPixelstick

    Hooked it all up and it works! now to get the ESPixelstick and figure that out...
    Thanks again!

Page 1 of 6 123 ... 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
  •