tommy can you hear me?

Okay, so this week’s invention involves me being uncharacteristically-cheap. If you usually read about the gadgets I buy, you should know that I’m seriously into making things and using a variety of tools that I need to get these projects done. I’m happy to buy something if it’s worth the cost.

For these monthly talks I’ve been giving, I wanted to have a hands-free option for the Sennheiser FM transmitter. Because when you’re giving a talk and you’re also typing on the computer it just makes sense that both hands need to be free to do that. And yet, the Sennheiser has a propriety 1/8″ jack that makes it difficult to shop anywhere but their website for accessories.  And their cheapest headset is still hella expensive (~$180) and it’s just a standard headset with a standard microphone with a propriatary plug.  <_<  So I decided to try to build an entire rig instead.

The Gear

Of course, I’m starting things with a Raspberry Pi 3 at the moment but will likely port this over to a Raspberry Pi Zero W when I get things working.

raspberry-pi-3

I just picked up a digital USB microphone from Radio Shack (since they’re closing almost all the stores here in San Diego) so that was a mere $10 and has great quality in a tiny package.

mic

At REI, I snagged an FM radio so that I could do the development and listen in on the transmitted signal.

midland

The Sennheiser at the venue looks like this.  At the last monthly talk I took a photo using my phone so that I could record their tuning for their setup.

sennheiser

You can’t see the hand-held microphone on a cable from this stock photo but it’s kind of a pain, as it is right now.

Progress

So far, things are looking pretty good. I’m able to record from the microphone using the alsa-utils arecord program. I’m able to convert the output WAV file into something suitable for re-transmission. And I’m able to broadcast the signal from a GPIO pin on the Raspberry on a selected FM frequency. I believe I can make a longer antenna that should work out.

What’s missing at the moment is a way to (correctly) daisy-chain each of the commands together so that things will continuously transmit, say, upon startup.

arecord -D plughw:1 -f S16_LE -r 48000 - | ./pifm - - | sudo ./rpitx -m RF -i - -f 87900

Something like that, anyway. Any yet, it doesn’t seem to work like this.  The various, raw “-” hyphens as seen throughout are supposed to represent STDIN/STDOUT for streaming commands from one to the next. Many times this works as expected, albeit with the odd hyphen showing up here and there.

Anyway, things like this take a lot of hacking at the problem to get it solved. Perserverance usually wins a game like this.

Update

And of course the solution was a slight tweak to the earlier attempt.

arecord -D plughw:1 -f S16_LE -r 48000 /dev/stdout 2> /dev/null | ./pifm /dev/stdin /dev/stdout | sudo ./rpitx -m RF -i /dev/stdin -f 87900

the fun never ends

Pretty stoked about my recent orders from the glorious interweb-of-stuff yesterday. Because, obviously, five Raspi’s are never enough for one coder.

Raspberry Pi Zero W

w00t. It’s a single-core version of, say, the Raspberry Pi 3 as if it were stolen, driven to a chop-shop in east Los Angeles and then people ripped off things like the RJ-45 port, the four full-sized USB ports, the header, half the RAM, etc. So it’s definitely stripped-down by comparison.  Looks like the HDMI connector and the two USBs are now their tinier counterparts. I don’t see an audio jack. It still has Bluetooth.

The ‘W’ model (up from the Zero) now includes embedded wi-fi so this ought to be killer. Best of all, it only costs $10 compared to $35 for the Raspi3. Too bad it’s twice the price of the Zero, however. And at 2.6″ x 1.2″ it’s smaller than the ones I’ve had to-date.

Raspberry Pi Zero W

zero-wireless

What will I do with this? It may very well go into the aquarium project I’m working on.

NeoPixel Quarter-Ring 60 LEDs

I also ordered four quarter rings of NeoPixel(s) to build a lighting rig for the ecosystem-pi project.

NeoPixel

The intention is to apply realistic lighting to a closed-system aquarium project throughout the day, adjusting the total lighting to compensate for the measured CO2 levels inside. Basically, the more light, the more plant growth, the more O2 produced and the more CO2 consumed in the process. There becomes a point where too much CO2 is bad for the shrimp so you don’t want to stress them out. And then too little CO2 stresses out the plants.

Digital CO2 Sensor

I was able to find a CO2 sensor for the Arduino which could be tweaked for use in a Raspberry PI project. This particular model also includes relative humidity and temperature for better logging.

COZIR Ambient carbon dioxide sensor with RH and temp

CO2_RHT-ambient_sensor_large

The Project

So far—since I don’t have any sensors, LED lights and such yet—I’m stuck with the GUI design for the interface at this point and making sure that the shrimp are happy.

ecosystem-pi.png

Everything in the interface is mocked-up right now but it ought to be fun to get the Raspberry talking to the sensors and adjusting the lighting from programmatic control. A fair bit of research has been done so far in the areas of aquarium and plant health.

