Active today
Viewed 39 times

Currently I am trying to automate a coil winding machine using stepper motors. I wrote a Python code to send frequencies to the stepper motors. But for some reason, the frequencies produced by raspberry were not steady, their fluctuations were quite uncontrollable. So I ended up buying 2 XY-PWM Frequency Generators to give out frequency to the steppers, and they worked perfectly. Their wave-forms were rock steady , very stable.

Now, my question is, how am I able to control these 2 frequency generators or talk to them using Raspberry Pi via the UART protocol, and what Python script should I use for this communication between the Pi and the frequency generator to occur?? Please suggest…..Thank you..

 New contributor
  • 1
    I can’t see any Pi relevance. It appears to be a general programming question. – joan yesterday
  • @Nicholas Francis, Your coil winding machine application is interesting, reminding me of once upon a time, me using geared DC motor winding inductor coils with a optical detector to count the number of turns. BTW, earlier I made a quick reply which sig gen to try and I thought I have answered every thing, though I thought your sig gen + uart control does not seem perfect. Actually I am playing with PWM stuff and perhaps I can counter suggest something for brainstorming. – tlfong01 13 hours ago    
  • @Nicholas Francis, This XY-LPWM toy is dirt cheap but very “professional”, therefore super popular among poor hobbyists like me. If you google “XY-LPWM”, you will be surprised to see the number of searched results returned. You can also easily find Arduino programs with UART control. Happen python programming and cheers. – tlfong01 13 hours ago   



How can Rpi4B python UART talk to XY PWM Signal Generators?


I have been using the following “XY-LPWM” sig gen for a couple of years. This is the only cheap, hobbyist grade square wave signal generator I know that has both manual and software / UART control.

The manual control interface is very user friendly. You press frequency up button, frequency goes, up. Similarly for frequency down button and duty cycle up and down buttons.

I used a scope to check the waveform and found it steady, at least for low frequency range from 1kHz to 10kHz. Actually other analog sig gen like NE555 astable, or Rpi master clock divided software PWM signal, can not be compared with the very precise dedicated mcu processed signal. As the signal is actually generated by a MCU (Nuvoton H78E003), so UART control should be easy, though I have not tried it. I googled and found a couple of Arduino UART programming example controlling this XY-LPWM sig gen. It should be easy to convert the Arduino UART program to Rpi.

Actually I bought the sig gen from TaoBao, which is always cheaper than AliExpress or Amazon. AliExpress and Amazon usually include the reseller’s brand name. But this Taiwan based model is OEM, there is no distributor name, except the model number “XY-LPWM”.

So you google with search keywords “XY-LPWM” + “AliExpress” + “Amazon” + “PWM” + “signal Generator”, you should find it.

PS – The two MCUs used are from Holtek (HT1621B), and Nuvoton (H78E003A120). You may like to check out their new sig gen and other updated products (Refs 2, 3).



(1) XY-LPWM 1Hz-150KHz Signal Generator PWM Module

(2) Holtek Semiconductor

(3) Nuvoton Technology

(4) HT1621 RAM Mapping 324 LCD Controller for I/O MCU Datasheet

(5) Nuvoton H76E003 mcu datasheet

(6) AliExpress (UART support) XY-KPWM Signal generator 1 channel 1Hz-150KHz PWM pulse frequency duty cycle module adjustable LCD display – US$3.6


Appendix A – XY-LPWM sig gen pair calibration record

sig gen test 1

sig gen test 2

Appendix B – XY-LPWM sig gen user guide with serial communication instructions

sig gen uart

UART communication and parameter settings

1. UART parameter setting: TTL 9600, N, 8, 1

2. Set PWM frequency:

‘F101′ :Set frequency is 101Hz.’ 101′ can by replace by 001~999;

‘F1.05′ :Set frequency is 1.05KHz.’ 1.05′ can by replace by 1.00~9.99;

‘F10.5′ :Set frequency is 10.5KHz.’ 10.5′ can by replace by 10.0~99.9;

‘F1.0.5′ :Set frequency is 105KHz.’ 1.0.5′ can by replace by 1.0.0~1.5.0;

3. Set PWM duty cycle:

‘DXXX’: Set duty cycle is XXX. ‘ XXX’ can be 000-100.

Example: ‘D051’ means PWN duty cycle is be set as 51%.

4. Read set parameter:

Send ‘read’ and then get parameter.

5. Return value:

Returns ‘DOWN’: Set success.

Returns ‘FALL’: Set fail.

Appendix C- XY-KPWM Sig Gen Spec and UART user guide

AliExpress (UART support) XY-KPWM Signal generator 1 channel 1Hz-150KHz PWM pulse frequency duty cycle module adjustable LCD display – US$3.6


  1. UART support
  2. Frequency range (Normal mode): 1Hz ~ 150KHz;
  3. Frequency range (precise mode): 1Hz ~ 15 KHz;
  4. Frequency accuracy: 2%;
  5. Accuracy of the duty cycle: 1% in Normal mode;
  6. Accuracy of the duty cycle: 0.1% in accurate mode;
  7. Service cycle range: 0.00% -100%;
  8. Output current: approximately 5-30mA;
  9. output amplitude: identical to the input voltage;


xy kpwm uart

End of answer

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – From Review – Bex 16 hours ago
  • You suggestion is very good. So I have improved my answer. Cheers. – tlfong01 16 hours ago   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: