element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Python to Raspberry Pi to Arduino to Motors...
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 677 subscribers
  • Views 858 views
  • Users 0 members are here
  • raspberry
  • raspi
  • pi
  • gpio
  • pwm
  • motors
  • raspberry_pi
  • rpi
  • arduino
Related

Python to Raspberry Pi to Arduino to Motors...

wallarug
wallarug over 13 years ago

I have a software question based robotics question.

 

 

I know very little about Ardunio and the coding for it.  I have written some of the code that I require but I am now stuck at the Arduino Sketch.  There is two motors, a left and right motor which their speeds are defined as "a" and "b" respectivly.  All I know is that I have to use the analogWrite() command to get this to work with values between 0 and 255.  I have converted all values to work with this (ie. values between 0 - 255).

 

This is what I have so far:

 

 

[code]

/*

* Robot Motor Controller script with PWM speed control

*/

//---------------------- Motors

int motorL[] = {6, 7}

int motorR[] = {8, 9}

int ledPin = 13;

 

 

 

 

if y > 0:

  digitalWrite(motorL[0], HIGH);

  digitalWrite(motorL[1], LOW);

  digitalWrite(motorR[0], HIGH);

  digitalWrite(motorR[1], LOW);

  analogWrite(9, motor_a);

  analogWrite(6, motor_b);

 

 

if y < 0:

  digitalWrite(motorL[0], LOW);

  digitalWrite(motorL[1], HIGH);

  digitalWrite(motorR[0], LOW);

  digitalWrite(motorR[1], HIGH);

  analogWrite(9, motor_a);

  analogWrite(6, motor_b);

 

 

[/code]

 

 

Can someone please fix any Syntex errors and other errors that may be present in my code please.  I would really like this project to work as it is the most complicated I have tried with the Raspberry Pi.

 

 

What I need this to do is:

     - decide whether the motor is going forwards or backwards

     - (Based on the above) set the pins for that direction

     - Interpit the values that are given to it from the TCP server.

     - loop back continuly until the program is terminaled.

 

 

 

 

Any help will be appreciated.

 

 

For anyone who wants to know how the motors are controlled read on...

I will be controlling the robot by using a joystick on a remote computer using the pygame module.  The code for the below is below:

import pygame

[code]Removed By Request[/code]

 

 

So far, I have a TCP server and client working but I have not incorporated it in this script yet. 

 

 

I only want help on the Arduino Sketch.  The Joystick control and TCP are working nicely but the Arduino code is not working (as seen above).

 

 

Any help would be appreciated.

  • Sign in to reply
  • Cancel
Parents
  • GreenYamo
    GreenYamo over 13 years ago

    Hello Fergus,

    Will probably be worth asking this in the Arduino forum ? Although if Simon Monk pops in here (I have seen him in this forum a few times) he would probably be able to help, he is the authour of quite a few Arduino books.

    Steve

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to GreenYamo

    This is the updated sketch:

    [code]

     

    /*

    * Robot Motor Controller script with PWM speed control

    */

    //---------------------- Motors

    int motorL[] = {6, 7};

    int motorR[] = {8, 9};

    int ledPin = 13;

     

     

    void setup() {

    Serial.begin(9600);

    int i;

    for(i =0; i > 0; i < 0){

    pinMode(motorL[i], OUTPUT);

    pinMode(motorR[i], OUTPUT);

    pinMode(ledPin, OUTPUT);

    }

     

     

    }

     

     

    void loop() {

     

     

    drive_forward();

    if y > 0:

              digitalWrite(motorL[0], HIGH);

              digitalWrite(motorL[1], LOW);

              digitalWrite(motorR[0], HIGH);

              digitalWrite(motorR[1], LOW);

              analogWrite(9, motor_a);

              analogWrite(6, motor_b);

     

     

    drive_backwards();

    if y < 0:

              digitalWrite(motorL[0], LOW);

              digitalWrite(motorL[1], HIGH);

              digitalWrite(motorR[0], LOW);

              digitalWrite(motorR[1], HIGH);

              analogWrite(9, motor_a);

              analogWrite(6, motor_b);

     

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • GeorgeIoak
    GeorgeIoak over 13 years ago in reply to wallarug

    I'm not sure what type of motors you're using, perhaps servos, looking at your code? You might want to look at Adafruit's page for some helpful tips http://www.ladyada.net/make/mshield/use.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to GeorgeIoak

    They are DC motors.  I CANNOT use AF library becasue I don't have their shield.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • wallarug
    wallarug over 13 years ago in reply to GeorgeIoak

    They are DC motors.  I CANNOT use AF library becasue I don't have their shield.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube