Previous post: In-the-Air-Challenge: Air Quality Sensor Box
Roadtesters for In-the-Air-Challenge received fom Element14 a free Beaglebone Black (BBB) microcomputer with Angstrom Linux on internal 4 GB flash. It has one USB port, where one could connect a HDD and make low power consumtion server for IoT data storing.
Dust particles in air scatter light when illuminated by a powerful LED or laser, floodlights or flashlight. I have done dust counting in webcam images on a Windows PC using LabVIEW. I wanted to give a try and use BBB for that purpose. Particle identification and counting on BBB I planned to do using OpenCV. While OpenCV is ready to use in Processing on a Windows PC, it appeared that one needs to compile OpenCV for BBB and it could take hours and result with some error code meaning that your day has been wasted. Another approach could be used to send pictures from a BBB to a Windows server that is doing image processing and particle counting.
Home-built airborne particle counter using image processing
From your childhood probably you remember seeing dust flying around in a room in sunny days. Nowadays one can see dust flying in a dark room using a mobile phone LED. Physicists distinquish several types of scattering. Sky is blue because of Rayleigh scattering from air molecules that are smaller than the wavelength of light. Blue light is scattered more than red. Mie scattering is from particles comparable to the wavelenght of light. Unlike Rayleigh scattering Mie scattering is not strongly wavelength dependent. Geometrical scattering occures from larger particles.
About a year ago we vave installed a HEPA cleanroom box in a university optics lab and wanted to know if it really helps to filter air. Commercial cleanroom airborne particle detectors use a laser, cost thousands and can get polluted if used in dusty rooms.
I had a 1W output 445 nm blue laser diode lying around and togather with my student gave a try. LED would be better to use thinking about eye safety. Light output from a 10W LED measured with a laser power meter was 0.25W. So 10W is the electrical power, not the optical. In the case of laser diodes 1W is optical power and consumed power is just 2W. Laser diodes are more efficient than LEDs and can be focussed much tighter visualizing smaller dust.
We directed laser light into a darkened chamber and recorded scattered light from dust with a webcam. Using image processing tools allows to count the number of particles in air and determine their size from the scattering intensity. The light beam has to be terminated on a bent dark surface without causing too much scattering from surface. We used LabView 2012 for image processing. LabView .vi file is attached to this post. Camera lens was defocussed, to make circle detection easier.
We can clearly see increase of particle count after dry sweeping the room. 50 particles/cm3 is actually 50 million/m3. Quite a lot!
Inside a cleanroom flowbox after a HEPA filter air is clean. Recently Electrolux has started to use HEPA13 class filters stopping 99.95% of particles in vacuum cleaners keeping air fresh after cleaning.
There are also mechanical wirpool filters, electrostatic filters and active coal filters. Latest can remove cigarette smoke odor. Odor molecules are smaller than dust but larger than air molecules.
We got some limitations. Camera frame rate of 15 fps was not enough and when some air flow was present particles smeared out from circles into lines. Smearing into lines was more pronounced when using a macro lens because particles quicker crossed the small field of view. But macro lens was esential to be able to see small size particles. I would say that human eye is still superiour to a webcam.
First steps with BeagleBone Black
The BeagleBone Black is relatively well described in Internet, so I only will write down some short notes:
Plugged into a USB appears as a SD disk. Installed drivers from the SD disk.
In Windows7 Device manager "cdc serial unknown" device still appears but it seems not to be a problem.
Surprise: Could open in a webbrowser site 192.168.7.2 Cool! BBB acts like a USB network card.
Next will continue with terminal connection from Putty ssh 192.168.7.2 Default login: root pass: <none>
Most things are like on regular Linux PCs.
|Header 1||Header 2|
Size Used Avail Use% Mounted on
rootfs 3.4G 1.5G 1.8G 45% /
|shows ram usage|
|shows processes, among other also apache2 webserver running|
|shows watchdog present|
|shows processes running|
|Linux beaglebone 3.8.13-bone47 #1 SMP Fri Apr 11 01:36:09 UTC 2014 armv7l GNU/Linux|
|dmesg||shows boot log|
|ifconfig||shows that there is an active network connection over usb|
|ping google.com||edit network settings|
|ntpdate -b -s -u pool.ntp.org||time server|
USB Wi-Fi donge to BBB Angstrom (no success)
Cable ethernet started to work after uncommenting lines in /etc/network/interfaces.
Wi-Fi setup described here:
Connected external 5V power. Plugged in a USB Wi-Fi donge.
Bus 001 Device 005 ID 7392:7811 Edimax Technology Co Ltd EW-7811Un 802.11n Wireless Adapter[Realtek RTL8188CUS
[ 1065.852675] rtl8192cu 1-1:1.0: usb_probe_interface
[ 1065.978194] rtlwifi: wireless switch is on
shows Wi-Fi networks around
iface wlan0 inet dhcp
ifconfig wlan0 up
iwlist wlan0 scan
iwconfig wlan0 essid Wifi2Home key s:ABCDE12345
PING google.com (22.214.171.124) 56(84) bytes of data.
64 bytes from lb-in-f139.1e100.net (126.96.36.199): icmp_req=1 ttl=44 time=75.5 ms
I managed to connect only to password protected networks. Not to the open networks.
OpenCV image processing with BBB Angstrom (no success)
apt-get install OpenCV
E: Unable to locate package OpenCV
It appears that thing is not so easy.
One needs to download OpenCV source code and to compile it takes 10 hours. It is a crazy long time. After waiting some hours got got make: *** [all] Error 2
Was no more space left on 4 GB. It is much easier in Processing on a PC. So I probably will not use OpenCV and make my own C or Python code to find dust spots in a picture.
Tried Debian. Flashed Debian transfer image from a 2GB card to emmc.
During transfer external 5V power is needed.
Same Wi-Fi problems. Could not get it working. Probably I have an unsupported adapter.
Webcam and Ramdisk
Plugged in a USB webcam Logitech C270.
It appeared in ls/dev as video0
Next installed fswebcam programm to take photos
apt-get install fswebcam
cd /tmp # this is RAM
fswebcam --device /dev/video0 `date +%y%m%d-%H%M%S`.jpg
A .jpg file should should appear.
Next would like to store photos in a www directory to be able to see them over webbrowser. Usually Linux PCs store webpages here:
But it is empty directory. Let's make a test html file.
chmod 777 index.html
Apache2 at port 80 is displaying Beaglebone page. So we need to look in settings how to display our page..
Apache2 settings are here.
I did not change them as read there that port 8080 is an alternative page.
Our test webpage should be displayed at
Lets make a Ramdisk under /var/www for storing webcam picture so that flash does not get weared out.
And add a line in fstab that Ramdisk gets mounted on the boot.
tmpfs /var/www/tmp tmpfs size=10M,mode=0755 0 0
df -h # shows that we have now a 10 MB ramdisk at /var/www/tmp
Filesystem Size Used Avail Use% Mounted on
rootfs 3.4G 1.7G 1.6G 51% /
tmpfs 10M 0 10M 0% /var/www/tmp
Now let's take a test photo.
fswebcam --device /dev/video0 -r 800x600 current.jpg
A picture appeared in
The problem is that fswebcam programm compresses image to jpg. And quality goes down. Dust is much less visible than in uncompressed image.
It is possible to upload the photo file to a server where a mobilewebcam.php script saves it:
curl -F userfile=@/tmp/current.jpg asi.lv/alnis/webcam2/mobilewebcam.php
Tried to use another webcam programm.
apt-get install uvccapture
uvccapture -v -t1 -B148 -S128 -C32 -G4 -q90 -o/var/www/tmp/test.jpg
uvccapture -v -m -t1 -B96 -S32 -C32 -G16 -x640 -y480 -o/var/www/tmp/test.jpg
Using videodevice: /dev/video0
Saving images to: /var/www/tmp/test.jpg
Image size: 320x240
Taking snapshot every 1 seconds
Taking images using mmap
Setting camera brightness to 148
Setting camera contrast to 32
Setting camera saturation to 128
Setting camera gain to 4
Saving image to: /var/www/tmp/test.jpg
width=640 height=480 interval=4 output=/home/httpd/webcam.jpg capture=/usr/local/bin/capture.sh
uvccapture -v -m -t1 -B96 -S32 -C32 -G16 -x640 -y480 -o/var/www/tmp/test.jpg
Picture was saved OK, but despite trying I could not get highter jpg resolution than 320x240. Seems that there is a bug and uvccapture on BBB is presently pretty unusable.
- Nowadays it is possible to make a low-cost dust detector using a Beagle Bone Black board and a webcam togather with a diode laser.
- Camera is similar to a human eye. With an eye clearly see dust flashes. Image processing allows to count dust particles in a photo.
- Image recognition allows to see large changes in air pollution when when a room is dry-swept.
- Bringing eye close to beam reveals much more small dust. Camera needs magnification or macro lens to see small dust.
- There is a huge number of small particles in air. They are not molecules. Something bigger. For example pollen, aerosols, viruses.
- Camera needs to look at a small-sized light beam. In a broad beam there are so many particles in a field of view that they overlap and are impossible to count. Some particles 20 per frame ar OK.
- In a focussed beam light scattering intensity is higher and disturbing background is less.
- Camera at 15 or 30 fps is quite slow and air velocity should be low. If air flow is fast then the dust tracks smear out and appear as lines. Then image recognition of circles does not work anymore.
- Solution would be a strobe flashlight or pulsed laser or LED. I tried once and ended up with a burned out laser diode.
After spending a couple of weeks on BBB and image processing I decided to try out a classical dust counter approach with a laser and a photodiode. Please see the upcoming blogposts.