Sensor Filters For Coders

Anybody interested in building their own robot, sending spacecraft to the moon, or launching inter-continental ballistic missiles should have at least some basic filter options in their toolkit, otherwise the robot will likely wobble about erratically and the missile will miss it’s target.

What is a filter anyway? In practical terms, the filter should smooth out erratic sensor data with as little time lag, or ‘error lag’ as possible. In the case of the missile, it could travel nice and smoothly through the air, but miss it’s target because the positional data is getting processed ‘too late’. The simplest filter, that many of us will have already used, is to pause our code, take about 10 quick readings from our sensor and then calculate the mean by dividing by 10. Incredibly simple and effective as long as our machine or process is not time sensitive – perfect for a weather station temperature sensor, although wind direction is slightly more complicated. A wind vane is actually an example of a good sensor giving ‘noisy’ readings: not that the sensor itself is noisy, but that wind is inherently gusty and is constantly changing direction.

It’s a really good idea to try and model our data on some kind of computer running software that will print out graphs – I chose the Raspberry Pi and installed Jupyter Notebook running Python 3.

The photo on the left shows my test rig. There’s a PT100 probe with it’s MAX31865 break-out board, a Dallas DS18B20 and a DHT22. The shield on the Pi is a GPS shield which is currently not used. If you don’t want the hassle of setting up these probes there’s a Jupyter Notebook file that can also use the internal temp sensor in the Raspberry Pi. It’s incredibly quick and easy to get up and running.

It’s quite interesting to see the performance of the different sensors, but I quickly ended up completely mangling the data from the DS18B20 by artificially adding randomly generated noise and some very nasty data spikes to really punish the filters as much as possible. Getting the temperature data to change rapidly was effected by putting a small piece of frozen Bockwurst on top of the DS18B20 and then removing it again.

Continue reading “Sensor Filters For Coders”

Following Pigs: Building An Injectable Livestock Tracking System

I’m often asked to design customer and employee tracking systems. There are quite a few ways to do it, and it’s an interesting intersection of engineering and ethics – what information is reasonable to collect in different contexts, anonymizing and securely storing it, and at a fundamental level whether the entire system should exist at all.

On one end of the spectrum, a system that simply counts the number of people that are in your restaurant at different times of day is pretty innocuous and allows you to offer better service. On the other end, when you don’t pay for a mobile app, generally that means your private data is the product being bought and sold. Personally, I find that the whole ‘move fast and break things’ attitude, along with a general disregard for the privacy of user data, has created a pretty toxic tech scene. So until a short while ago, I refused to build invasive tracking systems – then I got a request that I simply couldn’t put aside…

Continue reading “Following Pigs: Building An Injectable Livestock Tracking System”

Airport Runways And Hashtags — How To Become A Social Engineer

Of the $11.7 million companies lose to cyber attacks each year, an estimated 90% begin with a phone call or a chat with support, showing that the human factor is clearly an important facet of security and that security training is seriously lacking in most companies. Between open-source intelligence (OSINT) — the data the leaks out to public sources just waiting to be collected — and social engineering — manipulating people into telling you what you want to know — there’s much about information security that nothing to do with a strong login credentials or VPNs.

There’s great training available if you know where to look. The first time I heard about WISP (Women in Security and Privacy) was last June on Twitter when they announced their first-ever DEFCON Scholarship. As one of 57 lucky participants, I had the chance to attend my first DEFCON and Black Hat, and learn about their organization.

Apart from awarding scholarships to security conferences, WISP also runs regional workshops in lockpicking, security research, cryptography, and other security-related topics. They recently hosted an OSINT and Social Engineering talk in San Francisco, where Rachel Tobac (three-time DEFCON Social Engineering CTF winner and WISP Board Member) spoke about Robert Cialdini’s principles of persuasion and their relevance in social engineering.

