Friday, July 30, 2010

Corrupted Registry

Corrupted Registry?



This will be my first computer-based entry.  Many techs have found situations where a Windows PC would hang at the boot process or the PC would state that part of the registry is corrupted.  This has been seen in the past as the sort of thing that can only be fixed by either a recovery install, which basically reinstalling Windows over Windows and hoping that nothing gets messed up along the way, or a complete reinstall.

However, these two solutions are not the only solutions.  The truth is that the System Restore feature that we have enjoyed access to since it was first introduced in Windows ME can still help us even though the system is not bootable.  System Restore Point files are still on the hard drive and accessable via tools such as BartPE or other "Live" CDs.

Windows keeps the registry in the location of "C:\windows\System32\config".  System Restore makes restore points in "C:\System Volume Information\_restore{Your GUID}\_restore..." and a backup copy of your registry is contained in each restore point.  My procedure involves copying that backup copy over your current corrupted copy.  This will give you a usable registry that will let you boot the system.  After booting up you would then perform a proper System Restore.  

I have included a guide that I have developed for this procedure.  The guide is below.


References:
How to recover from a corrupted registry that prevents Windows XP from starting

Bart's Preinstalled Environment (BartPE) bootable live windows CD/DVD
http://www.nu2.nu/pebuilder/

==========================


Manual System Restore Instructions for a Corrupted Registry
Written by Nickolas Andersen, 08/01/2010
Reference:  http://support.microsoft.com/kb/307545
Notes:  
My version is modified process from the referenced Microsoft guide.  It uses a BartPE CD instead of the recovery console.  This removes unnecessary complications to the process as well as shortens the process.  You may also be able to use other "Live" CDs with my guide as well although this guide does not attempt to cover them.  
Instructions:Boot the system from your BartPE CD and drop to the command prompt.  This guide focuses on using the command line to accomplish its goal and assumes that you are familiar with the command line.  

  • Make a backup of the current registry:
    • mkdir C:\windows\system32\config\tmp
    • copy C:\windows\system32\config\system C:\windows\system32\config\tmp\system.bak
    • copy C:\windows\system32\config\software  C:\windows\system32\config\tmp\software.bak
    • copy C:\windows\system32\config\sam       C:\windows\system32\config\tmp\sam.bak
    • copy C:\windows\system32\config\security  C:\windows\system32\config\tmp\security.bak
    • copy C:\windows\system32\config\default   C:\windows\system32\config\tmp\default.bak
  • Delete the old registry:
    • del c:\windows\system32\config\system
    • del c:\windows\system32\config\software
    • del c:\windows\system32\config\sam
    • del c:\windows\system32\config\security
    • del c:\windows\system32\config\default
  • Determine the most recent system restore point
    • Example of a path to a system restore point:  C:\System Volume Information\_restore{D86480E3-73EF-47BC-A0EB-A81BE6EE3ED8}\RP1\Snapshot
    • Please note that you need to navigate (with the “cd” command) to C:\System Volume Information\ then to \_restore{GUID}\ then to RPx\Snapshot where RPx indicates each individual System Restore Point
  • Copy the registry backup from that recent System Restore point to C:\windows\config

    • Use the “copy” command to both copy and rename the files
      • Do this from the Snapshot directory of the specific System Restore Point folder that you are drawing upon:
    • copy _REGISTRY_USER_.DEFAULT C:\Windows\System32\Config\DEFAULT
    • copy _REGISTRY_MACHINE_SECURITY C:\Windows\System32\Config\SECURITY
    • copy _REGISTRY_MACHINE_SOFTWARE C:\Windows\System32\Config\SOFTWARE
    • copy _REGISTRY_MACHINE_SYSTEM C:\Windows\System32\Config\SYSTEM
    • copy _REGISTRY_MACHINE_SAM C:\Windows\System32\Config\SAM
REBOOT the system
Windows should be able to boot up now but the job is not yet complete.


