Raspberry pi course

In STEM land a person from Auroville came to the iSMART class to conduct a course about raspberry pi course. Initially I dont know how to use raspberry pi. I was curious to learn raspberry pi. I also learnt the differences and advantages between Arduino and Raspberry pi. I learnt the different pin functions and the number of pins on a raspberry pi board. Day 1&2 was fully theory session which was boring.

In order to make it interesting I started ask many question to the teacher and the session was engaged by the participants. What really was interesting in the course was that the Arduino can’t drive a relay but with a raspberry pie we can drive a relay. One the teacher told that a relay can be driven by rapberry, he had a relay module but he couldn’t drive it. I took as a challenge and struggled for two days and I figured it to drive a relay. We made a small circuit with 2 LED where when the relay is on one of that LED will turn on and when the relay is off the other LED will turn on.

      

After this the teacher was also very happy and he also learnt something from us. Then the next challenge was that to send and to receive inputs from a raspberry pi to a web page.The teacher had asked who knows web page development.

             

Since I learnt Django web framework in STEM land, I was able to connect What I knew with what I lean now.  So I had asked him to show an example how to pass inputs from raspberry to a web page. Then finally in the last class we were able to complete all the task that we planed to accomplish in the course. Now I have some knowledge about raspberry pi and also I can build something with it.

To learnt about raspberry pi visit this link      Click here

requirements.txt

Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once.

Use pip’s freeze command to generate a requirements.txt file for your project:

In the terminal type:

pip freeze

If you save this in requirements.txt,

pip freeze > requirements.txt

then you can install the dependencies using.

pip install -r requirements.txt

Shell commands

I learnt about shell commands. A Shell is an environment which is used to run our commands and programs. It is an user interface with the operating system. There are many different types of shell. I learnt some commands in bash and C shell. Bash is one of the original shell which developed for UNIX computers. C shell was developed based on model of C programming syntax. To know which shell you are using type echo $0.
I learnt how to define variables both in bash and C shell. Bash is denoted by $. The syntax to define a variable is $a = 5
To print the value of the variable use the command echo $a. In C shell we need to set the environment variable. So the syntax goes like this. setenv a 10. An environmental variable has the name and the value.
To go to the home directory ~/.cshrc and ~/.bashrc for C shell and Bash respectively.

scratch programming for teaching physics concepts

I started to learn a scratch program software to create interactive model for learning. Then I got a task to create a model for: How pressure of gas change with respect to temperature and volume to container: I chose to represent it using Scratch. Initially, I had a problem on bouncing of gas molecules with same angle when it hit the wall of container. Then sanjeev helped me to solve it. In the model, I scaled the pressure in range of 0 to 150 and temperate in range of 0 to 300. But it didn’t give exact value of pressure for given temperature ( I will figure out it soon), because main goal of this model is show how pressure (no. of hit in wall by gas molecules) is affect by temperature and volume. I shared the model in scratch.mit.edu website. click this link to see the model https://scratch.mit.edu/projects/205711792/

Engfmt(Engineering Format) Documentation

Link : https://pypi.python.org/pypi/engfmt/1.1.0

engfmt – It is a package used to read and write numbers in engineering format.

In engineering format a number generally includes the units if available and uses SI scale factors to indicate the magnitude of the number.

For example:

1ns

1.4204GHz

This package is designed to convert quantities between the various ways in which they are represented. Those ways are:

As a tuple:

For Eg: “1ns” – would be represented as (1e-9, ‘s’).

As a string in conventional formats:

For Eg: “1ns” – would be represented as ‘1e-9 s’ or as ‘0.000000001s’.

– This form is difficult to read for people.

– engfmt treats it more as a format meant for machines rather than people.

As a string in engineering format:

For Eg: “1ns” – would be represented as ‘1ns’.

– This form is difficult to read for machines

– engfmt treats it more as a human readable format.

The Quantity class is provided for converting between these various forms.

  • A quantity is the pairing of a real number and units, though the units may be empty.

1.It takes one or two arguments.

Eg: Quantity(1e-9) or Quantity(1e-9, ‘s’)

  • The first is taken to be the value, and the second, if given, is taken to be the units.
  • The value may be given as a float or as a string.
  • The string may be in floating point notation, in scientific notation, or in engineering format and may include the units.

Some examples of the conversions are given below:

For example, any of the following ways can be used to specify 1ns:

As a tuple:

>>> from engfmt import Quantity

>>> period = Quantity(1e-9, ‘s’)

>>> print(period)

1ns

As a string in conventional formats:

>>> period = Quantity(‘0.000000001 s’)

>>> print(period)

1ns

>>> period = Quantity(‘1e-9s’)

>>> print(period)

1ns

As a string in engineering format:

>>> period = Quantity(‘1ns’)