Cialdini is a psychologist known for his writings on how persuasion works — one of the core skills of social engineering. It is important to note that while Cialdini’s principles are being applied in the context of social engineering, they are also useful for other means of persuasion, such as bartering for a better price at an open market or convincing a child to finish their vegetables. It is recommended that they are used for legal purposes and that they result in positive consequences for targets. Let’s work through the major points from Tobac’s talk and see if we can learn a little bit about this craft.

Continue reading “Airport Runways And Hashtags — How To Become A Social Engineer”

Build A Fungus Foraging App With Machine Learning

As the 2019 mushroom foraging season approaches it’s timely to combine my thirst for knowledge about low level machine learning (ML) with a popular pastime that we enjoy here where I live. Just for the record, I’m not an expert on ML, and I’m simply inviting readers to follow me back down some rabbit holes that I recently explored.

But mushrooms, I do know a little bit about, so firstly, a bit about health and safety:

  • The app created should be used with extreme caution and results always confirmed by a fungus expert.
  • Always test the fungus by initially only eating a very small piece and waiting for several hours to check there is no ill effect.
  • Always wear gloves  – It’s surprisingly easy to absorb toxins through fingers.

Since this is very much an introduction to ML, there won’t be too much terminology and the emphasis will be on having fun rather than going on a deep dive. The system that I stumbled upon is called XGBoost (XGB). One of the XGB demos is for binary classification, and the data was drawn from The Audubon Society Field Guide to North American Mushrooms. Binary means that the app spits out a probability of ‘yes’ or ‘no’ and in this case it tends to give about 95% probability that a common edible mushroom (Agaricus campestris) is actually edible. 

The app asks the user 22 questions about their specimen and collates the data inputted as a series of letters separated by commas. At the end of the questionnaire, this data line is written to a file called ‘fungusFile.data’ for further processing.

XGB can not accept letters as data so they have to be mapped into ‘classic LibSVM format’ which looks like this: ‘3:218’, for each letter. Next, this XGB friendly data is split into two parts for training a model and then subsequently testing that model.

Installing XGB is relatively easy compared to higher level deep learning systems and runs well on both Linux Ubuntu 16.04 and on a Raspberry Pi. I wrote the deployment app in bash so there should not be any additional software to install. Before getting any deeper into the ML side of things, I highly advise installing XGB, running the app, and having a bit of a play with it.

Training and testing is carried out by running bash runexp.sh in the terminal and it takes less than one second to process the 8124 lines of fungal data. At the end, bash spits out a set of statistics to represent the accuracy of the training and also attempts to ‘draw’ the decision tree that XGB has devised. If we have a quick look in directory ~/xgboost/demo/binary_classification, there should now be a 0002.model file in it ready for deployment with the questionnaire.

I was interested to explore the decision tree a bit further and look at the way XGB weighted different characteristics of the fungi. I eventually got some rough visualisations working on a Python based Jupyter Notebook script:

 

 

 

 

 

 

 

Obviously this app is not going to win any Kaggle competitions since the various parameters within the software need to be carefully tuned with the help of all the different software tools available. A good place to start is to tweak the maximum depth of the tree and the number or trees used. Depth = 4 and number = 4 seems to work well for this data. Other parameters include the feature importance type, for example: gain, weight, cover, total_gain or total_cover. These can be tuned using tools such as SHAP.

Finally, this app could easily be adapted to other questionnaire based systems such as diagnosing a particular disease, or deciding whether to buy a particular stock or share in the market place.

An even more basic introduction to ML goes into the baseline theory in a bit more detail – well worth a quick look.

Turning Scrap Metal Into Something To Work With

Blacksmiths will frequently work to a customer’s commission, and sometimes those commissions can be somewhat unusual. [Copperrein] had just such a piece of work come his way, a ceremonial sword to be made from a supplied collection of iron and steel items. To render them into something useful he had to melt them together, and the story of how he did that is particularly interesting.

