Ads

Tuesday, October 28, 2008

Easier than I thought...

So I had a free 15 minutes today and the result:



I implemented the four LED counter that I was talking about last time. One of the pins that I used is also used to program the device, so I have to move the reset and that pin (17/PB3/MOSI).

code:
#include < avr/io.h >
#include < util/delay.h >

#define nop() __asm__ __volatile__ ("nop")
//My chip is 20 Mhz
#define F_CPU 20000000UL

int main(void)
{
DDRB = 0xFF;
PORTB = 0x0;
while(1)
{
PORTB += 1;
_delay_ms(1000.0);

if(PORTB == 16) {PORTB = 0;}
}
return 0;
}

//endcode
So, I just realized that my header info last time probably didn't work, as I used < and > .

Next step, do the same thing with the shift register chip in there.
After that, figure out timers/interrupts.

Monday, October 27, 2008

Manpower

I just want to point out some pitfalls of trying to make the government/our military have a ROI and super efficiency. Actually, it can also apply to anything that becomes extremely optimized with humans in it.

Robo-Cannon's Manpower Problem

So they won't have enough people for 24 hr operations, as someone has to drive, and the other to pay attention. It would be like trying to drive cross country by yourself ... you can't take a nap cuz the car crashes. If one dude is out of the fight, there is no excess capacity.

Bad thing for the military, often people are used in ways that are not designated by their MOS.

When designing stuff, remember the big picture, and add some resilience, just in case. It normally works out that you need it.

Pumpkins!

We carved pumpkins yesterday. I like to make my own pattern and was a bit rushed. I was inspired by an upcoming vacation and decided to make a turtle. Its not very Halloween, but eh.

The pattern:


Pictures of the four pumpkins:



















Friday, October 24, 2008

Great success!



I was having lunch with a good friend on Wed and we mentioned some interesting projects that we could get into. I stopped myself from dreaming because I have not worked on the alarm clock for a long time. I resolved to write code, flash it, and blink an led by the end of the week.

As you can see above, I made the LED blink. Next step is to setup 4 or 8 LEDs and make them "count" from 0000->1111 (0->16). Then do the same, but using a shift register.

The reason that I have not done it before is because I was scared. It really was as easy as reading 1-2 pages in the datasheet. I had to figure out how to make a "nop" (no operation) but I could have just made the device add a number or something. There seems to be delay code already written in util/delay.h so I will try and use that in the 0->16 counter step to make it change once a second. I also turned all of the ports in "B" to output and on, so I should be able to just add LEDs and have 8 that flash together.

Summary:
xn ... so x can be like, C or B and n can be lik 0-7 (makes sense if you see the pin names)
DDxn: 1->output , 0->input
DDxn configures how the PORTxn acts.
PORTxn: input: 1->pullup resistor active,0->pull up resistor inactive
ouput: 1->driven high,0->driven low
PINxn: 1 -> toggle PORTxn
There was some warning about switching between input and output, it works better if you make sure that you use a specific sequence if you don't want the pin to be in a random state for a period of time.

My LED was on Pin 14 on the DIP, otherwise known as PORTB0 (PB0).

Code (blinkin.c):
#include < avr/io.h >
#define nop() __asm__ __volatile__ ("nop")

int main(void)
{
int i = 0;

DDRB = 0xFF; // set all B's to output
while(1)
{
PORTB = 0xFF; //All On
for(i=0;i<30000;i++)
{ nop(); }

PORTB = 0x00; //All off
for(i=0;i<30000;i++)
{ nop(); }
}

return 0;
}

for the record, these are the commands used to compile/flash:
avr-gcc -I. -I/usr/local/AVR/avr/include -g -mmcu=atmega168 -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -Wstrict-prototypes -Wa,-ahlms=blinkin.lst -c blinkin.c -o blinkin.o

avr-gcc -Wl,-Map,blinkin.out.map -mmcu=atmega168 -lm -o blinkin.out blinkin.o

avr-objcopy -j .text -j .data -O ihex blinkin.out blinkin.hex

avr-objcopy -j .eeprom \

--change-section-lma .eeprom=0 \
-O ihex blinkin.out blinkin.ee.hex

avrdude -c bsd \
-p m168 -P /dev/parport0 -e \
-U flash:w:blinkin.hex


I didn't write those all by hand, I found a nifty Makefile online that I configured, all I have to do is type "make writeflash" to compile/flash it onto the device. I can post the Makefile if anyone is interested.

The big problem that frustrated me was that I wasn't exactly sure how to "start" the code. So for a while I thought I did it wrong because I couldn't even make the LED light. I originally just kept cycling the power. That does not work if you have the programmer still plugged in. Turns out that if you pull the reset line out (pin 1), you start the device.You can leave the other programming pins attached. I might wire a switch to that line so that I can leave the programmer attached and run the code without pulling out a wire and reinserting it.

Should be relatively smooth sailing from here, I am assuming that the hardest parts are setting up the compiler/flasher, learning how to make the code run, and plugging everything into the correct pins.

Wednesday, October 22, 2008

All I really want....

is a friend. (if I was a terrorist)

or so says Max Abrams in his paper "What Terrorists really want: Terrorist Motives and Counterterrorism Strategy".

My ten word summary of the paper.
Terrorists are terrorists because they want to have a friend.

Using his words on page 94 (it was published in a journal, the whole paper is like 28 ish pages)

There is comparatively strong theoretical and empirical evidence that people become terrorists not to achieve their organization's declared political agenda, but to develop strong affective ties with other terrorist members.
It seems to be some quality research. He identifies seven puzzles that can not be explained by conventional wisdom about terrorists. Also brings up some good numbers about what the captured terrorists say about why they joined. They seem to act almost like cults and exist to keep the group alive as he could not find one group that met its political aims.

Save the world, befriend a loner! (but only if he has relatives in a terrorist organization or visits their forums).

Track fidel update

So I was curious about the health of Fidel, he has been posting fairly recently.

When I ran my code, I ended up with a negative number of days, investigating, I found something interesting around June 22th 2008. The post is labeled and seems to have been posted on June 22th, but the date on the file seems to be June 4th.

He might have written the article on the 4th, but then decided to post it on the 22nd. June 4th is in the middle of a 17 day drought of posts, and also when he seemed to not be feeling well both before and after based on his posts. He broke the 2 week barrier three times around that date.

I am going to make the code sort the dates, I am assuming that the date on the file is more accurate than the date in the listing. I'll try and remember this though, it did identify a date range where he was lacking on posting.

Also, on the 20th and 21st, the numbers ((2 and 0) and (2 and 1)) are split up in the text, and are actually different fonts. You find more weird things about words or numbers being different in the html, but not on the visible side. (see October for a recent set)

Anybody have enough free time to figure out the Castro html blog cipher? (heh)





Overall diagnosis: Zombie Castro is healthy!

Friday, October 17, 2008

ssh tunneling

I recently got bitten by the "lets learn about practical uses of encryption" bug and have been cleaning up the methods used to connect between the boxes that I use.

I used to use two scripts (because that was the only way I could get it to work).
I present a concise and short version below:

3333 is the port of the program that you want to use, 3389 for remote desktop for windows, 5900 for vnc. 192.168.0.115 is the ip of the box in the distant network. example.com is the ip for the computer that is connected to the outside and has ssh-ness. luser1 is your username. Fix your bit depth and resolution for rdesktop, similar for vnc. "Billy Bob" is your windows login at the destination.

Your program connects to the local host on the same port that it would be connected to on the other side. The local port gets the dataz, its encrypted, sent,arrives, and decrypted and sent to the port on the other side as if you connected to it unencrypted like.

#!/bin/bash
ssh -2 -L 3333:192.168.0.115:3333 -N luser1@example.com &
## Uncomment one of the following...
#rdesktop -a16 -g1280x990 -z -u "Billy Bob" example.com
#vncviewer -FullScreen localhost:0
sleep 5 #sometimes stuff can be slow?
kill -15 `ps -C "ssh -2 -L 3333:192.168.0.115:3333 -N luser1@example.com" | awk 'NR==2{print $1}'`

The last two lines are actually one line. (the kill -15 line ends with {print $1}'` )

The magic is the "-N" which makes it so that you don't need to send a command, and the last line, which kills the tunnel when you are done.

Friday, October 03, 2008

Taxes and this election

I am not saying this is the only thing you should care about when voting, but it is an interesting data point that backs up one candidate's position on taxes.

IT companies moving to Ireland because taxes rock there.


Why have your company here if it will hurt your competitiveness and reduce profits? You can still do business in the United States, just shift the accounting such that no income occurs here that you can be taxed on. Other American (like.. Halliburton!) moved to Dubai to get away from taxes.

If you tax the rich to give to the poor, the rich will just move away. Remember, they own the jets that enable them to do that.

Thursday, October 02, 2008

First try at baking bread

I got a rice cooker as a gift recently and realized that I could probably use it as a crock pot. In researching that idea on the web, I found that I could also bake bread in it. What follows is the tale of the first bread.

1. Dough after kneading - I had to add quite a bit more flour than he used. Maybe I messed up when I added the water.
2. Halfway through a rise (there were two rise periods)
3. At the end of a rise
4. First flip of the bread - very good amount of browning, may have been rough and collapsed some bubbles
5. Second flip - as you can see, a bit burnt, I tried to oursmart the rice cooker and failed. DO NOT FORCE YOUR RICE COOKER TO STAY ON THE "COOK SETTING, YOU MAY DAMAGE YOUR RICE COOKER)
6. Finished bread cooling (yes, I know I spilled tomato soup on the range and need to clean it)
7. Loaf cut in half - you can see that one side was cooked better than the other side which seems collapsed. Bread was sort of chewy because of the lack of air bubbles.

So you can cook bread in a rice cooker!

Recipe from instructables. Be sure to watch it, the times for cooking are very dependent on your brand and size of rice cooker.









1



2



3


4



5


6


7







Wednesday, October 01, 2008

Experiments for change

I find it really interesting that States can try out things like this. California is going to require restaurants to post the nutritional information about the dishes that they serve.

It gives us a chance to gather real data on different policies and the effect that a policy would have.

You would be amazed at how your eating habits change once you start being exposed to the number of calories. Weight Watchers is built on this principle.

I wish that meals at restaurants cost $5 but were for one meal, rather than $10 for two meals that I end up eating at one sitting anyway.