Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Given my Raspberry Pi work, Happy Pi day Perlmonks!

by stevieb (Abbot)
on Mar 15, 2017 at 04:23 UTC ( #1184633=CUFP: print w/replies, xml ) Need Help??

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 ;)

Replies are listed 'Best First'.
Re: Given my Raspberry Pi work, Happy Pi day Perlmonks!
by stevieb (Abbot) on Mar 15, 2017 at 05:02 UTC

    My biggest beef looking at it from an outside view, is that many of the APIs for the sub-objects aren't similar. That's very clear in the above example.

    Feedback welcome on that, and anything else one may think of.

      Why should they be, if the sub-objects have differing applications? (great stuff by the way)

        The whole point of RPi::WiringPi is to consolidate a whole bunch of other C and Perl (the only lib that isn't mine that I'm wrapping/including is wiringPi C library itself), with the goal to ensure all sub-objects have the same, consistent interface (where humanly possible at least).

        I mean it's not bad, but I just know there's room for improvement. I'm not changing anything else (except for brokenness/bugs) until I'm done writing all of the tests for the suite I have in mind, as that'll allow me to get a better understanding and feel for any changes that may be made later.

        The good thing is that I have very sane defaults in most cases, and currently, the API will be able to be finagled without breaking the way it currently works :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1184633]
Approved by Athanasius
Front-paged by Corion
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-12-16 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (449 votes). Check out past polls.

    Notices?