Mastodon Politics, Power, and Science: November 2014

Thursday, November 20, 2014

Shift register using 74HC595

I used two 74HC595 chips hooked to the Serial Peripheral Interface Bus of an Arduino.   This bus will runs at 4MHz so the updates to the LEDs were very snappy.





A single chip can only control 8 LED's.  In order to control another 8 chips you have to connect a second chip to the first chip in series.   


/*
 Shift Register Example
 for 74HC595 shift register

 This sketch turns turns your arduino into a cylon.

 Hardware:
 * 74HC595 shift register attached to hardware SPI
 Arduino               74HC959
  pin# name            pin#  name
  10 SS        --->    12 RCK
  11 MOSI      --->    14 SI
  13 SCK       --->    11 SCK
 
 * LEDs attached to each of the outputs of the shift register

 Created 02 Oct 2014
 by James M. Rogers

 Based on work of others found in following locations:
 http://forum.arduino.cc/index.php/topic,149470.0.html
 http://arduino.cc/en/tutorial/ShiftOut
 http://arduino.cc/en/Tutorial/SPIDigitalPot

 */

#include <SPI.h>

int pinSS=10; //latch

int d=40;

void setup() {
  SPI.begin(); 
}

//#define d 40
void loop() {

    int i;
    for (i=0 ; i<16 ; i++) {
      registerWrite(i, HIGH);
       delay (d);
    }
    for (i=15 ; i>=0 ; i--) {
      registerWrite(i, HIGH);
       delay (d);
    }

  if (d>10)
    d-=5;
  else 
    d--;
    
    if (d==0)
      d=40;
}

// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send
  byte lowbitsToSend = 0;
  byte highbitsToSend = 0;

  if (whichPin <8) {
    // turn on the next highest bit in bitsToSend:
    bitWrite(lowbitsToSend, whichPin, whichState);
  } else {
    bitWrite(highbitsToSend, whichPin-8, whichState);
  }
  
  SPI.transfer(highbitsToSend);
  SPI.transfer(lowbitsToSend);

  digitalWrite(pinSS,LOW);
  delayMicroseconds(1);
  digitalWrite(pinSS,HIGH);
}

Picked up a Radio Shack 46 Range Multimeter (part #: 2200029) on clearance the other day

It seems like a decent multimeter, but it only came with windows software for the usb port.  I made sure that the multimeter worked through the usb port to a windows machine, and it did.  This windows software is not scriptable, and it is obviously written over a decade ago without any software updates.  The worst part is that this software limited me to only running the meter hooked to a windows desktop machine.

If I could find some software to work with the newer usb version of the meter on Linux, that would be best, but I was only able to find very old versions of the software that could not decode the format. So I just began to dump the format out and work out the coding myself.

A friend of mine sent me a link to some older command line software that worked with a previous RS-232 version of the meter, and the decoding routines worked with the usb version I have.  Unfortunately this version of the software would not release the tty after it was ran once and then the program forced to quit.  But I found even older software that couldn't decode the format, but properly handled connecting to the tty so it would disconnect on exit.

At that point I added a date and time stamp and called it done, this version is here:

https://github.com/BuckRogers1965/Examples/blob/master/Multimeter/RadioShack2200039/mmlog2200039.c

Example of the log output

But I wasn't done yet.  There are times when I need to take a reading, but can't see the LCD screen from where I am positioned. Also it might be nice if a blind person could use this meter to read out meter settings under Linux for low voltage things like Arduino or building a little circuit. So I decided to make the meter talk.  This version is here:

https://github.com/BuckRogers1965/Examples/blob/master/Multimeter/RadioShack2200039/mmSpeak.c

I am thinking of making a graphical display of the meter, and graphical view of the logging to make things easier for non Unix people who are running Linux.

I was able to do this easily because I found this example code on how to use espeak library from a post on stackoverflow.  I have a copy of the example code that I cleaned up a little bit here:

https://github.com/BuckRogers1965/Examples/blob/master/Multimeter/RadioShack2200039/espeak_example.c

The 8th-Grade Crutch: How the 2-Body Problem Broke Modern Physics

J. Rogers, SE Ohio If you want to understand why fundamental physics has been stagnant for 70 years, don’t look at String Theory or the Mult...