leofric
Posts: 8
Joined: Sat Jan 11, 2014 9:33 am

XY-LPWM Signal generator [solved]

Mon Dec 10, 2018 9:21 am

Not sure where to post this. Has anyone linked a pi to the xy-lpwm signal generator? I am failing to get it to respond to signals from gpio Tx and not getting anything on Rx. Have tried linking pi Tx and Rx together and this confirms that my code sends and reads ok. Tried my code and a terminal program with pi connected to xy-pwm through a voltage converter. So pi sending and receiving 3.3v and xy-lpwm getting 5v. No joy. Only signal that xy-lpwm respond to is Ctrl c from a terminal - just sets display to 0000, 0000.

Have written a touch screen gui for controlling a lathe motor via a pwm motor controller. Thought the xy-lpwm might provide an interrupt free, cheap and easy way of providing a set frequency, variable duty cycle 5v PWM to motor controller while the pi drives the screen display and sets the required duty cycle.
Last edited by leofric on Thu Dec 27, 2018 11:41 am, edited 1 time in total.

ChillKroete89
Posts: 3
Joined: Sun Dec 23, 2018 10:12 pm

Re: XY-LPWM Signal generator

Sun Dec 23, 2018 10:36 pm

Hi leofric,

currently I have the same issue as you with this PWM generator. I use this to control the speed of multiple fans.
But now I'm struggeling with the serial communication to the PWM generator. I tried to write a script which sends a new Duty Cycle, but the module doesn't get it and I get no reaction.

Did you get it to run in the meanwhile? If so, it would be nice if you can share your code.


Here is my attempt:

Code: Select all

import time
import serial
import sys

print "Starting program"

ser = serial.Serial(
        #'/dev/ttyAMA0',  # just testing a few serial devices
        #'/dev/serial0',
        '/dev/ttyS0',
        baudrate=9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)

time.sleep(1)
print(ser.name)
try:
    ser.write('D050\r')
    time.sleep(1)
    print 'Data Echo Mode Enabled'
    while True:
        if ser.inWaiting() > 0:
            data = ser.read()
            print data

except KeyboardInterrupt:
    print "Exit Program"
    ser.close()
    sys.exit(0)
finally:
    ser.close()
    pass
    sys.exit(0)
Cheers

leofric
Posts: 8
Joined: Sat Jan 11, 2014 9:33 am

Re: XY-LPWM Signal generator

Thu Dec 27, 2018 11:40 am

Pleased that someone else is also trying this. Not had time to get back to it but will do soon. I am wanting to use it to provide a pwm input to an MC2100 treadmill motor controller for use in a lathe - the front end being a pi touch screen. Had hoped this was an easy solution...
My , not working, code is quite similar to yours.

I am passed the serial through
https://www.amazon.co.uk/gp/product/B07 ... UTF8&psc=1
with 3.3v on the pi side and 5 on the xy-lpwm side.

No joy though. From a terminal program, that can send text with and without line feed and/or carriage return, I have not been able to get it to respond. Apart from Ctrl C setting the display to 0000,0000. It immediately returns to the previous setting if I touch a button on the xy-lpwm. If I hold Ctrl C for a short while I can get FAIL returned to the terminal - but not to a via python3 with pyserial to a console.

I found this on YouTube showing how to do it from an arduino:

https://youtu.be/1gkhW2-eBPA

I have posted a question there. If I crack it then I will certainly post my code. I am not convinced that the issue is in the code though.

Are you also bridging between the pi and xy-lpwm in a similar way to me?

This was meant to be a quick, cheap and easy solution - now turned into a challenge! An alternative for me would be to use the pi for the front end and an arduino to generate the pwm directly (or control the xy-lpwm).

But, I still hope to avoid that.

Thanks for posting your code - will put something up when/if I get it going.

leofric
Posts: 8
Joined: Sat Jan 11, 2014 9:33 am

Re: XY-LPWM Signal generator

Thu Dec 27, 2018 9:58 pm

:D Prompted by somebody else being interested I have had another go.
Got it working both from Cutecom and a skeleton python program!
Will tidy up the code tomorrow and post it here. I don't think there was a problem with my old code. I was powering the xy-lpwm from the 5v output on the GPIO - although the xy-lpwm display was bright and stable I suspect it was drawing too much from my small pi power supply. Now I have the pi providing power to the tx/rx via a voltage converter (3.3v on pi side, 5v on xy-lpwm side) but a seperate 1amp 5v supply to the VIN+, VIN- on the xy-lpwm.

Cutecom let's you send to and read the port in a nice clear display.
I have sent the commands F5.01 D033 etc with no line feed or CR.
100% success. To read from the xy-lpwm send 'read' in lowercase.

leofric
Posts: 8
Joined: Sat Jan 11, 2014 9:33 am

Re: XY-LPWM Signal generator

Fri Dec 28, 2018 2:36 pm

Not very elegant but the code works OK. :D


Code: Select all

#!/usr/bin/env python3
import time
import serial
import sys

#setup the serial port - the AMA0 part will need changing for later versions
ser=serial.Serial(
    port='/dev/ttyAMA0',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=5
    )

readOut='none'
print('Welcome')
#loop to try different command
#NB the frequency and duty cycle commands are uppercase
#the read command to check current settings is lower case
#type end to exit

commandToSend='x'

while commandToSend!='end':
    commandToSend=input('Enter Command :')
    if commandToSend!='end':
        ser.write(str(commandToSend).encode('ASCII'))
        # if it is a read command return the frequency and duty cycle
        if commandToSend=='read':
            readOut=ser.readline().decode()
            print("Frequency: ",readOut)
            readOut=ser.readline().decode()
            print("Duty Cycle: ",readOut)
        else:
            #confirmation will return DOWN if
            #frequency or duty cycle command is accepted FAIL if not
            readOut=ser.readline().decode()
            print("Reply: ",readOut)      

    else:
        ser.close()
        print('Goodbye')
        sys.exit(0)

ChillKroete89
Posts: 3
Joined: Sun Dec 23, 2018 10:12 pm

Re: XY-LPWM Signal generator

Sun Dec 30, 2018 2:24 pm

Thank you very much for the code and the link for the I2C shifter!
I ordered a few and I'm looking forward to test it ;) It may took a few days until I have the chance to do so, but I will give a reply.

ChillKroete89
Posts: 3
Joined: Sun Dec 23, 2018 10:12 pm

Re: XY-LPWM Signal generator [solved]

Wed Jan 09, 2019 2:17 pm

Well, it works! Somehow. It took some time until I realised that I soldered TX to TX and RX to RX on the logic shifter. After resoldering the cables I was able to send commands to the pwm module. But I can‘t read the setting via the command „read“. I get always empty results. So sending is possible, receiving not (in my case). For my purpose I didn‘t need the feature of receiving the values from the module. But maybe you have an idea what I maybe need to change to get it work properly?
Thanks for the code and the advices. Seems so that a few people got problems to get this running via serial communication.

leofric
Posts: 8
Joined: Sat Jan 11, 2014 9:33 am

Re: XY-LPWM Signal generator [solved]

Sat Jan 12, 2019 11:08 pm

My code above reads ok. Are you using my code or have you put it into Python 2.7? There are encoding differences for strings. Make sure you are sending read in lower case.

Return to “Automation, sensing and robotics”