I'm really beating my head on this one. I'm trying to send "$1AO+00020.00" to a DGH voltage module, and it's just not working. I can send it OK to RealTerm on the PC, and RealTerm sends OK to the module, but not the Arduino to the module. Just standard 19200,8,1 RS-232. I've tried several soft libraries and the UART too. Right now I'm using the altSerial library. I thought I could just use altSerial.println("$1AO+00020.00"); but it's a no-go. What I get back is interesting though:
þ$1AO+00020.00
8>~pÌÀÀÀ<À0ÀÀ
Any ideas?
-Andy
And your code?
Do you have your DTE/DCE sorted out? Is the transmit pin of the Arduino going to the rx pin of the "DGH" and contrariwise?
I'm assuming the txd and rxd pins are correct since I can connect the Arduino to a PC running RealTerm and I see the information OK. I have switched them around this way and that while trying different libraries.
Code? It's really basic:
#include <AltSoftSerial.h>
AltSoftSerial altSerial; // start soft serial
char c;
int x = 0;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(19200);
altSerial.begin(19200);
delay(20);
String outStr = "$1AO+00020.00";
Serial.println(outStr);
altSerial.println(outStr);
}
// the loop routine runs over and over again forever:
void loop() {
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
I gave up on it.
A command is initiated with a command prompt, may be a dollar sign ($) or pound sign (#). Following the prompt a single address character must be transmitted. Each module on a communications bus must be setup with a unique address. The address is followed by a two character command. Every command is terminated with a carriage return.
Are you sending a carriage return?
Maybe using a PC is successful, because your PC could be configured to automatically add a carriage return to the end of your string.
To forum users, there is an example program and DGH Library available from DGH. The example program was developed and tested on the Arduino Mega2560. It uses 'Serial1' for communications with the DGH module on Mega pins #18 and #19.
The modules communicate using either RS-232 or RS-485. A serial communications driver chip will be required to interface the Mega2560 with the DGH module.
The example file maybe downloaded using this link : http://www.dghcorp.com/arduino/DGH_AsciiProtocol.zip.
The program code is heavily commented and easy to follow. The DGH Library contains the important functions for reading and writing analog or digital values to/from the module(s). The program and library can easily be expanded to develop more complicated applications.