I'm pretty new in the Arduino although I did some very basic projects. So I need some help from you guys.
The project I'm going to do is to use Arduino to receive and read the measurement data from a light meter, which can be used for measuring illuminance value. From the manual of the light meter, I noticed that in order to get the data, it is necessary to send a series of commands to the light meter so that it can respond and send the data back.
I used the RS232 cable to connect Arduino with the light meter(Rx,Tx, GND) and tried to send a series of string from Arduino to the light meter, but I didn't get any response. So I reckon my programming and my understanding of this communication might have some problems.
void loop()
{
strSndCommand = "00541 "; //First command that I need to send based on the manual
strSndBCC = "13";
strSendStr = strSndSTX + strSndCommand + strSndETX + strSndBCC + "\r" + "\n"; //according to manual
mySerial.println(strSendStr); //send the serieal of command
strReceiveStr = Serial.read(); // read the response, but I didn't get any response
Serial.println(strSendStr);
Serial.println(strReceiveStr);
delay(1000);
}
I have attached the manual of the light meter so that you guys can have a look.
Any suggestions will be appreciated. Thank you so much.
Why do you concatenate a whole series of strings that are all written sequentially to the same port? Ditch the String class, it isn't reliable on a machine as small as the AVR. Have you tried connecting and sending commands to the meter manually? Does the meter have RS232 electrical levels or TTL levels?
aarg:
Why do you concatenate a whole series of strings that are all written sequentially to the same port? Ditch the String class, it isn't reliable on a machine as small as the AVR. Have you tried connecting and sending commands to the meter manually? Does the meter have RS232 electrical levels or TTL levels?
Hi Aarg,
Thank you for your reply.
The manual provides some code examples written in Visual Basic Language, and it uses String to send the command, so that's why I used String as well. But I'm not really sure how should I send all the commands using C language, can you give me some suggestions?
How should I send commands to the meter manually? Is it by using the serial monitor?
I measured the voltage level of the meter outlet, it was 5V. So I reckon it should be TTL level, am I correct?
But what should I type in the serial monitor when sending the command manually? According to the manual of the meter, it is necessary to send the command like this:
STX(02h) + "00541 " + ETX(03h) + "13"
So how should I send the STX and ETX from serial monitor?
Should I type and send each element separately or combine them as one line?
I'm pretty new in the Arduino although I did some very basic projects. So I need some help from you guys.
The project I'm going to do is to use Arduino to receive and read the measurement data from a light meter, which can be used for measuring illuminance value. From the manual of the light meter, I noticed that in order to get the data, it is necessary to send a series of commands to the light meter so that it can respond and send the data back.
I used the RS232 cable to connect Arduino with the light meter(Rx,Tx, GND) and tried to send a series of string from Arduino to the light meter, but I didn't get any response. So I reckon my programming and my understanding of this communication might have some problems.
void loop()
{
strSndCommand = "00541 "; //First command that I need to send based on the manual
strSndBCC = "13";
strSendStr = strSndSTX + strSndCommand + strSndETX + strSndBCC + "\r" + "\n"; //according to manual
mySerial.println(strSendStr); //send the serieal of command
strReceiveStr = Serial.read(); // read the response, but I didn't get any response
Serial.println(strSendStr);
Serial.println(strReceiveStr);
delay(1000);
}
I have attached the manual of the light meter so that you guys can have a look.
Any suggestions will be appreciated. Thank you so much.
Maybe because you read the serial from Serial, not from mySerial. Try this (untested):
void loop()
{
strSndCommand = "00541 "; //First command that I need to send based on the manual
strSndBCC = "13";
strSendStr = strSndSTX + strSndCommand + strSndETX + strSndBCC + "\r" + "\n"; //according to manual
mySerial.print(strSendStr); //send the serieal of command
delay(1000);
do {
strReceiveStr = mySerial.read();
Serial.print(strReceiveStr);
}
while (mySerial.available());
}
Thank you for your reply.
I modified my code as what you said, but it still doesn't work. I can't receive any response from the light meter. Maybe it's because the light meter doesn't receive the command? I'm sure whether I used a right way to send the command. Should I send it as a string or other types of data?
I'm trying to connect Arduino UNO with a light meter device used for measuring illuminance value, so that Arduino can read and process the measured data from the meter. But I got some issues regarding the serial communication between these two devices.
I read the manual of the light meter and it says in order to receive the measured data, it is required to send a serial of commands to the light meter using RS232. I connected Arduino with the light meter (Tx,Rx,GND), and wrote the code for sending the commands and reading the data, but I didn't get any response from the light meter.
The communication format: STX(02h) + Command Characters + ETX(03h) + BCC + CR(0Dh) + LF(0Ah)
I read the manual of the light meter and it says in order to receive the measured data, it is required to send a serial of commands to the light meter using RS232. I connected Arduino with the light meter (Tx,Rx,GND)
The Arduino Serial interface uses TTL level signals so you need a converter between the two
Is the device really an RS232 device? The Arduino can not handle an RS232 device directly. The serial signals are the wrong voltage and are inverted. You need a MAX232 chip between the Arduino and any RS232 device to handle the voltage differences.
Sorry, this is my first time using this Forum. I was not quite sure where is the most appropriate place to post my question, so I posted in multiple sections. Sorry again
PaulS:
Is the device really an RS232 device? The Arduino can not handle an RS232 device directly. The serial signals are the wrong voltage and are inverted. You need a MAX232 chip between the Arduino and any RS232 device to handle the voltage differences.
Thanks Paul.
Yeah, I was thinking maybe I should use a converter between this two devices as well.
I did some research about the TTL voltage and RS232 voltage, and I noticed that the output voltage coming from RS232 would be as high as 25V. But when I used the voltage meter to measure the output port of the light meter, the voltage value was only 5V.
So I'm confused. The cable they provide is a RS232 cable, but the output doesn't reach the 25V.
Do I still need the MAX232 chip in this condition?