Posts: 24
Joined: Wed May 11, 2016 3:56 am

Moving a Motor

Wed Oct 12, 2016 2:17 am

Below is a code that moves my motor through connection to the arduino. My arduino is serially connected to the pi for which transmission of data is handled through the nanpy motor drivers are connected to my arduino...

Code: Select all

from nanpy import (ArduinoApi, SerialManager)
from time import sleep

directionPin1 = 38
directionPin2 = 40
pwmPin = 5
speedVal = 100
stopVal = 0

    connection = SeriaManager()
    a = ArduinoApi(connection = connection)
    print¨Failed to connect to arduino¨

#setup the pinmodes as if we were in ARDUINO IDE
a.pinMode(directionPin1, a.OUTPUT)

    a.digitalWrite(directionPin1, a.LOW)
    a.digitalWrite(directionPin2, a.HIGH)
    a.analogWrite(pwmPin, speedVal)

    a.analogWrite(pwmPin, stopVal)

    a.digitalWrite(directionPin1, a.HIGH)
    a.digitalWrite(directionPin2, a.LOW)
    a.analogWrite(pwmPin, speedVal)

    a.analogWrite(pwmPin, stopVal)

except KeyboardInterrupt:
When you use the nanpy firmware, its as if you are wrting on the arduino ide....with a ArduinoApi connection prefix attached in front of the arduino syntaxes....

My question is such that how will i write this code to be a function so that i can call it or execute it when a particular parameter of my main code changes....


Posts: 9
Joined: Thu Nov 19, 2015 2:13 am
Contact: Website

Re: Moving a Motor

Wed Oct 12, 2016 4:08 am

Have you solved this issue. I am working on a similar project and is unable to do the communication between arduino and raspberry Pi 3 so if someone knows the solution please share it here. I am using the Visual Studio to get the data from Arduino and I am following this tutorial How to use Serial Port in VB2010.

You should also check The Engineering Projects because they have posted a lot of Arduino Projects and PIC Microcontroller Projects and have also designed many new Proteus Tutorials and C# Tutorial and MATLAB Projects and LabView Projects and Engineering Projects . I hope you guys are gonna like them.
Last edited by theenggprojects on Tue Jan 10, 2017 12:08 am, edited 1 time in total.

Posts: 1
Joined: Fri Oct 28, 2016 9:12 am

Re: Moving a Motor

Fri Oct 28, 2016 9:25 am

This is a site that help me a lot when trying to use nanny: ... ith-nanpy/. The project is quite advanced so I am guessing you will find you answer it you look through there code (or perhaps just there website). The link to there code from here:

Hope this helps.

Return to “Beginners”