Hello,
I am a beginner. I have spent some time trying to read up on my goals. I'm attempting to communicate with a device using the TX and RX pins with limited success. I have read many serial communication tutorials. They mention similar things involving the serial monitor, but I cannot find any that help me to communicate with my device automatically.
The device: A PWM frequency generator with TXD and RXD pins. "XY-LPWM LCD signal generation module"
The product page has this,
...the serial port control (one-chip computer TTL level communication)
Communication Standard : 9600 bps Data Bits : 8
Stop Bits : 1
Parity : none
Flow Control : none1, set the frequency of PWM
"F101": Setting frequency is 101 HZ (001 ~ 999)
"F1.05": Setting frequency is 1.05 KHZ (1.00 ~ 9.99)
" F10.5 ": Setting frequency is 10.5KHZ (10.0 ~ 99.9)
"F1.0.5": Setting frequency is 105KHZ (1.0.0 ~ 1.5.0)
2, set the duty cycle of PWM
"DXXX": set the duty cycle of PWM to XXX ; (001 ~ 100)
For example, D050 , set the PWM duty cycle is 50%
3, read the setting parameters
Send " read " string, read the set parameters.
Set successfully returned: DOWN ;
Setting failed to return: FALL .
I hooked up the device to an Arduino Nano clone. I used an empty sketch with a simple "Serial.begin(9600);". With this sketch I am able to type in appropriate commands into the serial monitor and it works, as described in the quote above section 1 and 2.
What I want to do is have Arduino send those commands automatically and be able to "read" as in section 3. I can do neither.
Regarding, sending the instructions of the form Dxxx and Fxx.x to the Arduino, I have tried code like this from reading many examples,
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600);
}
void loop() {
//Attemps to send serial data
Serial.println("D010");
Serial.println('D010');
Serial.write('D010');
Serial.write("D010");
delay(1000);
//Attempts to read serial data
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
}
It doesn't do what I want though. It sends those messages to the screen, not to my device. I can manually type in message to my device, how do I get Arduino to do it? I don't see anything that does that in the Serial commands here...
My main, simple question - How can I get my Arduino to send the command "D010" automatically as though it had been typed in?
My secondary request is for some help in reading the data as described in section 3. When I type "read" or "READ" nothing happens.
I hope I have been clear, thanks for your help!