And now for something completely different: Tariffs and Makers

For those of us who like to play around or build things with electronics, the tariffs the US government is about to put into place on Chinese goods will have a  direct effect.This will be bad for the Maker movement. Components like LEDs, resistors, capacitors, and PCBs will have an additional 25% tariff added. Yikes!

Tariffs on many finished consumer goods, such as cell phones, will remain unchanged. Hackaday writes: “this hurts small companies buying components. Startups buying subassemblies from China will be hit as well. Educators buying parts kits for their classes also face the tax hike. Who won’t be impacted? Companies building finished goods. If the last screw of your device is installed in China, there is no tax. If it is installed in the USA, then you’ll pay 25% more on your Bill of Materials (BOM). This incentivizes moving assembly offshore.”

The tariffs also apply to chips designed in the US by American companies and built for those companies by Chinese manufacturers. (see Chip Makers: We’ll End Up Paying Tariffs on Our Own Goods)

Moog, the synthesizer company, is among those affected, and they are stating that their entire business is at risk. (Moog Asks Customers to Protest Trump Tariffs)

You can read more about this on Andrew “bunnie” Huang’s blog, Bunnie’s Blog. From his blog:

The Adafruit MetroX Classic Kit is representative of a typical electronics education kit. Items marked with an “X” in the above image are potentially impacted by the new USTR tariffs.

Calibration for 3-axis accelerometer and magnetometer

For my latest project, I’m using an 3-axis accelerometer / magnetometer, specifically Adafruit’s Triple-axis Accelerometer+Magnetometer (Compass) Board that uses the LSM303DLHC chip. .

The 3-Axis Magnetometer and Accelerometer Board

The 3-Axis Magnetometer and Accelerometer Board

 

My specific project may not require much precision, but I still decided it would be a good idea to calibrate the outputs. There are a number of  both sophisticated and simpler tools for magnetometer bias measurements, but I wanted a simple solution I could run on my headless Pi zero W and that dealt with calibrating both the magnetometer and accelerometer.  An excellent discussion that I borrowed heavily from is the blog post “How to Calibrate a Magnetometer.”

There are two general types of distortions in the outputs. One is a straight shift (bias) in a given direction, while the other distorts the response. The former is the easiest to deal with computationally. One can rotate the unit around all axes (a figure 8 movement with rotation is what I use) and measure the minimum and maximum values reported for the 3 axes (six values in all). If there is no bias, the absolute values for the + and – direction of each axis would be the same. If the response is shifted towards one or the other, there’s a bias present. One can simply compute the average of the min and max for each axis, and then subtract that value from the reported output for that axis.

plot showing an offset circle.

Offset bias. Called “hard iron distortion” in a magnetometer, as it is often due to the presence of exterior ferrous substances. (source: Vectornav)

The other type of error distorts the shape of the response. 3D matrix algebra is needed to fully address this type of error, but a simpler approach that provides an approximate correction is to just look at the 3 axes. Calculate the average delta between the maximum and minimums for each axis, then compute the scaling factor for each individual axis that scales the delta for that axis to match the average.

Plot showing rotated and offset ellipse

Plot showing both offset bias and non-linear response. The non-linear response is called “soft iron” bias in a magnetometer. (source: Vectornav)

My code then does the same thing for the accelerometer. For that calibration, you want to slowly (so as not to introduce large motion accelerations) position the board so that each of the 6 faces points up while the calibration program is running.

One that is done, the code then writes the magnetometer and accelerometer offsets and scaling factors for each axis (so 12 values in total) to a .ini file so that they can be called and used by the application program that will be making the measurements.

In my initial measurements, I found appreciable bias errors for the magnetometer (on the order of 12%), with much smaller bias errors for the accelerometer (on the order of 1.5%). The scaling factor corrections were  smaller for the magnetometer than the bias (the correction factors were 7.5%, 1%, and 6%). For the accelerometer, I measured 0.03%, 6%, and 5.5%).

The code is published at https://gist.github.com/ViennaMike/d8b8f9636694c7edf4f115b28c9378c0

Easy Come, Easy Go

Dang! Haven just written about the wonders of both open source and free services, I came face to face with a downside. What’s given freely in an API can just as easily disappear. I’m about 1/8th of the way through two online courses from DataCamp on using python to analyze financial data, only to find out that Google and Yahoo have both dropped (as of late last fall) their historical price data API (Application Programming Interface) that everything depends on. The key tools, an open source program called pandas, has been updated with work-arounds, but the course material hasn’t been updated, leaving me dead in the water. The data was provided free by both Yahoo and Google for decades, so while they have no obligation to keep providing the data, it has a pretty wide-spread impact when they stop. Lots of dependent applications broken!