arduino serial communcation with vixen -
i trying use arduino take incoming data vixen software through serial comm. , move data 12 other arduino works if keep channel numbers vixen 43 need control 480 channels. first arduino controls 43 channels next 44-87 , on.
this master code: `void setup() { serial.begin(9600);
serial3.begin(9600); } void loop() { // read port 0, send port 1: if (serial.available()) { int inbyte = serial.read(); serial3.write(inbyte);
} } slave code:
// output
int cue1 = 3; int cue2 = 4; int cue3 = 5; int cue4 = 6; int cue5 = 7; int cue6 = 8; int cue7 = 9; int cue8 = 10; int cue9 = 11; int cue10 = 12; int cue11 = 13; int cue12 = 22; int cue13 = 23; int cue14 = 24; int cue15 = 25; int cue16 = 26; int cue17 = 27; int cue18 = 28; int cue19 = 29; int cue20 = 30; int cue21 = 31; int cue22 = 32; int cue23 = 33; int cue24 = 34; int cue25 = 35; int cue26 = 36; int cue27 = 37; int cue28 = 38; int cue29 = 39; int cue30 = 40; int cue31 = 41; int cue32 = 42; int cue33 = 43; int cue34 = 44; int cue35 = 45; int cue36 = 46; int cue37 = 47; int cue38 = 48; int cue39 = 49; int cue40 = 50; int cue41 = 51; int cue42 = 52; int cue43 = 53; int = 0; int incomingbyte[43]; void setup() // run once, when sketch starts { serial3.begin(9600); pinmode(cue1, output); // sets digital pin output pinmode(cue2, output); // sets digital pin output pinmode(cue3, output); // sets digital pin output pinmode(cue4, output); // sets digital pin output pinmode(cue5, output); // sets digital pin output pinmode(cue5, output); // sets digital pin output pinmode(cue6, output); // sets digital pin output pinmode(cue7, output); // sets digital pin output pinmode(cue8, output); // sets digital pin output pinmode(cue9, output); // sets digital pin output pinmode(cue10, output); // sets digital pin output pinmode(cue11, output); // sets digital pin output pinmode(cue12, output); // sets digital pin output pinmode(cue13, output); // sets digital pin output pinmode(cue14, output); // sets digital pin output pinmode(cue15, output); // sets digital pin output pinmode(cue16, output); // sets digital pin output pinmode(cue17, output); // sets digital pin output pinmode(cue18, output); // sets digital pin output pinmode(cue19, output); // sets digital pin output pinmode(cue20, output); // sets digital pin output pinmode(cue21, output); // sets digital pin output pinmode(cue22, output); // sets digital pin output pinmode(cue23, output); // sets digital pin output pinmode(cue24, output); // sets digital pin output pinmode(cue25, output); // sets digital pin output pinmode(cue26, output); // sets digital pin output pinmode(cue27, output); // sets digital pin output pinmode(cue28, output); // sets digital pin output pinmode(cue29, output); // sets digital pin output pinmode(cue30, output); // sets digital pin output pinmode(cue31, output); // sets digital pin output pinmode(cue32, output); // sets digital pin output pinmode(cue33, output); // sets digital pin output pinmode(cue34, output); // sets digital pin output pinmode(cue35, output); // sets digital pin output pinmode(cue36, output); // sets digital pin output pinmode(cue37, output); // sets digital pin output pinmode(cue38, output); // sets digital pin output pinmode(cue39, output); // sets digital pin output pinmode(cue40, output); // sets digital pin output pinmode(cue41, output); // sets digital pin output pinmode(cue42, output); // sets digital pin output pinmode(cue43, output); // sets digital pin output } void loop() { if (serial3.available() >=43) { (int i=0; i<43;i++) { incomingbyte[i] = serial3.read(); } digitalwrite(cue1, incomingbyte[0]); digitalwrite(cue2, incomingbyte[1]); digitalwrite(cue3, incomingbyte[2]); digitalwrite(cue4, incomingbyte[3]); digitalwrite(cue5, incomingbyte[4]); digitalwrite(cue6, incomingbyte[5]); digitalwrite(cue7, incomingbyte[6]); digitalwrite(cue8, incomingbyte[7]); digitalwrite(cue9, incomingbyte[8]); digitalwrite(cue10, incomingbyte[9]); digitalwrite(cue11, incomingbyte[10]); digitalwrite(cue12, incomingbyte[11]); digitalwrite(cue13, incomingbyte[12]); digitalwrite(cue14, incomingbyte[13]); digitalwrite(cue15, incomingbyte[14]); digitalwrite(cue16, incomingbyte[15]); digitalwrite(cue17, incomingbyte[16]); digitalwrite(cue18, incomingbyte[17]); digitalwrite(cue19, incomingbyte[18]); digitalwrite(cue20, incomingbyte[19]); digitalwrite(cue21, incomingbyte[20]); digitalwrite(cue22, incomingbyte[21]); digitalwrite(cue23, incomingbyte[22]); digitalwrite(cue24, incomingbyte[23]); digitalwrite(cue25, incomingbyte[24]); digitalwrite(cue26, incomingbyte[25]); digitalwrite(cue27, incomingbyte[26]); digitalwrite(cue28, incomingbyte[27]); digitalwrite(cue29, incomingbyte[28]); digitalwrite(cue30, incomingbyte[29]); digitalwrite(cue31, incomingbyte[30]); digitalwrite(cue32, incomingbyte[31]); digitalwrite(cue33, incomingbyte[32]); digitalwrite(cue34, incomingbyte[33]); digitalwrite(cue35, incomingbyte[34]); digitalwrite(cue36, incomingbyte[35]); digitalwrite(cue37, incomingbyte[36]); digitalwrite(cue38, incomingbyte[37]); digitalwrite(cue39, incomingbyte[38]); digitalwrite(cue40, incomingbyte[39]); digitalwrite(cue41, incomingbyte[40]); digitalwrite(cue42, incomingbyte[41]); digitalwrite(cue43, incomingbyte[42]); } }`
thank help
first did not ask question. bad form forum.
seeing have copied typical vixen code , added on top of mega, can see several areas need addressing. how expand multiple units, framing , buffer size.
the typical example appears proliferated arduino's receiving vixen. scary in not frame start or end of stream of cues. rather requires stream , stay synchronized, being dependent upon length. work until 1 byte lost. out of sync until each component reset , restarted. not want multiple arduino's.
the following code enhances configuring vixen's general serial port setup enable "send text footer" sending single letter "e".
taking advantage in implementation output cues boolean. being on or off. vixen send either 0x00 or 0xff each cue in sequence. above footer enabled vixen terminate each sequence byte 'e' or 0x45 (hex). cues range 0x00 through 0xff intensity. if case, more complex footer needed, 0x45 may legitimate value. whereas in case 'e' work nicely.
#define first_in_chain 1 // set 1 first in chain #define size_of_array(x) (sizeof(x)/sizeof(x[0])) //total length divided length of 1 element // specified in vixen's general serial port setup "send text footer" #define vixen_end_of_text 'e' #if (first_in_chain == 1) #define serialin serial #else #define serialin serial2 #endif // general gpio used output cues uint8_t pins[] = {3,4,5,6,7,8,9,10,11,12,13,\ // not used serialx ports // 14,15, \ // txd3/rxd3 // 16,17, \ // txd2/rxd2 // 18,19, \ // txd1/rxd1 // 20,21, \ // sda/scl 22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53}; void setup() { serialin.begin(9600); serial3.begin(9600); // initialize cue pins off , output (uint8_t pin = 0; pin < size_of_array(pins); pin++) { digitalwrite(pins[pin], low); pinmode(pins[pin], output); } } void loop() { // first 43 cues arduino (uint8_t pin = 0; pin < size_of_array(pins); pin++) { while(!serialin.available()); // wait data. char c = serialin.read(); if(c == vixen_end_of_text) { return; } else if(c > 0) { digitalwrite(pins[pin], high); } else { digitalwrite(pins[pin], low); } } // read port 0, send port 1: while(1) { while(!serialin.available()) ; // wait next data. // echo byte on next stage char c = serialin.read(); serial3.write(c); if(c == vixen_end_of_text) { // when carriage return received exit while , wait new frame break; } } }
now not perfect , since don't have vixen , such set has not been proven. however, compile , appears should work fine.
configured footer of 'e' vixen sends out stream of bytes representing each cue terminating frame 'e'. above sketch listens first 43 cues , applies them local pins. if chance script gets out of sequence , footer of 'e' inadvertently detected loop() returned start a-new. if recieves cues locally applied moves onto echo remaining in cues out serial3 (txd3) next arduino's serial2 (rxd2), until footer 'e" received denoting end of sequence. @ point starts over. note cue's locally applied not echo'ed, means next arduino again act on next 43 or first 43 cues receives , echo remainder on until chain exhausted.
few points of interest:
note use of
while(!serialin.available()); // wait data.
which "wait while there no data read" or wait until there something. these blocking (meaning code stuck) until received. whereas expected vixen periodically sending stream of cues. , if 1 'e' missed next frame contain it, code autonomously re-synchronize.
also worth noting pins cue definition more flexible. if want possible use 47 cues, un-comment:
// 18,19, \ // txd1/rxd1 // 20,21, \ // sda/scl
the code automatically resize. or comment out other pins if used other purposes.
it worth noting 9600 baud approximately 960 bytes per second. means sequence can update less twice second or approximately 2 hz. , daisy chaining add noticeable propagation delays , difference between arduino's. vixen 2 can configured maximum rate of 57600 baud can yield approximately 12 hz. hence recommend configuring both vixen , arduino's @ least 57600 baud. minimize these affects. vixen 3 can go faster. recommend 115200 baud or 24 hz.
to summarize first unit compiled first_in_chain defined 1. causes lead arduinomega receive data serial port attached pc running vixen. remaining mega's compiled first_in_chain defined 0. serial3 of preceding unit connected next units serial2. possible drive serial. simpler reserve serial debugging , such. vixen configured foot of 'e'.
where buffer size not issue in solution each byte handled individually. not waiting them build in arduino's serial.read() buffer. on fill beyond 62.
Comments
Post a Comment