Archive for April 2008

Atmel AVR Device List as of 2008-04-15

Converting *.flac to *.mp3

flac is an audio format (Free Lossless Audio Codec) that is excellent for archiving, but few if any portable players will be able to play it, so a method to convert to mp3 is shown below.

convert .flac to .mp3

flac -cd "FILENAME.flac" | lame -h - "FILENAME.mp3"

flac: -c is output to console, -d is decode
lame: -h is shorthand for “-q 2″ and -q is quality (in this case a high quality), “-” is input from console

same but for all .flac files in a directory

for FILE in *.flac; do $(flac -cd "$FILE" | lame -h - "${FILE%.flac}.mp3"); done

same options in a bash for loop, the ${FILE%.flac} strips “.flac” from the name

Notes:
id3 options for lame:
–tt <title> –ta <artist> –tl <album> –ty <year> –tc <comment> –tn <track> –tg <genre>
will automatically add an id3v1 or id3v2 as needed (choice is based on the size of the fields),
“–add-id3v2″ “–id3v2-only” “–id3v1-only” can be used to modify choice.

more complicated operations are beyond the scope of this article, but I’d suggest using K3B.

AVR Toolchain - Build 2008-04-15

Contains all the tools for developing on the AVR under Linux.

This includes:
AVR-gcc - a full-featured ANSI C compiler.
AVR-Binutils - includes tools capable of linking and managing archives, including handling object code, libraries, profile data, and symbol names.
AVR-Libc - this package provides a subset of the standard C library for Atmel AVR 8-bit RISC microcontrollers.
AVRDUDE - an open source utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers using the in-system programmer (ISP).
AVR-gdb - a debugger, GDB lets you to see what is going on ‘inside’ another program while it executes.
ddd - this works with command-line debuggers such as GDB to give a graphical front-end.
Simulavr - A simulator for the Atmel AVR family of microcontrollers.
 

Known MCU names:
avr1 avr2 avr3 avr4 avr5 avr6 at90s1200 attiny11 attiny12 attiny15 attiny28 at90s2313 at90s2323 at90s2333 at90s2343 attiny22 attiny26 at90s4433 at90s4414 at90s4434 at90s8515 at90s8535 at90c8534 at86rf401 attiny13 attiny2313 attiny261 attiny461 attiny861 attiny24 attiny44 attiny84 attiny25 attiny45 attiny85 attiny43u attiny48 attiny88 atmega103 at43usb320 at43usb355 at76c711 at90usb82 at90usb162 atmega48 atmega48p atmega8 atmega88 atmega88p atmega8515 atmega8535 atmega8hva at90pwm1 at90pwm2 at90pwm2b at90pwm3 at90pwm3b atmega16 atmega161 atmega162 atmega163 atmega164p atmega165 atmega165p atmega168 atmega168p atmega169 atmega169p atmega32 atmega323 atmega324p atmega325 atmega325p atmega328p atmega329 atmega329p atmega3250 atmega3250p atmega3290 atmega3290p atmega32hvb atmega406 atmega64 atmega640 atmega644 atmega644p atmega128 atmega1280 atmega1281 atmega1284p atmega645 atmega649 atmega6450 atmega6490 atmega16hva at90can32 at90can64 at90can128 at90pwm216 at90pwm316 at90usb646 at90usb647 at90usb1286 at90usb1287 at94k atmega2560 atmega2561
 

core package:
binutils-2.18
gcc-4.2.2
avr-libc 1.6.2
avrdude 5.5


AVR-Toolchain - Core - 2008-04-15 Build Binary Package


AVR-Toolchain - Core - 2008-04-15 Build Binary Package - No Docs

debug package:
ddd-3.3.11
gdb-6.8
simulavr-0.1.2.5


AVR-Toolchain - Debug - 2008-04-15 Build Binary Package


AVR-Toolchain - Debug - 2008-04-15 Build Binary Package - No Docs

 

AVR Toolchain - Build 2008-04-15 - Build Tests

AVR Toolchain - Build 2008-04-15 - Man Pages

Every version of UNIX comes with an extensive collection of online help pages called man pages (short for manual pages). The man pages are the authoritative documentation about the system.

This is a web-accessable front end for the man pages generated by the packages in the GNU AVR toolchain, namely: AVR-gcc, AVR-binutils and AVR Libc.

Continue reading ‘AVR Toolchain - Build 2008-04-15 - Man Pages’ »

Eagle3D Component - Simple Jumpers

some very simple jumpers for Eagle3D, I tend to use a lot of them due to single-sided board restrictions.

the include file, to be placed in “[Eagle3D Root]/povray” and added to “[Eagle3D Root]/povray/user.inc”. see this post for details.
user_jumper.inc

 

and the associated images (to be placed in “[Eagle3D Root]/ulp/img” to aid in identification, optional):

Zip archive of images

Method to simplify adding Eagle3D components

assuming the Eagle3D directory structure looks as follows:

[Eagle3d Root]
    |- doc
    |- examples
    |- povray
    \- ulp
        \- img

the file “[Eagle3d Root]/povray/user.inc” will contain, by default, nothing.
if the following lines are placed within it (note that the shown filenames are only examples):

#ifndef(__user_inc)
#declare __user_inc = true;

//#include "user_includefile01.inc"
//#include "user_includefile02.inc"

#end

adding new parts is a simple matter of adding the new file to the [Eagle3d Root]/povray/ directory, copying an #include directive, changing the name, and uncommenting it.

in my own installation, I follow the recomended prefix style of filenaming, as do the files available on this site.

additionally, if the current user.inc file is not empty, it can be renamed to “user_orig.inc” or similar, a new user.inc file containing the above added, and the line #include “user_orig.inc” placed within it.

