TKHouse:
Two things,Firstly, there are three different functions to write out serial data:
serial.print(),serial.println(), andserial.write().Looking at the reference for
serial.print(), what actually happens is that the data is sent to the serial port in a human-readable format, but in the format specified by the second parameter.So the number 65 sent with
serial.print(65, HEX)would write 0x41 (65 in HEX) to the serial port, but using human readable characters. So in actuality, the binary values 0x34 and 0x31 would be sent (producing ASCII characters '4' and '1' on the serial monitor). This function is primarily intended to make monitoring and debugging easier, while not being what you need in your case.So in your case,
Serial.print(dimmerON,HEX)is actually writing the following bytes to the serial port:
0x30
0x32
0x66
0x66
0x34
0x30
0x30
0x64You need to use the
serial.write()that will actually write the binary value for 0x02ff400d to the serial port. You will probably want to use the method using an array of bytes.Secondly, it will likely not be quite that simple. RS-232 has more to its protocol than simply writing serial data on the lines. I am not certain, but it does not appear that you are using any type of RS-232 driver chip. I've never implemented anything using RS-232, so I'm definitely not experienced in working with it.
There is an Arduino Software RS-232 tutorial: http://www.arduino.cc/en/Tutorial/ArduinoSoftwareRS232
There are also Arduino RS-232 shields available.
Either the software version with a driver chip, or the shield version are probably your best options. If you're working on an UNO, the shield will probably use the available serial port, so if you'll be reprogramming a lot it might be in your interest to look at the version using software serial.
i tried Serial.write() , and this actually send 02 FF 40 0D to the serial port, i used a software to check it
but it still cannot turn on the dimmer.but i cant use the array of byte, it's because when i use the array , it will have an error with overload with stuff
and i know that the dimmer has the following setting
baud rate : 9600
parity : none
data bits: 8
stop bits : 1
handshaking : none
in fact, does it any library need in my case? or sample??