An average computer’s operating system maintains some logistics about the cpu, like its input voltage, temperature and the like. The Raspberry Pi single board computer is no exception and will even scale back its speed if it determines that its internal temperature is getting too high. That’s a good thing but another approach is to proactively cool the cpu with a fan when it’s approaching that threshhold.
…that is the question. Rather than a Shakespeare reference, I’m here referring to a term in software development which determines how a language deals with variables, for example.
When you create a variable in a computer language, it’s usually something like this:
var someVarName = 1;
Two Schools of Thought
There are two camps out there: those who like languages which force the variable type and those who don’t.
A statically-typed language usually involves a step in which your code is converted into something else (compiling) and any type-related issues must be fixed before a program can be created.
A dynamically-typed language is run “as is” and the code is evaluated at the moment of truth—determinations about the type of a variable are made at this time. If there is a type-related issue, your end-user could be the first person to see the error.
The Pendulum Swings
Over the past three decades, the popularity of either approach has waxed and waned. It’s safe to suggest for the moment that the less-strict languages are gaining rapidly in popularity over their stricter counterparts.
Seeing the Future
I don’t know, though. Maybe it’s time that we just relax and let the cat hang out in the fish bowl.
Note that the “zero” in the title of the repository and in js-gpiozero does not refer to the Raspberry Pi Zero but to the original gpiozero Python library.
This should remove some of the guess work when attempting to use the relatively-new library since their documentation examples at the moment are taking a back seat to their code port from the more-extensive Python offering.
This approach can easily be modified to instead exercise external LEDs (as soldered or otherwise attached to the header pin locations seen below). Note that you’ll use “BCM numbering” for APIs such as this one. For external LEDs, you would need to connect it inline with a resistor from a selected pin to one of the grounds for this to work with correct orientation of the LED’s anode/cathode, of course.
// Existing code, for a Raspberry Pi Zero
var ledActivity = new LED(47, false);
// For Raspberry Pi 3, for example
var ledActivity = new LED(47);
And that’s it. Since the Raspberry Pi Zero assumes an opposite value for true/false than the bigger models, it’s necessary to configure this in the device constructor to make things work as expected. Since BCM pin 47 is the activity light on the board itself, this will allow you to control it.
Today’s inventiveness involves a new teaching method for music, a synesthetic approach to colorizing musical notes. The title’s quote comes from Franz Liszt, a 19th-century composer who was a synesthete—he saw music in full color.
Although western doctors probably think of synesthesia as a malady, I would suggest that it is a product of beneficial neuroplasticity. The brain has cross-wired itself across the senses to allow for better recognition and appreciation of something. There’s a long list of famous musicians and composers who wrote of this personal condition and in each case it helped them to succeed.
I have always had a fondness and an early aptitude for music. In fact, I had such a brilliant audible memory and an ability to play anything I’d just heard, that I used this as a crutch when confronted with the task of learning to read musical notation. I didn’t actually have to read the notation in band since the sound of the music was in my head. So although I was a slow reader with respect to notation, nobody actually could tell.
My earliest formal training was for the saxophone, noting of course that you only play a single note at a time. Unfortunately, this led to my later difficulties in learning to play the piano in my thirties. Piano chords on a stave? To me, this just seemed like jumbles of notes piled on top of each other. I had no easy way of interpreting what I was seeing.
After many weeks of painstakingly trying to decypher these heiroglyphics, if you will, I began to have a small breakthrough. My brain started to recognize some patterns. Due to some unfortunate timing, I had to stop all this training and abruptly move and had to sell the piano. It would be another decade until I’d bought another piano to re-learn piano notation.
Attacking the learning of chords-in-notation anew, I realize that colorizing the notes would be a benefit to me. All C notes are red. All E notes are yellow. C-E-G are primary colors (C-maj). The Eb in the middle of the C-min chord is more orange than the original yellow. A synesthetic approach to musical notation is a wonderful adaptation to a centuries-old teaching methodology I’d suggest, at least in my own case.
My two packages arrived today at the post office so I just hauled in all the loot from this earlier post in which I’ve purchased some new toys.
Raspberry Pi Zero W
The photos from their website don’t really describe how truly small this computer is now. They’ve somehow managed to stack the RAM on top of the microprocessor to save space. As I’ve apparently ordered the wrong video adapter cable, I’ve got a trip over to Best Buy Frye’s Electronics this evening so that I can sort that one out. I need a female HDMI to DVI, in other words. Otherwise, I’m still pretty stoked. Since there’s only one micro-USB I think I’ll temporarily need a small USB hub while I’m at it.
This arrived as well, all four of the segments but it was lost on me that I’ll need to solder each of them together. Fortunately, I have a soldering iron here somewhere. :looks around: I’m certain of it.
COZIR CO2 Sensor with RH/Temp
And in the other relatively BIG package is the relatively small sensor package. No wonder they charged me $21.88 to ship this to me. Seriously, it weighs about an ounce.
And it looks like I’ll need a 2×5 jumper to attach this over to the Raspi, with a solder-able header for that, too.
Alright, I’m back from Frye’s with a handful of stuff and I’m back in business. The video adapter allows me to see what’s coming out of the Raspberry Pi Zero W and the micro-USB hub allows me to hook up a keyboard and mouse to talk to it locally. A first install with the Raspbian Jessie Lite image resulted in a terminal-only configuration (I must have been in a hurry and didn’t read the differences on their page) so a second install of Raspbian Jessie with Pixel was just what it wanted: a full desktop experience. If I get some time this weekend I’ll try to have it talk to either the sensor or the light ring.
I just managed to solder together the NeoPixel ring. Due to the size of the electrical pads on the ends of these, I’d suggest that this falls into the catagory of advanced soldering and not to be taken on by the average person.
Additionally, I’d say that this feels a bit fragile in the area of the soldering joints between each quarter-circle. I’m going to suggest that anyone who incorporates one of these into their project needs to seriously think about ways of making this more stable/reliable since the soldering joints between them are tenuously-small. (Imagine three distinct electrical connections across the tiny width of this thing.)
What I also found is that there isn’t anywhere to clamp a hemostat for soldering these jumpers since the LEDs run all the way to the end where the connections should go.
I did add an inline resistor as Adafruit suggested to lower the input voltage or perhaps to lower start-up voltage spikes.
I managed to re-purpose a nice external 5V switching power supply that should drive all the LEDs nicely. It was left over from the supercomputer project when I swapped in a USB-based charger instead for that. Amazingly, Adafruit suggests that those 60 LEDs need a whopping 3.6A of power to drive them. I’m guessing that reality is more like 1A but I’ll play this safe. Per Adafruit’s suggestion I included a 1000 µF electrolytic capacitor across the output voltage to protect the NeoPixels.
So I’m prepped to do a final test of the NeoPixel ring for power and functionality on a standard Raspberry Pi 3 rig (since it sports an actual header). Once I’ve coded a test and verified that it works then I’ll take the soldering iron to the Raspberry Pi Zero W and wire it in with a quick-connect.
I’ve now got the Raspberry Pi Zero W booting with just the power adapter. Note that you can rename its hostname, toggle on the VNC Server, adjust the default screen resolution to your liking and then—in the Finder program in OS X—open up a remote session to its Desktop with vnc://firstname.lastname@example.org, for example. Or, toggle on the SSH Server and connect from a Terminal session with ssh email@example.com.
Have I mentioned how awesome it is to have a fully-functioning computer for $10 (plus $6 for the micro SD)?
And now the power supply is completed and wired to the NeoPixel ring. Everything’s set for 5V DC in at the moment but I may try to adjust the input voltage down to 3.3V later for technical reasons. (The NeoPixels are designed for the Arduino and its output data voltage is 5V whereas the Raspberry Pi is only 3.3V. By adjusting the input voltage down then it makes a 3.3V data line look bigger than it is. There are other tricks like adding a 3V-to-5V data inverter chip but I’d like to avoid that one if possible.)
I’ve smoke-tested the power supply/ring combination and it’s looking good. To make things easier for this step, I’ve now setup a surrogate Raspberry Pi 3 for testing things but since I only had a leftover 4GB microSD, I was forced to use the no-desktop “Lite” Jessie version of Raspbian. But that’s now ready and I’ll likely have some time this weekend to do a basic blink test.
Cool stuff, indeed. Out-of-the-box, it looks like you publish your Electron-based app like you would anything on github:
git clone https://github.com/Somebody/Repository.git
But there’s also a way of downloading OS-specific images and then adding your own app into this subdirectory structure. The result is a stand-alone EXE and folderset which reasonably looks like a drop-in replacement for something you normally would build locally using Microsoft Visual Studio perhaps. In this version though, you’d run Electron.exe but there are instructions on their website for renaming your application, updating the icon’s, etc.
I’ve just used it today to build a basic music player. I wouldn’t say that the layout is as responsive as a typical mobile app’s ability to move content but I did tweak things so that it can squash down to a mini-player and it stills looks great.
This allows you to build cross-platform desktop apps in much the same way that you’d use Adobe PhoneGap, say, to build for mobile apps.
So far, it seems to be well-behaved.
If you don’t want others to easily see your code, there’s a step where you can use asar to zip-up everything into a tidy package.
I didn’t have to digitally-sign anything like you might have to for a Windows 10 application or for OS X, say.
For people who have git and npm, the install is as easy as anything you’ve seen in the open-source space and a familiar workflow.
Currently, I don’t see any support for mobile platforms.
The complete foldedset comes in a 216MB which strikes me as a little big for what it’s doing. The app itself for the music player weighs in at 84MB of this so the remainder is everything that Electron is doing to present all this.
You would need to setup three different build sites to maintain a specific download for your own app. (It’s not like PhoneGap in which you just submit the common code and Adobe builds it in the cloud.)
Given that you’re not digitally-signing your code, you might have to talk your users through the hurdles of having the user “trust” the content within their particular OS.
This might be so popular soon that none of us can really afford to just use Electron.exe by default to serve up our app; we’ll need to rename it before publishing, in other words.
I can see myself wanting to really learn this one deeply. It has a lot of potential for delivering a more native-app experience for users.
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.
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.
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.
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”.
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.
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.
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.
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.
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.
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.
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.
Since I’d created a network share earlier I simply edited the default Express-generated files using Wordpad on my Windows—based computer remotely.
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.