We’re introduced to the Aristotle furnace, a fairly simple top-fed air blast charcoal furnace capable of melting almost any ferrous scrap into a so-called “bloom”, a lump of iron with some slag and carbon inclusions. These furnaces are often built as holes in the ground, but he’s made his atop a portable forge at working height to save bending over it for seven hours.

The source material was a very mixed bag, so the first order was to strip it in an acid bath of any coatings which might contaminate the resulting bloom. The parts, including things as diverse as a huge wrought-iton bolt, a scythe blade, and a pair of dividers, were then cut into small pieces one by one and fed into the furnace. They melt as they progress down through the furnace, resulting in a bloom of iron. The bloom is impure and will need significant working to expel any inclusions, but the final result will be something like the wrought iron of old. Let’s hope he has a power hammer, working the bloom would be hard work by hand!

If this catches your attention, you may be interested in a bit of blast furnace iron smelting. And of course, there is also our ongoing blacksmithing series to get you going at the anvil. You could even make a nail.

Via Reddit.

Thanks [Mike] for the tip.

Spin Me Right Round, Baby: Generator Building Experiments For Mere Mortals

How many of you plan to build a wind-powered generator in the next year? Okay, both of you can put your hands down. Even if you don’t want to wind your coils manually, learning about the principles in an electric generator might spark your interest. There is a lot of math to engineering a commercial model, but if we approach a simple version by looking at the components one at a time, it’s much easier to understand.

For this adventure, [K&J Magnetics] start by dissect a commercial generator. They picked a simple version that might serve a campsite well, so there is no transmission or blade angle apparatus to complicate things. It’s the parts you’d expect, a rotor and a stator, one with permanent magnets and the other with coils of wire.

The fun of this project is copying the components found in the commercial hardware and varying the windings and coil count to see how it affects performance. If you have ever wound magnet wire around a nail to make an electromagnet, you know it is tedious work so check out their 3D printed coil holder with an embedded magnet to trigger a winding count and a socket to fit on a sewing machine bobbin winder. If you are going to make a bunch of coils, this is going to save headaches and wrist tendons.

They use an iterative process to demonstrate the effect of multiple coils on a generator. The first test run uses just three coils but doesn’t generate much power at all, even when spun by an electric drill. Six windings do better, but a dozen finally does the trick, even when turning the generator by hand. We don’t know about their use of cheap silicone diodes though, that seems like unintentional hobbling, but we digress.

Making turbine blades doesn’t have to be a sore chore either, and PVC may be the ticket there, you may also consider the vertical axis wind turbine which is safer at patio level. Now, you folks building generators, remember to tip us off!

Continue reading “Spin Me Right Round, Baby: Generator Building Experiments For Mere Mortals”

That E-Cig Battery Probably Fits Into Sunglasses

This particular e-cigarette is a little bigger than a typical cigarette, with a matching battery.

E-cigarettes use electrical power to rapidly heat and vaporize a base liquid such as propylene glycol, and that power comes from a battery. These devices are functionally straightforward but it can be a messy process on the inside. Thankfully though the batteries can be salvaged once components like heating elements either gum up or burn out.

[facelesstech] decided to use the battery from an e-cig as the power source for a smart sunglasses project, which uses two RGB LED rings to put on a light show. Opening up the device it was discovered that the battery was a straightforward lithium-polymer cell, in AAAA size. If you’ve ever torn open a 9 v battery and discovered the six diminutive cylinders inside, an AAAA cell is about the same size as one of those. However, the battery from the e-cig is both rechargeable and has a nominal voltage of 3.7 volts, which can happily drive a microcontroller project. The small battery fit nicely into one arm of the glasses, and when covered with heat-shrink, was hardly noticeable. The battery charger doesn’t fit inside the glasses, but one can’t have everything.

The ability of an e-cigarette to pump out clouds of vapor has led to some interesting hacks. One such is a DIY portable fog machine, which opens all kinds of doors for costuming applications.