DC Motor Control using Raspberry Pi, chipKIT Pi and the Arduino Motor Control Shield


This post is intended to demonstrate compatibility of the chipKIT Pi with certain existing Arduino shields. In the second part of this post, we will also demonstrate how to communicate with the chipKIT Pi over a simple I/O line on the Raspberry Pi®, from a terminal window, to control the Arduino™ shield connected to the chipKIT Pi.

Hardware/Software Needed


Let’s begin by simply controlling a common Arduino shield. NOTE: Always check the electrical characteristics of any shield that will be connected to the chipKIT Pi. As with the Raspberry Pi, this is a 3.3V system. Therefore, if a shield outputs voltages greater than 3.3V there is a possibility that you could damage the chipKIT Pi or the Raspberry Pi. Connect the Arduino Motor Control Shield as shown:
motor shield 1
  1. Start a new sketch in MPIDE
  2. We will be using Brian Schmalz’s SoftPWMServo library for this application. This is a very flexible library that will enable a PWM (square wave) output on any pin we like. This library comes already included as a core library with the MPIDE. Therefore, to use, simply add the header file to the library at the top of your sketch as follows:
      #include <SoftPWMServo.h>
  3. The remainder of the sketch follows set up as per the Arduino Motor Control Shield specifications. I’ve added comments to explain each line of code.
    //Include the SoftPWMServo Library
    void setup() {
      //set up channel B on the Arduino Motor Control Shield
      pinMode(13, OUTPUT); //Pin 13 controls direction
      pinMode(8, OUTPUT); //Pin 8 controls the brake
    void loop() {
      //Turn the motor
      // First we disengage the brake for Channel B
      //Depending on how your motor leads are connected to the Arduino
      //motor B header, the direction could be clockwise or counter clockwise
      //So let's just start by calling this direct 1 and drive pin 13 HIGH
      //We need to send a PWM to the Arduino MC shield to start the motor
      //turning. We also define a duty cycle that will set the motor speed.
      //The higher the duty cycle, the faster the motor will turn. Duty cycle
      //is set between 0 and 255.
      //So we send the PWM to pin 11 according to the Arduino MC specs at say
      // a duty cycle of 100
      SoftPWMServoPWMWrite(11, 100);
      //Let's run the motor for about 5 seconds
      //Now lets brake the motor
      //Give the motor a chance to settle
      //change directions
      //and run the motor for about 5seconds in the other direction
      //Again, we brake the motor
      //give the motor a chance to settle
      //and repeat
So, this is nothing really special and can be done on any chipKIT Board. However, we can make something pretty interesting by introducing some Python-based communication from the Raspberry Pi to the PIC32 MCU on the chipKIT Pi. Proceed to the next page to continue.
VN:F [1.9.22_1171]
Rating: 6.5/10 (11 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)