Now perform a system restore from the same recent System Restore point that you used with the manual restore.




    • Click Start, and then click All Programs.
    • Click Accessories, and then click System Tools.
    • Click System Restore, and then click Restore to a previous Restore Point.
  • You can also click start, click run, and then enter %SystemRoot%\system32\restore\rstrui.exe into the run menu and click ok.  
The system should be up and running again.

Friday, June 25, 2010

Digital Potentiometers (MCP42010)

Digital Potentiometers (MCP42010)
 


Potentiometers act as voltage dividers but are also commonly configured as Rheostats (variable resistors.)  Potentiometers, or ANALOG potentiometers in this case, are used to control the volume of your radio, motor speeds, lamp dimmers, or to drive the remote control of your toy remote control car.

In my case I had such a toy car and I wanted to determine a way to use an Arduino micro-controller to drive it (and with a wireless router controlling the Arduino, which will be in a future post.)  At the time, I was unable to determine how the remote actually worked in order to build a replacement for it so I did the next best thing.  As I could not control the ANALOG potentiometers in the remote, I instead decided to learn how to use DIGITAL potentiometers instead to do what the analog potentiometers were doing.  After reading some articles by Sebastian Tomczak on the Internet, I decided that the digital potentiometer ICs that he was using would also suit my purpose as well.  His purpose was to use them for varying sounds but in effect we were both using the digital potentiometer to do the same basic thing.

I ordered 4 digital potentiometer ICs from Jamco; two dual 10k digital potentiometer ICs and two single 10k digital potentiometer ICs.  (Dual MCP42010, Single MCP41010.)  This would be my first dealing with SPI communication as that is how these chips would need to have their resistances set.  According to their data sheet, to program these chips you would need to send a "Command Byte" that told the chip what it was about to do and a "Data Byte" that told the IC what value of resistance to be set at from 0 to 255.  For example, after sending the Command Byte, a 10k potentiometer could be set at 5k by sending the data byte of 10000000, or to 2.5k by sending 01000000.

I based my SPI programing code for the digital potentiometers on the "SPI By Hand" by Sebastian Tomczak.  In this one-way SPI communication for programming the ICs, the code would call "spi_out" passing the proper ChipSelect pin, Command Byte, and the Data Byte value.  Spi_out out would handle the ChipSelect pin and then call spi_transfer which did the actual sending each of the two bytes to send.  This process is commonly known as "Bit-Banging" or "Bit-Shifting" depending on your desired level of formality.  I have included example code at the bottom of this post from my "SuperCar" program.

My initial tests of my new digital potentiometers were with LEDs.  First I coded a for loop that would gradually decrease the resistance on the LED.  Next I coded another for loop that would gradually increase the resistance of the LED.  In effect I made the LED glow.  (Youtube video below.)

Later, control of those digital potentiometers became the heart of my "SuperCar" program as the project controlled the original remote (and not the car directly.)  I have included a youtube video of an early version of "SuperCar" that shows some of the initial electronics hookups and the ability to control the car by sending commands to the digital potentiometers connected to the car's remote. 

References:
Heather Dewey-Hagborg
SEBASTIAN TOMCZAK

Serial Peripheral Interface Bus - Wiki

SPI Bit Banging
http://en.wikipedia.org/wiki/Bit-banging



Example Arduino Code:  (incomplete, but the point is demonstrated)
int CS1     = 2  ;             // 1st Digital Potentiometer IC - TURN
int CLKdpot = 4  ;             // SHARED Clock for both Digital Potentiometer ICs
int MOSI    = 5  ;             // SHARED MOSI for both Digital Potentiometer ICs
int CS2     = 8  ;             // 2nd Digital Poteniometer IC - DRIVE
byte cmd_byte2 = B00010011  ;  // Binary values for sending to both pot1 and pot2 on the Digital

int resPARK   = 100

void NoDrive()  { spi_out(CS2, cmd_byte2, resPARK);  }    // Send PARK values 