But the two shrimp seem happy and have cleaned completely the two plants of their week’s worth of algae in three day’s time.

despicable me—themed supercomputer

I gave a talk on Tuesday to an eager group of 155 attendees at the monthly SanDiego.js meetup on the topic of “Supercomputing in JavaScript”. I had an opportunity to show the new Raspberry Pi 3 supercomputer which I’d built and took it through its paces.

I think they mostly loved the audio events for assembling the minions and sending them to bed (shutting off the remote nodes). There was just enough time to also show the obligatory “Hello, Minions!” demo program to exercise the Message Passing Interface. I received a wide variety of questions and compliments from the group. And of course afterward, everyone who owned a Raspberry Pi came over to discuss their own projects, which was cool.

Here’s the PowerPoint presentation from that talk, in case you’re interested.

e-mc2 repository with step-by-step instructions

does that make me a pi baker?

I discovered an awesome tool for cloning micro-SD cards like those used in the Raspberry Pi 3 computers for the project I’m working on.  It’s called ApplePi-Baker and it’s doing a fantastic job of speeding up that process.  Too bad it doesn’t work on operating systems other than OS X.

I’m guessing that it’s using the underlying/poorly-documented drive devices on the Apple like /dev/rdisk1 rather than /dev/disk1 (subtle, I know), but it’s blazingly fast by comparison and it seems to work.  And when I say “work” I mean:  you don’t have to go research all the many ways of using the dd command, for example.

Note that you’ll want a few available gigabytes on the destination drive you’re backing up to.  But the program has several compression options.  For example, backing up a 16GB image to a ZIP file only needed about 3.5GB when finished so it’s good when your space is limited.

It’s a little scary at first since it boldly asks for your Admin password as it gets started, as combined with the fact that it isn’t digitally-signed with an authorized Apple Developer key.  That said, you should be able to trust it since it does what it says it does and nothing else.  Note that after you download it, you can’t immediately run it.  You’ll need to open Finder, go to Downloads and then Ctrl-click it and choose Open the first time, then click the Open button.  Having done this once, you may then drag it to your Applications folder and then run it normally after that.

open-source minion supercomputer

It seems like every villian these days has their own plan for world domination. So I thought I’d better get started on my own by developing an open-sourced supercomputer design using the affordable Raspberry Pi 3 computer as the basic building block.

Here, I list some of the pertinent points regarding that design.

Minion Theme

The usual master-and-slaves paradigm for most supercomputer systems is replaced here with a gru-and-minions theme. I intend to add sound events at some point in the future, given the usual “headless computer” arrangement for servers. This should help to flag certain events as they’re happening and add some fun to the project as a whole.

Modular

Each squad of four computers would be contained in such a way that it could connect together with the next set of four.  The name for each squad is E=MC2 which stands for Expandable Minion Cube Cluster.

Self-Contained

Each E=MC2 has its own internal Ethernet switch and a USB charging hub to power things inside. The first in the system also includes a shared USB-based thumbdrive for common resources as well as the code that you wish to run in parallel.

Low-Power

Everything internally is powered with a USB charger so that’s about 15W per computer (or core). The power cost then is less than half the per-core cost of a typical supercomputer for electricity, noting that your average supercomputer must also be cooled.

Low-Cost

Weighing in at less-than-$300, the squad of computers has a per-core cost of less than $75. Throughout, I’m using open-source software. I hope to further minimize costs involved by renting time on a 3D printer locally rather than purchasing one.

Mobile

Since I hope to show this project to others, the entire thing should be relatively mobile by design.

In the “known wi-fi” mode, a single power cable could be the only connection to the device, allowing a laptop to connect to it wirelessly. It would be necessary to first educate the gru node and the laptop with the wi-fi credentials, however.

In the “unknown wi-fi” mode, you would add an Ethernet cable to a laptop computer to connect to the system. It would be necessary to configure the laptop’s Ethernet adapter to match that of the internal wired network.

When the 3D printing work has been completed I envision a clear, self-contained, 6″ cube weighing in a under two pounds (minus the power cord). We’ll see how that plays out soon enough.

Technical Savvy

I’m trying to make this as easy as possible for others to repeat. I’m carefully documenting the hardware list to make this easier to source and so that the same set of 3D printing designs I use might accommodate your own attempt at this.

I do, however, assume that you would have some basic electronics experience, have some tools and a small budget to work with and that you understand your way around Linux terminal commands like ls, cp, mv, mkdir, cd, chmod, chown, sudo, apt-get install as well as how to map a drive on a network in either OS X or Windows, say.

You’d also need to know how git and how github works in order to pull the code and design files.

It will be helpful if you understand DNS, DHCP, the concept of IP addresses and how to configuring these on a computer.

