Six accelerometer sensor applications that you didn’t know

MEMS accelerometers are powerful tools witch let you measure not only acceleration but much more. If you need to measure acceleration, mechanical vibrations or detect movement this post is for you! Here are some examples what you actually can measure with accelerometer.

VEHICLE DRIVER SAFETY MONITORS

Linear acceleration measurement can be useful in the transportation area. Everyone can tell that traveling on a bumpy road makes the car break down faster Imagine that you are car rental service and want to know how mach damage road made to suspension of your rented car. Mounting accelerometer inside car can solve that problem easily. Accelerometer can monition driver behavior too. If the driver starts too fast of hits break pedal too strong acceleometer will noticed that and simple threshold algorithm will check if driver wasn’t too crazy on road.

ACCELERATION OF REMOTE CONTROLS BOAT AND ROCKETS

Nowadays small and power efficient platforms like Raspberry Pi or Beaglebonne let you use USB devices. It is a great way to use an accelerometer for the remote control enthusiast. If you are one you can use the accelerometer to measure behavior of a model car, rocket, boat or plane! For example if you are an amateur rocket constructor you can measure its acceleration and then obtain velocity and position. Even the biggest accelerations can be measured with ADXL345 setting its range up to 16g. Acceleration measurement helps monitor rocket and engine behavior. You can find out what course vibrations or just calculate its speed.

TILT SENSOR ANGLE SENSOR

Next possible application of an accelerometer is angle measurement. It is possible because of the ubiquitous gravity filed. In the rest frame on earth accelerometer constantly measure gravity field acceleration. Sometimes it can be undesirable but in the case of angle measurement is the thing that makes it possible. Sadly it is possible to measure only two (pitch and roll) of three angles of rotation but it is enough in the case of for example screen orientation.

ACCELERATION AND DISMANTLEMENT

Next interesting application is displacement measurement. It may be not the most accurate method of measurement but it is possible. If you know calculus, you probably know that acceleration is second derivative of position, so if we want to obtaining position (up to constant) from acceleration we have to integrate twice. Numerical integration can be complex topic so let’s do not go into details here.

MECHANICAL FREQUENCY ANALYSIS

Wide area of accelerometers applications is mechanical vibration analysis. It is very helpful in diagnostics of different kinds of mechanism. Recording vibrations and analyzing its frequency spectrum can show defects and wear of the mechanism.

SPORTS APPLICATIONS

Finally if you are runner, boxer or other athlete that want to measure strength of your hit (like those boxing machined do) you can do it with accelerometer. Analyzing such a data is quite simple. You should find just peak value of recorded hit and that is your score! Using frequency analysis you can find steps per minute like the nowadays smart watched do.

That is it! Maybe you have idea for some application? Be sure to left your ideas in the comments section!

 

How to configure Ubuntu to program STM32

OpenOCD installation

The Open On-Chip Debugger (OpenOCD http://openocd.org/) aims to provide debugging, in-system programming and boundary-scan testing for embedded target devices. If you using Ubuntu or any Debian like OS, OpenOCD could be installed by running following command:

sudo apt-get install openocd

ARM toolchain installation

Now we need compiler, linker and assembler (toolchain) for ARM Cortex architecture (https://launchpad.net/gcc-arm-embedded).

sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded

Eclipse

First install Eclipse IDE (https://eclipse.org/). After installation run Eclipse and install plugin for STM32 procesors development. Follow this instruction http://gnuarmeclipse.github.io/plugins/install/ .

USB rules

Next thing is to add proper permission to new devices.

cd /etc/udev/rules.d/
sudo nano 50-usb-stlink.rules

After opening 50-usb-stlink.rules (you can chose number to be anything integer under 99) file in nano, paste following rules for different ST-Link devices.

#FT232
ATTRS{idProduct}=="6014", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
#FT2232
ATTRS{idProduct}=="6010", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
#FT230X
ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
#STLINK V1
ATTRS{idProduct}=="3744", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"
#STLINK V2 and V2.1
ATTRS{idProduct}=="3748", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"

If you have different programmer you should change idProduct and idVendor. To find out your numbers first plug your USB device and then type lsusb

~$ lsusb
Bus 002 Device 007: ID 041e:323d Creative Technology, Ltd 
Bus 002 Device 005: ID 04d9:1702 Holtek Semiconductor, Inc. Keyboard LKS02
Bus 002 Device 004: ID 09da:9090 A4Tech Co., Ltd. XL-730K / XL-750BK / XL-755BK Mice
Bus 002 Device 003: ID 0424:2504 Standard Microsystems Corp. USB 2.0 Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 064e:a219 Suyin Corp. 1.3M WebCam (notebook emachines E730, Acer sub-brand)
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In the end restart USB service by pasting to terminal

sudo service udev restart

Testing

For tests I am using ST-Link 2.1 programmer from NUCLEO-F401RE board and  STM32F103C8T6 procesor in my USB Accelerometer device connected to Nucleo by SWD.

sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg

That’s it. If you had any troubles preparing you Ubuntu to program STM microcontrollers please let me know in the comment section below.

 

How to plot serial data from Serial port or Arduino

Sometimes there is a need to visualize data from serial port in real time, like I had in my USB Accelerometer sensor project. The goal can be reach hard way by writing your own software but there is no need to do so. Smart people already write many good and free solutions and in this post I want to show you how to use them in your electronic project. For these who want to code this functionality by their own I will show how to plot serial data in Python and Matlab at the very end of this article.

1. SerialPlot



SerialPlot is my favorite project that has many configuration features and it is easy to use. It is a Qt based software for plotting data from serial port in real time. It can be installed in Linux and Windows! Here is the hackday website of the project: https://hackaday.io/project/5334-serialplot-realtime-plotting-software

SerialPlot accepts 3 different types of data input:

  • Simple binary stream, supports different number formats (unsigned/signed – 8/16/32 bits and float)
  •  ASCII data in CSV format
  • User defined custom frame format (frame start byte, frame size, checksum etc..)

2. CuteCom


CuteCom is a graphical serial terminal, like minicom. It can not plot the data but it is very useful for debugging and communicating with embedded device. Currently it runs on Linux, FreeBSD and Mac OS X. Website of the project http://cutecom.sourceforge.net/

 

USB accelerometer sensor, tilt sensor

Nowadays everyone has accelerometer sensor in its own smartphone. It’s there for several reasons. First of all it’s used for detection of screen orientation relative to the gravity field. This is the sensor which gives your phone information when the screen should be switched from landscape mode to portrait. Beside this there are many other ideas how to use accelerometer.

One of them is pedometer. An app or device which uses accelerometer to track your steps. Application tries to analyse real time data from sensor to find peaks witch corresponding to human steps. Knowing average step length the program is able to calculate traveled distance.

Some guy from Hackday even made mechanical vibrations spectrum analyser using accelerometer and fourier transform decomposition. As you can see usefulness of this type of sensors is bounded only by your imagination 🙂

Such sensor may work as spirit level or angle reader to make something like ball on plate controlling machine just like this one bellow.

I though that it would be nice to have such a sensor in ordinary PC or Rasperry Pi computer for similar purposes so I designed one. My version is small, compact and Plug & Play.  You don’t need any Arduino or embedded coding. It’s just Plug & Play device which communicates with computer by USB port. If you are interested you can purchase it in electromake store.

USB Accelerometer fatures

  • The device uses well known ADXL345 accelerometer
  • USB bus communication
  • USB powered
  • This USB dongle following ADXL345 has user-selectable resolution
  • Fixed 10-bit resolution (from -512 to +511)
  • It is compatible with Linux and Windows OS
  • It is compatible with Raspberry Pi
 

How to chose resistor for LED diode

LED diodes are non linear elements whom I-V characteristic depend from many external parameters such as temperature and manufacture. Mathematically I(U) dependence is described by Shockley diode equation. Unfortunately this exponential dependence, after adding resistor in series, becomes implicit function of current and supply voltage witch can be only solve numerically. That is why we have to simplify things for practical purposes. Here is useful table witch I use for fast choice of resistor for LED diode. It contains values of resistance calculated for four most common supply voltages at 20 mA current.

Color Voltage drop at 20 mA Resistor for 3.3 V Resistor for 5 V Resistor for 9 V Resistor for 12 V
Infrared 1.6 V 85 Ω 170 Ω 370Ω 520Ω
Red 2.2 V 55 Ω 140 Ω 340 Ω 490 Ω
Green 2.0 V 65 Ω 150 Ω 350 Ω 500 Ω
Blue 3.2 V 5 Ω 90 Ω 290 Ω 440 Ω
White 3.4 V 0 Ω 80 Ω 280 Ω 430 Ω
Ultraviolet 3.8 V 0 Ω 60 Ω 260 Ω 410 Ω