void spi_out(int CS, byte cmd_byte, byte data_byte)
{
digitalWrite (CS, LOW);       // Set the passed ChipSelect pin to low to start programming
  spi_transfer(cmd_byte);     // Send the passed COMMAND BYTE
  delay(2);
  spi_transfer(data_byte);    // Send the passed DATA BYTE
  delay(2);
digitalWrite(CS, HIGH);       // Set the passed ChipSelect pin to high to end programming
}

void spi_transfer(byte working)
{
for(int i = 1; i <= 8; i++)                          // Set up a loop of 8 iterations (8 bits in a byte)
{ if (working > 127) { digitalWrite (MOSI,HIGH) ; }  // If the MSB is a 1 then set MOSI high
else { digitalWrite (MOSI, LOW) ; }                  // If the MSB is a 0 then set MOSI low
digitalWrite (CLKdpot,HIGH) ;                        // Pulse the CLKdpot high
working = working << 1 ;                             // Bit-shift the working byte
digitalWrite(CLKdpot,LOW) ;                          // Pulse the CLKdpot low
}
}

Friday, June 18, 2010

Arduino's and Motors (using SN75441)

Arduino's and Motors (using SN75441)


I am very fortunate that I have the Internet available to me as there is so much available information available on so many subjects.  I like to think that once the user has a command or understanding of how search engines work that they have access to nearly limitless information resources.  For example, ITP Physical Computing has put together an Arduino class online that is available to the world.  Thank you very much!

Anyways, at this point I have had some experience with an Arduino motor shield that I used to test and control some small motors.  But, like anything, you can learn so much more by actually building the circuit instead of just using a ready-made solution, so I decided to do so.  I found that I had greater control over the motors and that I could put similar functionality in a smaller circuit than that which the motor shield offered, although initially the wiring would look scary.

I made a change to the original circuit suggested by ITP.  That change to the circuit was supplying SN75441  pin 8 (Vcc2) with power from a secondary battery instead of the 5v that the Arduino offered.  My reason for doing this is because powering the motors from the Arduino 5v would reset the Arduino.  I decided to relieve the stress on the Arduino and use an external battery to allow for more power to the motors. I also changed the code to allow for independent motor control via serial and I changed the use of the switch to an on/off switch for the motors.  The code is at the bottom of this post. 

Once I wired up the SN75441 motor driver IC to the Arduino and the individual motors from the dual-gearbox (bought from Sparkfun.com) I ran into a problem.  The problem was that even with only one motor on, both motors would spin which is obviously a serious problem for steering.  Sparkfun user "AdamBaba" commented that "You are only supposed to do 1 side for differential drive."  So, I removed the allen screw from the other hex nut, tested the Arduino code and found that his solution worked. 


REFERENCES:
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
http://www.sparkfun.com/commerce/product_info.php?products_id=319
http://www.ecs.umass.edu/ece/m5/tutorials/H-Bridge_tutorial.html


ARDUINO CODE:  (copy and paste)

// Basic H-Bridge Motor Driver Control 
// Author:          Nickolas Andersen
// Original Date:   06/14/2010
//                            Version 1
// Very modified version of "DC Motor Control Using an H-Bridge" from ITP Physical Computing
// http://itp.nyu.edu/physcomp/Labs/DCMotorControl

/*
  High Level Operation:
  User:     Uses serial terminal, PS2 gamepad to send commands.
  Arduino:  Accepts serial commands, PS2 gamepad commands.
  Arduino:  Controls the SN75441 Dual H-Bridge Motor Driver IC.
*/

// The switchPin allows or disallows motor control.
// The motor's "EN" pin on and set with a value. (on a PWM pin.)
// Motor1A/Motor2A (and Motor3A/4A) can be set HIGH or LOW each so that polarity (spin direction) is set.

