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/