“Free Energy!”

There’s a reason this post title is in quotes: one of the most unbreakable, solid scientific laws we know of — one of the ones that we’ve never known to be wrong — says that energy cannot be created or destroyed, other than conversions between mass and energy (as in nuclear reactions.)

In simpler words, this means that “free energy” cannot exist, unless you mean harvesting already-existing energy sources such as wind or solar power. Science is, after all, simply the process of figuring out what explanations make correct predictions about actual events, and which do not.

And we figured out a long time ago that energy cannot be created from nothing. Even the one minor exception that Einstein found unlocked all of atomic power for humankind — from nuclear power plants to hydrogen bombs, as well as much of modern medicine.

So we know the laws of thermodynamics quite well. Energy (if you include matter as energy, as Einstein showed) cannot be created or destroyed. This is right up there with “two things cannot be in the same place at the same time” and universal gravitation. It’s right, every time. We’ve never come across any macro-scale exceptions.

This doesn’t stop the thousands of YouTube videos purporting to show how to build “free energy” gizmos that can power your whole house by connecting up some spark plugs and magnets to a battery-powered fan or something. It’s understandable: it costs almost nothing to make a quick video and post it online. People are gullible and bored, and they’ll watch just about anything.

And views are views, whether you’re a scam artist or one of the good ones promoting solid science, engineering, or math. Unfortunately, really bad science is sometimes passed off as good entertainment and the distinction isn’t always clearly labeled.

Now, as Ross Perot would have said, here’s the deal. Let’s suppose for a minute that the scientists and engineers have overlooked some clever way of tricking the Universe into providing truly limitless, free energy. It could happen, you might think. Similar stuff has happened before, and the electric motor was pretty magical when it was first invented. Suppose some garage inventor, working in his or her lab just like Faraday, came up with just the right combination of wires and magnets to go over-unity and produce a net energy gain.

This wouldn’t be a world-changing invention. This would be THE world-changing invention — probably beating out more mundane ones like the invention of fire and the wheel, over time. We would, as a species, suddenly have the ability to travel, for cheap. We could desalinate as much water as we need from the world’s oceans. It would benefit everybody even the billionaires would become quadrillionaires!

This would be Minecraft on creative mode. There would be no reason on Earth to suppress such an invention, and absolutely no way to do so, once anybody else learned about it. We wouldn’t just be able to power our homes for free. We’d have our own spaceships!

So if you believe in true “free energy” devices, you are required to also believe that:

  • The vast majority of the world’s scientists and engineers are complicit in covering up the biggest secret in history,

    or
  • Some obscure inventor has come up with this idea, but Big Oil or the Illuminati or whomever has suppressed it, and is sitting on it or is trying to destroy it. (Hint: they would patent it and put it into production as fast as possible and sell energy 5% cheaper than the next guy, while they paid nothing) — and nobody else has managed to figure out how it was done. If a set of plans or an Internet video exists of it, this is not the case. If people have bought these plans and they worked, at some point an engineer will see one, they’ll call the news, and then everybody will know. And the media would cover it. Some reporter would be getting a Pulitzer to go with the inventor’s Nobel.

TL;DR: These so-called “free energy” devices are almost certainly not possible, despite the fact that they would benefit absolutely everybody. If they did exist, they would be civilization-changing in a way we’ve never seen before, and there would be no keeping it secret.

So if you didn’t know better, that’s why these videos are invariably clickbait and complete nonsense. Please don’t encourage their makers (except to make legitimate claims about what they create.)

If you do know better, please don’t make these videos! The last thing we need right now is more people doubting good science and thinking the world is run by some shadowy Deep State.

And if you’re Mehdi, thank you. Good to see a fellow Jedi. Maybe don’t lick the science next time, though?

Posted in Current Events, Digital Citizenship, Science | Leave a comment

The Sound Of Music