>>> print(period)

       1ns

Note: In all cases, the giving the units is optional.

Conversions – Using quantity object you are able to convert it to any representations:

>>> h_line = Quantity(‘1420.405751786 MHz’)

# to converting to tuple with units

>>> h_line.to_tuple()

       (1420405751.786, ‘Hz’)

# to converting to string with engineering format

>>> h_line.to_eng()

       ‘1.4204GHz’

# to converting to string with conventional format

>>> h_line.to_str()

        ‘1420.405751786e6Hz’

You can also access the value without the units:

# convertig to float

>>> h_line.to_float()

       1420405751.786

# converting to a string with conventional format – without units

>>> h_line.to_unitless_eng()

       ‘1.4204G’

# converting to string with engineering format – without units

>>> h_line.to_unitless_str()

       ‘1420.405751786e6’

# Get the units only

>>> h_line.units

        ‘Hz’

There are many other functions also in this package, which is available in the link given.

Some of the functions are given below:

  • Quantities As Reals – You can use a quantity in the same way that you can use a real number, meaning that you can use it in expressions and it will evaluate to its real value.

For Example:

     >>> period = Quantity(‘1us’)

     >> print(period) 

         1us

  • Quantity Class – Quantity class can be used directly, like shortcut functions.

      For Example:

      >>> from engfmt import Quantity

      >>> h_line = Quantity(‘1420.405751786 MHz’)

      >>> str(h_line)

           ‘1.4204GHz’

      >>> float(h_line)

            1420405751.786

  • Physical Constants – The Quantity class also supports a some physical constants.

      For Example:

     Plank’s constant:

      >>> plank = Quantity(‘h’)

      >>> print(plank)

            662.61e-36J-s

  • Exceptions:

The best thing in this is it also gives Exceptions:

Eg: A ValueError is raised if engfmt cannot convert a string it into a number:

For Example:
			>>> try:
			...     value, units = quant_to_tuple('xxx')
			... except ValueError as err:
			...     print(err)
			xxx: not a valid number.

Installation / Usage :

Requires Python2.7 or Python3.3 or better.

1. Use ‘pip install engfmt’ in the cmd prompt to install.

2. By importing the .py file:

  • Download the package from the link.
  • Copy the engfmt.py from the package and put in the working directory of the python.
  • Import the file by from engfmt import* / from engfmt import Quantity.

Dynamic image changing and JavaScript debugging

I and my  colleague are creating a software to track the students plan regarding their progress in their academic . In that we wanted to upload the students pictures when they select their name. I learnt to deal with dynamic images and to debug the code in JavaScript using

<div class=”animptext” id=”animptext”>This is just a text I want to change </div>

document.getElementById(“animptext”).innerHTML = standard;

Two HTTP Request Methods: GET and POST

GET – Requests data from a specified resource
POST – Submits data to be processed to a specified resource
In computing, POST is a request method supported by the HTTP protocol used by the World Wide Web. By design, the POST request method requests that a web server accept the data enclosed in the body of the request message, most likely for storing it. It is often used when uploading a file or when submitting a completed web form.

Note that the query string (name/value pairs) is sent in the HTTP message body of a POST request:
POST /test/demo_form.php HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
POST requests are never cached
POST requests do not remain in the browser history
POST requests cannot be bookmarked
POST requests have no restrictions on data length

jQuery Syntax

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
1) A $ sign to define/access jQuery
2) A (selector) to “query (or find)” HTML elements
3) A jQuery action() to be performed on the element(s)

$(this).hide() – hides the current element.
$(“p”).hide() – hides all <p> elements.
$(“.test”).hide() – hides all elements with class=”test”.
$(“#test”).hide() – hides the element with id=”test”.

$ is just a shortcut for jQuery. The idea is that everything is done with the one global symbol (since the global namespaces is ridiculously crowded), jQuery, but you can use $ (because it’s shorter) if you like.

// These are the same barring your using noConflict (more below)
var divs = $(“div”); // Find all divs
var divs = jQuery(“div”); // Also find all divs, because
console.log($ === jQuery); // “true”

Javascript # and . Symbols – CSS selectors

Code 1:
$(‘#row DIV’).mouseover(function(){
$(‘#row DIV’).addClass(‘testing’);
});
Code 2:
$(‘.row div’).mouseover(function(){
$(this).addClass(‘testing’);
});

The hash (#) specifies to select elements by their ID’s
The dot (.) specifies to select elements by their classname
$(‘.row’) will select any element with class=”row”
$(‘#row’) will select the element with id=row

Asteroid game

I developed an Asteroid game from the python course . I did this game since two weeks .I had some difficulties while writing the codes. My team members helped me to over come errors in the program. Here’s a video on the game .I really enjoyed developing this.

-Prathap