sbcshop / MotorShield

Designed to help you get your Raspberry Pi based Robot. This board can control DC motor as well as the stepper motor. You can connect your IR and Ultrasonic sensors to tell your robot about its environment. You can easily make your Line Following, Object following, Wall following, Maze-Solver Robots.
https://shop.sb-components.co.uk/products/motorshield-for-raspberry-pi
53 stars 47 forks source link

Nodejs package request #12

Closed mlnima closed 5 years ago

mlnima commented 5 years ago

Hi,

i wanna write with nodejs but i dont know which motor is on which pin in gpio, can tell me pin numbers ?

Thanks

GaltresIT commented 5 years ago

Hey @mlnima , Look at PiMotor.py https://github.com/sbcshop/MotorShield/blob/master/PiMotor.py

The pins config is defined in the first few lines....

''' Class to handle interaction with the motor pins
Supports redefinition of "forward" and "backward" depending on how motors are connected
Use the supplied Motorshieldtest module to test the correct configuration for your project.

Arguments:
motor = string motor pin label (i.e. "MOTOR1","MOTOR2","MOTOR3","MOTOR4") identifying the pins to which
        the motor is connected.
config = int defining which pins control "forward" and "backward" movement.
   motorpins = {"MOTOR4":{"config":{1:{"e":32,"f":24,"r":26},2:{"e":32,"f":26,"r":24}},"arrow":1},
                 "MOTOR3":{"config":{1:{"e":19,"f":21,"r":23},2:{"e":19,"f":23,"r":21}}, "arrow":2},
                 "MOTOR2":{"config":{1:{"e":22,"f":16,"r":18},2:{"e":22,"f":18,"r":16}}, "arrow":3},
                 "MOTOR1":{"config":{1:{"e":11,"f":15,"r":13},2:{"e":11,"f":13,"r":15}},"arrow":4}}

    def __init__(self, motor, config):
        self.testMode = False
        self.arrow = Arrow(self.motorpins[motor]["arrow"])
        self.pins = self.motorpins[motor]["config"][config]
        GPIO.setup(self.pins['e'],GPIO.OUT)
        GPIO.setup(self.pins['f'],GPIO.OUT)
        GPIO.setup(self.pins['r'],GPIO.OUT)
        self.PWM = GPIO.PWM(self.pins['e'], 50)  # 50Hz frequency
        self.PWM.start(0)
        GPIO.output(self.pins['e'],GPIO.HIGH)
        GPIO.output(self.pins['f'],GPIO.LOW)
        GPIO.output(self.pins['r'],GPIO.LOW)

If you are wanting to use node red, may I suggest you look at - https://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2016/04/04/controlling-motors-and-lights-with-node-red

Hope this helps.

GaltresIT commented 5 years ago

@sbcshop You can close this.

GaltresIT commented 5 years ago

I have built you an example using nodered on how you can control your motors. see - https://flows.nodered.org/flow/1a7da31268990e01902131db3bb28445

mlnima commented 5 years ago

Hi Jonathan ,

thank you so much for caring about my request :) , i am web developer and using nodeJs as backend , i wanna build big robot by using many Rasberypi together . is there any way you make some package for node js not the red node ?

Thanks in advance and Best Regards

On Sat, Feb 9, 2019 at 8:11 PM Jonathan Taylor notifications@github.com wrote:

I have built you an example using nodered on how you can control your motors. see - https://flows.nodered.org/flow/1a7da31268990e01902131db3bb28445 http://url

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sbcshop/MotorShield/issues/12#issuecomment-462071126, or mute the thread https://github.com/notifications/unsubscribe-auth/AlgcRNf43ttYNRks1Ktf9v1Wts82dj_3ks5vLx17gaJpZM4Z9WS_ .

GaltresIT commented 5 years ago

You can use ... https://github.com/fivdi/pigpio. Replace the example with the pins in my comment in your Github issue and build from there. Let me know if you have any questions.

Jonathan

On Sat, 9 Feb 2019 at 23:46, Nima Malayeri notifications@github.com wrote:

Hi Jonathan ,

thank you so much for caring about my request :) , i am web developer and using nodeJs as backend , i wanna build big robot by using many Rasberypi together . is there any way you make some package for node js not the red node ?

Thanks in advance and Best Regards

On Sat, Feb 9, 2019 at 8:11 PM Jonathan Taylor notifications@github.com wrote:

I have built you an example using nodered on how you can control your motors. see - https://flows.nodered.org/flow/1a7da31268990e01902131db3bb28445 http://url

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/sbcshop/MotorShield/issues/12#issuecomment-462071126 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AlgcRNf43ttYNRks1Ktf9v1Wts82dj_3ks5vLx17gaJpZM4Z9WS_

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sbcshop/MotorShield/issues/12#issuecomment-462090187, or mute the thread https://github.com/notifications/unsubscribe-auth/APtmDDOFj52EUp5_s17Kc1ibN1Bq9Rgxks5vL13zgaJpZM4Z9WS_ .

-- Jonathan Taylor

GaltresIT commented 5 years ago

Please close this issue