Sunday, January 18, 2015

Using ATtiny85 With nRF24L01+ For Wireless Communication

After learning to program ATtiny85 MCUs using Arduino as ISP, next thing I wanted to try was how to use them with nRF24L01+ wireless modules. I found some libraries which facilitate it and after successfully trying it, I decided to write the steps down here.

Setting up software for Arduino IDE:

(1) Download the codes from the GitHub project https://github.com/stanleyseow/arduino-nrf24l01. I forked it into my account for my own future use which can be found in https://github.com/asanka-code/arduino-nrf24l01.

(2) Extract the downloaded ZIP file and copy the two directories "Mirf" and "SPI85" into the libraries directory inside your sketchbook directory inside home directory.

(3) Download the "attiny" directory from the following project into the "hardware" directory of the sketchbook directory. It contains the board definitions for ATtiny85 and other ATtiny MCUs. This is a fork from the high-low-tech guys ATtiny library.

Now our software setup is ready. We are going to setup an ATtiny85 chip with an nRF24L01+ module to behave like a client program which send packets continuously into another device which is an Arduino Uno board with an nRF24L01+ module.

Setting up ATtiny85 with nRF24L01+:

(1)  Follow the steps in my previous article which can be  found in this link and
setup ATtiny85 chip together with Arduino Uno board as the ISP programmer. Plug this Arduino board into the computer.

(2) Open the Arduno IDE (I used version 1.0.5) and open the example program
"attiny85_counter_example" which is available inside  out newly copied "Mirf" directory. Program it into the ATtiny85 chip.

(3) Remove the ATtiny85 chip from the above programming setup and set it up
with another Arduino board and nRF24L01+ module as shown. Pin connectivity between nRF24L01+ module and ATtiny85 chip should go as below.

MISO -> PB0
MOSI -> PB1
SCK -> PB2
CE -> PB4
CSN -> PB3


VCC pin of the nRF24L01 module should be provided with 3.3v while the VCC
pin of the ATtiny85 module should be provided with 5v. Both can be achieved
by connecting them with the appropriate pins in an Arduino board. Both GND
pins also should be grounded properly. 

ATtiny85 with nRF24L01+ powered by an Arduino board
This ATtiny85 MCU is now ready for communication. It can be powered up by an
Arduino board.

Setting up Arduino Uno with nRF24L01+:

(1) Plug a new Arduino Uno board with the computer.

(2) Start Arduino IDE again and open the example program "ping_server" inside "Mirf" directory. Program it into the Arduino Uno board.

(3) Connect an nRF24L01 module with this Arduino board according to the pin
connectivity details given below. 

MISO -> 12
MOSI -> 11
SCK -> 13
CE -> 8
CSN -> 7
GND -> GND
VCC -> 3V3


This Arduino Uno board is also now ready for communication. 

Arduino Uno board connected with nRF24L01+
Running the setups:

Now, supply power to both setup, Arduino server and ATtiny85 client. Open the
serial monitor of the Arduino server side using Arduino IDE and check for any information on a baud rate of 9600. You will see that the server is receiving data from the client as the figure shown below. What happens is our ATtiny85 chip continuously send packets which are received and retransmitted by the Arduino Uno board as a reply.

Output of the serial monitor at the server side


Thursday, January 15, 2015

Programming ATtiny85 MCU using Arduino as ISP

I was in need of learning how to program ATtiny microcontrollers and more specifically ATtiny85 for a project work using Arduino IDE. There are different programmer boards available to program ATtiny85 chips in the market. Among those different methods, one nice way of doing it is using an Arduino board as an ISP (in-system programming) device. After doing some searches on the web, I tried it yesterday. I'm writing down the steps I followed to program an ATtiny85 chip with a simple LED blink program using Arduino as ISP. I tried it  on an Ubuntu 12.04 LTS system and used an Arduino Uno board as the supporting hardware for the ISP programming task.

Turn the Arduino board into an ISP programmer:

(1) I used Arduino IDE 1.0.5 version since 1.0 version which I had initially didn't work as I expected. Arduino IDE 1.0.5 version can be downloaded from the link and start it.

(2)  Open the ArduinoISP program from the Examples and program it into an Arduino Uno board. Now our Arduino Uno board is ready as an ISP programmer.

Programming ATtiny using Arduino board:

(1) Download the master branch of this attiny project as a ZIP file from GitHub which is available in this link. I forked it for my future use which is available in this link.

