Directly Executing Chunks Of Memory: Function Pointers In C

In the first part of this series, we covered the basics of pointers in C, and went on to more complex arrangements and pointer arithmetic in the second part. Both times, we focused solely on pointers representing data in memory.

But data isn’t the only thing residing in memory. All the program code is accessible through either the RAM or some other executable type of memory, giving each function a specific address inside that memory as entry point. Once again, pointers are simply memory addresses, and to fully utilize this similarity, C provides the concept of function pointers. Function pointers provide us with ways to make conditional code execution faster, implement callbacks to make code more modular, and even provide a foothold into the running machine code itself for reverse engineering or exploitation. So read on!

Function Pointers

In general, function pointers aren’t any more mysterious than data pointers: the main difference is that one references variables and the other references functions. If you recall from last time how arrays decay into pointers to their first element, a function equally decays into a pointer to the address of its entry point, with the () operator executing whatever is at that address. As a result, we can declare a function pointer variable fptr and assign a function func() to it: fptr = func;. Calling fptr(); will then resolve to the entry point of function func() and execute it.

Admittedly, the idea of turning a function into a variable may seem strange at first and might require some getting used to, but it gets easier with time and it can be a very useful idiom. The same is true for the function pointer syntax, which can be intimidating and confusing in the beginning. But let’s have a look at that ourselves.

Continue reading “Directly Executing Chunks Of Memory: Function Pointers In C”

Accessing Blockchain On ESP8266 Using The NodeMCU Board

Blockchains claim to be public, distributed, effectively immutable ledgers. Unfortunately, they also tend to get a little bit huge – presently the Bitcoin blockchain is 194GB and Ethereum weighs in at 444GB. That poses quite an inconvenience for me, as I was looking at making some fun ‘Ethereum blockchain aware’ gadgets and that’s several orders of magnitude too much data to deal with on a microcontroller, not to mention the bandwidth cost if using 3G.

Having imagined a thin device that I could integrate into my mobile phone cover (or perhaps… a wallet?) dealing with the whole blockchain was clearly not a possibility. I could use a VPS or router to efficiently download the necessary data and respond to queries, but even that seemed like a lot of overhead, so I investigated available APIs.

As it turns out, several blockchain explorers offer APIs that do what I want. My efforts get an ESP8266 involved with the blockchain began with two of the available APIs: Ethplorer and Etherscan.

Continue reading “Accessing Blockchain On ESP8266 Using The NodeMCU Board”

How To Put The ‘Pro’ In Prototype

It’s easy to get professional-quality finishes on your prints and prototypes if you take the right steps. In the final installment of his series about building with Bondo, product designer [Eric Strebel] shows us how it’s done no matter what the substrate.

How does he get such a smooth surface? A few key steps make all the difference. First, he always uses a sanding block of some kind, even if he’s just wrapping sandpaper around a tongue depressor. For instance, his phone holder has a round indent on each side. We love that [Eric] made a custom sanding block by making a negative of the indent with—you guessed it—more Bondo and a piece of PVC. The other key is spraying light coats of both primer and paint in focused, sweeping motions to allow the layers to build up.

If you need to get the kind of surface that rivals a baby’s behind, don’t expect to prime once, paint once, and be done with it. You must seek and destroy all imperfections. [Eric] likes to smooth them over with spot putty and then wet sand the piece back to smooth before applying more primer. Then it’s just rinse and repeat with higher grits until satisfied.

There’s more than one way to smooth a print, of course. Just a few weeks ago, our own [Donald Papp] went in-depth on the use of UV resin.

Continue reading “How To Put The ‘Pro’ In Prototype”

Circuit VR: Oscillating Bridges

Circuit VR is where we talk about a circuit and examine how it works in simulation with LT Spice. This time we are looking at a common low-frequency oscillator known as the Wien bridge oscillator.

What makes an oscillator oscillate? A circuit with amplification that gets the same amount of the output signal fed back into its input, in phase, will oscillate. This is the Barkhausen criterion. Here, we’re going to look into what makes an oscillator work in simulation, and gain some insight into what happens when there’s too much feedback and too little.

In particular, we’ll look at the Wien bridge oscillator, a very simple design that originated as a way to measure impedance back in 1891. Modern versions add some additional features, but let’s start with the most simple implementation and work our way up.

Continue reading “Circuit VR: Oscillating Bridges”

Is It On Yet? Sensing The World Around Us, Starting With Light

Arduino 101 is getting an LED to flash. From there you have a world of options for control, from MOSFETs to relays, solenoids and motors, all kinds of outputs. Here, we’re going to take a quick look at some inputs. While working on a recent project, I realized the variety of options in sensing something as simple as whether a light is on or off. This is a fundamental task for any system that reacts to the world; maybe a sensor that detects when the washer has finished and sends a text message, or an automated chicken coop that opens and closes with the sun, or a beam break that notifies when a sister has entered your sacred space. These are some of the tools you might use to sense light around you.

Continue reading “Is It On Yet? Sensing The World Around Us, Starting With Light”

DIY Magnetic Actuator, Illustrated And Demonstrated

Electromagnetic actuators exert small amounts of force, but are simple and definitely have their niche. [SeanHodgins] took a design that’s common in flip-dot displays as well as the lightweight RC aircraft world and decided to make his own version. He does a good job of explaining and demonstrating the basic principles behind how one of these actuators works, although the “robotic” application claimed is less clear.

It’s a small, 3D printed lever with an embedded magnet that flips one way or another depending on the direction of current flowing through a nearby coil. Actuators of this design are capable of fast response and have no moving parts beyond the lever itself, meaning that they can be made very small. He has details on an imgur gallery as well as a video, embedded below.

Continue reading “DIY Magnetic Actuator, Illustrated And Demonstrated”

DIY Drill-Powered Water Pump

Whether you need to pump water out of your basement this spring, or just want to have fun shooting water around in the yard this summer, here’s a way to build a pump instead of buying one. This is a simple but ingenious build, and [NavinK30] did everything shy of machining his own hardware and making his own tools. Well, it looks as if he might have made that drill.

As you’ll see in his how-to after the break, this centrifugal pump is mostly acrylic, PVC, and fasteners. [Navin] cut two sides and a base for the paddles from acrylic, and joined them with a heat-formed sidewall made of PVC. We love that he cut and bent his own paddles from sheet metal. These are bolted to a round piece of acrylic that attaches to the outside with a long hex bolt. A ball bearing mounted on the drill side allows the pump to churn freely as long as the bolt is chucked into the drill, and the hose clamp is tight enough to hold down the trigger.

Have an extra drill, but don’t need to pump water? Add a camping stove and use it to power a small-batch coffee roaster.

Continue reading “DIY Drill-Powered Water Pump”