Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

XS, raspberry pi, and a hundred bucks

by Aldebaran (Curate)
on Oct 31, 2021 at 23:27 UTC ( #11138285=perlquestion: print w/replies, xml ) Need Help??

Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I was happy to see that stevieb is among us, as we were both dislocated by fires. When I thought he needed a leg up, I bought his raspberry pi book, programmingtheraspberrypiwithperl.pdf, and soon, I would like to deploy and test. I'm hoping the purchase comes with inner-monastery support.

Anyways, my question is for any takers with experience but the author in particular:

If I want to have a wifi-capable pi, with a camera, what would be the first sensible hundred bucks to spend on acquisitions? I rarely *need* the latest anything, and usually prefer not to be on the bleeding edge. Is a hundred enough?

Also, I'd like to call for links to helpful reading. I seemed to have stumbled onto xs by mistake on somebody else's thread, but now I realize, I'm not going to use it there, I'm going to use it here. Before I ask other questions, I'll read up beginning with perlxs#Introduction

Think that about covers it,

Thanks for your comments,

Replies are listed 'Best First'.
Re: XS, raspberry pi, and a hundred bucks
by stevieb (Canon) on Nov 01, 2021 at 14:36 UTC

    Hi Aldebaran,

    Thanks for buying the book! :)

    Buy a Pi 3 and a NoIR Camera Board v2. Make sure you've got a 2.1A USB charger plug with a good quality cable. You'll also need a good micro SD card. Mine all range from 16-64GB. Spend a little more here; a quality card makes a difference. All in all, you should be right there in around $100.

    I learned XS over time and don't remember the reading I did. WiringPi, which is the backend to RPi::WiringPi which the Raspberry Pi book is based on is an XS module. Most of the code wraps an external C/C++ library, but there is some XS involved. A very trivial XS module I've written is Bit::Manip. There's not much XS there either, but it's a good example of how to present C functions to Perl code, how the files all hang together and such.

    Happy travels,

    -stevieb

      Inline::C is a very nice way to introduce compiled libs, if you're doing C stuff. It handles a lot of situations including presenting interface to shared libraries, if needed. There are other FFIs out there, and XS is also the most fundamental option.

        I usually use Inline::C for initial prototypes and quick one-off tests before I write an actual XS module. I never want a user to have to require Inline.

      Thanks for buying the book! :)

      Youbetcha.

      Buy a Pi 3 and a NoIR Camera Board v2. Make sure you've got a 2.1A USB charger plug with a good quality cable. You'll also need a good micro SD card. Mine all range from 16-64GB. Spend a little more here; a quality card makes a difference. All in all, you should be right there in around $100.

      I got a pi 3B+, NoIR Camera Board v2, 3000 mA power, 32 gig micro sd card. I can hardly believe that it already works. I did not fdisk the sd card as it was already loaded with a perfectly-good unix. Output is vivid and quick.

      I learned XS over time and don't remember the reading I did. WiringPi, which is the backend to RPi::WiringPi which the Raspberry Pi book is based on is an XS module. Most of the code wraps an external C/C++ library, but there is some XS involved. A very trivial XS module I've written is Bit::Manip. There's not much XS there either, but it's a good example of how to present C functions to Perl code, how the files all hang together and such.

      It was very helpful for me to work through the first 2 examples, EX-1. XS interface description is comprehensive, and difficult. Before this, I never understood what was happening in the command:

      h2xs -A -n Mytest

      It finally covers page 176 of Intermediate Perl to work through it.

      Regarding the install, things are moving forward pretty well, but I have run into my first roadblock. I'm getting 404's beginning with this guy:

      libgstreamer-plugins-base1.0-dev

      and it tanks whatever is to follow.

      E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/ +g/gst-plugins-base1.0/gir1.2-gst-plugins-base-1.0_1.14.4-2_armhf.deb + 404 Not Found [IP: 93.93.128.193 80] E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/ +g/gst-plugins-ugly1.0/gstreamer1.0-plugins-ugly_1.14.4-1_armhf.deb 4 +04 Not Found [IP: 93.93.128.193 80] E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/ +g/gst-plugins-base1.0/libgstreamer-plugins-base1.0-dev_1.14.4-2_armhf +.deb 404 Not Found [IP: 93.93.128.193 80] E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/ +g/gst-plugins-bad1.0/gir1.2-gst-plugins-bad-1.0_1.14.4-1+b1_armhf.deb + 404 Not Found [IP: 93.93.128.193 80] E: Unable to fetch some archives, maybe run apt-get update or try with + --fix-missing? pi@raspberrypi:~ $ sudo apt-get update Hit:1 http://archive.raspberrypi.org/debian buster InRelease Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 +kB] Reading package lists... Done E: Repository 'http://raspbian.raspberrypi.org/raspbian buster InRelea +se' changed its 'Suite' value from 'stable' to 'oldstable' N: This must be accepted explicitly before updates for this repository + can be applied. See apt-secure(8) manpage for details.
      Update:

      I've isolated the commands that result in 404-errors:

      sudo apt-get install gstreamer1.0-plugins-ugly sudo apt-get install gir1.2-gst-plugins-bad-1.0 sudo apt-get install gir1.2-gst-plugins-base-1.0 sudo apt-get install libgstreamer-plugins-base1.0-dev

      Since the problem seems to be in the plugins department, I thought I might be able to get away with autogen.sh, but no dice:

      checking for GST... no configure: error: You need to install or upgrade the GStreamer development packages on your system. On debian-based systems these are libgstreamer1.0-dev and libgstreamer-plugins-base1.0-dev. on RPM-based systems gstreamer1.0-devel, libgstreamer1.0-devel or similar. The minimum version required is 1.0.0. configure failed

      I think this brands me as a debian user:

      $ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 10 (buster) Release: 10 Codename: buster $ cat /etc/apt/sources.list deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non- +free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source +' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib + non-free rpi $

      I took a look around to see what what I could checking both gst-plugins-base1.0 and gstreamer. I seem not to have a lot of elbow grease when it comes to distributions, if it veers off the main path....

      Q1) Do I look for newer versions or change my settings?

      Thx all for comments,

        Q1) Do I look for newer versions or change my settings?

        The syntax I was lacking was this:

        sudo apt-get update --allow-releaseinfo-change

        , along with:

        sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove

        and then this command just chugs away...

        sudo apt-get install wiringpi cpanminus libperl-dev libgdbm-dev libdb- +dev libgstreamer1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugin +s-good gstreamer1.0-plugins-ugly gobject-introspection gir1.2-gst-plu +gins-bad-1.0 gstreamer1.0-tools gir1.2-gst-plugins-base-1.0 gir1.2-gs +treamer-1.0 libglib-object-introspection-perl autoconf automake libto +ol pkg-config libgstreamer-plugins-base1.0-dev libraspberrypi-dev git + opencv-data

        Then to complete the "Hurry Up and Wait" chapter of stevieb's guide for rpi's:

        cd gst-rpicamsrc ./autogen.sh --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf/ make sudo make install

        These commands seem to be successful, with the results being a whole bunch of .so files:

        $ cd /usr/lib/arm-linux-gnueabihf/gstreamer-1.0 $ ls include libgstmodplug.so libgst1394.so libgstmonoscope.so libgsta52dec.so libgstmpeg2dec.so ... libgstmidi.so libgstzbar.so libgstmms.so $

        Thanks all for comments. Also, let me repost haukex's very useful guide to configuring rpi's. More on this topic at Re: CPAN 2.29 stuck with Net::SSLeay.

Re: XS, raspberry pi, and a hundred bucks
by kcott (Bishop) on Nov 01, 2021 at 05:27 UTC

    G'day Aldebaran,

    I moved your post from CUFP to SoPW as that seemed more appropriate. My thought process: the software you're asking about may be "cool" but you're actually asking questions related to it (equipment to use with the software & related reading). If you, or anyone, strongly disagrees, feel free to move it back.

    Anyway, I had no problems with post itself: I both approved and upvoted it.

    — Ken

Re: XS, raspberry pi, and a hundred bucks
by davido (Cardinal) on Nov 01, 2021 at 19:34 UTC

    For $100 you can get a PI4 with 4GB RAM and a 32GB Micro SD card as a kit at BestBuy. It's a Canakit or something like that. And it includes a case with fan, power supply, and two mini-HDMI to HDMI cables. From there, grab an old laptop SSD and throw it in an enclosure. Set up USB/SSD boot, and you've got a USB3 booting PI4. It performs very well for what it is.

    After that it's up to you what you do with it. I use a PI4 as a file server and occasional alternate desktop system.

    I use a PI3B+ as my 3D printer's OctoPrint platform (octopi). For that, all I needed was the PI3B+, a 32GB MicroSD (that's more storage than I need but it's cheap), power supply, heat sinks, and a small leftover fan from some old device. I 3D printed the case. I did add a $20 PI-Cam v2, and a longer cam ribbon cable so that I could use OctoLapse for time lapses of the 3D prints. But that wasn't strictly necessary. Octoprint will run on a PI4 too, but that's more hardware expense than is really needed. A four year old 3B+ is plenty for Octoprint and OctoLapse. Mine drives a Creality Ender 3 v2. But the majority of 3D printers should be compatible with Octoprint. And you can print your case, and camera mount.

    Some people a PI3B+ or PI4 as a Plesk server in their homes. For one or two streams, a 3B+ is sufficient. For more than that the broader network and USB bus of the PI4 is desirable.

    There seem are Perl modules already on CPAN in the RPi:: namespace that would expose the GPIO pins, etc. without getting into the Perl XS world. I suppose if you're also writing C libraries that you need to bind in, or wanting to bind existing C libraries Inline::C or another approach to XS could be useful.

    Writing scripts to run on a PI is not all that different from writing code to run on any other resource-constrained linux system.

    That reminds me; I've briefly thought about setting up a PI0v2 with a small LCD screen to monitor things like transmission fluid temperature while towing, oil pressure, coolant temperature, and so on in my 26 year old Bronco 5.8 since some of the gauges in its instrument cluster are dead. It seems like a fun exercise that will certainly end up being more costly than just fixing the cluster. :)


    Dave