(2) Create a new directory called hardware inside my sketchbook directory inside home directory.

(3) Unzip the downloaded attiny project ZIP file and copy the attiny directory into the hardware directory which we just created inside sketchbook.

(4) Start Arduino IDE and goto the Tool->Board menu where we should see the ATtiny chips now appear as boards.

(5) Connect Arduino Uno board with the ATtiny85 chip through a breadboard as shown in the following figure. We need a 10uF capacitor in addition to the breadboard and jumper wires to complete this task. Pay close attention to the correct pin connectivity.

(Image source: http://highlowtech.org/?p=1706)

(6) Open the Blink example which is available in the Arduino IDE and change the blinking pin from 13 to 0. Select the ATtiny85 board and Arduino as ISP options from the Tools menu. Now program the Blink application. When we say Pin 0 in Arduino IDE, what we actually mean is the physical pin 5 on ATtiny85 MCU. Refer to the following figure to understand the pin numbering convention between Arduino boards and ATtiny85 MCUs.

Click on image to enlarge. (image source: http://www.pighixxx.com/)

(7) After  programming the Blink application, connect an LED in series with a resister (I used a 1kΩ resister) between the ATtiny85 MCU's physical pin 5 and GND to see it blinking by the program running on ATtiny85 chip.

References:
[1] http://highlowtech.org/?p=1706
[2] http://highlowtech.org/?p=1695
[3] http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/?ALLSTEPS

Friday, January 9, 2015

Reading RFID tags with Arduino

Last night I tried a little thing, following the details provided in this link. I received a simple RFID reader module which I wanted to try by connecting to an Arduino board. According to the details provided in the above link, I succeeded in reading a passive RFID tag details. For my future reference, I'm writing it down in this article. The RFID module I used for this task is RDM6300 which comes as a small PCB together with externally pluggable coil for the antenna. We have to connect this gadget with an Arduino board to be able to access it from our Arduino program. Pin connectivity details of the device is as follows.

Arduino pin RFID module pin
2 LED
6 TX
+5V +5V
GND GND

Pins of the RFID module can be identified from the following diagram.


After connecting the RFID module to the Arduino board, we have to program the Arduino board with a special firmware which can read RFID tag details. In Maniacbug's blog post, there are two programs provided where first one just print the raw data read from RFID tags while the second one prints the correct TAG ID after making some processing with checksum calculations. I forked his codes from GIST for my purposes which can be accessed from following links.


Running the second program resulted in the following output in my serial monitor which shows the tag ID correctly.

Serial monitor output when reading a tag.


Thursday, January 8, 2015

A Visit To Kandy

Our group at Kandy (photo credit: Chathura)
The end of last year was an interesting time period due to the ICTer 2014 conference and its related events. After the conference, there was an official tour organized by University of Colombo School of Computing for some of the international participants of the conference such as Invited speakers and international paper authors. Even though I got to know many people during the conference at BMICH, still there were some people whom I couldn't get to know. This tour was the time  for that.

(photo credit: Chathura)
We started the journey from Colombo in the early morning of 14th Sunday, December 2014. We went in the university van and the only three Sri Lankans we had in the van are our driver, me and Chathura Suduwella. Chathura brought a very good camera which provided lot of nice photos for our memory. Our foreign members of the tour consisted of Dr. Alan S. Weber from an American collange in Qatar, Mr. Chala Tesgera, an Ethiopian  student in Germany, Dr. Paul Cunningham from Ireland, Dr. Enric Mor, Dr. Antonia Huertas and another professor from Spain. In addition to the van, Mr. Herath who is the conference coordinator came with us by his car together with his family. We picked all the foreign participants of the journey from the hotels where they were staying and headed to Kandy.

(photo credit: Chathura)
Our first destination of the journey was Pinnawala elephant orphanage which is situated along the way to Kandy. This place is the home for elephants who have faced different troubles and unable to live on their own in the jungle. It includes  baby elephants who have lost their mothers and grown-up elephants who have got injured due to human activities.  We had our breakfast from a restaurant while watching elephants having a bath in the river next to the orphanage. The restaurant had a balcony from which we had a clear view of the elephants. A lot of foreign tourists were present in this restaurant to see elephants having bath. If we came a little early to this place, we could have watched how they feed baby elephants in the morning.

(photo credit: Chathura)
After the elephant orphanage, we reached Dalada Maligawa (Temple of the Sacred Tooth Relic) in Kandy. Since it is the most sacred place of Buddhists, I was so glad that we came there. My fiancé messaged me that I should present a bunch of Jasmine flowers to the temple. So, I bought some Jasmine from a little flower boutique in front of the temple. Inside the premises of the temple, there were various other places to visit and see. Those places includes a museum for the Raja tusker, a palace of an old king, and world buddhist museum sponsored by India. After walking along the premises for a long time, we got together to discuss where we should move next. We had two choices. Either we should go for lunch or go for another sight seeing before the lunch. Since it was getting delayed, we decided to go for lunch. On our way to a restaurant for lunch, we went through University of Peradeniya to see its beautiful environment.

(photo credit: Chathura)
We had our lunch somewhere near Kandy in a buffet restaurant. This meal was a really good one and I ate as much as I wanted. After the lunch we wanted to visit Embekka Devalaya. However unfortunately it was not that easy because we didn't know the correct way to reach there. Additionally, we faced lot of traffic jams in the middle of the journey forcing us to go though different unfamiliar shortcuts. We had to rely on Google maps and  GPS to get us to the Embekka Devalaya. It was not a big place but it is famous for ancient wood carvings it has. We spent a short while in this place and an old person in this place took us a walk through describing various important things about the place. I've  read and heard about Embekka Devalaya from my childhood but this was the first time I visited to see the real thing.

Chathura, my research colleague.
After seeing Embekka devalaya, we again went to Kandy city since Dr. Cunningham was going to stay in Queens hotel without returning to Colombo. So, we went there and dropped him at Queens Hotel. Finally we started to return back to Colombo. We had a quick dinner in a place around Ambepussa and started to move again. The reason we had to hurry was Mr. Chala. He was leaving in a flight at that night and therefore we were supposed to drop him at the airport directly. So, when returning to Colombo, we directly went to Katunayake international airport and said good bye to Mr. Chala. Then we dropped the remaining members at their relevant hotels around Colombo city area.

Throughout the journey, Chathura and me sat in the front seats of the van and talked about various things. Since the journey was several hours long to each side, we had enough time to talk so many things. Time to time, we turned back and talked few words to our foreign tour partners. I hope they enjoyed this journey just like we did. I learned a new thing about Spain during this journey. Spanish is not the only language they have in Spain. They have a language called Catalan which is spoken by a significant number of people in Spain. It is not a dialect of Spanish but a completely different language.

~*******~

Friday, January 2, 2015

Interacting With Arduino Serial Out From Linux Terminal

While testing a wireless transceiver module which is connected to an Arduino Uni board, I had to interact with the program running on the Arduino board. For that, the standard way available is the serial monitor in Arduino IDE. However I'm not happy with this serial monitor utility. I wanted to interact with it from my Linux terminal. After trying different options, finally the method I selected is 'CU' tool.

We can install it from the terminal using the following command.

sudo apt-get install cu

After plugging the Arduino Uno board into the computer through USB cable, it was shown as /dex/ttyACM1. Since my program in Arduino board communicate in serial with a baud rate of 57600, I can start interacting with the serial port through terminal using following command.

cu -l /dev/ttyACM1 -s 57600

The way to exit from this tool is a bit weird. We have to enter the following key combination on the terminal to exit from the tool.

~.

I hope this tool will be useful to me in the future works which involves serial communication with Arduino boards.


Note (2015-07-09):
In case we need to log this output into a file while the output is displaying on the screen, we can use the following command.
cu -l /dev/ttyACM0 -s 9600 2>&1 | tee mylog.txt


Thursday, January 1, 2015

System beep for Ubuntu 12.04 LTS

In recent Ubuntu versions, I noticed that system beep sound in the  terminal is disabled due to some reason. I searched how to re-enable it but it seems not that  easy. Finally I found some workaround for this problem from this link. So, in this post, I'm just writing down the steps I followed to enable system beep. Open a terminal and enter following commands.

pactl upload-sample /usr/share/sounds/ubuntu/stereo/bell.ogg bell.ogg

pactl load-module module-x11-bell display=:0.0 sample=bell.ogg

xset b 100

Now, system beep should work. I can try it by entering following line in the terminal  and enter.

echo -e '\a'

Following content can be saved as a shell script and used to continuously play system beep.


1
2
3
4
5
6
7
8
#---------------------------------------------------------------------
while [ 1 ]
do
        echo "Welcome $count times"
        echo -e '\a'
        sleep 0.5s
done
#---------------------------------------------------------------------