Wednesday, November 25, 2015

Tuesday, November 24, 2015

Wireless Communication using CC2530 Zigbee Wireless MCU

CC2530 is an system-on-chip (SoC) solution for IEEE 802.15.4 and Zigbee that combines RF transceiver and 8051 MCU. To develop a wireless module using it, we had bought a CC2530DK devolopment kit that consists of 2 CC2530EM Evaluation Modules, 2 SmartRF05EB Evaluation Boards, and a CC2531 USB Dongle. It cost about USD 400. At first, we installed SmartRF Studio which was available for free at TI's website.


Monday, November 16, 2015

Fitting a curve to a function

An example MatLab code to fit a curve to a piecewise linear function with the fixed end points.

%Fitting a curve to a piecewise linear function using least square method
%with the fixed start and end points

%clear command windows

%clear workspace
clear all;
%Read curves
load Curve.dat;

%find lower left and upper right corners 
x0=min(xD); x1=max(xD); 
y0=min(yD);  y1=max(yD);
n=5;%order n i.e, the number of segments
global xs;
global yB;
global yE;
%initialize coefficients (y values) to find 
%excluding the first and the last one
% options = optimset('MaxFunEvals',1000,'MaxIter',1000);
% LowerBoundC=y0;
% UpperBoundC=y1;
% ys =lsqcurvefit(@LineSeg,ys_initial,xD,yD,LowerBoundC,UpperBoundC,options);
ys =lsqcurvefit(@LineSeg,ys_initial,xD,yD);
%fixed start and end points
ys=[y0 ys y1];
hFig1 = figure(1);
set(hFig1, 'Position', [600 100 500 300])
hold on;             
hold off;        
grid on;

function [y] = LineSeg(ys,x)

global xs
global yB
global yE
ys=[yB ys yE];
for i=1:L
    %find segment
    for j=2:LS

Saturday, September 19, 2015

Controlling Your Hardware from the Web Using Arduino

Using Arduino Ethernet shield 2 to control a hardware from the web is discussed. Arduino Ethernet 2 Library is used to implement in an Arduino Uno board as a server in an example as well as a client in an another example. The latest version Arduino IDE ( 1.7.6 in our case ) is used in the following examples. An Arduino Uno board with Ethernet shield 2 is shown below.

Figure. Arduino Uno paired with Arduino Ethernet shield 2.

Thursday, September 10, 2015

Accelerometer LIS3DSH

LIS3DSH is an 3-axis MEMS accelerometer made by STMicroelectronics. Its full scale range is selectable from ±2g to ±16g. The size is small and it is only 3mm x 3mm. Either SPI or I2C can be used to interface with it. Supply voltage is from 1.71 V to 3.6 V. In this article, testing and evaluation of STEVAL-MKI134V1 adapter board is discussed.

Figure. STEVAL-MKI134V1 - LIS3DSH adapter board for standard DIL24 socket.

Tuesday, August 4, 2015

Bluetooth Module to be Used with Microcontroller

HC-05 Master/Slave Bluetooth Module is a cheap (~SGD 16) and easy to use Bluetooth module with UART interface. Interfacing and using HC-05 with Arduino Uno microcontroller to control an LED light as commanded by a hand phone via Bluetooth communication is discussed in this post. In fact, any microcontroller with UART interface can be used with it.

Figure. HC-05 Bluetooth module with Arduino Uno.

HC-05 uses 3.3V for its digital logic pins while the voltage level for Arduino Uno is 5V. A bi-directional logic level converter can be used to interface them. But, here, we just use simple voltage dividers using readily available components in our labs to interface them as shown in the following diagram.

Figure. Interfacing HC-05 Bluetooth module with Arduino Uno.

To communicate this Bluetooth module from an Android phone, we can search and use any 'Bluetooth SPP' app in the Play store. We have used 'Bluetooh spp tools pro' by Jerry.Li. After opening the app and scanning for Bluetooth devices, you can connect HC-05 using '1234' as the pairing pin. Thereafter, characters sent to RX pin of HC-05 UART will be received by the phone and the characters sent by phone will be output from TX pin of UART of HC-05. If you connect the Bluetooth module using computer instead of the phone, a serial port will appear in your computer which can be used as a normal comm port sending and receiving data to and from the Bluetooth module.

#include <SoftwareSerial.h>
#define RxD 2
#define TxD 3
char recvChar;
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);

    pinMode(13, OUTPUT);
void loop()
      recvChar =;
      if(recvChar == '1') digitalWrite(13, HIGH);
      else if(recvChar == '0') digitalWrite(13, LOW);
      recvChar  =;

This Arduino program forwards the characters sent by phone to the serial monitor and vice versa. It turns on or off the LED which is connected to the pin 13 of Arduino Uno microcontroller board when 1 or 0 is sent from the phone. The push button on HC-05 Bluetooth module needs to be pressed to send AT commands and to configure it.

Figure. Sending and receiving characters to and from the Bluetooth app using Serial monitor.

Another Bluetooth module called Bluetooth Shield is also tested. That module is designed for Arduino Uno and can be directly fixed on the Arduino Uno board. Therefore, no additional interfacing or connection is needed to make it work. But you need to make sure that the jumper settings are correct. As shown in the following figure, the jumper for HBT_TX is connected to D2 pin of the Arduino Uno board and HBT_RX is connected to D3. Therefore, D2 needs to be configured as RX pin and D3 as TX pin respectively in the demo program which is available at Bluetooth Shield Wiki page. You can define Bluetooth device name and pairing pin in that example program.

Figure. Bluetooth Shield.

Thursday, May 14, 2015

Image Retrieval

This is a MatLab program which receives a test image and find the most similar images in the database.