Go Down

Topic: Serial communications with XY-LPWM using Serial1 (Read 368 times) previous topic - next topic

Hanzz23

I have arduino mega 2560 and LCD PWM generator with ttl.  i would like to control 4pin fan controlling PWM with arduino.

https://abra-electronics.com/voltage-regulator-modules/mod-xy-lpwm-pwm-square-wave-signal-generator-w-adjustable-frequency-and-duty-cycle.html

my code is:

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial1.begin(9600);
}

char buf[40];
int count=0;

void loop() { // run over and over
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
  if (Serial.available()) {
    char ch = Serial.read();
    if(ch=='\r'){
      buf[count]=0;
      Serial1.print(buf);
      count = 0;   
    }else if(ch=='\n'){
      ;   
    }else{
      buf[count++] = ch;
    }
  }

}

comunication doestn work :/

I try to modify the code but it still does not work. on yesterday's communication attempt FAIL .....

Robin2

@Hanzz23, I have suggested to the Moderator to move your question to its own Thread as there is no sign of an answer emerging in the present Thread

The words "doesn't work" give us no information from which to help you. Tell us in as much detail as possible what happens when you run your program.

Aslo make a drawing showing how you have everything connected and post a photo of the drawing.  See this  Simple Image Guide


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

horace

are you transmitting '\r' to the program?
you don't appear to be adding an end of line (\r or \n) to your buffer before transmission over Serial1

Hanzz23

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

https://www.youtube.com/watch?v=1gkhW2-eBPA&lc=z22mzjrx3qjmdpfn4acdp430cbdjz04ajm3udr3qwbpw03c010c.1529308375163440

I am sorry for my bad English...

Hanzz23

thanks everbody! my code its works.  I did not have Both NL & CR on serial communication.......

Go Up