Measure

From OLPC
Revision as of 23:50, 22 July 2007 by Arjs (talk | contribs) (elaborating on s/w)
Jump to: navigation, search

Introduction

Children learn by doing things. It is said "Give the child a hammer, and the world are his nails".

This activity is a tool that allows kids an expression of their curiosity. It is a tool that allows kids to explore and learn by doing, by connecting and observing span physical phenomena and real world events. Kids would learn by recording and observing the physical phenomena and by connecting their observations to a previously learned concept, or even better - learn the concept based on the experiments and observation.The basic functionality of this activity spans being able to measure DC and AC voltages by observing them on a oscilloscope like interface, logging data at a specified time interval and drawing the graph of logged data.


WARNING : Do not measure the mains voltage, it would destroy your XO

Elements of the Measure activity

Screen shot of Measure Activity


  • There is a 1050 X 800 pixels window in which one sees the waveform. There is a light Grey colored grid in the background.
  • A slider for selecting different frequency ranges (top slider)
  • A slider for selecting the sensitivity of the display - along the Y axis (bottom slider)
  • A button to select AC measurement or DC measurement
  • A button to switch Off/On the internal bias - Some microphones don't require an internal bias, most sensors do require a bias.
  • A button to Stop/Start the waveform display


  • Radio buttons to selectable data logging interval
  • A button to Start / Stop the data logging and record it onto a file
  • Draw graph of logged data from a previously recorded log file


A short video

<youtube>FE1ufEIXLVo</youtube>

Learning activities

1. Record animal sounds , for example, sounds of birds and observe their waveforms. Which of these are high frequency sounds, which are the low frequency ones ? Adjust the frequency sliders accordingly.

2. Whistle into the mic and compare the loudness and frequency of whistles by observing the waveforms.

3. Turn the sensitivity slider up to the maximum and observe ambient noise - in a quiet room , near a noisy road

4. Measure the voltage of an AA size pencil cell. What settings do you use ? AC or DC ?

5. Measure resistance of water , other liquids

6. Log temperature using a temperature sensor at one hour intervals. When in the day is it the hottest ? The coldest ?


(Ideas 1 and 2 given by Erik )

All ideas presented here are not necessarily supported by the current version of the measure activity.

TODO - add full pages of each activity including video

Downloading and running the activity on the XO

git-clone git://dev.laptop.org/projects/measure/ ./Measure.activity


This would download the activity code in a folder Measure.activity which you should copy to /usr/share/activities/ folder on your XO . If you are using sugar-jhbuild emulation, then you should copy it to <sugar-jhbuild>/build/share/activities/ folder where <sugar-jhbuild> is the path of the sugar-jhbuild folder on your machine (PC).

Activity has been found running well on builds 490 and higher


Ideas for the future

--to do--


Hardware details

The Analog Devices AD1888 sound chip has the ability to sample DC voltages. Experimentally it has been found out that the range is fairly linear, however the range that it can sample is restricted to 0.3V - 1.9V , with all the internal gains turned to the minimum.

The XO hardware has been designed to facilitate measurement of DC voltages by the addition of an electronic switch that can be controlled via a setting on the Alsa mixer called 'Analog Input' . The high pass filter can also be turned on/off by a setting 'High Pass Filter' in Alsamixer. The ability to control V_REFOUT (bias voltage) is also available and is done by the control 'V_REFOUT' in alsamixer.


All the above settings are being handled in the activity by using an os.system("amixer <control name> <mute/unmute>")


? Maximum range of input that can be applied without destroying the hardware is not known ? Maximum range of AC signal


For software developers

A brief explanation of the code

The code consists of the following 6 basic files


1. measure.py

2. audiograb.py

3. drawwaveform.py

4. config.py

5. buttons.py

6. loggingUI.py


measure.py is the main file which initiates all the classes and creates the main widget in which it adds all various other widgets. It also incorporates a gobject timeout which queues up the expose event after a time interval specified in config.py file.

audiograb.py is the file that takes care of grabbing input audio samples. It uses a gstreamer pipeline in which the handoff signal of the fakesink element is used to intercept the data in the pipeline. Data logging is done in this class since we can use the sampling rate as a time reference; i.e. we know the sampling rate and also the number of elements in each buffer that is intercepted from the pipeline. So each atomic time interval is (1/Fs * bufferSize). This is the time interval after which we get a handoff signal.

drawWaveform.py is the class that handles the waveform drawing part. It creates and uses a cairo context to draw the background, the grid and the waveform. It uses a combination of pango and cairo for displaying the text as it was found out that cairo is itself not good at rendering text. All drawing occurs in the expose function which is the gtk expose event handler. It does drawing from the real time samples or from a file. In real time, it can either draw time domain or display the frequency domain samples. self.integer_buffer is one buffer that is obtained from audiograb.py and self.main_bufers is the buffer that accumulates all these buffers. The self.main_buffers is sampled at varying intervals of time, depending upon the frequency range selected, to form self.buffers which is the buffer that is scaled and drawn. self.main_buffers is sampled at a larger interval (set by self.spacing) for lower frequencies and at a shorter interval for higher frequencies. An example calculation is as follows. If we form 1 self.buffers by taking all consecutive elements, we would be sampling at 48khz. I have found that to draw a reasonable representation of a sine wave, one needs at least 8 -12 points. Hence the largest frequency that can be represented accurately is given by 48/12 = 4Khz, or less.Text is updated after every self.update_text expose events.


config.py contains all global variables.

buttons.py


--explanation of each-- --signals structure-- --why signals adopted such-- --links to tutorials--

There would always be an updated 'Software task list' on this page, have a look at it to know ways in which you can contribute.


For content developers

--content and activities--


Software task list

1. Check all settings of Alsamixer at startup and shutdown of activity. Make kernel patch.

2. Find appropriate smoothing algorithm

3. Include header in log file , also include all relevant information - scale, interval etc.

4. Explore a scrolled window for graph of logged data

5. Set spacing interval when drawing from file

6. Explore pylab/matplotlib as an alternate rendering option or maybe just for the plot from log part

7. Calculate and display Fourier transform, add a button in UI

8. Work on optimizing the display, esp the background display method (explain)

9. Incorporate sharing wherein shared waveform would be drawn with a separate color. Basically self.buffers list is required to be shared

10. Calculate scale on different ranges and display it along other details in "Show Details"

11. Scale RMS, AVG and Pk Pk display values to correspond the voltage values.

12. Installation of NumPy and related dependancies on XO


Some Links

--to do --

WARNING : Do not measure the mains voltage, it would destroy your XO


Contact

Email: arjun@laptop.org

IRC: arjs on #freenode usually in #olpc , #sugar and #olpc-content

--Arjs 23:50, 22 July 2007 (EDT)