Code help!!
 
Notifications
Clear all

Code help!!

53 Posts
3 Users
0 Reactions
16 K Views
Posts: 37
Topic starter
(@sherman-desouza)
Eminent Member
Joined: 13 years ago
[#46013]

So I have implemented ZParticle's idea for the 32 channel controller using an arduino Mega 2560.

I am a hardware guy so the software is just plain greek to me....

The hardware works as intended but i cant get version 2 of the code to work at all...

here are my issues and if anyone can help me I would be ever so grateful!

1. Using code 1, I can get a power on self test in proper sequence. random mode works and it even listens to vixen version 3. the moment i switch to vixen however I lose control of channel 1 which stays off the whole time. I cant then go back to random mode either using the switch across pins 6 and 7....I think the outputs are inverted too...

2. Using code 2... i can see in the serial monitor that it is getting the vixen header and footer but there is zero response to vixen.
the power on self test jumps from 1 to 9, 2 to 10, 3 to 11 and so on so forth... my connections to the arduino are not in line but even if I change the channel definitions to reflect the physical connections I cannot get the power on self test to change the order in which it runs. The random mode switch works as in the serial monitor shows random data being written but nothing goes out to the relays.
once the power on sequence is done all 4 relays are turned on and they stay on...

I have not been able to test the output of the ZCD... not a 100% sure if that is working properly and how to test it without access to a scope.

what I would like to have ideally:
1. full dimming across all 32 channels
2. Mechanical random switch across pins 6 and 7
3. software random switch that switches to random mode once it detects no data coming from vixen...

if anyone can please help me ....i have tried really hard to understand the code but i just dont have it in my to do the software side.
I have also attached a schematic drawing of my execution...

32 Channel Schematic

52 Replies
Posts: 1387
 kev
(@kev)
Noble Member
Joined: 12 years ago

1. Do you have the header and footer setup in Vixen? STRT for header, END for footer.
2. For Zero Cross test, I used the code listed below to show the ZC circuit is working. Read the comments at the top. For that code, you need to set the baud rate of your serial monitor to 115200.
3. Some screenshots of your generic serial controller setup would help.


/*  This sketch was designed to test for the existence of a pulse created by a zero crossing
circuit.  The zero crossing circuit is used to indicate when the voltage of a 60 hz A/C signal 
crosses the 0V line.  Depending on the load resistor, the H11AA1 IC data sheet indicates that the
ON switching time is between 1-5 micro-seconds and the OFF switching time is between 1-1000 microseconds.
The pulseIn function returns a value measured in micro-seconds, therefore, I look for the pulseIn 
duration to exceed 1 before incrementing the count.
I am using a 120VAC - 12VAC step down transformer to reduce the A/C voltage to a safe level on my 
breadboard.  Using 330 ohm resistors on pin 1 and 2 of the H11AA1 results in a pulse duration of 
approximately 360 microseconds, while using 470 ohm resistors results in a pulse duration of 
approximately 405 microseconds, using 2.2K ohm resistors result in a pulse duration of approximately 820 
microseconds, and using 10K ohm resistors results in a pulse width of approximately 2720 microseconds.  
Since the zero crossing pulse will be used to trigger an external interrupt with a rising edge, the
duration of the pulse is not too important as long as it is shorter than half of the A/C cycle, which
is 8300 microseconds (8.3 milli-seconds).  So I will choose to use 2.2K ohm resistors which result in a 
pulse width approximately 1/10 of the half cycle A/C period.

Designed by Kevin Graff, 1-16-2015.

*/

// setup constants
const int  zcPin = 2;    // the pin that the zero crossing circuit output is attached to
const int ledPin = 13;   // the pin that the LED is attached to
unsigned long zcDuration;  // for storing the pulse duration
// setup variables
int zcCounter = 0;       // counter for the number of zero cross pulses


void setup() {
  pinMode(zcPin, INPUT);  // initialize the zc pin as a input
  pinMode(ledPin, OUTPUT);  // initialize the ledPin as an output
  Serial.begin(115200);    // initialize serial communication
}


void loop() {
  // turns on the LED every 120 zc pulses and prints the information
 zcDuration = pulseIn(zcPin, HIGH);
 
 if (zcDuration > 1){
     zcCounter = zcCounter + 1;
     }
    
 if (zcCounter == 120) {
    digitalWrite(ledPin, HIGH);
    Serial.print("number of zero crossings:  ");
    Serial.println(zcCounter);
    }
    
   // turn off the LED after another 120 zc pulses and print the information
  if (zcCounter == 240){
      digitalWrite(ledPin, LOW);
      Serial.print("number of zero crossings:  ");
      Serial.println(zcCounter);
      zcCounter = 0;
      Serial.print("zc duration:  ");
      Serial.println(zcDuration);
      Serial.print("number of zero crossings:  ");
      Serial.println(zcCounter);
      }
 
  zcDuration = 0;

}


Reply
Posts: 37
Topic starter
(@sherman-desouza)
Eminent Member
Joined: 13 years ago
kev wrote:1. Do you have the header and footer setup in Vixen? STRT for header, END for footer.
2. For Zero Cross test, I used the code listed below to show the ZC circuit is working. Read the comments at the top. For that code, you need to set the baud rate of your serial monitor to 115200.
3. Some screenshots of your generic serial controller setup would help.


/*  This sketch was designed to test for the existence of a pulse created by a zero crossing
circuit.  The zero crossing circuit is used to indicate when the voltage of a 60 hz A/C signal 
crosses the 0V line.  Depending on the load resistor, the H11AA1 IC data sheet indicates that the
ON switching time is between 1-5 micro-seconds and the OFF switching time is between 1-1000 microseconds.
The pulseIn function returns a value measured in micro-seconds, therefore, I look for the pulseIn 
duration to exceed 1 before incrementing the count.
I am using a 120VAC - 12VAC step down transformer to reduce the A/C voltage to a safe level on my 
breadboard.  Using 330 ohm resistors on pin 1 and 2 of the H11AA1 results in a pulse duration of 
approximately 360 microseconds, while using 470 ohm resistors results in a pulse duration of 
approximately 405 microseconds, using 2.2K ohm resistors result in a pulse duration of approximately 820 
microseconds, and using 10K ohm resistors results in a pulse width of approximately 2720 microseconds.  
Since the zero crossing pulse will be used to trigger an external interrupt with a rising edge, the
duration of the pulse is not too important as long as it is shorter than half of the A/C cycle, which
is 8300 microseconds (8.3 milli-seconds).  So I will choose to use 2.2K ohm resistors which result in a 
pulse width approximately 1/10 of the half cycle A/C period.

Designed by Kevin Graff, 1-16-2015.

*/

// setup constants
const int  zcPin = 2;    // the pin that the zero crossing circuit output is attached to
const int ledPin = 13;   // the pin that the LED is attached to
unsigned long zcDuration;  // for storing the pulse duration
// setup variables
int zcCounter = 0;       // counter for the number of zero cross pulses


void setup() {
  pinMode(zcPin, INPUT);  // initialize the zc pin as a input
  pinMode(ledPin, OUTPUT);  // initialize the ledPin as an output
  Serial.begin(115200);    // initialize serial communication
}


void loop() {
  // turns on the LED every 120 zc pulses and prints the information
 zcDuration = pulseIn(zcPin, HIGH);
 
 if (zcDuration > 1){
     zcCounter = zcCounter + 1;
     }
    
 if (zcCounter == 120) {
    digitalWrite(ledPin, HIGH);
    Serial.print("number of zero crossings:  ");
    Serial.println(zcCounter);
    }
    
   // turn off the LED after another 120 zc pulses and print the information
  if (zcCounter == 240){
      digitalWrite(ledPin, LOW);
      Serial.print("number of zero crossings:  ");
      Serial.println(zcCounter);
      zcCounter = 0;
      Serial.print("zc duration:  ");
      Serial.println(zcDuration);
      Serial.print("number of zero crossings:  ");
      Serial.println(zcCounter);
      }
 
  zcDuration = 0;

}

Hi Kevin,
thanks for the info.
I have been using VIXEN_START and VIXEN_END as the header and footer... it seems to be working in some versions of the code but not working right....
I tried your ZCD code and its not giving me anything. I also had another friend check this code and he thinks maybe my ZCD isnt working right. so tomorrow i will check that out again.
what is the generic serial controller setup? is that the setup in vixen?


Reply
Posts: 1387
 kev
(@kev)
Noble Member
Joined: 12 years ago
sherman_desouza wrote:Hi Kevin,
thanks for the info.
I have been using VIXEN_START and VIXEN_END as the header and footer... it seems to be working in some versions of the code but not working right....
I tried your ZCD code and its not giving me anything. I also had another friend check this code and he thinks maybe my ZCD isnt working right. so tomorrow i will check that out again.
what is the generic serial controller setup? is that the setup in vixen?

- ZParticle changed the header/footer text for version 2. It is now STRT and END respectively.

- Version 2 requires a working Zero Cross circuit for the Vixen part to work. The self test will run regadless of the Zero Cross circuit.

- Yes, the Generic Serial setup is the controller setup in Vixen. It is where you enter the communication parameters such as baud rate, header/footer, port etc.....

How are you connecting from your MEGA to the other boards? Are you simply plugging in the little jumper wires or do you have some type of shield? If the jumper wires, make sure they have good contact.

A couple of pictures of your setup might help.


Reply
Posts: 37
Topic starter
(@sherman-desouza)
Eminent Member
Joined: 13 years ago
kev wrote:- ZParticle changed the header/footer text for version 2. It is now STRT and END respectively.

- Version 2 requires a working Zero Cross circuit for the Vixen part to work. The self test will run regadless of the Zero Cross circuit.

- Yes, the Generic Serial setup is the controller setup in Vixen. It is where you enter the communication parameters such as baud rate, header/footer, port etc.....

How are you connecting from your MEGA to the other boards? Are you simply plugging in the little jumper wires or do you have some type of shield? If the jumper wires, make sure they have good contact.

A couple of pictures of your setup might help.

Hi Kevin,
yeah i have changed the header and footer to STRT and END.
i get a power on self test that jumps from channel 1 to 9 then 2 to 10, 3 to 11 so on so forth... and this doesnt change no matter what i change these lines to:
#define CHANNEL_PIN_1 CHANNEL_PIN_START
#define CHANNEL_PIN_2 CHANNEL_PIN_START+1...

i also know all my hardware works because i can get them to go on or off without dimming using other code....

I cant seem to get the ZCD working though... i am positive the circuit is correctly wired and i have gone through 3 H11AA1 chips so far but I cant get any output. i can trigger the interrupt if i touch pin 2 to ground using that testing code you gave me...
need to figure out why the ZCD circuit isnt working...

i have attached a few pics of my hardware... i am indeed using a shield to breakout all the pins...and there is continuity on all of them... i can get the hardware working with version 1 code...

am i limited to using vixen 2.1.1 for this code? cause i can see it respond better with vixen 3...

20170901 151513
20170904 131008

Reply
Posts: 37
Topic starter
(@sherman-desouza)
Eminent Member
Joined: 13 years ago

and some pics from vixen setup

Vixen 3 2
Vixen 3   1
Vixen 2 1
Vixen 2 2
Vixen 2   3

Reply
Posts: 1387
 kev
(@kev)
Noble Member
Joined: 12 years ago

First off - VERY CLEAN BUILD!!

I have been using Vixen 3.3 u2 build 305 and it works well. I have never used 2.1.
Looking at the photo of your hardware setup, I don't see the usb/TTL converter that should be connected to Serial1 pins. Is it hidden? If you don't have the converter, you can use the standard USB connection on the MEGA by changing a few lines of the code.
Everything about the Zero Cross looks correct as far as I can tell. Is the power supply 5VDC??


Reply
Posts: 37
Topic starter
(@sherman-desouza)
Eminent Member
Joined: 13 years ago
kev wrote:First off - VERY CLEAN BUILD!!

I have been using Vixen 3.3 u2 build 305 and it works well. I have never used 2.1.
Looking at the photo of your hardware setup, I don't see the usb/TTL converter that should be connected to Serial1 pins. Is it hidden? If you don't have the converter, you can use the standard USB connection on the MEGA by changing a few lines of the code.
Everything about the Zero Cross looks correct as far as I can tell. Is the power supply 5VDC??

Hi Kevin,
Thank you for the kind words 🙂

that picture was taken a bit before I finished the project. the FT232RL is installed now and working as expected....

so I checked code 2 with vixen 3 and it works! still no luck with the ZCD but I can see it working if iI touch pin 2 with my finger and create a false interrupt....

The only issues i am still having are these...
1. With no vixen data all lights are on instead of off... was that how the code was written?
2. My power on self test is not working as intended... I know the code assumes the output pins are wired in order but mine are not...currently because of the way I have physically wired my outputs channel 2 is outputting on 9, 3 is 2, 4 is 10, 5 is 3 and so on so forth...
3. Is there any code that I can add such that it goes to random mode when it doesn't detect any code from vixen for say 20 seconds...i like having the mechanical switch to go between random and vixen but it would be great if i could also have it go to random if vixen stops sending data

here are my output pins...and my #define Channel_PIN_
Output 1: Pin 22
Output 2: Pin 24
Output 3: Pin 26
Output 4: Pin 28
Output 5: Pin 30
Output 6: Pin 32
Output 7: Pin 34
Output 8: Pin 36
Output 9: Pin 23
Output 10: Pin 25
Output 11: Pin 27
Output 12: Pin 29
Output 13: Pin 31
Output 14: Pin 33
Output 15: Pin 35
Output 16: Pin 37
Output 17: Pin 38
Output 18: Pin 40
Output 19: Pin 42
Output 20: Pin 44
Output 21: Pin 46
Output 21: Pin 48
Output 23: Pin 50
Output 24: Pin 52
Output 25: Pin 39
Output 26: Pin 41
Output 27: Pin 43
Output 28: Pin 45
Output 29: Pin 47
Output 30: Pin 49
Output 31: Pin 51
Output 32: Pin 53

This is how I have defined my channels…but it doesn’t seem to want to change the way it outputs no matter what I define here…is there something else i need to change?

#define CHANNEL_PIN_1 CHANNEL_PIN_START
#define CHANNEL_PIN_2 CHANNEL_PIN_START+2
#define CHANNEL_PIN_3 CHANNEL_PIN_START+4
#define CHANNEL_PIN_4 CHANNEL_PIN_START+6
#define CHANNEL_PIN_5 CHANNEL_PIN_START+8
#define CHANNEL_PIN_6 CHANNEL_PIN_START+10
#define CHANNEL_PIN_7 CHANNEL_PIN_START+12
#define CHANNEL_PIN_8 CHANNEL_PIN_START+14
#define CHANNEL_PIN_9 CHANNEL_PIN_START+1
#define CHANNEL_PIN_10 CHANNEL_PIN_START+3
#define CHANNEL_PIN_11 CHANNEL_PIN_START+5
#define CHANNEL_PIN_12 CHANNEL_PIN_START+7
#define CHANNEL_PIN_13 CHANNEL_PIN_START+9
#define CHANNEL_PIN_14 CHANNEL_PIN_START+11
#define CHANNEL_PIN_15 CHANNEL_PIN_START+13
#define CHANNEL_PIN_16 CHANNEL_PIN_START+15
#define CHANNEL_PIN_17 CHANNEL_PIN_START+16
#define CHANNEL_PIN_18 CHANNEL_PIN_START+18
#define CHANNEL_PIN_19 CHANNEL_PIN_START+20
#define CHANNEL_PIN_20 CHANNEL_PIN_START+22
#define CHANNEL_PIN_21 CHANNEL_PIN_START+24
#define CHANNEL_PIN_22 CHANNEL_PIN_START+26
#define CHANNEL_PIN_23 CHANNEL_PIN_START+28
#define CHANNEL_PIN_24 CHANNEL_PIN_START+30
#define CHANNEL_PIN_25 CHANNEL_PIN_START+17
#define CHANNEL_PIN_26 CHANNEL_PIN_START+19
#define CHANNEL_PIN_27 CHANNEL_PIN_START+21
#define CHANNEL_PIN_28 CHANNEL_PIN_START+23
#define CHANNEL_PIN_29 CHANNEL_PIN_START+25
#define CHANNEL_PIN_30 CHANNEL_PIN_START+27
#define CHANNEL_PIN_31 CHANNEL_PIN_START+29
#define CHANNEL_PIN_32 CHANNEL_PIN_START+31


Reply
Posts: 2541
(@lightup)
Famed Member
Joined: 17 years ago

It's been awhile since I looked at this stuff, but it all works as designed by zparticle. So I wouldn't expect any code issues, or Vixen issues.
But, Vixen 3 always sends serial data even when your sequence is done.

You must get the zcd working or the channel outputs are "scrambled" due to a lack synchronization with the 60HZ line frequency. kev wrote a test sketch so you can troubleshoot your board. Once that is working you can reload zparticle's sketch V2.


Reply
Posts: 1387
 kev
(@kev)
Noble Member
Joined: 12 years ago

First of all, I am not a programmer, but I did sleep in a Holiday Inn last night! I know enough to be dangerous!

When you say "so I checked code 2 with vixen 3 and it works!" what exactly does "it works" mean?

As far as adding code to cause random in between songs or when Vixen is off, I don't know how to incorporateit into this existing sketch. As LightUp said, Vixen 3 always sends data whether playing a song or not. It is sendimg all 0's. If you are wantimg random lights in between songs, you could devise a sequence that appears random and just add it to the playlist wherever you wanted random lights.

If the outputs are ON when they should be OFF, you could comment out the following line of code. That line is towards the bottom of the sketch.
// channelValue[index++]= map(inByte,0,255,255,0); // save the channel value, reverse it 0-255 becomes 255-0

To define your channels so that it is more easy to read/understand, you could do something like the following (if I got your numbers correct).


#define CHANNEL_PIN_1 22
#define CHANNEL_PIN_2 24
#define CHANNEL_PIN_3 26
#define CHANNEL_PIN_4 28
#define CHANNEL_PIN_5 30
#define CHANNEL_PIN_6 32
#define CHANNEL_PIN_7 34
#define CHANNEL_PIN_8 36

#define CHANNEL_PIN_9 23
#define CHANNEL_PIN_10 25
#define CHANNEL_PIN_11 27
#define CHANNEL_PIN_12 29
#define CHANNEL_PIN_13 31
#define CHANNEL_PIN_14 33
#define CHANNEL_PIN_15 35
#define CHANNEL_PIN_16 37

#define CHANNEL_PIN_17 38
#define CHANNEL_PIN_18 40
#define CHANNEL_PIN_19 42
#define CHANNEL_PIN_20 44
#define CHANNEL_PIN_21 46
#define CHANNEL_PIN_22 48
#define CHANNEL_PIN_23 50
#define CHANNEL_PIN_24 52

#define CHANNEL_PIN_25 39
#define CHANNEL_PIN_26 41
#define CHANNEL_PIN_27 43
#define CHANNEL_PIN_28 45
#define CHANNEL_PIN_29 47
#define CHANNEL_PIN_30 49
#define CHANNEL_PIN_31 51
#define CHANNEL_PIN_32 53


Reply
Page 1 / 6
Share: