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 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…

I am new with ChibiOS. Where do I start?

PLAY Embedded default featured image

We have written a lot of articles about this topic and they are all in the ChibiOS section. Our suggestion is to start trying to understand what you goals are. Independently from that there is always a basic path to follow to overcome the first step.

  1. Gather information about ChibiOS. Some are provided in the article The ChibiOS project, others can be found on the ChibiOS official website and official forum.
  2. Set up a working environment to train yourself and understand how things works. This is eased for Windows users since ChibiOS releases periodically an eclipse-based IDE named ChibiStudio and we have provided a guide for its setup.
  3. Explore the IDE: this our article could be useful. Do not undervalue this part since here you have to discovery what are the tools you can use to solve problems you will face.
  4. Run a demo for your board and try to figure out what code mean crossing information so far gathered.
  5. Duplicate the original program and make it works (at this point you should be able to do this or come back to the point 3).
  6. Try to figure out what is the most simplest main you have to write to make a LED blinking. It’s not a coincidence that there isn’t an article about that: this is something you must do on your own.
  7. Start to explore the HAL drivers. The best way is to start with PAL and this article is the best way to do this.
  8. According to your goal explore other HAL drivers. There are a lot of demo under the folder testhal you can consult in order to master the fundamentals. Remember that most likely someone else has tried to accomplice your same goal facing same problems. Take look to articles in the ChibiOS section and try to search in the ChibiOS official forum.
  9. Don’t be shy: get in touch with us and with the community.