family alarm clock project III

trinket Pro 5V 16MHz based alarm clock / stereo project using a PCF8523 real time clock breakout from adafruit
trinket Pro 5V 16MHz based alarm clock / stereo project using a PCF8523 real time clock breakout from adafruit

Nearly done with our family project.  It has been so much fun, and I hate that it’s nearly over, but Eli and Addy are pumped for another project.  The maker space  has been the new cool hangout:  loud music, chips + cheese dip, Teen titans Go, roller skating, and making a killer boom box that everybody loves.

trinket Pro 5V 16MHz based alarm clock / stereo project using a PCF8523 real time clock breakout from adafruit
the brains is a trinket Pro 5V 16MHz

This is my first project with a trinket Pro.  I love this platform.  Tiny, cheap, powerful,  easy to use; comparable to an arduino nano.  I did run out of GPIO pins (mostly due the the 16×2 LCD display), but got around it adding an MCP23008 for the alarm control buttons (also using libraries from adafruit) .

PCF8523 adafruit trinktet project
It’s adisaster on the inside, but pretty cool on the outside.

family alarm clock project II

We are making progress on our alarm clock / boom box project.  Eli soldered the 220 ohm resistors to the cathodes of the LEDs for the hours and Addy soldered the common ground wire to the resistors, hot glued them to the clock face, and tested them with a 6V battery.  I re-purposed an old POW3U prototype board for the 10 74HC595 shift registers we will need for the LEDs (they hate when I help!).  We put together what we have of the cabinet so far, and it looks pretty cool.  Not only that, it THUMPS!  Tested it with Wildflower from The Cult.  The kids are more enthused with seeing the progress.

The PCF8523 RTC breakout came in.  I downloaded the RTC libraries from Adafruit and ran the example scripts.  I am very impressed.  I will definitely buy more for other projects.  I connected it to an old CHIP pro I have and experimented with it just using i2cget commands reading the different registers and it seems to be an easy , straightforward RTC IC to use.  It is really coming together.

array of 74HC595 shift registers to drive our LED clock on a POW3U prototype board
array of 74HC595 shift registers to drive our LED clock on a POW3U prototype board
alarm clock / boom box cabinet front
alarm clock / boom box cabinet front
cabinet back view with sub woofer

using pine64 gpio to control a 120VAC light bulb

I’ve used gpio on various SBCs to drive small signal relays  on a few projects, but never any high-current, high-voltage stuff.  The principle is exactly the same, I just hadn’t used it before.  The elegoo 37-sensor kit I just got had a handy break out board for a 10A 250VAC relay.  I used a gpio line on a pine64 to drive the relay coil using a PN2222A transistor circuit.  The script is no different than blinking an LED.

pine64 gpio driving a 10A 250VAC relay circuit using a PN2222A NPN transistor to provide ground

 

 

pine64 turning on and off light bulb
perl script for pine64 relay control

Next, I controlled the relay by reading the voltage drop across a photo resistor voltage divider using an MCP3004 10-bit ADC.  When the OP code from the ADC rose above 400, the light comes on (because it is dark).

Controlling a relay by reading the voltage drop across a photo resistor using an MCP3004 ADC
Controlling a relay by reading the voltage drop across a photo resistor using an MCP3004 ADC

family alarm clock project

Eli, Addy, and I are working on an arduino-based LED alarm clock project.  The design is totally Eli’s idea.  He wants 60 LEDs around the face of the clock for the minutes, and 12 LEDs on the top for the hour.  We gutted the audio system from one of their old gaming chairs that got tore up, and are using it for the sound.  I ordered a PCF8523 real time clock breakout board from adafruit to keep time, and are going to use a 5V 16MHz Trinket Pro for the brains. With over 72 LEDs to drive, we plan on using 10 74HC595 shift registers.  We are also going to use a 16X2 LCD display to show the time and maybe temperature.  So far, Eli has cut all the pieces out with a jig saw and he and Addy drilled all the holes for the LEDs.  Eli soldered a 220 Ohm resistor to the cathode of all the LEDs, and Addy used a glue gun to fasten them to the clock face.  I am new to arduino, so I am experimenting with using it to drive the LCD and the 74HC595’s.

Elegoo Uno driving a 16X2 LCD and 74595 shift register
family LED clock project

pi pet camera

We’re on spring break this week, and couldn’t get any takers to look after out guinea pig, Mon$ter.  The plan was to just put lots of extra food and water in his habitat.  I repurposed my pi-zero based front door security device (because we replaced it with a ring) and set it up to take a picture of Mon$ter every hour, and post it on my home web server so we can see how he’s doing.

rasspberry pi pet cam
Screenshot of my web browser pet cam app
pi zero w with camera and 12VDC lead-acid backup battery
pi zero w with camera and 12VDC lead-acid backup battery facing Mon$ter’s cage

