Detecting obstacles using an ultrasonic sensor HC-SR04

Detecting obstacles using an ultrasonic sensor HC-SR04

1 HC-SR04: a cheap ultrasonic sensor

1.1 Description

HC-SR04 front view
Fig.1 – An HC-SR04 seen from front side.

HC-SR04 is a commonly used ultrasonic sensor which is capable to detect obstacles in a range of 2-300cm. The sensor looks like a small PCB having two metal cylinders on the front-side and a small circuit on the back-side (see Fig.1).

1.2 Documentation

In this article we will provide a simple demo to use HC-SR04. This requires a preliminary read of the sensor user manual:
HC-SR04 User Manual

1.3 Pinmap description

The sensor has 4 PIN:

  1. VCC, which must be connected to 5V;
  2. Trig, which is an input PIN to trigger the measurement;
  3. Echo, which is an output PIN which sent out a square wave;
  4. GND, which must be connected to ground.

Note that user manual specifies which GND must be connected first since a floating 5V could permanently damage the sensor.

2 How it works

The two cylinders are actually an ultrasonic receiver (R) and an ultrasonic transmitter (T) which are driven by the circuitry. The working principle is quite simple: when triggered the transmitter shoots some pulses. When sound encounters an obstacle it is echoed back and detected by the receiver. continue reading…

How to drive a HD44780 with I2C backpack with a STM32

How to drive a HD44780 with I2C backpack with a STM32

1 I2C backpack advantages

The HD44780 is a de-facto standard controller for display. We have already use it providing a source code to use a 16×2 LCD with a STM32. In this article we will step over introducing an I2C backpack for that display. Of course we will explain how to edit old code in order to get it work with this new hardware configuration.

Even if it is still popular, this controller was made commercially available in the late eighties. At that time serial communications were not so widespread because their were costly and involved constraint about clock speed. Because of that, the HD44780 comes with a parallel bus and requires up to 16 lines to work (8 for data, 3 for handshake, 2 for supply, 1 for contrast and 2 for backlight). With fastest MCU it is possible to use the 4-bit mode and with a couple of welds and a potentiometer we can reduce to 9 the required lines.

Nowadays, serial communication are largely used and SIPO (Serial-in Parallel-Out) converters are very cheap. Using a SIPO, it is possible to drive a HD44780 with less wires accepting a small extra charge due to additional hardware. Today it is possible to buy our display with the SIPO already mounted with a small extra amount (about 3.90 USD instead of 2.80 USD considering a 16×2 LCD).

The most used solution is based on PCF8574A, an I2C I/O expander from NXP. This solution is available as a backpack ready to be  soldered on our display. The backpack reduce the number of wires to 4: 2 for supply and 2 for the I2C communication. continue reading…

How to switch to the development version of ChibiOS

How to switch to the development version of ChibiOS

1 Trunk!

First time I started to deal with a software a little bit more complicated than the one used to print “Hello World”, I have encountered some words like “versioning”, “revision”, “diff”, “branch”, “trunk”, “checkout” and I heard about certain software like “svn”, “git”, “mercurial”.

Do you keep in mind when your friends knows something you don’t know and they continuously talk about that making you feel like a complete dumbass? Well that was my feeling! It is much simpler than how it seems: there are certain programs which purpose is to keep trace of every single character edited in your code. They are named version control software (as example git or subversion also know as svn). ChibiOS is versioned through subversion even if the svn repository is also unofficially mirrored (in read only) to a git repository.

I will summarise subversion in few lines in order to at least give an idea of what you’re going to do. With subversion code is saved on a remote repository identified by an URL. The operation of creating a local copy of the whole repository is usually known as checkout while updating that copy is known as update. The developer which has also read permission of the repository can save code through the commit operation: each commit is like a “snapshot” of the versioned folder (files, hierarchy, content) and this snapshot, known as revision, is saved on the remote repository. In subversion, revisions are identified by a progressive number (as example r9901). continue reading…