4 Apr 2012

Mass Effect 3 - online HUD








Timer displays remaining time to reach mission goal or for shuttle extraction.

6 Mar 2012

Mass Effect 3

Wohooo, Mass Effect 3 is finally here.


gEDA pcb command line arguments

These are the command line arguments for pcb version 20110918:

PCB Printed Circuit Board editing program, http://pcb.gpleda.org
pcb [-h|-V|--copyright]   Help, version, copyright
pcb [gui options]   to edit
Available GUI hid:
 gtk      Gtk - The Gimp Toolkit
pcb -p [printing options]  to print
Available printing hid:
 lpr      Postscript print
pcb -x hid [export options]  to export
Available export hids:
 bom      Exports a Bill of Materials
 gcode    G-CODE export
 gerber   RS-274X (Gerber) export
 nelma    Numerical analysis package export
 png      GIF/JPEG/PNG export
 ps       Postscript export
 eps      Encapsulated Postscript

gtk gui options:
 --listen                       Listen for actions on stdin
 --bg-image             Background Image
 --pcb-menu             Location of gpcb-menu.res file

lpr options:
 --lprcommand           Command to use for printing
 --drill-helper                 Print a centering target in large drill holes
 --align-marks                  Print alignment marks on each sheet
 --outline                      Print outline on each sheet
 --mirror                       Print mirror image of every page
 --fill-page                    Scale board to fill page
 --auto-mirror                  Print mirror image of appropriate layers
 --ps-color                     Prints in color
 --ps-bloat            Amount to add to trace/pad/pin edges
 --ps-invert                    Draw objects as white-on-black
 --media 

   media type
 --psfade                  Fade amount for assembly drawings (0.0=missing, 
1.0=solid)
 --scale                   Scale value to compensate for printer sizing 
errors (1.0 = full scale)
 --multi-file                   Produce multiple files, one per page, instead 
of a single file
 --xcalib                  Paper width. Used for x-Axis calibration
 --ycalib                  Paper height. Used for y-Axis calibration
 --drill-copper                 Draw drill holes in pins / vias, instead of 
leaving solid copper
 --show-legend                  Print file name and scale on printout

bom options:
 --bomfile              Name of the BOM output file
 --xyfile               Name of the XY output file
 --xy-unit  XY units

gcode options:
 --basename             File name prefix
 --dpi                     Resolution of intermediate image (pixels/inch)
 --mill-depth              Milling depth
 --safe-Z                  Safe Z for traverse move
 --tool-radius             Milling tool radius compensation
 --drill-depth             Drilling depth
 --measurement-unit  Measurement unit

gerber options:
 --gerberfile           Gerber output file base
 --all-layers                   Output all layers, even empty ones
 --verbose                      Print file names and aperture counts on stdout
 --copy-outline  Copy outline onto other layers
 --name-style 
   Naming style for individual gerber files

nelma options:
 --basename             File name prefix
 --dpi                     Horizontal scale factor (grid points/inch)
 --copper-height           Copper layer height (um)
 --substrate-height        Substrate layer height (um)
 --substrate-epsilon       Substrate relative epsilon

png options:
 --outfile              Graphics output file
 --dpi                     Scale factor (pixels/inch). 0 to scale to 
specified size
 --x-max                   Maximum width (pixels).  0 to not constrain
 --y-max                   Maximum height (pixels).  0 to not constrain
 --xy-max                  Maximum width and height (pixels).  0 to not 
constrain
 --as-shown                     Export layers as shown on screen
 --monochrome                   Convert to monochrome
 --only-visible                 Limit the bounds of the PNG image to the 
visible items
 --use-alpha                    Make the background and any holes transparent
 --format         Export file format
 --png-bloat            Amount (in/mm/mil/pix) to add to trace/pad/pin 
edges (1 = 1/100 mil)
 --photo-mode                   Photo-realistic export mode
 --photo-flip-x                 Show reverse side of the board, left-right flip
 --photo-flip-y                 Show reverse side of the board, up-down flip

