element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Blog Controlling a robot with Raspberry Pi and Arduino
  • 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
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bernhardmayer
  • Date Created: 15 Mar 2020 10:59 PM Date Created
  • Views 5328 views
  • Likes 5 likes
  • Comments 4 comments
Related
Recommended
  • raspberrypi
  • mobile robot
  • jeccbot
  • arduino

Controlling a robot with Raspberry Pi and Arduino

bernhardmayer
bernhardmayer
15 Mar 2020

A simple can easily controlled by a single Arduino. But when the robot ( like the Open Source Outdoor Robot platform JECCbot mini  ) and its task get more complex you need a real computer to do most of the calculations. In most cases this would be a Raspberry Pi. Using only the Raspberry Pi without an additional microcontroller is also no option because the Raspberry Pi is not very good a real time tasks like controlling the motors.

 

So most robots use a combination of a computer and a microcontroller like a Raspberry Pi and an Arduino board. The structure is mostly like on the following diagram:

 

image

The low level real time tasks like motor control and some sensors are connected to the Arduino. High level tasks like path planing and image detection run on the Raspberry Pi.

 

To get a working robot the Raspberry Pi and the Arduino have to communicate heavily.

There are three types of commands which have to be exchanged:

  1. Raspberry Pi to Arduino: driving commands
  2. regular repetitive updates from Arduino to Raspberry Pi: battery level
  3. Sudden events from Arduino to Raspberry Pi: collision detection, emergency switch

 

The most common implementation is a master-slave-system where the Raspberry Pi is the master and the Arduino is the slave. Communication is always initiated by the master. This is good for type 1 commands. For type 2 commands this is acceptable. The Raspberry Pi has to poll the Arduino regularly. Because this information requires no sudden action this is OK. Type 3 commands require sudden actions. So they are not handled very well in this system. One option is to increase the polling frequency. Then the system reacts faster but also the computing and communication load is increased.

 

A typical protocol for this system is Modbus ( https://en.wikipedia.org/wiki/Modbus  ). There exist implementations for Raspberry Pi and Arduino.

You could also make your own protocol similar to the modbus protocol because you won't need all the functions of the modbus protocol. But then you still have the disadvantages mentioned above.

 

To improve the reaction on type 3 commands and keep the polling frequency low you could add an additional interrupt line. This line is activated every time a sudden event happens. Then you don't have to use your protocol to poll the status often. The disadvantage is that you have to poll the input of the trigger line with a high frequency. But this should be easier than going over USB to the Arduino. Another problem is that you need the trigger line in hardware between Arduino and Raspberry Pi. The single USB connection is now not enough.

 

To sum this up: I still haven't found the right setup to connect an Arduino and a Raspberry Pi on a robot to form a high performance system. All solutions have some disadvantages. When I find something new I will update this post.

If you have some better option I am very interested to get to know them!

  • Sign in to reply

Top Comments

  • balearicdynamics
    balearicdynamics over 5 years ago +2
    Just two questions: did you make this project? And second, how do you implement the Modbus protocol? Thanks in advance. Enrico
  • genebren
    genebren over 5 years ago +2
    Interesting project! Robots are a fun way to try new product/concept/ideas. Thanks for sharing!
  • bernhardmayer
    bernhardmayer over 5 years ago in reply to balearicdynamics +2
    Hi Enrico, Over the years I built various versions of this communication. But it was always on a reduced modbus protocol. I will post some code examples tonight. Bernhard
  • balearicdynamics
    balearicdynamics over 5 years ago in reply to genebren

    Thank you Breniman,

     

    I have already used the serial connection between the Pi and Arduino in several projects (Seven of Nine, The Scary Mirror, and others) but frankly, I have not considered using this protocol. Thank you for your update, I'll wait to see how it works; I am sure that it is better than custom protocols.

     

    Enrico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bernhardmayer
    bernhardmayer over 5 years ago in reply to balearicdynamics

    Hi Enrico,

     

    Over the years I built various versions of this communication. But it was always on a reduced modbus protocol.

     

    I will post some code examples tonight.

     

    Bernhard

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 5 years ago

    Interesting project!  Robots are a fun way to try new product/concept/ideas.  Thanks for sharing!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 5 years ago

    Just two questions: did you make this project? And second, how do you implement the Modbus protocol?

     

    Thanks in advance. Enrico

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
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