// Global Variables
  const int switchPin = 2;    // switch input

  const int motorEN12 = 9;   
  const int motor1A   = 3;
  const int motor2A   = 4;

  const int motorEN34 = 10;
  const int motor3A   = 11;
  const int motor4A   = 12;

  const int ledPin = 13;      // LED

  char SerialValue;

  int speedvalueA = 0 ; 
  int speedvalueB = 0 ; 

void setup() {

  Serial.begin(57600);
  pinMode(switchPin, INPUT); // set the switch as an input:

  // Set Motor pins as output
  pinMode(motorEN12, OUTPUT);
  pinMode(motor1A, OUTPUT);
  pinMode(motor2A, OUTPUT);

  pinMode(motorEN34, OUTPUT);
  pinMode(motor3A, OUTPUT);
  pinMode(motor4A, OUTPUT);

  pinMode(ledPin, OUTPUT);
}

void loop()
  {
  if (Serial.available() > 0)  { Check4SerialCOMMANDS() ; }

  if (digitalRead(switchPin) == HIGH)
    {
    analogWrite(motorEN12, speedvalueA);
    digitalWrite(motor1A, HIGH);
    digitalWrite(motor2A, LOW);
   
    analogWrite(motorEN34, speedvalueB);
    digitalWrite(motor3A, HIGH);
    digitalWrite(motor4A, LOW);
    }
  else
    {
    digitalWrite(motorEN12, LOW);
    digitalWrite(motorEN34, LOW);
    digitalWrite(motor1A, LOW); 
    digitalWrite(motor2A, LOW); 
    digitalWrite(motor3A, LOW); 
    digitalWrite(motor4A, LOW); 
    }
  }