ps options:
 --psfile               Postscript output file
 --drill-helper                 Print a centering target in large drill holes
 --align-marks                  Print alignment marks on each sheet
 --outline                      Print outline on each sheet
 --mirror                       Print mirror image of every page
 --fill-page                    Scale board to fill page
 --auto-mirror                  Print mirror image of appropriate layers
 --ps-color                     Prints in color
 --ps-bloat            Amount to add to trace/pad/pin edges
 --ps-invert                    Draw objects as white-on-black
 --media 

   media type
 --psfade                  Fade amount for assembly drawings (0.0=missing, 
1.0=solid)
 --scale                   Scale value to compensate for printer sizing 
errors (1.0 = full scale)
 --multi-file                   Produce multiple files, one per page, instead 
of a single file
 --xcalib                  Paper width. Used for x-Axis calibration
 --ycalib                  Paper height. Used for y-Axis calibration
 --drill-copper                 Draw drill holes in pins / vias, instead of 
leaving solid copper
 --show-legend                  Print file name and scale on printout

eps options:
 --eps-file             Encapsulated Postscript output file
 --eps-scale               EPS scale
 --as-shown                     Export layers as shown on screen
 --monochrome                   Convert to monochrome
 --only-visible                 Limit the bounds of the EPS file to the visible 
items

Common options:
 --help                         Show help on command line options
 --version                      Show version
 --verbose                      Be verbose on stdout
 --copyright                    Show Copyright
 --show-defaults                Show option defaults
 --show-actions                 Show available actions
 --dump-actions                 Dump actions (for documentation)
 --grid-units           Default grid units (mm|mil)
 --black-color          color value of 'black'
 --white-color          color value of 'white'
 --background-color     color for background
 --crosshair-color      color for the crosshair
 --cross-color          color of the cross
 --via-color            color of vias
 --via-selected-color   color for selected vias
 --pin-color            color of pins
 --pin-selected-color   color of selected pins
 --pin-name-color       color for pin names and pin numbers
 --element-color        color of components
 --rat-color            color of ratlines
 --invisible-objects-color  color of invisible objects
 --invisible-mark-color  color of invisible marks
 --element-selected-color  color of selected components
 --rat-selected-color   color of selected rats
 --connected-color      color to indicate connections
 --off-limit-color      color of off-canvas area
 --grid-color           color of the grid
 --layer-color-1        Color for layer 1
 --layer-color-2        Color for layer 2
 --layer-color-3        Color for layer 3
 --layer-color-4        Color for layer 4
 --layer-color-5        Color for layer 5
 --layer-color-6        Color for layer 6
 --layer-color-7        Color for layer 7
 --layer-color-8        Color for layer 8
 --layer-color-9        Color for layer 9
 --layer-color-10       Color for layer 10
 --layer-color-11       Color for layer 11
 --layer-color-12       Color for layer 12
 --layer-color-13       Color for layer 13
 --layer-color-14       Color for layer 14
 --layer-color-15       Color for layer 15
 --layer-color-16       Color for layer 16
 --layer-selected-color-1  Color for layer 1 when selected
 --layer-selected-color-2  Color for layer 2 when selected
 --layer-selected-color-3  Color for layer 3 when selected
 --layer-selected-color-4  Color for layer 4 when selected
 --layer-selected-color-5  Color for layer 5 when selected
 --layer-selected-color-6  Color for layer 6 when selected
 --layer-selected-color-7  Color for layer 7 when selected
 --layer-selected-color-8  Color for layer 8 when selected
 --layer-selected-color-9  Color for layer 9 when selected
 --layer-selected-color-10  Color for layer 10 when selected
 --layer-selected-color-11  Color for layer 11 when selected
 --layer-selected-color-12  Color for layer 12 when selected
 --layer-selected-color-13  Color for layer 13 when selected
 --layer-selected-color-14  Color for layer 14 when selected
 --layer-selected-color-15  Color for layer 15 when selected
 --layer-selected-color-16  Color for layer 16 when selected
 --warn-color           color of offending objects during DRC
 --mask-color           color for solder mask
 --via-thickness       default diameter of vias in 1/100 mil
 --via-drilling-hole   default diameter of holes
 --line-thickness      initial thickness of new lines
 --rat-thickness       thickness of rat lines
 --keepaway            minimum distance between adjacent copper
 --default-PCB-width   default width of the canvas
 --default-PCB-height  default height of the canvas
 --text-scale              default text scale in percent
 --alignment-distance  distance between the boards outline and 
