its to control a serial DMX device.
The device expects to recieve Hex pairs to set the params. ex 01FF (channel 1 to 255).
I've run the code as above, but something odd still seems to be happening.
I needed to verify that the data being sent is correct, so i have a com cable hooked up to serial1 on the mega.
When I run the code below, FF is echoed in the IDE as I would expect, but 73 73 00 is echoed over the other com port (2 wire, running realterm to capture data) 0 now im confused!
void setup(){
char valStg[6]; //final
int value=255; //starting
Serial.begin(9600); //open soft serial
Serial1.begin(9600); //open hardwired
sprintf(valStg, "%X", value); //convert data
Serial.write(valStg); //write soft
Serial1.print(valStg); //write hard
}
The ide output is correct (write) - the print is giving me 73 73 00 as the data.
Just had a thought, ive got the serial port hooked directly to the mega serial1 and gnd - would I need a max233 or similar in the middle of this setup?
You are using two different methods to send serial data to the two ports - write and print.
One works, one doesn't.
It really shouldn't require too much brain power to figure out a solution.
ive got the serial port hooked directly to the mega serial1 and gnd
What "serial port"? Whatever device you have receiving the data should be hooked to the TX and RX pins for Serial1 on the Mega. Grounds need to be connected, too.
Yes - but no matter which I use, the data isnt consistent.
Here is how it is configured.
Mega > USB > PC (monitor open on com22)
Serial1tx > Other PC Rx (rx > tx and gnd > gnd)
Code modified as follows;
void setup(){
char valStg[6]; //final
int value=255; //starting
Serial.begin(9600); //open soft serial
Serial1.begin(9600); //open hardwired
sprintf(valStg, "%X", value); //convert data
Serial.print(valStg); //write soft
Serial1.print(valStg); //write hard
}
But the serial console within the IDE is showing the recieved data as FF (as I expect), but the other PC is showing the recieved data as 73 73 00 - ssNULL- when I would expect to see FF as the data?