This is my first time posting on here, so if I screwed up anything in this post let me know and I will try to fix it.
I bought an XY-LPWM PWM generator to use for work. It can generate PWM signals as high as 30V. The frequency and duty cycle of the generator can be set using serial control. I am trying to get it to work on Serial1 of my Mega 2560, but I cannot. If I connect the RX & TX to Pins 0 and 1 I can open the serial monitor and send commands to it which set it properly
String setPWM;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() >0) {
setPWM = Serial.readString();
Serial.println(setPWM);
Serial1.println(setPWM);
}
}
it does not change the settings of the generator. I have tried it with the generator RX connected to the Mega RX and the generator TX connected to the Mega TX and also with RX-TX and TX-RX, but neither way worked. Any thoughts on this issue would be appreciated.
You have not explained how you have connected everything in the two different scenarios. Please make some simple pencil drawings of the connections in the two cases and post photos of the drawings. See this Simple Image Guide
And you have not told us exactly what the Arduino receives in the first case.
Initially I had the generator connected to Serial. Then I ran this code. With this code running I then opened the Serial Monitor. I could then type a command ("F101") and the PWM frequency was set to 100. So, I know that the PWM Generator communication is working.
As I stated in the original post I then tried connecting the generator to Serial1 I tried it with the Gen TX to Mega TX & Gen RX to Mega RX first (Serial1.jpg).
Initially I had the generator connected to Serial. Then I ran this code. With this code running I then opened the Serial Monitor. I could then type a command ("F101") and the PWM frequency was set to 100. So, I know that the PWM Generator communication is working.
As I stated in the original post I then tried connecting the generator to Serial1 I tried it with the Gen TX to Mega TX & Gen RX to Mega RX first (Serial1.jpg).
I see you tried Serial1 connections both with Tx-Tx and Tx-Rx, but with Serial it seems you only did Tx-Tx. Can you try Serial with Tx-Rx or have you already done that?
I tried it with setPWM = "F105\r\n";. That did not work either.
One more thing to be clear. I need to be able to communicate with this board using Serial1 because I need Serial to be open for communication with my PC.
Having said that, I did try to send commands to the generator using Serial and code (no Serial Monitor). It did not work with either Tx-Tx, Rx-Rx of Tx-Rx, Rx-Tx.
dougrider:
I tried it with setPWM = "F105\r\n";. That did not work either.
One more thing to be clear. I need to be able to communicate with this board using Serial1 because I need Serial to be open for communication with my PC.
Having said that, I did try to send commands to the generator using Serial and code (no Serial Monitor). It did not work with either Tx-Tx, Rx-Rx of Tx-Rx, Rx-Tx.
That seems very strange. I did some research and found this Arduino Forum article that may give some clues as to what can solve your issue.
Initially I had the generator connected to Serial. Then I ran this code. With this code running I then opened the Serial Monitor. I could then type a command ("F101") and the PWM frequency was set to 100. So, I know that the PWM Generator communication is working.
I hope you realise that the code in the Mega had nothing to do with this occurring.
You were sending serial commands directly to the generator from the Serial Monitor because they were connected to the same Serial port terminals.
Thanks to everyone for your input.
I got it working now.
I needed to convert my string to a char array and then write (not print) the array to Serial1.
I want to connect the arduino mega and pwm module with ttl communication (arduino pin RX18, TX19) did not send the wiring diagram. as it appeared in the previous post. my colleague has managed to solve the problem. i thought it would sound ..... i would like to control the pwm module with 4pin PC fan 12v and controlling pc ... after uploading the code to arduin, nothing will appear on serial communication. i can write command read and display FAIL. in the code I was inspired by youtube