Motor Controller from Raspberry Pi

I've finally got off my backside and tested out the N20 motors I ordered what feels like a billion years ago.  Part of the delay was that I lost the original L293D motor controllers I was going to use.  I am just that awesome.

It took a little fiddling around, but I got the motor and raspberry pi powered from an ATX PSU and the pi's pins connected via an IDE cable to the L9110S module I got from ebay.

Then, I used gpiozero's PWMOutputDevice to create a forward device on one pin and a backward device on the other.  I didn't even have to faff about with the frequencies - just set the value on the object and away it went!


So now, my plan is to build the base frame for my CNC router and attach this motor to a threaded rod and rotary encoder.  Fingers crossed that tiny motor has enough torque to move the cutting tray. :S

Comments

  1. Hi, this is from Japan.
    Could you put the source code of it?

    ReplyDelete
    Replies
    1. Thanks for the comment! I've got to get the source off my pi, but I'm planning to go back to this project at the weekend - I'll let you know!

      Delete
    2. It took me a while to find the pi, but I finally have the code! I've tested it on the latest raspberry pi os image: https://www.raspberrypi.org/downloads/

      #!/usr/bin/python3
      from gpiozero import PWMOutputDevice
      from time import sleep

      motorAForward = PWMOutputDevice(17)
      motorABackward = PWMOutputDevice(18)

      try:
      while True:
      motorAForward.value=1
      sleep(1)
      motorAForward.value=0
      sleep(1)
      motorAForward.value=0.25
      sleep(1)
      motorAForward.value=0
      sleep(1)
      motorABackward.value=1
      sleep(1)
      motorABackward.value=0
      sleep(1)
      except:
      pass

      motorAForward.close()
      motorABackward.close()

      Delete

Post a Comment

Popular posts from this blog

Micro:Bit and SPI display

DCS World with TrackIR under Ubuntu

Polygon Triangulator!!