Man Cave Sign – Stepper Motor Control with chipKIT

Man Cave Stepper Motor Control with chipKIT

As a follow-on to a previous post about the “Man Cave Sign“, today’s post shares Darryl’s tutorial for how he put together the stepper motor portion of the Man Cave Sign. Note that stepper motor PCBs vary, but he assures you that they function in the same way. Check it out for all the details!

VN:F [1.9.22_1171]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

chipKIT Text-Message-Enabled Sign and Music Light Box (Man Cave Sign)



Using our DIY chipKIT-board tutorial, Darryl Gardner, a student of the University of South Florida, created something he calls the “Man Cave Sign” for his MakeCourse. This techie sign not only displays messages (via 5 LED dot matrices), reacts to playing music, and lights up in different colors (via 2 LED light strips), but is also controllable via Text Message or Android Apps (which he wrote) that allow the user to do many things like change the display message, control the stepper motor, the color of the light strips, and even make your phone talk out loud!

His PIC32BLUE(+) Android App and PIC32BTN Android App allow you to connect to your microcontroller using a Serial Bluetooth Module and do various things like send messages/commands to/from your Android phone and control things like servo motors, LED matrices, RGB lights, LCD screens or anything you’d like. He incorporates other technologies as well, like a microphone to adjust the light strip colors according to sound fluctuations in the room, a stepper motor to rotate a USF Bulls logo, and he powers it all with a 10,000mA battery for a battery life of over 10 hours.

In this Instructable, he provides more details along with a YouTube playlist of some Arduino tutorials he referenced for the project. Keep an eye out for more details on the various portions of this project! 😀

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

chipKIT Pro and Stepper Motors

A typical stepper motor
A typical stepper motor


Stepper motors seem to be the thing these days! As a follow-on to a couple of posts regarding the use of chipKIT Pro with I/O control and Delays, we want to share Learn.Digilentinc’s chipKIT Pro with Stepper Motors project, which builds upon the knowledge learned in the two previous projects and teaches you how to apply a software-based state machine approach to control the speed, rotation direction, and operation mode of stepper motors. It requires knowledge of C or C++ programming, MPLAB X IDE, finite state machines, and the two previously mentioned projects. Go get your learn on!

VN:F [1.9.22_1171]
Rating: 8.3/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Multiple Servos on chipKIT uC32

Can you do it? Yes you can! James at Digilent has put together a post to show how you can run five or more servos on chipKIT uC32 quite easily, as long as you follow some guidelines. The chipKIT Servo library makes the coding easy, so all you may have to worry about is the power consumption. Read on to find out more! 🙂
VN:F [1.9.22_1171]
Rating: 10.0/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

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

Overview

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

Procedure

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
    #include<SoftPWMServo.h>
    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
      digitalWrite(8,LOW);
      //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
      digitalWrite(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
      delay(5000);
      //Now lets brake the motor
      digitalWrite(8,HIGH);
      //Give the motor a chance to settle
      delay(500);
      //change directions
      digitalWrite(13,LOW);
      //and run the motor for about 5seconds in the other direction
      delay(5000);
      //Again, we brake the motor
      digitalWrite(8,HIGH);
      //give the motor a chance to settle
      delay(500);
      //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)

Line Following Robot with Arduino Shield

OVERVIEW:

Here is a fairly basic robot application that implements a line following algorithm. This application uses off the shelf components along with a very basic chassis built from common materials. This could be a good weekend project. The Line-Follower chassis for this Demo was constructed with 2½” wide by ¼” thick poplar project wood purchased at a local home improvement center. Note that a box was also created to house the battery holder.

HARDWARE USED

CONSTRUCTION

The Arduino Motor Shield is mounted to a chipKIT Uno32 Development Platform with all component connections made to the shield as indicated in labels next to component.  

LOGIC OVERVIEW

The line following robot is programmed to basically avoid the color black. If both sensors see black, then the robot will back up until it no longer sees black. If one sensor sees black, then the robot will turn in the direction of that sensor until it no longer sees black. Other than that, if the robot doesn’t see black on either sensor, it will simply move for- ward. In this application, the black line is created using common electrical tape. The logic for this algorithm is shown below along with a graphical representation of the front of the line following bot for reference.  

 SKETCH

 
/*
 9/10/2012
 Marc McComb

The line following robot is programmed to basically avoid the color black. If both sensors see black, 
then the robot will back up until it no longer sees black. If one sensor sees black, then the robot will
turn in the direction of that sensor until it no longer see black. Other than that, if the robot doesn’t 
see black on either sensor, it will simply move forward. In this application, the black line is created 
using common electrical tape. 

This application uses the following hardware:
chipKITâ„¢ Uno32 available at http://www.digilentinc.com/chipkit 
Arduino Motor Shield available at: http://arduino.cc/en/Main/ArduinoMotorShieldR3 
Sparkfun QRE1113 Line Sensor Board- Analog(Item #: ROB-09453) https://www.sparkfun.com/products/9453 

Software used:
The Aruino Motor shield is designed for a PWM on pin 11. Since the Uno32 doesn't have a hardware PWM 
on that pin, no worries, we just use Brian Schmaltzs SoftPWMServo library:
http://www.chipkit.org/wiki/index.php?title=Library_Status#SoftPWMServo_library 

You will need to make sure that you add the library. To do this:
1) Make sure that you have a folder in your Documents:/MPIDE folder called Libraries
2) Copy the SoftPWMServo library folder from C:\mpide-0023-windows-20120903\hardware\pic32\libraries 
    to the Libraries folder above
3) If MPIDE is open, close and reopen. 
4) Now all you have to do is go to the MPIDE toolbar and select Sketch>Import Library>SoftPWMServo

More info on libraries at:
http://arduino.cc/en/Reference/Libraries

*/

#include <SoftPWMServo.h>

//Setting up the Hardware pins
// First the line following (IR) sensors
const int irLeft = 2; //Left line sensor is on pin A2
const int irRight = 3; //Right line sensor is on pin A3

//Setting up the Arduino Motor Shield
const int leftDIR = 12; 
const int rightDIR = 13;
const int leftPWM = 3;
const int rightPWM = 11;
const int leftBrake = 9;
const int rightBrake = 8;
const char bothSpeed = 100; //sets how fast the motors will spin (0 to 255)

//Here we set up variable that will hold the ADC value representing the line sensor values
int leftSees = 0; //A2 ADC value (0 to 1023)
int rightSees = 0; //A3 ADC value (0 to 1023)

void setup() 
{ 

  //Make sure to set all of our control signal pins as output
  pinMode(leftDIR, OUTPUT); 
  pinMode(rightDIR, OUTPUT); 
  pinMode(leftBrake, OUTPUT); 
  pinMode(rightBrake, OUTPUT); 

  //Next we make sure our brake signals are set LOW
  digitalWrite(leftBrake, LOW);
  digitalWrite(rightBrake, LOW);
} 

void loop() 
{ 
    //Start by reading the left sensor on A2
  int leftEye = analogRead(irLeft);

  //delay a little bit
  delay(5);

  //next read the right sensor connected A3
  int rightEye = analogRead(irRight);

  //Next, we run the motors based on the sensor reading

  //If both sensors see black (ADC value greater than 1000), then back up
  if ((leftEye >= 1000)&&(rightEye >= 1000)) reverse();

  //Otherwise, if only the left sensor sees black, then turn off the left motor
  //so the robot veer to the left
  else if ((leftEye >= 1000)&&(rightEye < 1000)) turnLeft();

  //Otherwise, if only the right sensor sees black, then turn off the right motor
  //so the robot veer to the right
  else if ((leftEye < 1000)&&(rightEye >= 1000)) turnRight();

  //Otherwise, move forward
  else forward();

}

//Turn right by turning off the right motor 
//i.e disable the PWM to that wheel
void turnRight(void)
{
  digitalWrite(leftDIR, HIGH); 
  digitalWrite(rightDIR, HIGH);
  SoftPWMServoPWMWrite(leftPWM, bothSpeed);
  SoftPWMServoPWMWrite(rightPWM, 0);
}

//Turn left by turning off the left motor
//i.e disable the PWM to that wheel
void turnLeft(void)
{
  digitalWrite(leftDIR, HIGH); 
  digitalWrite(rightDIR, HIGH);
  SoftPWMServoPWMWrite(leftPWM, 0);
  SoftPWMServoPWMWrite(rightPWM, bothSpeed);
}

//Move forward by enabling both wheels
void forward(void)
{
  digitalWrite(leftDIR, HIGH); 
  digitalWrite(rightDIR, HIGH);
  SoftPWMServoPWMWrite(leftPWM, bothSpeed);
  SoftPWMServoPWMWrite(rightPWM, bothSpeed);
}

//Reverse by enabling both wheels 
void reverse(void)
{
  digitalWrite(leftDIR, LOW); 
  digitalWrite(rightDIR, LOW);
  SoftPWMServoPWMWrite(leftPWM, bothSpeed);
  SoftPWMServoPWMWrite(rightPWM, bothSpeed);
}
 
VN:F [1.9.22_1171]
Rating: 6.9/10 (27 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)