alignment targets
 --bloat               DRC minimum spacing in 1/100 mil
 --shrink              DRC minimum overlap in 1/100 mils
 --min-width           DRC minimum copper spacing
 --min-silk            DRC minimum silk width
 --min-drill           DRC minimum drill diameter
 --min-ring            DRC minimum annular ring
 --grid                Initial grid size in 1/100 mil
 --minimum polygon area   
 --backup-interval         Time between automatic backups in seconds. Set 
to 0 to disable
 --layer-name-1         Name for layer 1
 --layer-name-2         Name for layer 2
 --layer-name-3         Name for layer 3
 --layer-name-4         Name for layer 4
 --layer-name-5         Name for layer 5
 --layer-name-6         Name for layer 6
 --layer-name-7         Name for layer 7
 --layer-name-8         Name for layer 8
 --groups               Layer group string
 --font-command         Command to load a font
 --file-command         Command to read a file
 --element-command      Command to read a footprint
 --print-file           Command to print to a file
 --lib-command-dir      Path to the command that queries the library
 --lib-command          Command to query the library
 --lib-contents-command 
   Command to query the contents of the library
 --lib-newlib           Top level directory for the newlib style library
 --save-command         Command to save to a file
 --lib-name             The default filename for the library
 --default-font         File name of default font
 --route-styles         A string that defines the route styles
 --file-path           
 --rat-command          Command for reading a netlist
 --font-path            Colon separated list of directories to search 
the default font
 --element-path         A colon separated list of directories or 
commands (starts with '|')
 --lib-path             A colon separated list of directories
 --action-script        If set, this file is executed at startup
 --action-string        If set, this is executed at startup
 --fab-author           Name of author to be put in the Gerber files
 --layer-stack          Initial layer stackup, for setting up an export.
 --make-program         Sets the name and optionally full path to a 
make(3) program
 --gnetlist             Sets the name and optionally full path to the 
gnetlist(3) program
 --pinout-offset-x     Horizontal offset of the pin number display in 
mil
 --pinout-offset-y     Vertical offset of the pin number display in mil
 --pinout-text-offset-x 
   Horizontal offset of the pin name display in mil
 --pinout-text-offset-y 
   Vertical offset of the pin name display in mil
 --draw-grid                    If set, draw the grid at start-up
 --clear-line                   If set, new lines clear polygons
 --full-poly                   
 --unique-names                 Prevents identical component names
 --snap-pin                     If set, the cursor snaps to pads and pin centers
 --save-last-command           
 --save-in-tmp                  When set, all data which would otherwise be 
lost are saved in /tmp
 --all-direction-lines          Allow all directions, when drawing new lines
 --show-number                  Pinout shows number
 --reset-after-element          If set, all found connections are reset before 
a new component is scanned
 --ring-bell-finished           Execute the bell command when all rats are 
routed

.

14 Feb 2012

Mmmmh, Raspberry Pi

It looks like we can soon play with the Raspberry Pi.

Their slogan: «An ARM GNU/Linux box for $25. Take a byte!»

The RasPi is an ARM based is a cheap education computer running various Operating Systems (Linux, Android, Risc OS, Risc iX and probably more). The board comes in two flavours; $25 without and $35 with ethernet (and 256MB instead of 128MB ram). This is great hardware for tinkering. It has a hand full of GPIO ports, SPI, I2C, UART, USB, Ethernet on board as well as a HDMI/Composite output.

 



 Spcifications