Documentation in Real-Time

I’ve purchased the new hardware for this, having done some work already preparing the working image for gru, the master node of the system. I’ve created a repository for everything at e-mc2, noting that there are more than one README.md file within the collection of instructions so far.

As I install the full set of software and dependencies again I will be updating the documentation so that everyone may follow along and be assured that I’ve not glossed over any of the details.

Design Hurdles

I had some problems with the first (several) attempts to power everything with a chassis-based switching power supply but the connections themselves proved to be too problematic. And given the open-sourced nature of the project I would hope that others would build their own so I deemed this attempt “too fussy”. Additionally, the “green” Ethernet switch’s tendency to lower its power demands before any nodes came on then confused this power supply which looked something like this:

  1. The “Green” Ethernet switch would power on and the switching power supply would adjust the input current and output power
  2. The switch would determine that none of the nodes had “linked in” to their Ethernet connections (yet)
  3. The switch then would go into green mode and lower its power consumption and the switching power supply then would attempt to toggle down the output power
  4. The switch and other devices wouldn’t get enough power and then would power cycle, repeating the pattern

This next iteration then changes the power system completely which so far promises to be much easier, resulting in solid connections to the devices.

Common Protocols and Code

I’ve decided to use the Message Passing Interface (MPI) for inter-node communications and the Samba software so that the coder may map a drive to the shared data/code area.

Since I like Node.js, I’ll be developing something so that this is a choice as well. The initial “Hello, Gru!” demo may likely be written in Python, however.

Plastic

I’ve found a local place that rents 3D printers. Hopefully I can get some help designing the files necessary to house all this in a clear cube.

As far as external connections/openings to the cube, there should be one rectangular cutout for the IEC320C5 three-prong power plug and a Keystone receptacle for the Ethernet connector so that it can snap into place. Also, there should be some holes adjacent to an internally-mounted speaker. Optionally, there might be openings on both sides if a fan is added. Overall, it should be a pair of clear plastic parts which snap together to form a cube.

Internally, there should be screw holes and possibly slide rails or bumpers for the Ethernet switch, the USB charging hub and the four Raspberry Pi 3 computers. There should be room for five 1′ Ethernet cables as well as five or six 1′ micro-USB cables for power. As preferences go, it should be relatively easy to open up, remove a computer and its micro-SD card for the sake of maintenance, say.

Although it should operate well without a fan, I’m trying to source a usable 5V-powered fan for the design. Since some of you will want to overclock, this is probably a good idea, I’d guess. That being the case, a cube-to-cube side orientation of venting would create a continous flow of air through all. It may be difficult for everyone to source something like a 5V-to-12V boost module but that’s probably the route to go, combining this then with an inexpensive and readily-available 12V computer fan.

Using the Last USB Port Wisely

The existing design calls for four USB cables to power the computers and a fifth to power the Ethernet switch. That leaves one last USB port to power something. Here are some options.

  1. The existing design utilizes a tiny USB thumbdrive which goes directly into the gru node and is shared by all. Instead, this could be a USB-powered external drive with faster throughput, if so desired. One USB cable would connect the drive to gru and the second would provide power over USB to the charging hub.
  2. A small speaker attached to the grunode should allow sound events to be played in conjunction with code execution. Some speakers are USB-powered and this may be an option.
  3. A USB-powered fan would be the logical choice, however, for the remaining port.

Repository

In case you missed the link above, the repository is now at e-mc2 on github. As of today, it’s probably a bit premature to start your own supercomputer from these designs. I personally would wait until I’ve got more of the MPI-based coding in place and have added the step-by-step instructions for some of the dependencies.

Update 3/27/2017

Things are looking great for the repository and the supercomputer itself. The MPI-based code is now working as well as the website for managing the minions.


server-side tone synth with node

I thought I’d work on another Raspberry Pi 3 project and this time was looking to expand my repertoire for server-side audio.  I suppose I was imagining an application in which you’d carry the Pi along with you using a USB-based power bank and plugging in your headphones, controlling the interface via your cellphone’s browser, let’s say.

Platform

Logically then this would need to be a Node.js—based webserver which could synthesize a sine wave tone with a specified frequency on both left/right audio outputs on the server itself (rather than streaming it back to the client browser).  I chose the Raspian image for the microSD card because, as a Debian modification, it’s likely the closest to the standard Ubuntu flavor of Linux which I work with the most.

Open Source

Searching the npm space I found nothing useful, to be honest. It’s rare when the open source world fails to deliver but this was one of those times. I was going to need to innovate on this one. There are many repositories out there which use the browser’s window object but that just wasn’t available here on the server. I installed module after module only to find that one of its dependencies relied upon that same pesky window object. So each time, I had to perform another npm remove --save whatever from my project to return things back to “square one”.