Here’s the simple script.  It makes some system calls to some other scripts I wrote to scp the images to the web server.

interfacing elegoo uno R3 to pine64

elegoo UNO R3 interfaced to a pine64 via UART
elegoo UNO R3 interfaced to a pine64 via UART

I’m really late to just now be getting on board (no pun intended) with arduino.  Until now, I have focused on SBC’s that run a full linux distribution.  I just bought an elegoo 37 sensor kit off amazon, and it was only $11 to throw in an elegoo UNO R3.

Just to try it out, I modified the serial output example.  Instead of using a potentiometer,  I used a 16K ohm photoresistor in a voltage divider circuit with a 330 ohm resistor.  When the binary value of the analog read drops below 200,  digital pin 13 turns on an LED so you can have some light.

Analog binary value on the pine64 to the left of the IDE
Analog binary value on the pine64 to the left of the IDE

Here’s the setup->

elegoo UNO R3 photo resistor voltage divider analog read
elegoo UNO R3 photo resistor voltage divider analog read

subnet scanner utility in perl using Net::Ping

I often times have to assign an ipv4 address to a device at work and need to know what addresses are available on a particular subnet.  On other occasions, I just need to know what hosts are up / down on a subnet.  Normally, I would use nmap on my personal laptop, but only authorized devices are allowed on my company network, and I certainly want to stay out of trouble. Plus, I have to use windows 10 at work, and I do not have admin privelages.  I wrote a simple perl script that scans a user-defined range of ip addresses using the Net::Ping module from cpan.

This is the first of a suite of network utilities that I am writing to help troubleshoot network issues in cases where I do not have nmap available.   Here is a scan of a small portion of my home network:

Perl based subnet scanner using Net::Ping
Perl based subnet scanner using Net::Ping

Here is the source code so far:

 

#!/usr/bin/perl -w
use Net::Ping;
use Time::HiRes qw(gettimeofday);
use Term::ANSIColor;
use 5.010;
 
print "ping tester\n--------------------------\n";
#print "enter ip: ";

#get address
#chomp(my $host = );
#print "host: $host\n";

#create ping object
my $p = Net::Ping->new('icmp');
#hi res time
$p->hires();

#a single ip address
my $host;

#up / down devices
my @online_devices; 
my @offline_devices; 

#get address range from user
print "Enter IP address range: ";
chomp(my $ip_range = );
#print "range: $ip_range\n";
$ip_range =~ /(\d+\.\d+\.\d+)\.(\d+)-(\d+)/;
my $network = $1;
my $start_ip = $2;
my $end_ip = $3;
#print "start IP: $start_ip\nend IP: $end_ip\n";

#get t0 for benchmark
my $t0 = gettimeofday();

for(my $i=$start_ip;$i<=$end_ip;$i++)	{
	$host = "$network.$i";
	print "checking $host....\n";
	
	#list context, returns duration
	my ($ret, $dur, $ip) = $p->ping($host, 0.25);
	
	#format time
	$dur = sprintf("%.6f", $dur); 	
	
	#results
	if($ret){
		print colored  ("$host is up  latency: $dur seconds", 'white on_green');
		print "\n";
		push @online_devices, $host;
	}#end if
	else{
		print colored ("$host down", 'white on_red');
		print "\n";
		push @offline_devices, $host;
	}#end else		
	print "-----------------------------\n";
}#end for

#kill ping object
$p->close();

#benchmarking results
my $t1 = gettimeofday();
my $elapsed = $t1 - $t0; 
$elapsed = sprintf("%6f", $elapsed);
print "\ntime elapsed: $elapsed....\n";

#report file
open RP, ">", "report.txt" or die $!;

#results
my $up_sz = @online_devices;
my $down_sz = @offline_devices;
print "$up_sz devices online\n$down_sz devices offline\n";

print "\nOnline devices....\n------------------------------------------------------\n";
print RP "Online devices....\n------------------------------------------------------\n";
foreach $a (@online_devices){
	say $a;
	print RP $a."\n"; 
}#end foreach

print "\n\nOffnline devices....\n------------------------------------------------------\n";
print RP "Offline devices....\n------------------------------------------------------\n";
foreach $a (@offline_devices){
	say $a;
	print RP $a."\n"; 
}#end foreach

close RP;

remake of 80’s computer toy word game

80's computer word game
80’s computer word game

Way back on Christmas of ’87, my sister got a computer toy similar to this one.  I couldn’t put it down.  It had a word game with 8, 14-segment LEDs where you had to enter letters one at a time and guess the word before your tries ran out, sort of like wheel of fortune.  I got bored on Sunday night, and wrote a command line version.

perl command line word game
perl command line word game

