http://qs1969.pair.com?node_id=1184633

Pi day isn't quite over, but given that most know about my Raspberry Pi work, I thought I'd share something.

I have been focusing on creating a physical layout for all of the supported Integrated Circuits and other peripherals that are available to Perl under the Pi, so that I can create a full-blown automated test regimen that runs continuously against the code using my Test::BrewBuild software.

Because the work is very precise and requires diligence to ensure everything is as connected properly as it is confirmed that numbers match up so that when proper tests are finally written everything aligns, I thought I'd share a tiny piece of what I was working on before Pi day is over.

Given this diagram, which utilizes a RPi 3, an MCP3008 analog to digital converter, an MCP4922 digital to analog converter and a 74HC595 shift register as a baseline, here's some base initial test code that produces human-readable output so I can ensure the setup is reasonable:

use warnings; use strict; use feature 'say'; use RPi::WiringPi; use RPi::WiringPi::Constant qw(:all); my ($dac_cs_pin, $adc_cs_pin) = (12, 26); my $adc_shiftreg_in = 0; my $adc_dac_in = 1; my $pi = RPi::WiringPi->new; my $dac = $pi->dac( model => 'MCP4922', channel => 0, cs => $dac_cs_pin ); my $adc = $pi->adc( model => 'MCP3008', channel => $adc_cs_pin ); print "DAC...\n\n"; for (0..4095){ $dac->set(0, $_); if ($_ % 1000 == 0 || $_ == 4095){ say $adc->percent($adc_dac_in); } } my $sr = $pi->shift_register(100, 8, 21, 20, 16); print "\nShift Resgister...\n\n"; my $sr_pin = $pi->pin(100); $sr_pin->write(HIGH); say $adc->percent($adc_shiftreg_in);

Output:

DAC... 0.00 24.24 48.68 73.02 97.46 99.80 Shift Resgister... 100.00

Much is on the chopping block for change, but I am making no fundamental changes until my CI is complete, and I get a much better understanding of what isn't working properly, and where. I know that PWM requires root which actually crashes the Pi if you don't sudo, and I know that Interrupts aren't doing the right thing.

This step back from coding to focus on tests first, is how I usually do things. Having wrapped a lot of this code, it's come off as a bit of a new challenge to me (because it isn't write tests first then code, it's been code first, then think tests), but I've realized I need to get back to basics; test it first, then move on.

Anyways, as I said early this morning, I'll say the same thing heading out. Happy Pi day ;)