This research took a little longer than I’d hoped for but it turns out that Raspian out-of-box includes the Open Sound System (OSS) aspi-utils collection and its speaker-test program can be used in a terminal to generate tones from both speakers. Okay, so now how do you run terminal programs from JavaScript?

Starting External Programs From Node

It turns out that Node has an internal module called child_process which allows you to spawn (run) something you might normally invoke from the command line. It took some reading but I was able to navigate the documentation and to start a speaker-test session with the necessary arguments. One task down, (one to go).

Stopping External Programs From Node

Fortunately, Node also has an internal module process with a kill command to stop a running process.

Implementation

It takes a bit of state management: the webserver needs to remember if you’ve started a process, what its process ID is and whether or not you’ve now stopped it. A proper open source project would support systems other than Linux but this is the starting point and this wouldn’t work, say, with a Windows-based computer using the PowerShell module control, for example.

Since this wasn’t an exercise in UX design the interface couldn’t really be any simpler. It’s your basic Express-generated website with the Pug view engine and a simple pull-down list for selecting some preset frequencies. Submitting your tone choice POSTs back to the same index page; selecting the Stop button POSTs to a virtually-routed /stop routine which then redirects back to the original index page.

Source Code

Check it out if you’re curious. I’ll likely be using this same technique to create a more self-contained module for managing external programs.

github.com/OutsourcedGuru/heal

raspberry pi 3 with node.js

First day with the Raspberry Pi 3 and I’m already having way too much fun with this! Today, I decided to see how fast I could get a Node.js—based webserver running on it and was not disappointed.

Out-of-the-box it comes with the NOOBS installation manager at bootup which politely asks you to install an operating system from the selection. I chose the default Raspian operating system because it’s basically a Debian project and well-trusted.

My task was made simpler because I’d purchased one of the Raspberry Pi 3 kits which included a microSD card pre-loaded with NOOBS. I’d suggest doing the same since the markup over a standard 16GB microSD wasn’t much, to be honest. The empty Raspberry Pi 3 board costs about $35 these days but the kit at $60 includes the NOOBS-preloaded microSD and a 5V power adapter. My kit also included a basic/clear case but I opted for a $9 red case which seems to be more standard.

Setup

For the initial setup, you need spare Ethernet and HDMI-to-DVI cables, USB mouse, USB keyboard and a monitor. Everything gets plugged in before adding the power adapter to boot it.

One thing to note if you’ve just purchased one and are confused, you’ll need to remove the microSD adapter from the included SD adapter before inserting the former into the Pi. They include the larger SD adapter because some people might need that, in theory, to insert it into their workstation if the need arrives. Store the adapter for future use.

microsd

I found that the latest release of Raspian somewhat hides the wi-fi configuration compared to earlier versions. You’ll find what you need by left-mouse clicking the network symbol in the upper taskbar. I also found it necessary to manually edit the /etc/network/interfaces file in a terminal session to change the wi-fi from manual to dhcp. I would imagine that subsequent versions of Raspian will fix this however, you might not be able to easily update the operating system until you’ve achieved a working network connection in the first place.

Headless Boot

Confirming that the networking was happy, I shutdown the Pi, removed everything but the power adapter and booted it again, doing everything next remotely via ssh or RDP.  First I updated the software via a terminal session and then installed tightvncserver, xrdp and samba. I configured a shared drive for use later in /etc/samba/smb.conf file and created a Samba network user for the default pi operating system user. Next, I tested remote connectivity from both a Mac and a Windows-based computer and all looked good for the share.

Next, I installed Node.js globally from a Nodesource.com—based distribution as well as the express-generator. I created a ~/share/sites subfolder and then used Express to generate a new hello application below this. I then started up the newly-created website.  Fortunately, the Samba client recently installed publishes its own hostname to the DHCP server so that I could then surf the website from Windows without knowing its IP address as seen here. The default port for an Express website is 3000, btw.

raspberrypi_webserver

Since I’d created a network share earlier I simply edited the default Express-generated files using Wordpad on my Windows—based computer remotely.

What Next?

From here, I’ll likely be investigating earlier projects like the magnetic card swipe visitor station to convert it to using a Raspberry Pi 3 instead of a larger workstation. By adding a USB-based drive you could likely repeat the earlier Kloudspeaker project with a much smaller footprint.

I intend to create a squad of four Raspberry Pi 3’s in a housing which includes an Ethernet switch, a common power supply and a fan all in a self-contained housing which promotes good airflow and optional stacking. In this case, I’d need to change over to an Ubuntu operating system, I think, since some of the provisioning tools there might make something like this easier. I’ll ultimately have a supercomputer for a fraction of the cost of what you might expect to pay.

In a follow-up post, I’ll be discussing my attempts to install and evaluate the Ubuntu Core for the Raspberry Pi 3 operating system using a second microSD which I purchased for this purpose.