An icon of Computer Science, [Edsger Dijkstra], published a letter in the Communications of the Association of Computer Machinery (ACM) which the editor gave the title “Go To Statement Considered Harmful“. A rousing debate ensued. A similar criticism of macros, i.e. #define, in C/C++ may not rise to that level but they have their own problems.
Macros are part of the preprocessor for the C/C++ languages which manipulates the source code before the actual translation to machine code. But there are risks when macros generate source code. [Bjarne Stroustrup] in creating C++ worked to reduce the need and usage of the preprocessor, especially the use of macros. In his book, The C++ Programming Language he writes,
Don’t use them if you don’t have to. Almost every macro demonstrates a flaw in the programming language, in the program, or in the programmer.
As C retrofitted capabilities of C++, it also reduced the need for macros, thus improving that language.
With the Arduino using the GNU GCC compilers for C and C++ I want to show new coders a couple of places where the preprocessor can cause trouble for the unwary. I’ll demonstrate how to use language features to achieve the same results more cleanly and safely. Of course, all of this applies equally when you use any of these languages on other systems.
We’re only going to be looking at macros in this article but if you want to read more the details about them or the preprocessor see the GNU GCC Manual section on the preprocessor.
Continue reading “Code Craft: When #define is Considered Harmful”
[Elliot Williams’] column, Embed with Elliot, just did a great series on interrupts. It came in three parts, illustrating the Good, the Bad, and the Ugly of using interrupts on embedded systems. More than a few memories floated by while reading it. Some pretty painful because debugging interrupt problems can be a nightmare.
One of the things I’ve learned to watch out for over the years is the subtlety of stack based languages, like C/C++, which can ensnare the unwary. This problem has to do with the corruption of arrays of values on a stack during interrupt handling. The fix for this problem points up another one often used by black hats to gain access to systems.
Continue reading “Code Craft: Subtle Interrupt Problems Stack Up”
We’ve recently noticed two different fonts aimed at programmers, each with a different approach to editor customization. The first, Fira Code, transparently converts common programming digraphs into single characters. For example, <- becomes an arrow and != (or <>) becomes a proper not equal sign. The other font, Hack (can’t argue with the name), aims to make commonly confused characters distinct. For example, the zero glyph has a very distinct appearance from the letter O.
It is pretty easy to understand how Hack works, but Fira seems a mystery at first. Your C++ compiler expects <- not an arrow, right? Fonts support ligatures–sequences of two symbols that run together (like æ). Clever use of these ligatures means that the compiler still sees -> but the screen displays an arrow.
Continue reading “Hack an Editor: Fonts for Programming”
It’s the 21st century, and we’re still a long way from the voice-controlled computers we were all promised in the 60s, 70s, 80s, and 90s. The state of voice interaction has improved, though, and Amazon’s release of the Alexa Skills Kit (ASK) is another sure step towards a future of computers that will pay attention to you. This allows any hardware to become Alexa, your personal voice assistant with the ability to do just about anything you command.
Up to this point, Alexa was locked away inside the Amazon Echo, the ‘smart’ cylinder that sits in your living room and does most of what you tell it to do. Since the Amazon Echo was released, we’ve seen the Echo and the Alexa SDK used for turning lights on and off, controlling a Nest thermostat, and other home automation tasks. It’s not Google Now, Microsoft’s Cortana, or Apple’s Siri that is behind all these builds; it’s Amazon’s Alexa that is bringing us into a world where Star Trek’s [Scotty] talking into an old Mac is seen as normal.
We hope this changes the home automation game in a couple of different ways. First, the ASK processes everything in the cloud so very low power devices are now ready for some seriously cool voice interaction. Second, Amazon’s move to open up what you can do with the software backend means a community developing for the hardware could eventually exert pressure on Amazon to do things like making the system more open and transparent.
Already working on some hacks with the Echo or ASK? Send in a tip to your write-up and tells us about it in the comments below.
Developing new products can be challenging during the debug and test phases, often you have your head down trying to probe the lead of some SOT23 transistor, and just when you get it, you scan your eyes up and find that your multimeter is measuring resistance and not voltage.
[Charles] had this issue compounded on his NI Virtual Instrument. It has an interface totally driven from a PC, which may or may not be in a convenient location to mouse around. Luckily NI just released an API for the 5 in one lab test station and [Charles] quickly whipped up a python wrapper which gives him ultimate control over the instrument.
Tying the script to a USB footpedal and adding some text-to-speech capabilities using google’s API [Charles] is easily able to switch from continuity to voltage to resistance and anything else he pleases with just the tap of a foot and listening to the measurements, making sure he never takes his eyes off the work which is risking a short.
Join us after the break for a quick video demonstration.
Continue reading “Talking, Foot-Pedal-Controlled Bench Probes for VirtualBench”
[CWroos] has written an impressive GUI for the Flyfish FF32. The Flyfish is a port expander of sorts, allowing the user access to a large array of I/O , analog inputs, SPI, I2C and a few other connectivity options over a USB connection. There is no driver as it uses a native HID driver in the operating system of the device it’s attached to. It’s not just tethered to a PC either. It works with Raspberry Pi, Beaglebone and several other SBCs.
[CWroos]’s GUI makes it easier than ever to interact with the FF32. It has a script editor allowing you to run and edit scripts on the fly (pun intended). It appears he’s actually written his own basic like language for the scripting, which he goes into great detail on his site. There’s a blinky script example, and few more complex examples that will show you how to read temperature and control a servo.
There is also the ability to control the hardware directly allowing you to set pins, read firmware version, set the USB address and several other options. If you have an FF32 lying around, be sure to check out [CWroos]’s program and let us know how it works for you.
The world of free 3D-modeling software tends to be grim when compared to the expensive professional packages. Furthermore, 3D CAD modeling software suggestions seem to throw an uproar when new users seek open-source or inexpensive alternatives. Taking a step apart from the rest, [Matt] has developed his own open-source CAD package with a spin that inverts the typical way we do CAD.
Antimony is a fresh perspective on 3D modeling. In contrast to Blender’s “free-form sculpting” and Solidworks’ sequential extrudes and cuts, Antimony invites you to break down your model into a network of both primitive geometry and operations that interact with that geometry.
Functionally, Antimony represents objects as a graphical collection of nodes that encode both primitives and operations. Want a cylinder? Start with a circle node and pipe it into an extrude node. Need to cut out some part geometry? Try defining it with one or more primitives, and then perform a boolean intersection operation. Users can even write their own nodes with custom scripts written in Python. Overall, Antimony boasts the power of parametric design similar to OpenSCAD while it also boosts readability with a graphical, rather than text-based, part description. Finally, because part geometry is essentially stored as a series of instructions, the process of modeling the part does not limit the resolution of the output .STL mesh. (Think: vector-based images, versus pixel-based images).
Current versions of the software are available for both Mac and Linux, and the entire project is open-source and available on the Githubs. (For the shrewd-eyed software developers, most of the project is written with Python that interacts with lower-level routines handled in C++ and exposed through Boost.Python.) Take a video tour of an Antimony workflow with [Matt] after the break. All-in-all, despite that the software is still in its alpha stages, it’s highly functional and (for the block-diagram fans) intuitive. We’re thrilled to put our programming hats on and try CAD from, as [Matt] coins it “a parallel universe.”
Continue reading “Otherworldy CAD Software Hails From A Parallel Universe”