2009-03-29

Munny Hardware

A viewer asked to see the schematic and the BoM of the Munny project and finally had the time to do it. I didn't managed to produce a good schematic print, but I'm learning... I'll try to improve it...

The part list is the following:
U1 ATTiny15L (this part is obsolete)
U2 LM35CZ
U3 RGB LED from Sparkfun
R1,R4 10K
R2,R3,R5 100R
C1 10uF 15V
C2,C3 .1uF

I'll try to automate better the parts list with gEDA I'll post it again (using gnetlist ...something) and then I'll try to edit it to include datasheets and link to supplier.
As soon as I manage to assemble the program in linux with avr-gcc (avr-as) or have a C program compiled for the Attiny15 I'll post the software.

7 Segments LCD Displays

One can always point out some shortcomings of the Arduino platform, it's odd shape and pin location (not breadboard "enabled"), the size of the board (could be smaller), size of RAM/FLASH, etc.
Nonetheless it is a cheap and fast prototyping platform for any electronics enthusiast with some programming knowledge.
Recently my usual electronics shop had a stock clearance of 7 segment LCD displays, available in two digit (two dots) and four digit (three dots and clock colon). I bought two of each and went home trying to figure out how to use them.

Googling 7 segments LCD display pop-up a link to an AVR application note... Bingo!
Turns out you must drive the segments you want to lit up in AC, for that you must alternate the driving of the common and segments at a reasonable frequency.
I use a array to keep the bit patterns for the display as it makes it easier when you have to output one bit at the time.

/*
driving one 7-seg LCD display
value is incrementing every second
every 10ms display positive 10ms then negative
*/

// Data for digits 0-9 g.f.e.d.c.b.a.: 7 BITS ONLY
byte digs[] = { B0111111, B0000110, B1011011, B1001111, B1100110, B1101101, B1111101, B0000111, B1111111, B1101111 };
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
byte count;

void setup() // run once, when the sketch starts
{
pinMode(9, OUTPUT); // COMMON DISP 2
pinMode(8, OUTPUT); // DISP2 Seg-G
pinMode(7, OUTPUT); // DISP2 Seg-F
pinMode(6, OUTPUT); // DISP2 Seg-E
pinMode(5, OUTPUT); // DISP2 Seg-D
pinMode(4, OUTPUT); // DISP2 Seg-C
pinMode(3, OUTPUT); // DISP2 Seg-B
pinMode(2, OUTPUT); // DISP2 Seg-A
}

void loop() // run over and over again
{
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED
if (++count > 9) count=0;
}

output(count,true);
delay(10);
output(count,false);
delay(10);
}

void output(byte a,boolean inv) {
byte val=digs[a];
if (inv) val = !val; // invert DC current
digitalWrite(9,bitRead(val,7)); // COMMON DSP 2
digitalWrite(8,bitRead(val,6)); // DISP2 Seg-G
digitalWrite(7,bitRead(val,5)); // DISP2 Seg-F
digitalWrite(6,bitRead(val,4)); // DISP2 Seg-E
digitalWrite(5,bitRead(val,3)); // DISP2 Seg-D
digitalWrite(4,bitRead(val,2)); // DISP2 Seg-C
digitalWrite(3,bitRead(val,1)); // DISP2 Seg-B
digitalWrite(2,bitRead(val,0)); // DISP2 Seg-A
}

2009-03-17

Arduino Suse 10.3 installation

I had to reinstall SUSE Linux 10.3 in my Laptop and after installing the Operating System the first thing to install was the Arduino development IDE and the AVR cross toolchain.
If you have added Packman repositories just install the following packages, although most are in the Main OSS repositorie:
cross-avr-gcc
cross-avr-binutils
avr-libc
avrdude

The latter is a command line application that programs AVRs (and other micros), it is also useful if you program AVRs outside the Arduino environment.
The really important steps follow, as superuser do:
#chmod 777 /var/lock
#chmod 777 /dev/ttyUSB0

These are also useful when using minicom (/var/lock) and USB serial port to comunicate with RS232 computers (/dev/ttyUSB0).
These instructions were adapted from here, some of the steps are not necessary, others really important.


To use my AVRISP mk II in SUSE 10.3 I needed to change a udev rules to add the device as accessible to every use, I added the following line at the end of /etc/udev/rules.d/50-udev-default.rules :
# AVRISP mk II
SUBSYSTEM=="usb",SYSFS{idVendor}=="03eb",SYSFS{idProduct}=="2104",MODE="0666"
It turns out that it still doesn't work... when trying to use avrdude with the -P usb option it complaints that it was not compiled with USB support...
Uninstall avrdude (keep uisp, avrlibc needs one of them otherwise yast complains), download the sources then configure and install to /opt/cross..

# gunzip -c avrdude-5.8.tar.gz | tar xf -
# cd avrdude-5.8
# ./configure --prefix=/opt/cross
# make
# su
# make install

Test it connecting the AVRISP mk II to an Arduino with the command:
#avrdude -c avrispmkII -p m168 -P usb

2009-03-16

Time Lapse Agriculture

I always thought the one of the great pleasures of being a farmer was to "see plants grow". Maybe I'm too impatient, but after looking at them for 15 minutes and see nothing I decided to try and do a time lapse video.
Ana tried her film first, she used a regular camera and took pictures every 15 minutes for two days (most of it). Later I ordered the pictures, reduced the size and composed the video. In order to keep the same illumination during the day, she used an halogen lamp over the plants. Naturally it is quite clear that this fakes the results and her plants grow super fast...
I decided to use a computer and a webcam to do the job for me. First I tried a logitech quickcam messenger but the resolution was very coarse, it needs special drivers in linux and it does not auto adjust for the brightness.
Next, Tiago borrowed me a Philips Webcam PCVC830K, it worked out of the box in Suse 10.3, resolution is 640x480 and adjusts for the brightness.
I created two scripts, one to take the pictures every 6 minutes and another to compose the video.
Here is the snapshot script:
#!/bin/bash
## adapted from http://mydebian.blogdns.org/?p=261#more-261
## Takes a picture every (wait) seconds and renames it ${now}

# how long to wait between each download
wait=360

## main endless loop ##
while true
do
now=$(/bin/date '+%Y%m%d%H%M%S')

## fetch new webcam shot ##

ffmpeg -s vga -r 1 -t 1 -f video4linux -i /dev/video0 -y plant.jpg
mv plant.jpg "${now}.jpg"
## echo "${now:8:2}" just the hour
echo "${now}"
/bin/sleep $wait

done
Here is the script to compose the video:

#!/bin/bash
mencoder -ovc copy -mf w=640:h=480:fps=15:type=jpg 'mf://*.jpg' -o time.avi
During the shoot I hit the box with the vacuum cleaner, so there's a small shift... be warned. The shoot takes place from Friday night to Monday morning. The plant box is facing south and is close to the TV, so during the night there's a first level of darkness, then when we turn off the TV the only light is the webcam red led. The red led allows us to see some, although little movement.
Here is the video...

2009-03-05

New crops!

Time has arrived to start growing some more vegetables! Sowing should be done outside when you're certain that will be no more frost. Since in Holland you never know... we decided to start growing inside. Me and Ana also decided to "make a competition" to see who would have the best crop! Last Sunday we started, each of us would have a small wooden box with some yogurt plastic cups, we would sow the same seeds, each responsible for his box.. It is easy to see which one is mine (yes, the dirty one).

I placed yellow tags in each cup to know what was inside each of the yogurt cups, the names are in Portuguese, beware. The seeds are Tomato, Parsley, Celeriac, Rucola, Portuguese Cabbage and Araça.


By Tuesday my rucola was already germinating, Wednesday the cabbage was sprouting, today both are steadily growing.