It requires an external file, words.txt, from which it randomly chooses a word for each round.  Above is the game play.

Here is the source:

#!/usr/bin/perl -w
use Tie::File;
use strict;

#array of all letters
my @letters = 'a' .. 'z';
my $szletters = @letters;
my @used_letters;
my $n_tries = 0;
my $wf = 0;
my $iword = '';
my $letter = '';
my @wrd;

my @words;
tie @words, 'Tie::File', "words.txt" or die $!;

my $nw = @words;
#print "nwords: $nw \n";
my $num = int(rand($nw));

my $word = $words[$num];

#print "word: $word\n";

my $lngth = length($word);

for(my $l=0; $l < $lngth; $l++){
#print '-';
$iword = $iword."-";
}#end for
print "\n";

@wrd = split //, $word;
my $lef = 0;
do {
print $iword."\n";
print "enter a letter: ";
chomp($letter = );
#print "letter: $letter\n";

#clear out iword
$iword = '';

push @used_letters, $letter;
for(my $l=0;$l<$lngth;$l++){
foreach my $v (@used_letters){
if($wrd[$l] eq $v){
$iword = $iword.$v;
$lef = 1;#set flag true
}#end if
}#end foreach

unless($lef == 1){
$iword = $iword.'-';
}#end unless
$lef = 0;
}#end for

print "used letters: @used_letters \n";

if($iword eq $word){
print "$word\n";
print "YOU WIN!!!\n";
$wf = 1;
}#end if

} while($wf ==0);

underclocking raspberry pi 3 B+ to conserve power

pi lightning

While loading all the packages and software I need for my battery capacity tester / analyzer on my new pi 3 B+,  I would get the undervoltage lightning bolt, and the pi would reboot.  Half the time, it would crash again before getting to the desktop.  If I was lucky enough to get that far,  it would crash again while trying to install packages like apache2 and php7.

I have been using a simple power supply circuit for a long time based on an LM7805  voltage regulator chip in a TO-220 package plus a good heat sink, and with a couple of reservoir capacitors to power my pi projects.

LM7805 5VDC power supply circuit
LM7805 5VDC power supply circuit

It has worked great for me with no issues using a pi 2B and the pi 3B.  On the new pi 3B+, however it simply is not enough.  The new pi 3B+ has an aluminum heat sink to improve  thermal management issues due to the 1400MHz clock rate of the CPU and requires a 2.5 amp power supply.  The particular LM7805 chip I use can supply 2 amps;  enough to power on, but cannot supply power under a significant load.

I am looking into using an LM2576, however it requires several external components that I did not have on hand like a 100uH inductor,  and I wanted to get this dude up and running right now.

I decided to try and see if underclocking the CPU would get me by.   I added the following to /boot/config.txt to throttle the clock speed to 900MHz:


arm_freq=900

After rebooting,  I still got the occasional lightning bolt, but it never shutdown.  I then put the pi 3 B+ under a prolonged stress test that maxed out one core of the CPU for over 10 minutes and browsed heavily on chromium during the test.  I would reach 100% capacity on the CPU, but it never shut down.  I will pursue a better LM2576-based  power supply circuit, but this is a good temporary fix.

raspberry pi 3 B+ based battery capacity test analyzer
raspberry pi 3 B+ based battery capacity test analyzer
raspberry pi 3 B+ based battery capacity test analyzer
battery load test analyzer internals. Uses 3ea MCP3208 ADC’s, pi 3B+, adafruit pi cobbler, BPS POW-3U prototype board.

raspberry pi 3 B+ requires latest raspbian stretch

I just received a raspberry pi 3 B+ this week that I ordered from Newark.  I am using it to build another battery capacity test  data acquisition + analyzer.  I love the pi’s SD card copier accessory.  I used it to burn an exact copy of the image I have on a working analyzer to a fresh 8GB SD card.  This is particularly useful on this project because I have so many special packages, file systems, daemons, and configuration options set up on this pi, and wanted an exact copy.  The one I copied it from was running on a pi 3.  I put the SD card into my new pi 3 B+ and fired it up.

Raspberry pi 3 B+
Raspberry pi 3 B+

The power LED had a regular blinking pattern; three short, four long – if I remember correctly.  At first I thought I had a bad pi out of the box.  I then began to suspect the SD card.  It was the cheapest class 10 SD card I could find on Newark.  I put it into a pi 2 and it booted up just fine, so that wasn’t it.  Lo, and behold the pi 3 B+ will not run on raspbian jessie;  it must be stretch running linux kernel 4.1.

I downloaded the latest version of raspbian stretch, reformatted my SD card to a FAT file system, and used etcher to burn the image to the card.  Put it in, fired it up, and bam!  It started up just fine.  Bad thing is I will have to manually configure everything from scratch.