Soccerball

A rendering of a soccerball.

soccerball.jpg

soccerball.gif

Random Content in Wordpress

this example is for WordPress, but the concepts should work fine anywhere.

a quick note, though they are not in the code examples, it is important that the code go between <? and ?> bits. any syntax highlighting editor should make it plain where they are needed.

 

the simplest version of this would be to add the following to your template where you want the random content to show up:

//this line is only needed for PHP versions prior to 4.2
//srand((float) microtime() * 10000000);

$content = array(
	"just some text",
	"some more text",
	"yet more text",
);

$key = array_rand($content);
echo( "<p>" . $content[$key] . "</p>" );

 

to turn this into a function available throughout the theme, add the following to the end of the “functions.php” (it is in your theme folder).
if this file does not exist, you can create it.

//this line is only needed for PHP versions prior to 4.2
//srand((float) microtime() * 10000000);

$content = array(
	"just some text",
	"some more text",
	"yet more text",
);

function get_random_content() {
	global $content;
	if( is_array($content) ) {
		$key = array_rand($content);
		return $content[$key];
	}
	else {
		return "";
	}
}

function echo_random_content() {
	echo( "<p>" . get_random_content() . "</p>" );
}

this will allow you to add the following to any spot in your templates:

<? echo_random_content(); ?>

or better yet, wrap the call in a check:

<? if( function_exists("echo_random_content") ) { echo_random_content(); } ?>

 
 

if you want to extend this idea further, for example into different “databases” of content:

//this line is only needed for PHP versions prior to 4.2
//srand((float) microtime() * 10000000);

$content = array(
	"text" => array(
		"just some text",
		"some more text",
		"yet more text",
	),
	"other" => array(
		"just some other text",
		"some more other text",
		"yet more other text",
	),
);

function get_random_content($from) {
	//this is the default if no "$from" is set
	return get_random_content("text");
}

function get_random_content($from) {
	global $content;
	if( is_array($content) ) {
		if( isset($quote[$from]) ) {
			$key = array_rand($content[$from]);
			return $content[$key][$from];
		else {
			//this is the default if "$from" does not exist
			$key = array_rand($content["text"]);
			return $content[$key]["text"];
		}
	}
	else {
		return "";
	}
}

function echo_random_content() {
	echo( "<p>" . get_random_content() . "</p>" );
}

all that has been added is another dimention to the array, some error checking, and the ability to select the array to draw from.

this version will allow you to add the following to any spot in your templates:

<? echo_random_content(); ?>
<? echo_random_content("text"); ?>
<? echo_random_content("other"); ?>

or even better:

<? if( function_exists("echo_random_content") ) { echo_random_content(); } ?>
<? if( function_exists("echo_random_content") ) { echo_random_content("text"); } ?>
<? if( function_exists("echo_random_content") ) { echo_random_content("other"); } ?>

 

the code still does not check for the possibility of empty or erroneous content, but if you create a variable in echo_random_content() and use it to hold the results of get_random_content(), you can check if it is empty, contains bad characters, swap newlines out for break tags, or whatever else you would like.

Extracting RPM Package Contents

firstly, there is a package available called “alien” that will convert to/from packages for nearly any distro, I use this on machines that it can be installed on.

however, there are times that using standard tools is faster and simpler,

piping the output of “rpm2cpio” (extract cpio archive from RPM Package Manager (RPM) package.) into “cpio” (copy files to and from archives) will extract the RPM package into the current directory.

rpm2cpio package.rpm | cpio -dimv

where:
-d = make directories, -i = “in” mode, -m = keep date/time stamps, -v = verbose.

Designing a keypad for an AVR Microcontroller

by using the upper four bits as outputs and the lower four bits as inputs, a simple 4×4, 16 button keypad can be connected to a microcontroller.

the first picture shows the state after the “0″ key has been pressed.
the 0×24 corresponds to the “scancode”, the first digit being the column and the second being the row.
to be exact, in binary 0×24 equals 0b00101000, this shows that during the scan, the key in the second column and the fourth row was pressed.

the bracketed values under that are the contents of the key buffer.

HPIM0056-e.JPG mainboard-top.png mainboard-bot.png
mainboard-sch.png mainboard-brd-e.png mainboard-brd-silk.png

 
 
a simple code example for this:

//high bits are columns, low bits are rows
volatile uint8_t scancode = 0x00;
uint8_t i, j;

// set data direction on PORTD
//   pins 8,7,6,5 as output, pins 4,3,2,1 as input
outb(DDRD,  0b11110000);

//loop over pins
for( i=4; i<8; i++ ) {

	// sets outputs low one pin at a time
	//   also enables internal pull-ups on inputs
	outb( PORTD, ~(1<<i) );

	//debounce delay and settling time
	timerPause(5);

	//loop over port positions
	for( j=0; j<4; j++ ) {
		if( bit_is_clear(PIND,j) ) {
			//set scancode
			scancode = (1<<i)|(1<<j);
		}
	}

}

 
 
the “~(1<<n)” is an example of bitshifting, in this case it means “bitshift 1 left “n” times, then invert the result” or if we take n as 3, it would be:
~(1<<3)
after 0 shifts:
~(0b00000001)
after 1 shift:
~(0b00000010)
after 2 shifts:
~(0b00000100)
after 3 shifts:
~(0b00001000)
then inverted:
0b11110111

a slightly more complicated looking example of this is used in the inner loop:
(1<<n)|(1<<m)
or if we take n as 6 and m as 2 it would be:
(0b01000000)|(0b00000100)
and that would resolve to:
0b01000100

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Tags

  • Archives