Raspberry Pi LED Blinking and GPIO Demo using Python

September 15th, 2012 | by | technology

Sep
15

This is a demo video of using Raspberry Pi showing LED Blinking and using GPIO in Python.

More details can be found at the following links:



from time import sleep
import RPi.GPIO as GPIO

# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

# set up the GPIO channels - output
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

while 1:
    GPIO.output(13, False)
    sleep(1)
    GPIO.output(13, True)
    sleep(1)
    
    GPIO.output(15, False)
    sleep(1)
    GPIO.output(15, True)
    sleep(1)
    
    GPIO.output(16, False)
    sleep(1)
    GPIO.output(16, True)
    sleep(1)
    
    GPIO.output(18, False)
    sleep(1)
    GPIO.output(18, True)
    sleep(1)

No Comments »

State of the Indian News Channels

July 13th, 2012 | by | fun & entertainment

Jul
13

Here is how the Indian TV news channel would report the Jack and Jill nursery rhyme. All names (except those of Jack and Jill), are fictitious.

Prashant – TV Anchor:

Two persons have been injured in a freak climbing accident. Jack and his companion Jill had gone up a hill to fetch a pail of water when Jack fell down and broke his crown. Jill came tumbling after. Live from the hill, our reporter, Amrita Shah, takes up the story.

Amrita Shah:

Thank you Prashant. Well, as you say, two persons – Jack and Jill – had gone up a hill to fetch a pail of water. Suddenly, Jack fell down and broke his crown and Jill came tumbling after. Prashant.

Prashant:

Thank you Amrita. What do we know about the hill?

Amrita:

Not too much. Jack was going up the hill to fetch a pail of water when he fell down and broke his crown. Jill came tumbling after [Headline appears at the foot of the TV screen: "hill breaks crown of pail-boy Jack"]

Prashant:

What news of Jack and Jill?

Amrita:

Prashant, it seems that Jack had gone up the hill to fetch a pail of water. We know nothing about the pail, or how heavy it was but it seems that Jack fell down and broke his crown and Jill came tumbling after. I have here with me, an eyewitness to the accident, Mr. Shahid Trivedi. Mr. Shahid, tell us what you saw.

Shahid Trivedi:

Jack and Jill went up the hill to fetch a pail of water. Jack fell down and broke his crown and Jill came tumbling after. [Headline appears at the foot of the TV screen: "Boy and girl tumble down hill. Water spilled"]

Amrita:

Jack and Jill. What do we know about them? Are they brother and sister? Are they married? Just what were they doing on the hill together?

Shahid Trivedi:

Jack and Jill went up the hill to fetch a pail a water.

Amrita:

And what happened next?

Shahid Trivedi:

Jack fell down and broke his crown

Amrita:

Go on.

Shahid Trivedi:

And Jill came tumbling after.

Amrita:

Prashant, there you have it. Two people innocently going about their business to fetch a pail of water when one of them falls down, breaks his crown, and the other comes tumbling after. Back to you in the studio Prashant. [Headline appears at the foot of the TV screen: "Water errand ends in tragedy"]

Prashant:

I have with me in the studio now, Professor Chandrashekar Belagare from the Indian Institute of Applied Hill Sciences. Professor: a hill; Jack; Jill; a pail of water. A tragedy waiting to happen?

Professor:

Well that depends on the hill, the two persons, the object they were carrying and the conditions underfoot. Let us look at the evidence so far.

Jack and Jill

Went up the hill

To fetch a pail of water.

Jack fell down

And broke his crown

And Jill came tumbling after.

Clearly, one would suspect that if Jack’s fall was severe enough to break his crown then the surface of the hill must have been slippery or unstable. But I think we’re overlooking something quite fundamental here. Who was carrying the pail? Jack fell down and broke his crown and – this is the key – Jill came tumbling after. If Jack and Jill had been carrying the pail together, would they not have fallen at the same time? The fact that Jill came tumbling after suggests that Jack lost his footing first and perhaps knocked Jill over as he slipped.

Prashant:

Professor thank you very much. So there we have it, two persons – Jack and Jill – went up the hill to fetch a pail of water. Jack fell down and broke his crown and Jill came tumbling after. Later in the program, Shayad Halwa reveals names of ministers. But next up, join us after the break for a studio discussion about hills, boys and girls and whether water-fetching trips should be supervised. We’ll be right back…

3 Comments »

Intelligent Lighting Control using AVR Microcontroller

May 12th, 2012 | by | technology

May
12

This dissertation is an effort to learn embedded system development and embedded programming using AVR microcontroller.

This dissertation will look at the working of Analog to Digital conversion (ADC) and the usage of Pulse Width Modulation (PWM) for Digital to Analog conversion (DAC). This dissertation will also cover the features of AVR microcontroller and the usage of timers and ADC conversion in AVR microcontroller.

This dissertation will combine the Analog to Digital conversion (ADC) and Pulse Width Modulation (PWM) to create an intelligent lighting, which will be automatically controlled based on the external ambient lighting. So, at dusk, when the external sunlight gradually decreases, the intelligent light will start, and it brightness will start gradually increasing to its maximum. Similarly, at dawn, the first appearance of light in the sky before sunrise, the intelligent light will slowly start dimming and will automatically switch off in the morning.

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>

// initialize adc
void adcInit()
{
  // AREF = AVcc
  ADMUX = (1<<REFS0);

  // ADC Enable and prescaler of 128
  // 8000000/128 = 62500
  ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
}

// read adc value
uint16_t adcRead(uint8_t ch)
{
  // select the corresponding channel 0~7
  // ANDing with '7' will always keep the value
  // of 'ch' between 0 and 7
  ch &= 0b00000111;  // AND operation with 7
  ADMUX = (ADMUX & 0xF8)|ch;   // clears the bottom 3 bits before ORing

  // start single conversion
  // write '1' to ADSC
  ADCSRA |= (1<<ADSC);

  // wait for conversion to complete
  // till then, run loop continuously
  // The loop does nothing while ADIF is set to 0, 
  // it exits as soon as ADIF is set to one, 
  // i.e. conversion is complete. 
  while(!(ADCSRA & (1<<ADIF)));

  //Clear ADIF by writing one to it
  ADCSRA|=(1<<ADIF);
  
  return (ADC);
}

void pwmInit()
{
   /*
   TCCR0 - Timer Counter Control Register (TIMER0)
   -----------------------------------------------
   BITS DESCRIPTION
   

   NO:   NAME   DESCRIPTION
   --------------------------
   BIT 7 : FOC0   Force Output Compare [Not used in this example]
   BIT 6 : WGM00  Wave form generation mode  [SET to 1]
   BIT 5 : COM01  Compare Output Mode    [SET to 1]
   BIT 4 : COM00  Compare Output Mode    [SET to 0]

   BIT 3 : WGM01  Wave form generation mode  [SET to 1]
   BIT 2 : CS02   Clock Select         [SET to 0]
   BIT 1 : CS01   Clock Select         [SET to 0]
   BIT 0 : CS00   Clock Select         [SET to 1]

   The above settings are for
   --------------------------

   Timer Clock = CPU Clock (No Prescalling)
   Mode    = Fast PWM
   PWM Output  = Non Inverted

   */


   TCCR0|=(1<<WGM00)|(1<<WGM01)|(1<<COM01)|(1<<CS00);

   //Set OC0 PIN as output. It is  PB3 on ATmega16 ATmega32

   DDRB|=(1<<PB3);
}

/******************************************************************
Sets the duty cycle of output. 

Arguments
---------
duty: Between 0 - 255

0 = 0%

255 = 100%

The Function sets the duty cycle of pwm output generated on OC0 PIN
The average voltage on this output pin will be

         duty
 Vout=  ------ x 5v
         255 

This can be used to control the brightness of LED or Speed of Motor.
*********************************************************************/

void setPWMOutput(uint8_t duty)
{
   OCR0=duty;
}