FreeBASIC is a great language for informal messing around. In two lines of code, you can be drawing graphics in full-color 1080p. Now that FBC supports compiling for x64, you can allocate ridiculous size arrays using as much memory as you have available.

It’s the ideal modern back-of-the-envelope prototype language for those of us who grew up on BASICA, Tandy BASIC, and QBasic/QuickBasic. But as with most reboots of beloved childhood franchises, a few things seem to be missing.

Playing music, for one, was very easy back in the days of BASIC. Most languages included a “play” keyword that could be called to play various notes. Type something like “play cdefg” and you could make the speaker produce a simple scale.

FreeBasic, unfortunately, doesn’t have the “play” keyword (though, oddly, WinFBE still flags it as a keyword.) FreeBasic is cross-platform, being available for Windows, DOS, and Linux — and so hardware-specific things like speaker support weren’t included.

Fortunately, however, there’s a workaround that ends up being a significant upgrade. Windows provides various APIs that can be used by programs to request functionality from the OS. One of these is the ability to emulate General MIDI instruments, and to accept commands for these from programs. With a little setup, FreeBasic can have access to all of Windows’ General MIDI capabilities.

So now, instead of commanding simple beep melodies, we can produce almost-performance-quality music. The API is even relatively easy to set up once you know the right commands — and this is where Google helps immensely. After a brief search, I found an example by FreeBasic.net user “Mihail_B” that shows how to get Windows to play a couple of percussion samples via MIDI.

A quick look at the MIDI specification helped decode what was happening. For each note played, a MIDI “note on” command is sent. One of the relevant lines of code is:

midiOutShortMsg1(midihandle,&h403f90)

This calls the “midiOutShortMsg1” wrapper to the midiOutShortMsg() function provided by Windows. (See the code example above for the supporting API calls — there’s some setup needed.) The information as to what to play is contained in the three hex bytes at the end: 40, 3f, and 90.

Breaking these down, the “90” is the status byte, the “3f” is the note number, and “40” is the velocity. The first four bits of the status byte (the “9”) tell us that this is a Note On command, and the second four bits (the “0”) tell us that this command is being sent to MIDI channel zero.

The “3f” is the note number — decimal 63, where the notes are numbered from 0 to 127 with 60 being middle c. So note 63 (3f in hex) is three half-steps above Middle C, or D#4.

Finally, the “40” is the note-on velocity. This translates to 64 in decimal, which is halfway up the velocity scale (and the default velocity sent by keyboards and other instruments which don’t record velocity information.) A good electronic piano would send varying velocity information with the note commands; a harpsichord, which doesn’t have key-velocity dynamics, would probably just send 64 with each note.

With this understanding, a wrapper function can be written to play notes more easily. The FreeBasic code linked below (a spinoff using key pieces of the code linked above) implements the “playNote()” and “stopNote()” functions. Both take (note, velocity, channel) as arguments.

So, once MIDI is initialized and the instrument patch is selected (the default is grand piano), playing middle C is as simple as:

playNote(60, 64, 0)

It’s good MIDI practice to turn the notes off, as well. With patches like the grand piano, it may not matter much, since most instruments will automatically silence the oldest notes as needed if given more to play. But with other patches (pipe organ, violin, etc) which can play continuously, it becomes very important. Sending a Note Off command or a Note On with velocity zero will silence the selected note.

Here is a quick chord demo, easily modified to play whatever notes you like once you know the MIDI note numbers. Share and enjoy!

Posted in BASIC, Coding, HOW-TO, Music | Tagged , , , , , , , , | Leave a comment

A Change In The Weather

The original Weather Prognosticator worked well for several years, but the downside to relying on an external API is that it can get changed out from under you. Or removed entirely.

Last Fall, Weather Underground turned off the API that the Prognosticator had been using. I’d be tempted to ask for my money back, except that it was a free API. Oh, well.

