The PC serial connection is RS232, this means the serial voltages are +/- 12v. The serial output from the Arduino is 0 to 5V. Therefore if it works on the PC you need to put the serial signal from the Arduino through a RS232 voltage converter like a MAX232.
Yeah, i've already found that out myself. I even got it all working with some research. The real problem was dealing with the crc-code the chromoflex needs. In case anyone wants to try it out themself I'll post a test program that I've written:
The only things you really need to make something yourself is:
- reset_chromo/overnemen to put the chromo in the user-mode
- bereken_crc16 to calculate the crc-bits
- dec_to_hex the chromoflex only accepts hex send through
serials for some reason
int pinnummer = 0;
int positie = 0;
int resetcode[] = {202,0,0,0,0,0,254,140,240};
int userprog[] = {202,0,0,0,0,2,126,18,1,149,136};
int kleurcode[] = {202,0,0,0,0,5,126,4,255,0,0,100};
int vorige_positie =0;
int kleur_rood = 0;
int kleur_blauw = 0;
int kleur_groen = 0;
unsigned int tussen = 0;
unsigned int crc = 65535;
unsigned int test = 65535;
unsigned int crc16 = 0;
unsigned int crc16_1 = 0;
unsigned int crc16_2 = 0;
void setup(){
Serial.begin(9600);
reset_chromo();
delay(2000);
}
void loop(){
positie = analogRead(pinnummer);
if(positie<(vorige_positie-6) || positie>(vorige_positie+6)){
int h = positie%7;
int g = (positie - h) / 7;
if(g>=0 && g<25){kleur_rood = 127+(5*g);}
if(g>=25 && g<75){kleur_rood = 255-((g-25)*5);}
if(g>=125){kleur_rood = (g-125)*5;}
if(g>=25 && g<75){kleur_blauw = (g-25) * 5;}
if(g>=75 && g<125){kleur_blauw = 255-((g-75)*5);}
if(g>=0 && g<25){kleur_groen = 127-(5*g);}
if(g>=75 && g<125){kleur_groen = (g-75)*5;}
if(g>=125){kleur_groen = 255 - ((125-g)*5);}
kleurcode[7] = 4;
kleurcode[8] = kleur_rood;
kleurcode[9] = kleur_groen;
kleurcode[10] = kleur_blauw;
overnemen();
bereken_crc16();
dec_to_hex();
kleurcode[7] = 0;
bereken_crc16();
dec_to_hex();
vorige_positie = positie;
}
bereken_crc16();
}
void bereken_crc16(){
crc = 65535;
for(int i=0;i<(sizeof(kleurcode)/2);i++){
tussen = kleurcode*^crc;*
-
crc = tussen;*
-
for(int z=0;z<8;z++){*
-
if((crc&1)==1){*
-
int a = crc >> 1;*
-
crc = a^40961;*
-
} else {*
-
tussen = crc;*
-
crc = tussen >> 1;*
-
}*
-
}*
-
}*
}
void dec_to_hex(){
-
int hexarray[4] = {0,0,0,0};*
-
int b = 3;*
-
while(crc>16){*
-
unsigned int c = crc%16;*
-
unsigned int d = crc - c;*
_ hexarray = c;_
** crc = d / 16;**
** b--;**
** }**
__ hexarray = crc;__
crc16_1 = hexarray[0]*16 + hexarray[1];
crc16_2 = hexarray[2]*16 + hexarray[3];
** for( int q=0;q<(sizeof(kleurcode)/2);q++){**
** Serial.print(kleurcode[q],BYTE);**
** }**
** Serial.print(crc16_1,BYTE);
Serial.print(crc16_2,BYTE);
__}
void reset_chromo(){
for( int p=0;p<(sizeof(resetcode)/2);p++){
Serial.print(resetcode[p],BYTE);
}
delay(1000);
overnemen();
}
void overnemen(){
for( int p=0;p<(sizeof(userprog)/2);p++){
Serial.print(userprog[p],BYTE);
}
}**
If you have any questions regarding my code, just ask__