Re: XS, raspberry pi, and a hundred bucks
by stevieb (Canon) on Nov 01, 2021 at 14:38 UTC
    I was happy to see that stevieb is among us, as we were both dislocated by fires.

    I'm sorry to hear this. I hope all worked out for you. Interestingly enough, I was evacuated again this year, but this time took it in stride thanks to the past, much more terrifying experience I already had under my belt.

    I've learned that living in the lushness of the forested west coast, fires and even evacuations are part of the routine, much like tornadoes in Kansas, earthquakes in the Bay etc.

      I've learned that living in the lushness of the forested west coast, fires and even evacuations are part of the routine, much like tornadoes in Kansas, earthquakes in the Bay etc.

      It sounds live life can be tumultuous and hazardous over there...
      Here in the UK, it is toilet paper and petrol shortages that cause us concern!

Re: XS, raspberry pi, and a hundred bucks
by Bod (Curate) on Nov 02, 2021 at 18:46 UTC
    If I want to have a wifi-capable pi, with a camera, what would be the first sensible hundred bucks to spend on acquisitions

    Interesting timing of this question. Following on from my highly successful curtain controller, I am toying with creating a Raspberry Pi powered camera unit. Mainly for use taking pictures inside rooms to show the room well. So wide-angle is needed.

    I was thinking of using a Zero 2 board and the new camera module and wide-angle lens - although this lens might be a bit too wide!

    If you are interested you can find my previous Raspberry Pi project here -> Controlling USB on Raspberry Pi
    Something that probably would not have been possible without lots and lots of help and support many good Monks.

Re: XS, raspberry pi, and a hundred bucks
by cavac (Priest) on Nov 03, 2021 at 14:22 UTC

    It really, really depends on your exact requirements. I'm running my 3D printer (using OctoPi) on an ancient RPi 2 and the original camera module. The image quality is a bit, well, uhm, i get an imagine where i can see the printer moving with details high enough to see if everything works. So, the camera is good enough.

    Uploading a big model is painfully slow. But that's usually 5 minutes out of a 5 day print job after having spend a week designing the thing. After uploading, the printing works smoothely. As far as computing power, i'd say it's good enough.

    As far as Wifi goes, that too really depends on many factors. Using a USB Wifi dongle may not be the fastest solution, due to how the RPi implements USB. But especially if the Wifi signal in the target location is not very good, it's easy enough to go for a dongle that allows you to use an external antenna.

    When it comes to using Perl on RPi: That's pretty much the only programming language i use on those things. Here's a five year old demo where i run a distributed genetic algorithm (written in Perl) on 10 RPIs plus an additional one RPi 3 to run the GUI (webserver written in Perl, PostgreSQL database and a browser): https://www.youtube.com/watch?v=0ZJB1FeZzj4

    So i would say, unless you are requiring high quality video and high performance, go for a cheap option for your first project and see how you like it. Even if you decide to upgrade later, there will always be another projects that just needs a small Linux computer. Haven't had a single board computer yet that didn't eventually find a home in some one-off project or another.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
Re: XS, raspberry pi, and a hundred bucks
by karlgoethebier (Abbot) on Nov 02, 2021 at 13:36 UTC
    «…I seemed to have stumbled onto xs by mistake…»

    By chance I stumbled over FFI::Platypus. It might be worth to take a look at. In the sense of TMTOWTDI. See also Is this a way to Go Perl #1. An alternative title might have been «Is this a way to C Perl?». Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11138285]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-05-21 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?