int main()
{
  uint16_t adcResult;
  uint8_t pwmBrightness;

  // initialize adc and pwm
  adcInit();
  pwmInit();

  _delay_ms(50);

  while(1)
  {
    adcResult = adcRead(0);    // read adc value at PA0
    
    // Mapping the adc value in the range of 0-1024 (2^10 bits)
    // to 0-255, which can be sent to 8 bit OCR0 register.
    // So the adcResult is divided by 4, to make it in the 
    // range of 0-255.
    // After that the value is subtracted from 255, so that if 
    // the adc value is less, we want to send high value to the
    // OCR0, for increasing brightness, and if the adc value is
    // high, we want to send lower values for the PWM signal 
    // generation, to reduce the brightness of the LED.
    pwmBrightness = (uint8_t)(255 - (adcResult/4));
    
    //Send the pwm value to the OCR0, to control the LED brightness
    setPWMOutput(pwmBrightness);
   }
}

The presentation and the project report can be downloaded from the previous post: Seminar on Embedded System Development using AVR Microcontroller.

1 Comment »

Firefox New Download Manager Toolbar Interface

April 22nd, 2012 | by | technology

Apr
22

Firefox has released a new, easy and improved interface to the download manager. Instead of popping out a new download window, now a toolbar button will show the remaining time, and the toolbar window will automatically disappear when the download is complete. Also, when you click on that toolbar button, a new tool tip like window, will open, which will show each file details.

Firefox  New Download Manager Toolbar Interface

Firefox Download Manager Popup Window

2 Comments »

Google Reader’s UI Issue Fixed

February 22nd, 2012 | by | technology

Feb
22

In my last post, I have showed, how the new Google Reader’s user interface is so unfriendly, wasting more than 40% screen space. I came across, some user defined CSS to solve the Google user interface issues. I have modified the CSS by Ingmar Hupp to provide more reading space for news items. I am using Stylish addon for Firefox, to load the user CSS.

Google Reader's UI Layout Issue Fixed
Google Reader’s Fixed GUI

vs

Google Reader's Stupid GUI
Google Reader’s Stupid GUI

I am not a CSS expert, and this CSS has lot of issues, and it interferes with GMail and other Google products. So, I just disable it, when I am not using the Google Reader. The idea here is to show Google: how their GUI needs to be user friendly. Google Reader is basically a reader for RSS feeds, and any reader’s first priority should be to use the screen real estate efficiently.

No Comments »

How to remove Visual Source Safe binding from Visual Studio projects?

January 19th, 2012 | by | technology

Jan
19

Just wrote this script to remove the VSS source safe bindings from old visual studio projects, so that I can move to GIT repository. I just run these commands using the Cygwin shell, from the solution root folder, and it removes all traces of the source control of the Jurassic era.

find . -type f -name *.dsp -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*Scc_ProjName.*$//g'
find . -type f -name *.dsp -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*Scc_LocalPath.*$//g'
find . -type f -name *.dsw -print0 | xargs -0 -r sed -i '/begin.source.code.control/,/end.source.code.control/d'
find . -type f -name *.sln -print0 | xargs -0 -r sed -i '/GlobalSection(SourceCodeControl)/,/EndGlobalSection/d'
find . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccProjectName.*$//g'
find . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccLocalPath.*$//g'
find . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccProvider.*$//g'
find . -type f -name *.vssbak -print0 | xargs -0 -r rm -f 
find . -type f -name *.*scc -print0 | xargs -0 -r rm -f 

Now its easy, to create a GIT repository on top of it.

git init

No Comments »

Flashing STM32 MCU using ST-Link Command Line Utility

January 18th, 2012 | by | technology

Jan
18

You can directly download your compiled HEX file from the Keil µVision 4 IDE or any other IDE to your STM32 value discovery kit or any other STM32 microcontroller, using the command line ST-Link utility. That means, that you don’t need to manually search the HEX file and use the ST-Link Utility GUI to flash the MCU. Just a press of download button in the IDE, will be enough to load your new program to the STM32 MCU and reset it also.

You need to go to the Utilities tab in the project options (ALT + F7) and select the “Use External Tool for Flash programming“. Browse to the path of the “ST-LINK_CLI.exe” program and give the command line arguments as: ‘-c SWD -p "$H@H.hex" -Rst -Run‘.

	Flashing STM32 MCU using ST-Link Command Line Utility

No Comments »