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”

Friday Hack Chat: Building Robotics With The MeArm

Somewhere, in a storage closet used by every computer science or engineering program, is a robot arm. It’s there, you’ve probably never seen it, but it’s there. Originally, this hugely expensive robotic arm was intended to be a truly remarkable pedagogical tool, allowing students to learn about reverse kinematics and control systems. Now, most likely, that robotic arm is covered in dust, either because the arm itself is broken or because the only instructor that used it retired.

These days, robotic arms are within nearly everyone’s reach. Ben Gray’s MeArm is a popular robotic arm made out of laser cut acrylic and powered by hobby servos that anyone can put together. It’s the minimum viable robotic arm, and for this week’s Hack Chat, we’re going to be talking all about robot arms, what they can do, and how they can be used in education.

During this Hack Chat, we’ll be discussing the ins and outs of reverse kinematics and manufacturing robot kits with Ben. We’ll also be talking about Ben’s current efforts to get people of various backgrounds in on robotics education. Topics that will be covered include:

  • designing and manufacturing the MeArm
  • robotic arms
  • robotics kits
  • robots made for hacking

You are, of course, encouraged to add your own questions to the discussion. You can do that by leaving a comment on the Hack Chat Event Page and we’ll put that in the queue for the Hack Chat discussion.join-hack-chat

Our Hack Chats are live community events on the Hackaday.io Hack Chat group messaging. This week is just like any other, and we’ll be gathering ’round our video terminals at noon, Pacific, on Friday, May 4th.  Here’s a clock counting down the time until the Hack Chat starts.

Click that speech bubble to the right, and you’ll be taken directly to the Hack Chat group on Hackaday.io.

You don’t have to wait until Friday; join whenever you want and you can see what the community is talking about.

The Internet Of Claw Machines

Remote administration of machines is a very useful tool for all manner of commercial, industrial, and home applications. Now, it’s available for claw machines, too – thanks to [Code Your Venture Free].

The project uses an ESP32 board that includes a battery case on the back for a standard 18650 lithium battery that makes getting small battery powered projects off the ground much easier. You can find them at Banggood and AliExpress, but we’re not 100% sure that they’re kosher because they’re branded WeMos, but don’t show up on WeMos’ website or their official online retail store. Anyway, it’s a cute idea to strap a LiPo cell to the back like that. Let us know in the comments if you know more.

Back to the claw! An off-the-shelf thumbstick is then connected to the ESP32 which is programmed to send packets over the network to control the claw machine, which is wired up with its own network-connected microcontroller. It’s all wrapped up in the usual 3D printed case.

The one problem that the project doesn’t solve is delivery – how does the remote player, whether on the local network or online, collect their prize? We can only assume some cutting-edge form of drone delivery is the solution. It’s not the first remote claw machine we’ve seen, either. Video after the break.

Continue reading “The Internet Of Claw Machines”

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”

Scotty Allen Builds A USB Drive From An IPhone

What happens when you come across a mysterious, partially populated circuit board in the Huaqiangbei electronics market in Shenzhen? If you’re [Scotty Allen], the only answer is to make your own USB drive from iPhone parts.

[Scotty] made a name for himself through his YouTube channel Strange Parts where he built his own iPhone from scratch, added a headphone jack to an iPhone, and other various exploits involving hot air in Shenzhen. This latest build is no different. It begins with a random PCB [Scotty] found at the electronics market. It has a USB port on one end, it has pads for an iPhone memory chip, and it has an IC that looks like a USB to Flash converter.

The build involved finding a few broken iPhones, desoldering and reballing their Flash chips, and when those didn’t work, finding the correct Flash chips for this tiny little USB adapter board. Here, [Scotty] ran into trouble. The first Flash chip didn’t have the right pins, there was blue smoke, and the toolchain for initializing the USB to Flash IC was a mess.

In the end, [Scotty] managed to create a USB Flash drive after five or six visits to the electronics market, two stencils to reball Flash chips, and finding the OEM software for the USB to Flash chip on this very special PCB. That, itself, required Windows (the horror!), and finding the right version of the software.

Is this technically building a Flash drive purely from disposed iPhone components? We’d quibble. But is it a cool build, regardless? Absolutely. And the real story here is how quickly [Scotty] could iterate on his engineering. When the greatest electronics market is right around the corner, you can do anything with a microscope and a hot air gun.

Tron Inspired LED Desk Lighting

Reddit user [barbarisch] thought his computer desk was a bit boring, so he came up with a cool project to spice it up: A Tron-inspired computer desk with embedded LED strips!

[Barbarisch] took a basic desk and replaced the tops with ¾” oak plywood. The LED routes were planned out on the computer first and then marked out on the plywood. Using straightedges, [barbarisch] carefully used a router to create the straight grooves and then he created a jig for doing the circles. A bit of trimming and sanding and the three pieces of the desk match up.

After painting the desk, it was time to take a crack at the LEDs. Originally, [barbarisch] thought about 3D printing some diffusers to cover the individual WS2812B lights, but it wasn’t coming out to his liking, so diffusers have been put on the back-burner for now. Holes were drilled in the desk so that connections could be made between the different parts of the grooves and soldering was done between bits of the strips when turning corners. The whole thing’s being controlled by a Raspberry Pi and a Fadecandy USB controller for RGB strips. [Barbarisch] modified a Pi case so that the Fadecandy board would fit as well as printing out a bracket to mount the hardware under the desk.

A fun project to update that boring computer desk and to help you out, the python code which communicates with the Fadecandy server has been put up on GitHub. From the Reddit discussion, it looks like [barbarisch] might have found a solution for diffusing the LEDs! If it’s an LED desk you’re interested in, though, we’ve seen interactive LED tables and Mega LED desks before!

Continue reading “Tron Inspired LED Desk Lighting”

Hair Today, Gone Tomorrow, Via Electrolysis

We think of electrolysis as a way to split things like water into oxygen and hydrogen using electricity, but it has a second meaning which is to remove hair using electricity. An electrologist inserts very thin needles into each hair follicle and uses a burst of electricity to permanently remove the hair. [Abbxrdy] didn’t want to buy a cheap unit because they don’t work well and didn’t want to spend on a professional setup, so designing and building ensued.

You’ll have to read through the comments to find some build details and the schematic. The device uses commercial electrolysis needles and a DE-9 connector socket as a holder. The device can supply 6 to 22V at up to 2mA. A timer can restrict the pulse to 5 seconds or less.

Continue reading “Hair Today, Gone Tomorrow, Via Electrolysis”