Saturday, 27 October 2012

AVR development in Linux


* Install necessary packages

$ sudo apt-get install gcc-avr
$ sudo apt-get install avrdude
$ sudo apt-get install avr-libc

* Compiling code

Steps(2) -> .c => .elf => .hex

$ avr-gcc -Os -mmcu=$2 file_name.c -o file_name.elf
 $ avr-objcopy -j .text -O ihex file_name.elf file_name.hex

* Uploading code

$ sudo avrdude -p part_name -c programmer_id \
     -U flash:w:file_name.hex
  •  part_name => m16, m8
  •  prog_id => usbasp
  •  "flash" => programs flash
  •  "w" => write mode
  •  shld be run as super user => "sudo"
* Compiler optimization
  • specify an option -Ox while compiling (avr-gcc -Ox ... )
  • x => optimization levels
  • "-Os" => "s"=> small - for smaller code

Made a video of LED blinking @ 900ms


* FUSE BITS:

 # read
$ avrdude -p m16 -c usbasp -U fuse_name:r:file_name.txt:h
  •  fuse_name => lfuse,hfuse,lock
  •  "r" => read
  •  fuse value "h" in hex format
  • stored in file_name.txt file
# write
$ avrdude -p m16 -c usbasp -U fuse_name:w:0x82:m

  •  "0x82" => sample fuse value
  •  "m" => immediate ( use value in cmd directly )
  •  "w" => write
* Note: make use of AVR fuse CALC available online



Friday, 26 October 2012

Running Raspberry Pi Headless


Raspberry Pi, normally needs a keyboard, mouse and a display ( a hdmi-compatible monitor or tv) for input/output. But it is possible to avoid all of these and still use pi with a lot of ease. This can be done by tunneling through pi using SSH - Secure Shell. It is similar to telnet but its more secure. It uses port22 (by default) for transferring data/info from one system to another. Remember that, these systems are connected to a network - LAN.




Any account in a system connected to LAN can be accessed from any other system by knowing 1. IP address of the system, 2. Username and password of the account.

Raspberry Pi running Wheezy: Default login:

username: pi
password: raspberry

We can login to pi using the following command:

$ ssh pi@IP_address_pi

* Note: The IP address of pi can be found by guessing. Follow the video below to successfully login to pi: ( click here for notes/hints )





So, we have logged on to pi successfully. Lets now do more with SSH. The video below demonstrates the following:

1. login to pi thro' ssh
2. editing pi's password
3. navigating filesystem on debian Wheezy
4. Copying files on network
5. Shutdown, Reboot
6. Compile, run C program

click here for notes/hints



Now, lets move on to the PART2 of this tutorial. We could access pi thro' cmd line. But we need GUI - Graphic User Interface for more flexibility and ease of access. The video below walks you thro' the steps involved in accessing pi using a remote GUI (or GUI in remote system):



Thats it i guess... Bye Bye!


Monday, 22 October 2012

Git - Getting started



1. Backup any existing ssh keys
     $ cd ~/.ssh/
     $ mkdir key_backup
     $ mv *.pub ./key_backup/

2. Generate private ssh keys
     $ ssh-keygen -t rsa -C "developer.rps@gmail.com"
     $ Enter file in which to save the key: filename
     $ Enter passphrase : *****

3. Add private ssh key to git.gitorious.org account
     $ sudo apt-get install xclip
     $ xclip -sel clip < ~/.ssh/filename.pub
   



       - go to account setting in the user page of git.gitorious.org     
       - Go to your Account Settings
       - Click ssh keys
       - Click "Add SSH key"
       - Paste your key into keyfield
       - Click Add key


4. Check whether ssh key is successfully added
     $  ssh -v git@gitorious.org


5. Clone the remote repo
     $ mkdir ~/workspace/
     $ cd ~/workspace
     $ git clone git://gitorious.org/project_name/repo_name

6. Adding files to remote repo
     $ cd ~/workspace/athena
     $ nano someFile.txt

7. Add some msg to it, save and exit
     $ git add someFile.txt
     $ git status
     $ git commit -a
     $ git remote set-url --push origin git@gitorious.org:athena/athena.git
     $ git push origin master #only for the first time,
     $ #next time onwards just use "git push")

   If the step 7 throws an error like this,
          $ Permission denied(publickey).fatal:The remote end hung up unexpectedly

  do the following, then try pushing
     $ ssh-add ~/.ssh/id_rsa.pub
     $ git push

8. Getting files from remote repo
     $ git pull

Sunday, 22 April 2012

Serial Port Manipulation in Java

What we have today? Serial Port Manipulation in Java. Java seems to be popular for its high level user applications and Web application. But most of us, hobbyists use C for almost all our jobs to deal with hardwares.

   What do Java have for us. To be honest, Java is not good enough for ES programming or Driver development, because it is not meant to be. We have been struggling for getting precise delay for running a Servo motor by pulsing DTS and RTS. ( have a look at Serial Port Manipulation in C) Unfortunately the PC doesn't have the capability to provide precision.

   We then tried to use Tx and Rx terminals. That was just an experiment, where we really learnt quite a few things.The code that follows will count up to three. It can be tested by connecting two leds b/w DTS & GND  and RTS & GND respectively.

