Pages: 1 [2]   Go Down
Author Topic: Using android phone to control remote dimmer  (Read 7788 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i tried to directly wire up from arduino to RS-232 ( yea seriously). and I try to write a program.

i tested this program and i watched  the status from the serial monitor, it kept print the value 2FF000D repeatedly
while i send 1 to the monitor, it changed the value to 2FF400D but still repeatedly
and i tried to send another num to monitor, it stopped.

how come the value keep looping, how can i send  hex once only?

however i tried the above step after i connected between TX,RX and GND of arduino board and 232port 2,3,5 pin.
i sent 1 out , i could see the monitor that showed the hex of 2FF400D, but the remote dimmer didnt turn on.
what's the problem here?


   
Reference the serial.available() function: http://www.arduino.cc/en/Serial/Available .

Serial.available() returns the number of data bytes available. In your code the statement

if (Serial.available () == 0)

means that every time there are 0 bytes available to read,

Serial.print ( dimmerOFF,HEX);

will be executed.

What you want to do is test for when Serial.available() > 0 and then read the byte from serial. You can then have an if statement, or switch statement to determine what should happen when a given byte is received.

ok, i have just tested with a very simple program
the code are as following:

unsigned long dimmerON = 0x02ff400d;


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available() >0)
  {
    Serial.print(dimmerON,HEX);
    delay(5000);
  }
}

the program is just to test if i can send hex number through serial communication
if it is work, i think the lighting dimmer could turn on by the hex number.
but it doesnt work.
in the above program.
do i really send a hex number out through serial port?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Two things,

Firstly, there are three different functions to write out serial data:

serial.print(), serial.println(), and serial.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
0x64

You 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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Two things,

Firstly, there are three different functions to write out serial data:

serial.print(), serial.println(), and serial.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
0x64

You 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??
 
Logged

Pages: 1 [2]   Go Up
Jump to: