Pial's (We)Blog

Hobby electronics, interesting findings on the web



Recently I collected a broken hard drive to experiment on making a POV clock that I found on the web. After taking the hard drive apart, my first idea was to drive the stepper motor in the hard drive using Arduino. I looked around the web for writeup and tutorials about the principles of driving stepper motors. I particularly found this resource very useful: http://www.cs.uiowa.edu/~jones/step/. Reading this tutorial I found out the type of stepper motor the hard drive had, as there are couple of types of stepper motors available in the market. This hard drive had a Variable Reluctance Stepper Motor and the internal construction of it is like the figure below.

 . . . . . . . . 1 ---/\/\/\-  .            1 | . .      2   X   3 2 ---/\/\/\-|-- C        Y o Y |          3   X   2 3 ---/\/\/\-               1
The motor has 4 pins, the common pin is usually connected to the positive power supply and the three other pins are required to be supplied negative voltage in a sequence to get the stepper motor moving. The logic is visualized in the figure below:



Now that I understood the logic of driving the motor, I wrote up the code for Arduino. The code uses 3 arduino digital pins in output mode (Pin 2,3,4) to drive the 3 coils of the stepper motor. However the arduino digital I/O pins does not produce enough current to drive the motor coils. Therefore power transistors or Darlington array chips (ULN2003 etc.) or H-Bridge motor drive chip (L293D etc.) are required to successfully drive the motor. For the experiment I used couple of regular NPN switching transistors (2N3904). These transistors yield quite low current (around 150-200mA), so I couldn't drive the motor beyond a certain speed. I wrote the code that will start spinning the motor at a lower speed and then gradually speed up. You can play with the steppingDealy value to control the speed of the motor.

Here is the arduino code:


int pinA = 2;
int pinB = 3;
int pinC = 4;
int steppingDelay = 100;

void setup() {
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);

  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);  
}

void loop() {
  stepping(1);
  delay(steppingDelay);
  stepping(2);
  delay(steppingDelay);  
  stepping(3);
  delay(steppingDelay);
  if(steppingDelay > 10)
  {
    steppingDelay--;
  }
}

void stepping(int stage)
{
  switch(stage)
  {
  case 1:
    digitalWrite(pinA, LOW);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    break;
  case 2:
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, LOW);
    digitalWrite(pinC, HIGH);
    break;
  default:
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, LOW);
    break;
  } 
}

Arduino sketch download:

StepperTest.pde (829.00 bytes)


This is a experiment with arduino and nokia 3310 display module. I downloaded the library from http://www.nuelectronics.com/estore/index.php?main_page=product_info&products_id=12. I got the display modules from eBay and made my own simple breakout board. This demo shows the time reading from a DS1307 time keeping chip. Also demonstrates how to display a graphic image and animation on the display using the library.

Here is how it looks:

Here is a video clip:

 

Here is the arduino sketch:

Nokia3310_Clock.pde (5.80 kb)

pacman.h (5.87 kb)


I recently wrote some code to drive a 4 digit seven segment display using the arduino and 74HC595 shift register chip. The display is a seven segment common anode display with decimal dots. The pin configuration can be found here. I have connected a DS18S20 temparature sensor to read the temparature and display the reading on the seven segment display.

Here is how it looks:




Here is the arduino sketch:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

//]\const int ledPin =  13;// LED connected to digital pin 13
const int latchPin = 5;//Pin connected to ST_CP of 74HC595
const int clockPin = 6;//Pin connected to SH_CP of 74HC595
const int dataPin = 7;//Pin connected to DS of 74HC595

const int digitPins[4] = {
  8,9,10,11}; //pins to control the 4 common anode pins of the display

const byte digit[10] = //seven segment digit bits
{
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01001111, //5
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111  //9
};

int digitBuffer[4] = {
  0};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;

void setup()   {                
  TCCR2A = 0;
  TCCR2B = (1<//pinMode(ledPin, OUTPUT); 
  for(int i=0;i<4;i++)
  {
    pinMode(digitPins[i],OUTPUT);
  }
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  

  sensors.begin();
  sensors.getAddress(insideThermometer, 0);
}

ISR(TIMER2_OVF_vect) {
  soft_scaler++;
  if(soft_scaler==15)
  {
    refreshDisplay();
    soft_scaler = 0;
  }
};  

void refreshDisplay()
{
  for(byte k=0;k<4;k++)
  {
    digitalWrite(digitPins[k], LOW);
  }
  digitalWrite(latchPin, LOW);  
  shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(400);
  digitalWrite(digitPins[digitScan], HIGH); 

  digitalWrite(latchPin, LOW);  
  if(digitScan==2)
  {
    shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000)); //inserting the dot
  }
  else
  {
    shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
  }
  digitalWrite(latchPin, HIGH);
  digitScan++;
  if(digitScan>3) digitScan=0;
}

void loop()                     
{ 
  //digitalWrite(ledPin, HIGH);
  sensors.requestTemperatures();
  tempC = sensors.getTempC(insideThermometer);
  tempF = DallasTemperature::toFahrenheit(tempC);
  tmp = int(tempF*100);
  digitBuffer[3] = tmp/1000;
  digitBuffer[2] = (tmp%1000)/100;
  digitBuffer[1] = (tmp%100)/10;
  digitBuffer[0] = (tmp%100)%10;

  //digitalWrite(ledPin, LOW);
  delay(20);
}


Download the sketch from the link below: 

SevenSegmentTest.pde (2.27 kb)

If you have any questions, please feel free to ask me via the contact link.


I know this has been posted by many people already on different web sites and forums. Still I am posting the Arduino (Atmega168) fuse bit settings, as it appears in AVR Stuido 4 programming  interface:

Fuse bits:



Lock bits:



Please remember the programming sequence:

Step one: Flash the appropriate boot loader

Step two: Set the fuse bits

Step three: Set the lock bits


I hope this helps. I myself looked for this information earlier and it was not easy to find them all together.




Control panel


Blogroll


    Archive