Model A Model B
Target price:[1] US$25 (GBP £16) US$35 (GBP £22)
System-on-a-chip (SoC):[1] Broadcom BCM2835 (CPU + GPU + SDRAM)
CPU: 700 MHz ARM11 ARM1176JZF-S core
GPU: Broadcom VideoCore IV,OpenGL ES 2.0,OpenVG 1080p30 H.264 high-profile encode/decode
Memory (SDRAM): 128 MiB 256 MiB
USB 2.0 ports: 1(provided by the BCM2835) 2 (via integrated USB hub)
Video outputs:[1] Composite video|Composite RCA, HDMI (not at the same time)
Audio outputs:[1] TRS connector|3.5 mm jack, HDMI
Audio inputs: none, but a USB mic or sound-card could be added
Onboard Storage: Secure Digital|SD / MMC / SDIO card slot
Onboard Network:[1] None 10/100 wired Ethernet RJ45
Low-level peripherals: General Purpose Input/Output (GPIO) pins, Serial Peripheral Interface Bus (SPI), I²C, I²S[2], Universal asynchronous receiver/transmitter (UART)
Real-time clock:[1] None
Power ratings (provisional, from alpha board): 500mA, (2.5 Watt) [1] 700mA, (3.5 Watt)
Power source:[1] 5V via Micro USB or GPIO header
Size: 85.60mm x 53.98mm[3] (3.370 × 2.125 inch)

(Provisional - some of the expansion interfaces won't be available on production boards) (PCB IDs are those of the Model B Beta board)
  • SoC: Broadcom BCM2835 media processor (partial datasheet, BCM2835 datasheet errata) system-on-chip featuring:
    • CPU core: ARM1176JZF-S ARM11 core clocked at 700MHz; ARM VFP. The ARM11 core implements the ARMv6 Architecture. For details on ARM instruction sets and naming conventions, see ARM architecrture and List of ARM microprocessor cores.
    • GPU core: a Broadcom VideoCore IV GPU providing OpenGL ES 1.1, OpenGL ES 2.0, hardware-accelerated OpenVG 1.1, Open EGL, OpenMAX and 1080p30 H.264 high-profile decode. There are 24 GFLOPS of general purpose compute and a bunch of texture filtering and DMA infrastructure. Eben worked on the architecture team for this and the Raspberry Pi team are looking at how they can make some of the proprietary features available to application programmers
    • DSP core: There is a DSP, but there isn't currently a public API (Liz thinks the BC team are keen to make one available at some point)
    • RAM: 128MiB (Model A) or 256MiB (Model B) of SDRAM. The RAM is physically stacked on top of the Broadcom media processor (package-on-package technology)
  • LAN9512 (Data Brief | Data Sheet)(Model B) providing:
    • 10/100Mb Ethernet (Auto-MDIX)[4]
    • 2x USB 2.0
  • S1: Micro USB power jack (5v - Power Only)
  • S2: DSI interface. 15-pin surface mounted flat flex connector (possibly no-fit).
  • S3: HDMI connector providing HDMI 1.3a out
  • S4: Composite Video connector: RCA
  • S5: MIPI CSI-2 interface. 15-pin surface mounted flat flex connector (possibly no-fit).
  • S6: Audio connector: 3.5mm stereo jack (output only)
  • S8: SD/MMC/SDIO memory card slot (underside)
  • S7: Either 1x USB 2.0 (Model A) 2x USB 2.0 (Model B)
  • P1: 26-pin 2.54mm header expansion (header not fitted), providing: see Low-level peripherals
    • 8 GPIOs at 3v3
    • 2-pin UART serial console, 3v3 TTL (debug); or 2 GPIOs at 3v3
    • I2C interface (3v3); or 2 GPIOs at 3v3
    • SPI interface (3v3); or 5 GPIOs at 3v3
    • 3v3, 5v and GND supply pins
    • ARM JTAG (if pins are reconfigured in software)
    • Second I2C interface (3v3) (if pins are reconfigured in software)
    • I2S interface (if pins are reconfigured in software, hardware hack may be required[2])
    • 6 pins reserved for future use
  • P2 and P3: 8-pin and 7-pin 2.54mm header expansion (header not fitted), providing:
    • 6-pin GPU JTAG (ARM11 pinout)
  • P4: 10/100Mb RJ45 Ethernet jack (Model B)
  • 5 Status LEDs[5][6][7]:
    • D5(Yellow) - OK - SDCard Access (via GPIO16)
    • D6(Red) - PWR - 3.3V Power
    • D7(Green) - FDX - Full Duplex (LAN) (Model B)
    • D8(Green) - LNK - Link/Activity (LAN) (Model B)
    • D9(Yellow) - 10M - 10/100Mbit (LAN) (Model B)


  • Board size: 85.60mm x 53.98mm. Overall height expected to be less than 25mm. [8]
  • Weight: <40g? (Alpha board weighs ~55g [9])
  • 6 layer PCB [8]





5 Feb 2012

Python - Convert google Calendar ICS to CSV

#!/usr/bin/env python

import urllib2
from icalendar import Calendar#, Event

outfile = "output.xls"
theurl = 'https://...'
username = 'xxx'
password = 'xxx'

QUOTE='"'
DELIM_FIELD = ","
DELIM_ROW   = "\n"
DATE_FORMAT = "%d.%m.%Y"
# a great password

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# this creates a password manager
passman.add_password(None, theurl, username, password)
# because we have put None at the start it will always
# use this username/password combination for  urls
# for which `theurl` is a super-url

authhandler = urllib2.HTTPBasicAuthHandler(passman)
# create the AuthHandler

opener = urllib2.build_opener(authhandler)

urllib2.install_opener(opener)
# All calls to urllib2.urlopen will now use our handler
# Make sure not to include the protocol in with the URL, or
# HTTPPasswordMgrWithDefaultRealm will be very confused.
# You must (of course) use it when fetching the page though.

pagehandle = urllib2.urlopen(theurl)
# authentication is now handled automatically for us

if pagehandle.code != 200:
 print "Something went wrong. HTTP response code: %s" % pagehandle.code

fp = open(outfile,'wb')
fp.write(QUOTE)
fp.write("Start")
fp.write(QUOTE)
fp.write(DELIM_FIELD)
fp.write(QUOTE)
fp.write("End")
fp.write(QUOTE)
fp.write(DELIM_FIELD)
fp.write(QUOTE)
fp.write("Days")
fp.write(QUOTE)
fp.write(DELIM_FIELD)
fp.write(QUOTE)
fp.write("Summary")
fp.write(QUOTE)
fp.write(DELIM_ROW)

cal = Calendar.from_string(pagehandle.read())
for component in cal.walk():
 if component.name == "VEVENT":
  fp.write(QUOTE)
  fp.write(component['dtstart'].dt.strftime(DATE_FORMAT))
  fp.write(QUOTE)
  fp.write(DELIM_FIELD)
  days = (component['dtend'].dt-component['dtstart'].dt).days
  fp.write(QUOTE)
  if (days > 1):
   fp.write(component['dtend'].dt.strftime(DATE_FORMAT))
  fp.write(QUOTE)
  fp.write(DELIM_FIELD)
  fp.write(QUOTE)
  fp.write(str(days))
  fp.write(QUOTE)
  fp.write(DELIM_FIELD)
  fp.write(QUOTE)
  fp.write(component['summary'])
  fp.write(QUOTE)
  fp.write(DELIM_ROW)

fp.close()

23 Dec 2011

Fireworks, Revision 3

The 3rd one is always a good one ;)

