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

Tuesday, October 14, 2014

Making an inexpensive Internet Kiosk for MyMathLab


So far I have a monitor I fixed by replacing the capacitors, a Raspberry Pi in an enclosure I 3D printed, a short vga cable, and an hdmi to VGA converter.  I booted using an older raspberian distro on an 8GB SD card.

This is the hdmi to VGA converter I ordered:  http://www.amazon.com/gp/product/B00APJL1XG/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1

It was just $5.34 with free shipping.  The shipping did take about a month from China.

(Images to follow this weekend.)

At first I got no video at all, the monitor would just go right to sleep.   It was as if the brand new adapter did not work.  I tried it on another system to confirm that it did work. A quick google search found the following site:

http://www.raspberrypi.org/forums/viewtopic.php?p=269212

Which talked about needing to edit the config.txt file on the root file of the SD card to enable HDMI.  I uncommented one of the lines after reading the comment above the line to force the Raspi to always use the HDMI port.

After I rebooted with the changed card, the display came right back up.

Now I need to get a keyboard and mouse connected to the Raspi.  After that I can start working on configuring the SD card to only run a web browser that was locked down to just a couple of sites. :D

Saturday, September 27, 2014

Got a CP2102 usb to TTL serial adapter working with home made arduino clones.


How to fix a cp2102 usb to TTL serial adapter to automatically program a hackduino that you built yourself that is lacking an on-board USB adapter.

I was having to press the rest button on my home build arduino board in order to allow it to accept the programming from the arduino software program.  This took some timing, and is just annoying. So I finally looked up on the Google how to fix the problem.
1. Cut the trace.

2. Solder a jumper from dtr to the reset pin.
Step 2 could also replace the jumper wire with a .1 uf capacitor.  A capacitor turns a low state into jus a single pulse.

This would save the cost of having a capacitor added to each board.  I go ahead and put the capacitor on each board anyway, so no capacitor needed here.

Friday, August 1, 2014

Wood Carving again.

This was 3 hours of work today.  Drawn freehand onto a small 6x6 board and then hand carved out with a few tools. The design is based on a drawing on in a book, but I just did it by looking at the drawing and then drawing something similar on the board.  I started with a small V notch and went over the drawing, then moved to a larger V notch. and went over again. Then I dug out the field between the design and border.  Now I am shaping the stem, leaves, and acorns to get a 3D like feel to the design.


I am thinking about doing a few of these to get good at them, and then giving the next few of them to all my nieces/nephews as gifts.

Wednesday, July 16, 2014

User Authentication on ruby on rails

Devise is the ruby gem we need for this.


The official guide is here:

https://github.com/plataformatec/devise

I additionally had to make app/controllers/application_controller.rb look like the following to get the sign in to happen:
class ApplicationController < ActionController::Base  # Prevent CSRF attacks by raising an exception.  # For APIs, you may want to use :null_session instead.  protect_from_forgery with: :exception
  before_filter :require_login
  before_filter :check_if_devise
  private
    def check_if_devise        if params[:controller].include? "devise/registrations" and params[:action].include? "create"        end    end
    def require_login      if not current_user and not params[:controller].include? "devise"        redirect_to new_user_session_path      end    end
end
Then I had to make app/views/layouts/application.html.erb look like this:
<!DOCTYPE html><html><head>  <title>Universalnewsaggregator</title>  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>  <%= csrf_meta_tags %></head><body><p class="navbar-text pull-right"><% if user_signed_in? %>  Logged in as <strong><%= current_user.email %></strong>.  <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> |  <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link'  %><% else %>  <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link'  %> |  <%= link_to "Login", new_user_session_path, :class => 'navbar-link'  %><% end %><p class="notice"><%= notice %></p><p class="alert"><%= alert %></p><%= yield %>
</body></html>

The user auth code I got from here:
http://guides.railsgirls.com/devise/

And at this point I finally get a login for the site that looks like this:

The commands that I used for this project.
Create the heroku project and copy the given command to check out the project locally.
git clone git@heroku.com:universalnewsaggregator.git -o heroku
rails new universalnewsaggregator
cd universalnewsaggregator
vi Gemfile
  # add in devise and other required gems.
bundle install
rake db:drop
  # just to get rid of the old similar database I had created before on first try.
rails generate devise:install
rails generate devise user
  # or instead of user, you could call it member, or whatever.
rake db:migrate
vi apps/views/layouts/application.html.erb 
vi app/controllers/application_controller.rb
vi app/views/layouts/application.html.erb
rails generate scaffold news
vi config/routes.rb
  # make sure it has the following:
  devise_for :users
  resources :news
  root "news#index"

# edit the database to use postgress
vi config/database.yml
  # put in the postgres sections

#finally push it back up
git add -A .
git commit -m "Basic Site with User authentication"
git push heroku master



Wednesday, July 2, 2014

The Supreme Court is wrong in the Hobby Lobby case.

In America we take a reduced wage in order to have that reduction pay for our medical insurance before taxes. This is just an accounting trick so that the worker doesn't pay taxes on that cost. The worker is paying for the insurance by working, not Hobby Lobby. 

If someone wasn't working for Hobby Lobby, they sure wouldn't be getting any insurance from the company.

The reform that we need to move to in America is just to outlaw all employer benefit packages and have them pay that benefit package in cash to any employee, and then allow a 100% pretax deduction for all medical insurance costs.

Just become a nation of contractors.