Fortunately, other solutions exist, and OpenWeather’s API is still more or less what is needed. Their hourly data requires a subscription, but three-hour temperature forecasts are still free (within reason.) This means that, instead of displaying hourly temperature forecasts, data is available in three-hour increments — but is available several days out. So instead of displaying hourly data for the next ten hours, the display now shows three-hour temperatures for the next thirty.

The updated code is available here; you will need a free OpenWeatherMap API to be able to use the API.

Enjoy — and stay safe out there!

Posted in Internet, Networking, Projects | Tagged , , , , | Leave a comment

TinyFPGA / ICEStudio

Microcontrollers are deservedly a favorite component for many electronics hobbyists. They’re straightforward to use, cheap, powerful, and capable of doing any number of simple tasks well. The popularity of the Arduino ecosystem — not just the boards, but the IDE and the whole Arduino way of doing things — makes microcontroller-based prototyping easy, fast, and fun.

Although popular dev boards like Digilent‘s BASYS series do exist, FPGAs have been largely left out of this revolution. Programming even a low-end Spartan3E FPGA requires downloading, licensing, configuring, and installing ISE Webpack — a huge set of utilities from Xilinx. The download is several gigabytes, and it all unpacks to something like 10GB once installed.

Webpack, like the name would imply, is a suite of programs that work together to produce the final configuration bitstream for the FPGA. The IDE works with a synthesis tool as well as PlanAhead, where you plan out the inputs and outputs in terms of pins on the FPGA itself (not the board.) Once all that is done, you generally need an uploader program like Digilent‘s Adept. This is straightforward and reliable to use, but it’s an additional step.

Wouldn’t it be nice if something more like the Arduino IDE existed, with an option to quickly compile-and-upload to test code? Even better, what if you could use such an IDE with an inexpensive, breadboardable FPGA-on-a-stick?

The TinyFPGA BX board, wired up with some test peripherals.

The TinyFPGA BX board, plus the amazing ICEStudio IDE, makes this a reality. We finally have an open-source FPGA toolchain that makes getting up and prototyping with FPGAs almost as easy as programming an Arduino board.

FPGAs are, of course, fundamentally different from microcontrollers. Instead of having a fixed set of instructions to be executed, FPGAs are best thought of as a “sea of logic gates” which can be made into whatever sort of digital hardware you need for your task. You don’t tell them what to do — you tell them what to be.

If you’re used to thinking procedurally and writing programs in procedural languages such as C (and Python, and Java, and BASIC, and Fortran, and so on), this can take some getting used to. (One popular solution is to actually instantiate a microcontroller in the FPGA logic, and then program that in C, which sounds like cheating but works.)

The advantages to FPGAs, though, are that they’re inherently as parallel as you want them to be. FPGAs don’t have to just do one thing at a time; they can have hundreds or thousands of processes executing independently on different parts of the chip. They’re also fast. The TinyFPGA BX runs at 16MHz, which is pretty slow for an FPGA — but because the logic is so configurable, it can get a lot done in that one clock cycle. Simple Boolean logic and binary arithmetic can be done in real time, even if you need dozens or hundreds of calculations done in parallel.

ICEStudio tries to make this way of developing as intuitive as possible. FPGA-based design is often done with a mix of code and schematic capture, with data in the form of either single bits or buses representing binary numbers being carried from one module to another by lines.

For devices like FPGAs, which can be thought of as dataflow devices more than as procedural devices, it works. This approach is flexible enough to allow you to code what you like and connect the rest. Click on a module, edit the code, then press ctrl-u to compile and upload. Easy.

ICEStudio, showing a solution for a LED wave-of-light demo.
(Click for larger)
https://www.facebook.com/m.eric.carr/videos/10223344596951825/?t=1
The TinyFPGA running the solution above.

A breadboardable, open-source FPGA toolchain — and one that can go from updated code to reprogrammed board in ten seconds or so (for simple solutions like the example above)?

Global pandemics not withstanding, I love living in the future.

Posted in Digital, Electronics, FPGAs, Reviews, Tools, Toys, Verilog | Tagged , , , , , | Leave a comment