Hardware Section:


Refer to Serial Port Manipulation in C for RS232 pin-out....


We used an USB-Serial(DB9) converter as the interface.













RS232 male-female






Simple GUI to control the binary counter




Output in LED diplay




Coding:

We have used RXTXcomm library to access the Serial port. We need to add 3 jar files (core.jar,   RXTXcomm.jar and serial.jar ) to the build path as shown in the image below:





// CommExp Class -> the class that implements necessary methods for accessing SerialPort



// BinaryCounterFrame => This class is a frame with 2 buttons for inreasing and decreasing the count. Here an instance of CommExp class is created and the methods of the class are accessed through it.
     


The code could be better with counting logic, but we are presenting what Java can do for Port interfacing not Counting logic. If you are looking for basics of Port Manipulation, have look at Serial Port Manipulation in C.

Here's a low quality video we made:




Thursday, 12 April 2012

AVR guide for Hobbyists

INTRO



First things first,
 AVR ==> Advanced Virtual RISC 
 RISC ==> Reduced Instruction Set Architecture


As the name suggests, the instructions are simple and all are executed in single Instruction cycle. 

Why should Hobbyists choose AVR?

· Reduced complexity

Easy to use the features available. Consider the timers, there are a number of modes of operation but they are pretty simple to use. 

· Efficient architecture

Highly efficient core with a typical Instruction Cycle of 1MIPS    

· High flash memory (program memory)

With high program memory, more lines of code can be dumped in the flash which is always an advantage. 

· Variety

The AVR family has a lot of variety in it. The pin count of various micros ranges from 8 to 100. So, we are free to choose an AVR uC based on our specific needs. 


Types of 8-bit AVR micros:

1.Tiny

They are small yet powerful. Low power consumption. They are used to shrink the project size in times of space limitations. Typical flash size of 2Kb. 

2.Mega

These are general purpose 8-bit micros with a pin count of 28 to 100pins. Consist of more peripherals and features compared to tiny. 

3.Xmega

These micros are similar to Mega in terms of flash size, pin count etc. But they have better performance than Mega series. In fact X in Xmega refers to Extreme-performance. They have additional features like DMA, Event System etc, which are absent in Mega.




We are gonna work with Atmega8 uC in the fore coming posts. Lets take a look at some of the features of Atmega8 uC.

Features Available:

1.10 bit ADC

It converts analog input given externally at a pin into a digital number of 10 bit length. This number ranges from 0H to 3FFH (in Hex), 0 to 1024 (in dec).The least input voltage that can give 1bit change in the digital number is (Vstep= Vmax/1024) approximately 5mV considering the range of input voltage as 0 to 5V. 

2.PWM generation

3.Highly flexible Timers

4.Internal RC oscillator

5.External and Internal Interrupts

6.TWI(I2C) and SPI interfaces










Sunday, 8 April 2012

Guides : Basics Of Programming

     I had an intention to write a book just after completing my higher secondary to help students, and make them learn thing easily. But at that time, with very little experience in writing articles, how could I write a book. Also I didn't have expertise in any field. But the idea writing a book for C-programming strike long ago in the beginning of 2010. But I came to know that there are much better books available in internet, why should I write one.

Book Cover

    After completing the fourth semester, I realized that pupil still do not have enough experience with C-programming. I started writing this guide, with a title of "Programming in C for Embedded System". I have asked my fellow students about this, but the questions they asked me narrowed my research. I started rephrasing them into Basic constructs Programming text. It took nearly two weeks to finish with my so called record works. I thought I could publish this guide before a week. Unfortunately I was unable to complete the text. And finally, here it is.

      Section 01: Variables and Arrays
      Section 02: Execution and Control Flow
      Section 03: Functions

    Say something in comments sections.

Friday, 3 February 2012

Power Loss Indication

    Actually this stuff is made for a Simple(labs) competition. Problem statement is to indicate the power loss by blinking an LED after the power goes off. We thought of storing the charge in capacitor, like everyone. It seem simple at first, complex then, finally pretty easy.

    Operation is simple. When power is available the Capacitor is charged through the PN Junction Diode(1N4007). The transistor is kept ON by the power supply. When the power goes OFF, the Capacitor drives the 555 timer - Blinking Circuitry to indicate that the power is lost. Click here to see 555 timer Basics

Here is the circuit.

Operation Simplified....

   Actually the 555 timer circuitry operates in Astable Mutlivibrator Mode to generate a pulse. The pulse is used to drive the LED - On/Off. The supply to the 555 is supplied by the Charge Retention Capacitor (array). It is nothing but a ordinary capacitor of high capacitance value. Diode is used to prevent the transistor to be biased from capacitor. The transistor goes Off with the power, so the charge from Capacitor is used to run 555 timer circuitry.



Downloads:  Files    Video

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More