Hi everyone,
A few years ago, I upgraded my show from 12 channels to 60 using Vixen 2, an arduino uno, and the centipede shield ( http://macetech.com/store/index.php?main_page=product_info&products_id=23 ). Even with the header and footer, it still sometimes gets off sync and I have to stop and restart the shows which corrects the problem. I wanted to add 12 more channels this year. In order to do this, I am hoping to use the digital I/O on the arduino, in addition to the ones I use on the shield already. I have combined different codes to produce mine that currently works for the 60 channels:
int CHANNEL0 = 0;
int CHANNEL01 = 1;
int CHANNEL02 = 2;
int CHANNEL03 = 3;
int CHANNEL04 = 4;
int CHANNEL05 = 5;
int CHANNEL06 = 6;
int CHANNEL07 = 7;
int CHANNEL08 = 8;
int CHANNEL09 = 9;
int CHANNEL10 = 10;
int CHANNEL11 = 11;
int CHANNEL12 = 12;
int CHANNEL13 = 13;
int CHANNEL14 = 14;
int CHANNEL15 = 15;
int CHANNEL16 = 16;
int CHANNEL17 = 17;
int CHANNEL18 = 18;
int CHANNEL19 = 19;
int CHANNEL20 = 20;
int CHANNEL21 = 21;
int CHANNEL22 = 22;
int CHANNEL23 = 23;
int CHANNEL24 = 24;
int CHANNEL25 = 25;
int CHANNEL26 = 26;
int CHANNEL27 = 27;
int CHANNEL28 = 28;
int CHANNEL29 = 29;
int CHANNEL30 = 30;
int CHANNEL31 = 31;
int CHANNEL32 = 32;
int CHANNEL33 = 33;
int CHANNEL34 = 34;
int CHANNEL35 = 35;
int CHANNEL36 = 36;
int CHANNEL37 = 37;
int CHANNEL38 = 38;
int CHANNEL39 = 39;
int CHANNEL40 = 40;
int CHANNEL41 = 41;
int CHANNEL42 = 42;
int CHANNEL43 = 43;
int CHANNEL44 = 44;
int CHANNEL45 = 45;
int CHANNEL46 = 46;
int CHANNEL47 = 47;
int CHANNEL48 = 48;
int CHANNEL49 = 49;
int CHANNEL50 = 50;
int CHANNEL51 = 51;
int CHANNEL52 = 52;
int CHANNEL53 = 53;
int CHANNEL54 = 54;
int CHANNEL55 = 55;
int CHANNEL56 = 56;
int CHANNEL57 = 57;
int CHANNEL58 = 58;
int CHANNEL59 = 59;
int channels[] = {CHANNEL0,CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,
CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16,CHANNEL17,CHANNEL18,CHANNEL19,CHANNEL20
,CHANNEL21,CHANNEL22,CHANNEL23,CHANNEL24,CHANNEL25,CHANNEL26,CHANNEL27,CHANNEL28,CHANNEL29,CHANNEL30,
CHANNEL31,CHANNEL32,CHANNEL33,CHANNEL34,CHANNEL35,CHANNEL36,CHANNEL37,CHANNEL38,CHANNEL39,
CHANNEL40,CHANNEL41,CHANNEL42,CHANNEL43,CHANNEL44,CHANNEL45,CHANNEL46,CHANNEL47,CHANNEL48,CHANNEL49,CHANNEL50,
CHANNEL51,CHANNEL52,CHANNEL53,CHANNEL54,CHANNEL55,CHANNEL56,CHANNEL57,CHANNEL58,CHANNEL59};
#include <Wire.h>
#include <Centipede.h>;
Centipede CS;
// how many channel will vixen be sending
int CHANNEL_COUNT = 60;
// speed for the com port for talking with vixen
int VIXEN_COM_SPEED = 9600;
void setup()
{
Wire.begin();
CS.initialize();
Serial.begin(VIXEN_COM_SPEED);
// set the channel pins to output mode
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
CS.pinMode(channels[channelIndex],OUTPUT);
}
// turnLightsOff();
// powerOnSelfTest();
}
// !!!! note the PWM values that need to be sent to the relay board are reversed from the
// values comming in from Vixen. Vixen 0-255 (off-on), Relays 255-0 (off-on)
void loop()
{
readFromVixen();
}
void powerOnSelfTest()
{
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
analogWrite(channels[channelIndex], LOW); // turn on one channel at a time
delay(500); // wait .5 seconds
analogWrite(channels[channelIndex], HIGH);
}
turnLightsOff();
}
void turnLightsOff()
{
//turn them all off
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++)
analogWrite(channels[channelIndex], HIGH);
}
void outputToLights(unsigned char* buffer)
{
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++)
CS.digitalWrite(channels[channelIndex], buffer[channelIndex]);
}
void readFromVixen()
{
char *footer="VIXEN_END";
unsigned char buffer[CHANNEL_COUNT];
char buffer2[CHANNEL_COUNT];
int index=0;
unsigned long time = millis();
waitForVixenHeader();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
time = millis();
int lightByte = map(inByte, 0, 255, 255, 0);
buffer[index] = lightByte;
buffer2[index] = inByte;
buffer[index+1] = 0;
buffer2[index+1] = 0;
index++;
if(index==9 && strcmp(footer,buffer2)==0){
return;
}
else if(index==CHANNEL_COUNT){
outputToLights(buffer);
index=0;
}
}
Serial.println("");
}
void waitForVixenHeader()
{
char *header="VIXEN_START";
char buffer[12];
int index = 0;
unsigned long time = millis();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
time = millis();
buffer[index] = inByte;
if(buffer[index]!=header[index]) {// not the right sequence restart
index=-1;
}
buffer[index+1] = 0; // add null
index++;
if(index==11 && strcmp(header,buffer)==0){
return;
}
}
}
My problem is that when I try to adapt the code to also include the arduino I/O pins, there is no more synchronization at all. In Vixen, I added the new channels to the profile, and the baud rates are the same and such. I was thinking (and hoping) that the code would be able to quickly adapt since it didn't seem that hard to do, but I am struggling. Here is my idea for the new code, the main changes are in defining new channels, setting them as output, and then spitting out the bytes:
int CHANNEL0 = 0;
int CHANNEL01 = 1;
int CHANNEL02 = 2;
int CHANNEL03 = 3;
int CHANNEL04 = 4;
int CHANNEL05 = 5;
int CHANNEL06 = 6;
int CHANNEL07 = 7;
int CHANNEL08 = 8;
int CHANNEL09 = 9;
int CHANNEL10 = 10;
int CHANNEL11 = 11;
int CHANNEL12 = 12;
int CHANNEL13 = 13;
int CHANNEL14 = 14;
int CHANNEL15 = 15;
int CHANNEL16 = 16;
int CHANNEL17 = 17;
int CHANNEL18 = 18;
int CHANNEL19 = 19;
int CHANNEL20 = 20;
int CHANNEL21 = 21;
int CHANNEL22 = 22;
int CHANNEL23 = 23;
int CHANNEL24 = 24;
int CHANNEL25 = 25;
int CHANNEL26 = 26;
int CHANNEL27 = 27;
int CHANNEL28 = 28;
int CHANNEL29 = 29;
int CHANNEL30 = 30;
int CHANNEL31 = 31;
int CHANNEL32 = 32;
int CHANNEL33 = 33;
int CHANNEL34 = 34;
int CHANNEL35 = 35;
int CHANNEL36 = 36;
int CHANNEL37 = 37;
int CHANNEL38 = 38;
int CHANNEL39 = 39;
int CHANNEL40 = 40;
int CHANNEL41 = 41;
int CHANNEL42 = 42;
int CHANNEL43 = 43;
int CHANNEL44 = 44;
int CHANNEL45 = 45;
int CHANNEL46 = 46;
int CHANNEL47 = 47;
int CHANNEL48 = 48;
int CHANNEL49 = 49;
int CHANNEL50 = 50;
int CHANNEL51 = 51;
int CHANNEL52 = 52;
int CHANNEL53 = 53;
int CHANNEL54 = 54;
int CHANNEL55 = 55;
int CHANNEL56 = 56;
int CHANNEL57 = 57;
int CHANNEL58 = 58;
int CHANNEL59 = 59;
int CHANNEL60 = 2;
int CHANNEL61 = 3;
int CHANNEL62 = 4;
int CHANNEL63 = 5;
int CHANNEL64 = 6;
int CHANNEL65 = 7;
int CHANNEL66 = 8;
int CHANNEL67 = 9;
int CHANNEL68 = 10;
int CHANNEL69 = 11;
int CHANNEL70 = 12;
int CHANNEL71 = 13;
int channels[] = {CHANNEL0,CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,
CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16,CHANNEL17,CHANNEL18,CHANNEL19,CHANNEL20
,CHANNEL21,CHANNEL22,CHANNEL23,CHANNEL24,CHANNEL25,CHANNEL26,CHANNEL27,CHANNEL28,CHANNEL29,CHANNEL30,
CHANNEL31,CHANNEL32,CHANNEL33,CHANNEL34,CHANNEL35,CHANNEL36,CHANNEL37,CHANNEL38,CHANNEL39,
CHANNEL40,CHANNEL41,CHANNEL42,CHANNEL43,CHANNEL44,CHANNEL45,CHANNEL46,CHANNEL47,CHANNEL48,CHANNEL49,CHANNEL50,
CHANNEL51,CHANNEL52,CHANNEL53,CHANNEL54,CHANNEL55,CHANNEL56,CHANNEL57,CHANNEL58,CHANNEL59,CHANNEL60,CHANNEL61,
CHANNEL62,CHANNEL63,CHANNEL64,CHANNEL65,CHANNEL66,CHANNEL67,CHANNEL68,CHANNEL69,CHANNEL70,CHANNEL71};
#include <Wire.h>
#include <Centipede.h>;
Centipede CS;
// how many channel will vixen be sending
int CHANNEL_COUNT = 72;
int extraChannel = 60;
// speed for the com port for talking with vixen
int VIXEN_COM_SPEED = 9600;
void setup()
{
Wire.begin();
CS.initialize();
Serial.begin(VIXEN_COM_SPEED);
// set the channel pins to output mode
for(int channelIndex=0;channelIndex<extraChannel;channelIndex++){
CS.pinMode(channels[channelIndex],OUTPUT);
}
for(int channelIndex=extraChannel;channelIndex<CHANNEL_COUNT;channelIndex++){
pinMode(channels[channelIndex],OUTPUT);
}
// turnLightsOff();
// powerOnSelfTest();
}
// !!!! note the PWM values that need to be sent to the relay board are reversed from the
// values comming in from Vixen. Vixen 0-255 (off-on), Relays 255-0 (off-on)
void loop()
{
readFromVixen();
}
void powerOnSelfTest()
{
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
analogWrite(channels[channelIndex], LOW); // turn on one channel at a time
delay(500); // wait .5 seconds
analogWrite(channels[channelIndex], HIGH);
}
turnLightsOff();
}
void turnLightsOff()
{
//turn them all off
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++)
analogWrite(channels[channelIndex], HIGH);
}
void outputToLights(unsigned char* buffer)
{
for(int channelIndex=0;channelIndex<extraChannel;channelIndex++)
CS.digitalWrite(channels[channelIndex], buffer[channelIndex]);
for(int channelIndex=extraChannel;channelIndex<CHANNEL_COUNT;channelIndex++)
digitalWrite(channels[channelIndex], buffer[channelIndex]);
}
void readFromVixen()
{
char *footer="VIXEN_END";
unsigned char buffer[CHANNEL_COUNT];
char buffer2[CHANNEL_COUNT];
int index=0;
unsigned long time = millis();
waitForVixenHeader();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
//try adding loop incomingByte here???
time = millis();
int lightByte = map(inByte, 0, 255, 255, 0);
buffer[index] = lightByte;
buffer2[index] = inByte;
buffer[index+1] = 0;
buffer2[index+1] = 0;
index++;
if(index==9 && strcmp(footer,buffer2)==0){
return;
}
else if(index==CHANNEL_COUNT){
outputToLights(buffer);
index=0;
}
}
Serial.println("");
}
void waitForVixenHeader()
{
char *header="VIXEN_START";
char buffer[12];
int index = 0;
unsigned long time = millis();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
time = millis();
buffer[index] = inByte;
if(buffer[index]!=header[index]) {// not the right sequence restart
index=-1;
}
buffer[index+1] = 0; // add null
index++;
if(index==11 && strcmp(header,buffer)==0){
return;
}
}
}
If anyone can help me with either the adding of the new channels, or helping with the occasional time that the show gets off of sync, I would appreciate it!
Thanks,
Matt
I am not much of a programmer, but I think your baud rate could be a bottle neck. Try setting baud rate to 57600 and see if that helps.
I tried setting the baud rate to 57600, and nothing worked. When I brought it down to 19200, the synchronization still was off (it may have been slightly better however). any ideas as to why I can't increase the baud rate and have it work higher than 19200?
Hi, can you edit the second code (that you've changed) please and put some comments after the lines you've changed or added please.
//* changed *
or
// * added *
What FPS are you sequencing at in Vixen?
What happens if you do a simple chase - CH1 on for one frame, CH2 on for one frame etc? Does it miss every even numbered channel?
Updated code with commented additions:
int CHANNEL0 = 0;
int CHANNEL01 = 1;
int CHANNEL02 = 2;
int CHANNEL03 = 3;
int CHANNEL04 = 4;
int CHANNEL05 = 5;
int CHANNEL06 = 6;
int CHANNEL07 = 7;
int CHANNEL08 = 8;
int CHANNEL09 = 9;
int CHANNEL10 = 10;
int CHANNEL11 = 11;
int CHANNEL12 = 12;
int CHANNEL13 = 13;
int CHANNEL14 = 14;
int CHANNEL15 = 15;
int CHANNEL16 = 16;
int CHANNEL17 = 17;
int CHANNEL18 = 18;
int CHANNEL19 = 19;
int CHANNEL20 = 20;
int CHANNEL21 = 21;
int CHANNEL22 = 22;
int CHANNEL23 = 23;
int CHANNEL24 = 24;
int CHANNEL25 = 25;
int CHANNEL26 = 26;
int CHANNEL27 = 27;
int CHANNEL28 = 28;
int CHANNEL29 = 29;
int CHANNEL30 = 30;
int CHANNEL31 = 31;
int CHANNEL32 = 32;
int CHANNEL33 = 33;
int CHANNEL34 = 34;
int CHANNEL35 = 35;
int CHANNEL36 = 36;
int CHANNEL37 = 37;
int CHANNEL38 = 38;
int CHANNEL39 = 39;
int CHANNEL40 = 40;
int CHANNEL41 = 41;
int CHANNEL42 = 42;
int CHANNEL43 = 43;
int CHANNEL44 = 44;
int CHANNEL45 = 45;
int CHANNEL46 = 46;
int CHANNEL47 = 47;
int CHANNEL48 = 48;
int CHANNEL49 = 49;
int CHANNEL50 = 50;
int CHANNEL51 = 51;
int CHANNEL52 = 52;
int CHANNEL53 = 53;
int CHANNEL54 = 54;
int CHANNEL55 = 55;
int CHANNEL56 = 56;
int CHANNEL57 = 57;
int CHANNEL58 = 58;
int CHANNEL59 = 59;
///////******ADDED CHANNEL ADDITIONS***/////////////////
int CHANNEL60 = 2;
int CHANNEL61 = 3;
int CHANNEL62 = 4;
int CHANNEL63 = 5;
int CHANNEL64 = 6;
int CHANNEL65 = 7;
int CHANNEL66 = 8;
int CHANNEL67 = 9;
int CHANNEL68 = 10;
int CHANNEL69 = 11;
int CHANNEL70 = 12;
int CHANNEL71 = 13;
int channels[] = {CHANNEL0,CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,
CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16,CHANNEL17,CHANNEL18,CHANNEL19,CHANNEL20
,CHANNEL21,CHANNEL22,CHANNEL23,CHANNEL24,CHANNEL25,CHANNEL26,CHANNEL27,CHANNEL28,CHANNEL29,CHANNEL30,
CHANNEL31,CHANNEL32,CHANNEL33,CHANNEL34,CHANNEL35,CHANNEL36,CHANNEL37,CHANNEL38,CHANNEL39,
CHANNEL40,CHANNEL41,CHANNEL42,CHANNEL43,CHANNEL44,CHANNEL45,CHANNEL46,CHANNEL47,CHANNEL48,CHANNEL49,CHANNEL50,
CHANNEL51,CHANNEL52,CHANNEL53,CHANNEL54,CHANNEL55,CHANNEL56,CHANNEL57,CHANNEL58,CHANNEL59,CHANNEL60,CHANNEL61,
CHANNEL62,CHANNEL63,CHANNEL64,CHANNEL65,CHANNEL66,CHANNEL67,CHANNEL68,CHANNEL69,CHANNEL70,CHANNEL71};
///*ADDED NEW CHANNELS TO THE ARRAY///
#include <Wire.h>
#include <Centipede.h>;
Centipede CS;
// how many channel will vixen be sending
int CHANNEL_COUNT = 72;
int extraChannel = 60;
// speed for the com port for talking with vixen
int VIXEN_COM_SPEED = 9600;
void setup()
{
Wire.begin();
CS.initialize();
Serial.begin(VIXEN_COM_SPEED);
// set the channel pins to output mode
for(int channelIndex=0;channelIndex<extraChannel;channelIndex++){
CS.pinMode(channels[channelIndex],OUTPUT);
}
///SET NEW CHANNELS TO OUTPUT***///
for(int channelIndex=extraChannel;channelIndex<CHANNEL_COUNT;channelIndex++){
pinMode(channels[channelIndex],OUTPUT);
}
// turnLightsOff();
// powerOnSelfTest();
}
// !!!! note the PWM values that need to be sent to the relay board are reversed from the
// values comming in from Vixen. Vixen 0-255 (off-on), Relays 255-0 (off-on)
void loop()
{
readFromVixen();
}
void powerOnSelfTest()
{
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
analogWrite(channels[channelIndex], LOW); // turn on one channel at a time
delay(500); // wait .5 seconds
analogWrite(channels[channelIndex], HIGH);
}
turnLightsOff();
}
void turnLightsOff()
{
//turn them all off
for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++)
analogWrite(channels[channelIndex], HIGH);
}
void outputToLights(unsigned char* buffer)
{
for(int channelIndex=0;channelIndex<extraChannel;channelIndex++)
CS.digitalWrite(channels[channelIndex], buffer[channelIndex]);
////////////********OUTPUT NEW DATA TO NEW CHANNELS*********/////////////
for(int channelIndex=extraChannel;channelIndex<CHANNEL_COUNT;channelIndex++)
digitalWrite(channels[channelIndex], buffer[channelIndex]);
}
void readFromVixen()
{
char *footer="VIXEN_END";
unsigned char buffer[CHANNEL_COUNT];
char buffer2[CHANNEL_COUNT];
int index=0;
unsigned long time = millis();
waitForVixenHeader();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
//try adding loop incomingByte here???
time = millis();
int lightByte = map(inByte, 0, 255, 255, 0);
buffer[index] = lightByte;
buffer2[index] = inByte;
buffer[index+1] = 0;
buffer2[index+1] = 0;
index++;
if(index==9 && strcmp(footer,buffer2)==0){
return;
}
else if(index==CHANNEL_COUNT){
outputToLights(buffer);
index=0;
}
}
Serial.println("");
}
void waitForVixenHeader()
{
char *header="VIXEN_START";
char buffer[12];
int index = 0;
unsigned long time = millis();
while (true) {
int inByte = Serial.read();
if(inByte==-1){
if(index==0 && millis()-time>1000) // we haven't read anything in a second
return;
continue;
}
time = millis();
buffer[index] = inByte;
if(buffer[index]!=header[index]) {// not the right sequence restart
index=-1;
}
buffer[index+1] = 0; // add null
index++;
if(index==11 && strcmp(header,buffer)==0){
return;
}
}
}
I changed the baud rate to 19200 and it seemed to stay in sync a little before getting off sync permanently, even with the header and footer. I have a simple sketch to blink all the channels on the centipede shield, then all the ones through the regular digital outputs, and repeat that over and over. It then gets off sync and goes crazy or has lights stay on or something, so odd vs even doesn't seem to matter. I have it at 25ms so 40 times a second a channel could be changed, and everything is dedicated to sending output (ie no adjustable preview, nothing else running). I really have no idea why it seems to work for a little and then stops all of a sudden and can only get back in sync when I unplug and plug the arduino back in 🙁
Thanks
Matt
Hi, I'll have a better look later when I finish work but the baud rate and channel quantites don't add up. Just 60 channels at 8 bits each is 480 bits and if you send this 40 times a second thats 19,200 bit per second or baud and that doesn't include any header, tail or parity bits. Have you tried the old and new code at 10FPS? I'm not sugesting that you sequence at that speed for your show just do a test and depending on the result we can look at making changes. It could just be an issue with the serial buffer filling up and powering down clears it.
Hi,
Just tried the new code with the lower FPS, still no improvements. It works for a few seconds it seems and then gets off and never comes back on.
I was hoping this year wouldn't have any problems....
Hi, I'm sure we can get this sorted - I'm UK so this post is just after midnight our time. You'll need to check in during the day for updates.
Hi, try this as far as I can test without a shield it works. A bit of a hash up of the fastLED front end and some MCP23017 stuff. If it doesn't work and I'm in bed, it's most likley the MCP addressing.
Baud = 115200, Header = VIXEN, footer not needed and must have 64 channels of data after the header or it will use the start of the next serial to finish off the current 64, it doesn't matter if it has more and it shouldn't hang. The address jumper should be as you had it.
//#include <ESP8266WiFi.h>
#include <Wire.h>
unsigned int output_A;
unsigned int output_B;
unsigned int read_loop;
unsigned int IC_loop;
void setup() {
// WiFi.mode(WIFI_OFF);
Serial.begin(115200);
Wire.begin();
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
switch (IC_loop) {
case 0:
Wire.beginTransmission(0x20);
break;
case 1:
Wire.beginTransmission(0x21);
break;
case 2:
Wire.beginTransmission(0x22);
break;
case 3:
Wire.beginTransmission(0x23);
break;
}
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x12);
Wire.write(0x00);
Wire.write(0x01);
Wire.write(0x00);
Wire.write(0x13);
Wire.write(0x00);
Wire.endTransmission();
}
}
void loop() {
for (;;) {
while (!Serial.available());
if (Serial.read() != 'V') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'I') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'X') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'E') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'N') {
continue;
}
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
output_A = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_A, read_loop);
}
output_B = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_B, read_loop);
}
switch (IC_loop) {
case 0:
Wire.beginTransmission(0x20);
break;
case 1:
Wire.beginTransmission(0x21);
break;
case 2:
Wire.beginTransmission(0x22);
break;
case 3:
Wire.beginTransmission(0x23);
break;
}
Wire.write(0x12);
Wire.write(output_A);
Wire.write(0x13);
Wire.write(output_B);
Wire.endTransmission();
}
//ADD ANY EXTRA CHANNELS HERE
}
}
If this works I'll add comments so it can be followed.
EDIT: The output may be inverted, if so you will need to set output_A & _B to 255, use 'bitClear()' instead of 'bitSet()' and in setup Wire.write(0xFF) in lines 4 and 8 of that block instead of 0x00.
Hi Barnabybear,
Thank you! I will try that later tonight. I am a student in the US so I will not be able to do to classes and such until later today. I will post and let you know.
Matt