Firmware (arduino C++ code), Layout as PDF.

Revision 3 of the fireworks board:

All layers.
Bottom layer.
Top layer.

Everything is now much tighter packed! I decided to use RJ45 to connect every six-pack of rockets (spare 2 pins used as 12V power supply). The arduino's FTDI port can be easily used with an FTDI breakout board.


Lession learned:
  • Use small pads only where needed (in tight spots)
  • Pull out all available ɥC pins
  • plan mount holes
  • put as much as possible onto the lower layer (easier to solder)
  • 8705 is a very useful power regulator when used with 3-5 cell LIPOs
Hardware documentation is available as PDF or you can get the whole source code including pcb (beta version).

21 Dec 2011

Fireworks, the first prototype PCB

Yay, today I made the first prototype PCB. Already soldered the absolute minimum onto it for tesing.

Top layer, with Arduino Pro mini 5V (top) and a single 8 bit shift register (below the Arduino).

Bottom layer.
The final layout will certainly differ from this a bit. I did not know how painful it is to solder headers which have connections on the front layer. Thanks to swiss machine pins it is possible without funny chemicals.

Also, the copper around  the via and pin holes are much too small. They make drilling and sometimes proper soldering very hard. It's just looks ugly too.

Further more, a new design decision was to use RJ45 as connector for the expansion to the electric fuses (connectors at the bottom).

Back to the drawing board!

18 Dec 2011

Fireworks!

Not much time left until it is Silvester. The remote controlled fireworks launcher is in prototyping stage. I got the first PCB layout together.