void Check4SerialCOMMANDS()
  {
  SerialValue = Serial.read() ;   // Do a serial data read.
    if (  (SerialValue==('0') or (SerialValue==(char(0)))))    {  speedvalueA = 0;   Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
    if (  (SerialValue==('1') or (SerialValue==(char(1)))))    {  speedvalueA = 51;  Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
    if (  (SerialValue==('2') or (SerialValue==(char(2)))))    {  speedvalueA = 102; Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
    if (  (SerialValue==('3') or (SerialValue==(char(3)))))    {  speedvalueA = 153; Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
    if (  (SerialValue==('4') or (SerialValue==(char(4)))))    {  speedvalueA = 204; Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
    if (  (SerialValue==('5') or (SerialValue==(char(5)))))    {  speedvalueA = 255; Serial.print("A="); Serial.print(speedvalueA); Serial.println(" "); return; } 
   
    if (  (SerialValue==('p') or (SerialValue==(char('p')))))  {  speedvalueB = 0;   Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
    if (  (SerialValue==('q') or (SerialValue==(char('q')))))  {  speedvalueB = 51;  Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
    if (  (SerialValue==('w') or (SerialValue==(char('w')))))  {  speedvalueB = 102; Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
    if (  (SerialValue==('e') or (SerialValue==(char('e')))))  {  speedvalueB = 153; Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
    if (  (SerialValue==('r') or (SerialValue==(char('r')))))  {  speedvalueB = 204; Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
    if (  (SerialValue==('t') or (SerialValue==(char('t')))))  {  speedvalueB = 255; Serial.print("B="); Serial.print(speedvalueB); Serial.println(" "); return; } 
  }


SN754410 Pinout:Function/Pin Function/Pin
1,2EN (1)    (16) Vcc1
1A    (2)    (15) 4A
1Y    (3)    (14) 4Y
GND   (4)    (13) GND
GND   (5)    (12) GND
2Y    (6)    (11) 3Y
2A    (7)    (10) 3A
Vcc2  (8)    (9)  3,4EN

Main Circuit Wiring: 
SN754410 to Arduino Hookups:
SN754410 1,2EN to  Arduino 9
SN754410 1A to Arduino 3
SN754410 1Y to Motor +
SN754410 GND to Circuit Ground
SN754410 GND to Circuit Ground
SN754410 2Y to Motor -
SN754410 2A to Arduino 4
SN754410 Vcc2 to External Battery
SN754410 3,4EN to Arduino 10
SN754410 3A to Arduino 11
SN754410 3Y to Motor +
SN754410 GND to Circuit Ground
SN754410 GND to Circuit Ground
SN754410 4Y to Motor -
SN754410 4A to Arduino12
SN754410 Vcc1 to Arduino

Friday, June 11, 2010

GPS

BACKSTORY:
Back sometime in 2006 I had a Nokia E70-2 cellphone that seemed pretty advanced for it's time, and it was. It had Bluetooth and Wi-Fi and an Internet browser. Very shortly after purchasing the phone I decided that I wanted to use it's "GPS" features. These features could be accessed via an external, Bluetooth adapter and Nokia sold one such model for way too much money. I decided on buying a Bluetooth-enabled Holux M-1200 model. Although the GPS unit worked, the phone had poor support for it and the GPS unit lived in a dark box somewhere... until recently.

THE GOOD STUFF:
The Holux M-1200 GPS unit also had a "GPS Mouse" feature. In nerd-speak (my language) this meant that it was very possible that there was a serial-connection available to the unit that could be used to connect to it to use it's GPS data. Holux sells a cable for $20 or so that would allow access to this feature. However, upon investigation, I was able to determine that the cable would be no different than the FTDI cable that I used with my BoArduino. The BoArduino has a serial port but at the much lower +5 TTL levels. Normal RS-232 voltages would kill it as the the standard uses +12V and −12V (or plus or minus 3 to 15 volts.) My FTDI cable used a USB port and provided a serial port at +5 TTL levels on the other end (Model TTL-232R-5.0v) I tested the outputs of the Holux GPS unit and was able to determine that it used +3.3v logic levels, but not +5v logic levels. I did some research on the FTDI cable and the Arduino chip (ATMEGA328P) and discovered that data could be received from the GPS unit safely as a "1" from the GPS unit would still be recognized as a "1" by the Arduino. Transmitting back to the GPS at the higher logic level (5v vs 3.3) may damage the GPS unit so I only hooked up the receive as that was all that I really needed. The GPS unit may have been able to tolerate the higher voltage coming at it but I decided that it wasn't really all that important to be able to talk to the GPS at this point. In the future I may use resistors or a logic-level-shifter to communicate with the GPS.

MOVING ON:
So, after hooking the mini USB plug end from one of those "universal USB cables" and then to the Arduino/FTDI, I was able to test the GPS unit. It worked and I then connected it to the Arduino and was able to see GPS strings from the unit. I soon found the TinyGPS Arduino library written by Mikal Hart. This quickly enabled me to interpret the GPS strings from my device (although I would like to create my own library that can interpret more types of GPS strings.) TinyGPS was easy to use after reading through the code and it got me up to speed pretty quickly. For the second part of the project, I wired in a Serial-LCD that I got from Sparkfun. I put together some Arduino code (sketch) and had the Arduino output the longitude and latitude, bearing and GPS time (+8 hours for my time zone) to the LCD screen.

The next 3 hours involved walking around my block with what essentially looked like a bunch of wires and glowing lights on a clipboard. Later on I made my first attempt at GEOCACHING... however, the coordinates from geocaching.com were NOT within the 1 mile radius that I requested. Seeing the signs for customs to Canada quickly encouraged me to do a reality check on those GPS coordinates and they turned out to be for CANADA! Next time I begin, I'll remember to do a reality check. :)

Thanks to Awesome Electronics Workshop w/ Joe Grand and Bre Pettis for the inspiration for this project.

REFERENCES:
http://blog.makezine.com/archive/2007/07/integrate_lcd_and_gps_mod_1.html
http://www.geocaching.com
http://arduiniana.org/libraries/tinygps/
http://arduiniana.org/libraries/newsoftserial/
http://en.wikipedia.org/wiki/RS-232
http://www.gpsinformation.org/dale/nmea.htm
http://www.sparkfun.com/datasheets/GPS/NMEA%20Reference%20Manual1.pdf
http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF