pine64 guinea pig habitat comfort control

pine64 and perl guinea pig habitat environment automation
pine64 and perl guinea pig habitat environment automation

We’ve moved our guinea pig Monster out to the garage.  He’s in no danger of overheating (trust me, he is spoiled rotten!) but it does get a little warm out there.  I used my pine64 to turn on a 20W fan when it rises above a chosen temperature.  Temperature samples are taken with an analog TMP36 sensor which is read by an MCP3004 analog to digital converter.  It also gets pitch dark with the lights out at night, so there is also a photo resistor that is read by the MCP3004 ADC.  When it drops below a certain threshold, it turns on an LED night light for Monster.  I think he likes it.  He has been laying in front of the fan.

Once the ADC reading is taken of the TMP36 sensor, this is how it is converted into degrees Fahrenheit.

my $temperature = ((($voltage_t * 1000) - 500) / 10) * 1.8 + 32;

I am running armbian on my pine64 and have written my own gpio control script in perl.  Here is the perl script that controls Monster’s fan and night light.

#!/usr/bin/perl 
use strict;
require "./MCP3004.pl";

gpio_enable(17, 'out');
gpio_enable(13, 'out');

#get thermostat arg
my $thermostat = $ARGV[0];
if($thermostat eq ''){
	$thermostat = 85;
}#end thermostat


#channels: first bit is set to single, not differential
#5 bits because the first is the start bit
my @ch0 = (1,1,0,0,0);
my @ch1 = (1,1,0,0,1);
my @ch2 = (1,1,0,1,0);
my @ch3 = (1,1,0,1,1);
#differential
my @ch01 = (1,0,0,0,0);

init3004(18,19,24,25);

#loop global variables
my $tmp10 = 0;
my $tavg = 0;
my $bin10 = 0;
my $binavg = 0;
my $fan_f = 0;
my $lt_f = 0;

for(;;){
	$tmp10 = 0;
	$tavg = 0;
	$bin10 = 0;
	$binavg = 0;

	for(my $n=0;$n<10;$n++){ #photoresisitor reading------------------------------------------- my ($reading, $binval, $voltage ) = read3004(\@ch0, 50, 5.01); print "binval: $binval\t$voltage vdc"; $bin10 += $binval; #print RD "$s\n$voltage\n"; #photocell end---------------------------------------------------- #tmp36 temperature reading---------------------------------------- print "\n---------------------------------------\n"; my ($reading_t, $binval_t, $voltage_t ) = read3004(\@ch1, 50, 5.01); #print "binval_tmp: $binval_t\tvoltage_tmp: $voltage_t vdc\n"; my $temperature = ((($voltage_t * 1000) - 500) / 10) * 1.8 + 32; $temperature = sprintf("%5.2f", $temperature); print "temperature: $temperature deg F\n"; #accumulate temp $tmp10 +=$temperature; print "---------------------------------------\n"; #tmp36 end-------------------------------------------------------- #0.5 pause between samples usleep(500000); }#end for 10 #calculate temperature averages $tavg = $tmp10 / 10; if($tavg > $thermostat){
		#turns fan on
		gpio_write(17, 1);
		$fan_f = 1;
	}#end if
	else{
		gpio_write(17, 0);
		$fan_f = 0;
	}#end else

	#calculate light intensity averages
	$binavg = $bin10 / 10;
	if($binavg > 610){
		#turns light on
		gpio_write(13, 0);
		$lt_f = 1;
	}#end if
	else{
		gpio_write(13, 1);
		$lt_f = 0;
	}#end else

	print "\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n";
	print "avg temp: $tavg stat:$fan_f\tavg light: $binavg stat:$lt_f";
	print "\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n";

	#wait 1 minute
	sleep(60);
}#end outer for

That’s a lot of processing power just to control a light and a fan.  I plan to migrate the function to an arduino nano soon.

pine64 and perl guinea pig habitat environment controls
pine64 and perl guinea pig habitat environment controls
pine64 guinea pig night light
pine64 guinea pig night light
per & pine64 guinea pig automation
perl & pine64 guinea pig automation

lm386 work speaker

I always have some music going.  At work, if me and my co-worker have a job that takes longer than 10 minutes in a server room or microwave radio hut, he busts out his bluetooth speaker and we listen to his pandora channel.  I wanted to do something with these 2W speakers I hot-glued into the amazon box  that my yeeco 50W amp came in, so I decided to see if I could build a quality amp using an lm386 audio amplifier chip.

I found this great tutorial and bread boarded it for myself.

work speakers using an LM386 audio amplifier chip
work speakers using an LM386 audio amplifier chip
lm386 breadboard
lm386 breadboard

This particular circuit has gain control, bass boost, and volume control.  It actually sounds pretty decent.  I was surprised.  The next step is to solder everything to a prototype board, and add the knobs and audio jacks to the box.  To be continued…

armbian for pine64

armbian for pine64 CLI only
armbian for pine64 CLI only

When I first got my 512MB pine64 A64 sbc,  I initially loaded a great community based version of debian with an LXDE desktop.  I was really happy with it.  Recently, I was trying to install i2c-tools and was getting errors.  I then tried to update my system, and could not connect to the repository.  Same for perl  packages using cpan.  After searching for an answer in the pin64 forums, I learned that dude that made the awesome debian img for the pine64 stopped supporting it, and there was a suggestion to migrate to an armbian distro that was cli only.  I really wanted to use my i2c bus, so I burned a not-so-fresh sd card with armbian.

armbian for pine64 initial login via UART0
armbian for pine64 initial login via UART0 on the euler bus

Initially, I was happy.  I really don’t need a desktop environment.  I quickly noticed that my ethernet interface did not work at all.  Once again, I searched the forums, and found a solution.  Using martinayotte posted a solution that worked great for me.

Not very promising that my NIC did not work out of the box, but I am going to give it a fair try.

cool new software i’m playing with: mapscii & pulseeffects

screenshot of mapscii running on my ubuntu box centered on my usual milieu
screenshot of mapscii running on my ubuntu box centered on my usual milieu

I am amazed by the many ways developers have implemented graphics and video via the terminal.  I mean, you can watch star wars via telnet.  I regularly read Daniel Miessler’s blog and recently came across mapscii: a terminal based map of the world.  It is totally amazing.

Speaking of terminal applications, my main music player is the command line version of mplayer.  I wanted a great equalizer as well so I could enjoy my new speakers even more and I came across pulseeffects.

pulseeffects running on my ubuntu bionic beaver box
pulseeffects running on my ubuntu bionic beaver box

I am still experimenting with pulseeffects, but so far I am blown away!  I am getting the most out of my sound system and having a lot of fun tinkering.

CH6520 Boss 250W stereo system with yeeco 50W amplifier

cheap home made speaker cabinets using boss CH6520 speakers
cheap home made speaker cabinets using boss CH6520 speakers

We’re pretty low budget around here.  I just wanted to listen to loud music in my maker space for cheap.  I bought a totally awesome pair of Boss CH6520 speakers to go with my yeeco 50W / channel stereo amplifier and built some 8″ X 12″ cabinets out of 1/4″ plywood.  It thumps pretty hard.  I tested them with ‘Love Removal Machine’ by the Cult.

boss CH6520 2-channel speakers
boss CH6520 2-channel speakers