The pcb files are created with an open source program called pcb (free as in free code and free of charge) which should compile on nearly all UNIX like operating systems (incuding, osx, cygwin or mingw for windows).

The pcb application is also able to generate gerber files which are included in the pcb files download.

Some alpha code (written in C)  is available to be run on an Arduino Pro Min 5V.

This project builds on the knowledge gathered from 8 bit shift registers and Arduino in general.

Special thanks goes to Sämi for all his valuable input.

Circuit



Front side



Back side

11 Nov 2011

Mass Effect 2 in english

How to change the language settings of Mass Effect 2:

Edit "%CommonProgramFiles(x86)%\Steam\SteamApps\common\mass effect 2\data\sku.ini", set it to INT for English.

[SKU]
SKU=
VOLanguage=INT
TextLanguage=INT

Available languages:
  • FR - French
  • IT - Italian
  • DE - German
  • SP - Spanish
  • INT – English

26 Oct 2011

Export SVG vector graphic to different sizes of PNG

#!/usr/bin/env bash

function export() {
 width=$1
 height=$2
 
 inkscape -w $width -h $height \
  -e app_icon_${width}x${height}.png app_icon.svg
}

export 72 72
export 48 48
export 36 36

13 Oct 2011

Finally, a three some (74HC595)!

As a follow up to the first tests with the 74HC594 and 74HC595 with Arduino I got some more 595 delivered, finally chaining them together. This example uses the 74HC595 chip.



Code:

First, you need to install (extract) the MM74HC595 library I wrote into your "<\libraries>" folder.

/**
 * Board: Pro Mini 5V
 * 
 * Chained 74HC595 8 bit shift register demo. Knight Rider!
 *
 * $Id: test_74HC595.pde 319 2011-10-13 20:48:10Z wunderlins $
 */

// how many shift registers are we using in serie? (must be >=1)
#define NUM_SHIFT_REGISTERS 3

// include library (must be installed unter <sketches>/libraries/MM74HC595/)
// http://spliffy.freeshell.net/hardware/MM74HC595.zip
#include <MM74HC595.h>

/**
 * Arduino pins:
 * 
 * PIN_SER: is the arduino serial pin
 * PIN_SCK: is the arduino pin for the shift register
 * PIN_RCK: is the arduino pin for the output register
 */
int PIN_SER = 8;  // pin 14 on the 75HC595
int PIN_SCK = 9;  // pin 12 on the 75HC595
int PIN_RCK = 10; // pin 11 on the 75HC595

int i = 0;
int direction = 1; // 1 = L2R, -1 R2L

// shift register instance
MM74HC595 registers(PIN_SER, PIN_SCK, PIN_RCK, NUM_SHIFT_REGISTERS);

// module pins already initialzed
void setup() {;}               

void loop(){
 
 // reset all pins (set to LOW)
 registers.reset();
 
 // set pin(s) to high
 registers.set(i, true);
 
 // activate outputs
 registers.update();
 
 // check if we have to change direction
  if (i+1 == NUM_SHIFT_REGISTERS * 8) {
   direction = -1;
  } else if (i == 0) {
   direction = 1;
  }
  i += direction;

  delay(100);
}


12 Oct 2011

Moore's law slowing down?

According to Bunnie Huang moore's law is slowing down to doubling transistor density every 24 months (instead of 18 according to moore's law):


Full article: http://www.sparkfun.com/news/722

11 Oct 2011

Succesfull flight in Auto Mode

Finally the airspeed sensor is working, here is a plot of the last autonomous flight of the funjet (APM Auto mode):



Knight Rider with 74HC594 8 bit shift register

Please note, the next article «Finally a threesome» includes an arduino library for the 74HC595 (not for the 74HC594) and probably obsoletes this post.



As a follow up to the bit shift register (74HC595) example I ordered some more of these. Unfortunately MM74HC594 (Datasheet) were delivered. These chips are a bit more complicated to handle. Here is the same example as in the previous post:


As a byproduct of the above drawing,  I have created a Fritzing part for the 74HC594 chip.


Code:

/**
 * Board: Pro Mini 5V
 * 
 * Chained 74HC595 8 bit shift register demo. Knight Rider!
 *
 * Based on: http://bildr.org/2011/02/74hc595/
 * 
 * $Id: test_74HC595.pde 309 2011-10-13 18:50:44Z wunderlins $
 */

int PIN_SER = 8;   //pin 14 on the 75HC595
int PIN_SCK = 9;  //pin 12 on the 75HC595
int PIN_RCK = 10; //pin 11 on the 75HC595

// how many shift registers are chained? (must be >=1)
#define NUM_SHIFT_REGISTERS 3

// store all LED states in this array. every element of the array stores a 
// binary mask of of 8 pin states (per chip).
uint8_t pins[NUM_SHIFT_REGISTERS];

// reset all chips to 0
void sr_reset() {
 for(int i=0; i<NUM_SHIFT_REGISTERS; i++)
  pins[i] = 0;
}

// set a pin high or low. if you have 1 chip use pins 0-7, if youhave 2 chips
// you might use 0-7, 8-15 as pin numbers. state sets LED on (true) or 
// off (false)
void sr_set(int pin, bool state) {
 
 // check which register to manipulate
 int current = pin / 8;
 int p = pin - current*8;
 
 if (state == true) // set pin to true
  pins[current] |= 1 << p;
 else { // set pin to false
  int tmp = ~pins[current];
  tmp |= 1 << p;
  pins[current] = ~tmp;
 }
 
}

// check if pin is set to high
boolean sr_isset(int pin) {
 int current = pin / 8;
 int p = pin - current*8;
 if ((1 << p) & pins[current])
  return true;
 return false;
}

// move data into shift register and from there into storage at once. make 
// sure to fill the shift pins before acitivating the storage pins.
void sr_update() {
 
 digitalWrite(PIN_SCK, LOW);
 
 // set state
 for(int i=8 * NUM_SHIFT_REGISTERS - 1; i >= 0 ; i--) {
  digitalWrite(PIN_RCK, LOW);
  
  if (sr_isset(i))
   digitalWrite(PIN_SER, HIGH); // ON
  else
   digitalWrite(PIN_SER, LOW); // OFF

  digitalWrite(PIN_RCK, HIGH);
 }
 
 digitalWrite(PIN_SCK, HIGH);
}

void setup(){
  pinMode(PIN_SER, OUTPUT);
  pinMode(PIN_SCK, OUTPUT);
  pinMode(PIN_RCK, OUTPUT);

 // initialize pin state
 sr_reset();
 
}               

int i = 0;
int direction = 1; // 1 = L2R, -1 R2L
void loop(){
 
 sr_reset();
 sr_set(i, true);
 sr_update();
 
  if (i+1 == NUM_SHIFT_REGISTERS * 8) {
   direction = -1;
  } else if (i == 0) {
   direction = 1;
  }
  i += direction;

  delay(100);
}

6 Oct 2011

Knight Rider with 74HC595 8 bit shift register

Please note, the next article «Finally a threesome» includes an arduino library for the 74HC595 (not for the 74HC594) and probably obsoletes this post.





 
/**
 * Board: Pro Mini 5V
 *
 *  $Id: test_74HC595.pde 293 2011-10-06 17:30:05Z wunderlins $
 */

int SER_Pin = 8;   //pin 15 on the 75HC595
int RCLK_Pin = 9;  //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 10 on the 75HC595

//How many of the shift registers - change this
#define number_of_74hc595s 1 

#define numOfRegisterPins number_of_74hc595s * 8
boolean registers[numOfRegisterPins];

void setup(){
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);

  //reset all register pins
  clearRegisters();
  writeRegisters();
}               

//set all register pins to LOW
void clearRegisters() {
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 

//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
int direction = 1; // 1 = L2R, -1 R2L
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

int i = 0;
void loop(){
 
 clearRegisters();
 
  setRegisterPin(i, HIGH);
  
  writeRegisters();  //MUST BE CALLED TO DISPLAY CHANGES
  //Only call once after the values are set how you need.
  
  if (i+1 == numOfRegisterPins) {
   direction = -1;
  } else if (i == 0) {
   direction = 1;
  }
  i += direction;

  delay(100);
} 
 
Code example is borrowed from here: http://bildr.org/2011/02/74hc595/