Markdown Support for Experiment Docs in PSLab Android

The PSLab Android App and the PSLab Desktop App come with built-in experiments which include the experiment setups as well as the experiment docs. The experiment docs for PSLab have been written in the Markdown format. So, the markdown support had to be enabled in the PSLab Android App. There are numerous markdown file renderers for android. The most popular among them is MarkdownView (https://github.com/falnatsheh/MarkdownView) which is an  open-source service. This blog covers how to enable the support for markdown in apps and use to generate elegant documentation. Enabling MarkdownView MarkdownView can be enabled by simply adding a dependency in the build.gradle file compile 'us.feras.mdv:markdownview:1.1.0'   Creating the layout file The layout file for supporting a markdown file is fairly simple. The inclusion of the above dependency simplifies the things. The view holder for markdown is created and an id is assigned to it. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <br.tiagohm.markdownview.MarkdownView android:layout_width="match_parent" app:escapeHtml="false" android:layout_height="match_parent" android:id="@+id/perform_experiment_md" /> </LinearLayout>   Loading the markdown file In order to load the markdown file, a MarkdownView object is created. Since, in the PSLab Android app, markdown files which form the documentation part are a part of the experiments. So, the files are displayed in the documentation fragment of the experiments. private String mdFile; private MarkdownView mMarkdownView; public static ExperimentDocFragment newInstance(String mdFile) { ExperimentDocFragment experimentDocFragment = new ExperimentDocFragment(); experimentDocFragment.mdFile = mdFile; return experimentDocFragment; }   The MarkdownView object created is assigned to markdown viewholder of the relevant layout file. Here, the layout file was named experiment_doc_md and the view holder was assigned the id perform_experiment_md. The markdown files were stored in the assets directory of the app and the files were loaded from the there. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.experiment_doc_md, container, false); mMarkdownView = (MarkdownView) view.findViewById(R.id.perform_experiment_md); mMarkdownView.loadMarkdownFromAsset("capacitance.md"); return view; }   The available methods in markdown view are loadMarkdown - loads directly from the content in the string  mMarkdownView.loadMarkdown("**MarkdownView**");   loadMarkdownFromAsset - loads markdown files located in the assets directory of the app mMarkdownView.loadMarkdownFromAsset("markdown1.md");   loadMarkdownFromFile - loads markdown from a file stored in the app not present in the assets directory mMarkdownView.loadMarkdownFromFile(new File());   loadMarkdownFromUrl - loads markdown from the specified URL (requires internet connection, as file is loaded from the web) mMarkdownView.loadMarkdownFromUrl("url");   Important points for consideration Avoid using elements of GitHub Flavoured Markdown (GFM) as it is not fully supported. It is better to stick to the traditional markdown style. While adding images in the markdown files, avoid using specific dimensions as the images may not load properly in some cases due to the wide variety of screen sizes in android devices. It is better to store the Markdown files to be loaded in the assets directory of the app and load it from there instead of the other methods mentioned above. References A comprehensive markdown tutorial to learn markdown scripting https://www.markdowntutorial.com/ MarkdownView repository on Github by tiagohm https://github.com/tiagohm/MarkdownView Learn more about Github Flavoured Markdown (GFM) https://guides.github.com/features/mastering-markdown/

Continue ReadingMarkdown Support for Experiment Docs in PSLab Android

Performing Custom Experiments with PSLab

PSLab has the capability to perform a variety of experiments. The PSLab Android App and the PSLab Desktop App have built-in support for about 70 experiments. The experiments range from variety of trivial ones which are for school level to complicated ones which are meant for college students. However, it is nearly impossible to support a vast variety of experiments that can be performed using simple electronic circuits. So, the blog intends to show how PSLab can be efficiently used for performing experiments which are otherwise not a part of the built-in experiments of PSLab. PSLab might have some limitations on its hardware, however in almost all types of experiments, it proves to be good enough. Identifying the requirements for experiments The user needs to identify the tools which are necessary for analysing the circuit in a given experiment. Oscilloscope would be essential for most experiments. The voltage & current sources might be useful if the circuit requires DC sources and similarly, the waveform generator would be essential if AC sources are needed. If the circuit involves the use and analysis of data of sensor, the sensor analysis tools might prove to be essential. The circuit diagram of any given experiment gives a good idea of the requirements. In case, if the requirements are not satisfied due to the limitations of PSLab, then the user can try out alternate external features. Using the features of PSLab Using the oscilloscope Oscilloscope can be used to visualise the voltage. The PSLab board has 3 channels marked CH1, CH2 and CH3. When connected to any point in the circuit, the voltages are displayed in the oscilloscope with respect to the corresponding channels. The MIC channel can be if the input is taken from a microphone. It is necessary to connect the GND of the channels to the common ground of the circuit otherwise some unnecessary voltage might be added to the channels. Using the voltage/current source The voltage and current sources on board can be used for requirements within the range of +5V. The sources are named PV1, PV2, PV3 and PCS with V1, V2 and V3 standing for voltage sources and CS for current source. Each of the sources have their own dedicated ranges. While using the sources, keep in mind that the power drawn from the PSLab board should be quite less than the power drawn by the board from the USB bus. USB 3.0 - 4.5W roughly USB 2.0 - 2.5W roughly Micro USB (in phones) - 2W roughly PSLab board draws a current of 140 mA when no other components are connected. So, it is advisable to limit the current drawn to less than 200 mA to ensure the safety of the device. It is better to do a rough calculation of the power requirements in mind before utilising the sources otherwise attempting to draw excess power will damage the device. Using the Waveform Generator The waveform generator in PSLab is limited to 5 - 5000 Hz. This range…

Continue ReadingPerforming Custom Experiments with PSLab

Electrical Experiments with PSLab

PSLab has the capability to perform a variety of experiments. The PSLab Android App and the PSLab Desktop App have built-in support for over 70 experiments which are commonly performed by students. In addition to that, it can be used in other experiments conveniently. This blog post is in continuation with the previous two posts regarding performing experiments (links in the reference) and this blog deals with another category of experiments that can be performed using PSLab. The blog lists experiments which mainly involve the basic circuit elements like resistors, capacitors and inductors. These experiments involve the study of R-C, L-R, L-C and L-C-R circuits. These circuits have properties which make them important in real life applications and this blog attempts to give a rough picture of their importance. Ohm’s Law, Capacitive Reactance and Inductive Reactance These experiments involve the study of each of the basic circuit element individually. The current and voltage characteristics of each of the elements is studied. The definitions of the above are: Ohm’s Law - This is a law familiar to most. It relates the voltage and current of a purely resistive circuit stating that the voltage and current are proportional to each other and their ratio is a constant called the resistance. In this case, the current and voltage are in the same phase. Capacitive Reactance - Across a capacitor in an AC circuit, the current and voltage are not in the same phase and the current leads the voltage. For a purely capacitive circuit, this difference is 90o. Inductive Reactance -  Across an inductor in an AC circuit, the current and voltage are not in the same phase and the current lags behind the voltage. For a purely inductive circuit, this difference is 90o. The reactance is given for capacitor and inductor is given by 1/wC and wL respectively, where C & L are the values of capacitance and inductance respectively and w is the frequency of the AC signal. The circuit for the setup is shown below. We need to observe the plot of the input waveform and the plot of the voltage across individual elements to observe the phase shift. Connect CH1 & GND across the input terminals and CH2 & GND across the terminals of any of the elements. An external signal can be used or can be generated using the PSLab. Use the PSLab to generate a sinusoidal signal of frequency 1000 Hz. by connecting the ends of PV1 in the circuit. Observe the waveforms. In case of the resistor, there should be no observable phase lag between the two. In case of the capacitor and inductor, there will be an observable phase difference of 90o. For the capacitive and inductive circuits, just replace the resistor in the above circuit with capacitor/inductor. RC Circuits Drawing their names from their respective calculus functions, the integrator produces a voltage output proportional to the product (multiplication) of the input voltage and time; and the differentiator (not to be confused with differential) produces…

Continue ReadingElectrical Experiments with PSLab

Fascinating Experiments with PSLab

PSLab can be extensively used in a variety of experiments ranging from the traditional electrical and electronics experiments to a number of innovative experiments. The PSLab desktop app and the Android app have all the essential features that are needed to perform the experiments. In addition to that there is a large collection of built-in experiments in both these experiments. This blog is an extension to the blog post mentioned here. This blog lists some of the basic electrical and electronics experiments which are based on the same principles which are mentioned in the previous blog. In addition to that, some interesting and innovative experiments where PSLab can be used are also listed here. The experiments mentioned here require some prerequisite knowledge of electronic elements and basic circuit building. (The links mentioned at the end of the blog will be helpful in this case) Op-Amp as an Inverting and a Non-Inverting Amplifier There are two methods of doing this experiment. PSLab already has a built-in experiment dedicated to inverting and non-inverting amplification of op-amps. In the Android App, just navigate to Saved Experiments -> Electronics Experiments -> Op-Amp Circuits -> Inverting/ Non-Inverting. In case of the Desktop app, select Electronics Experiments from the main drop-down at the top of the window and select the Inverting/Non-inverting op-amp experiment. This experiment can also performed using the basic features of PSLab. The only advantage of this methodology is that it allows much more tweaking of values to observe the Op-Amp behaviour in greater detail. However, the built-in experiment is good enough for most of the cases. Construct the above circuits on a breadboard. For the amplifier, connect the terminals of CH1 and GND of PSLab on the input side i.e. next to Vi and the terminals of CH2 and GND on the output side i.e next to Vo. Usually, an Op-Amp like LM741 have a set of pins, one dedicated for the inverting input and the other dedicated for the non-inverting input. It is recommended to consult the datasheet of the Op-Amp IC used in order to get the pin number with which the input has to be connected. The terminals of W1 and GND are also connected on the input side and they are used to generate a sine wave. The resistors displayed in the figure have the values R1 = 10k and R2 = 51k. Resistance values other than these can also be considered. The gain of the op-amp would depend on the ratio of R2/R1, so it is better to consider values of R2 which are significantly larger than R1 in order to see the gain properly. Use the PSLab Desktop App and open the Waveform Generator in Control. Set the wave type of W1 to Sine and set the frequency at 1 kHz and magnitude to 0.1 V. Then go ahead and open the Oscilloscope. CH1 would display the input waveform and CH2 will display the output waveform and the plots can be observed. If the input is connected…

Continue ReadingFascinating Experiments with PSLab

Electronics Experiments with PSLab

Numerous college level electronics experiments can be performed using Pocket Science Lab (PSLab). The Android app and the Desktop app have all the essential features needed to perform these experiments and both these apps have quite a large number of experiments built-in. Some of the common experiments involve the use of BJT (Bipolar Junction Transistor), Zener Diode, FET (Field Effect Transistor), Op-Amp ( Operational Amplifier) etc. This blog walks through the details of performing some experiments using the above commonly used elements.   The materials required for all the experiments are minimal and includes a few things like PSLab hardware device, components like Diodes, Transistors, Op-Amps etc., connecting wires/jumpers and secondary components like resistors, capacitors etc. Most of these elements would be a part of the PSLab Accessory Kit. It is recommended to read this blog here, go through the resources mentioned at the end and also get acquainted with construction of circuits before advancing with the experiments mentioned in this blog. Half Wave and Full Wave Rectifiers The Bipolar Junction Transistor (BJT) can be used as a rectifier. Rectifiers are needed in circuits to obtain a nearly constant and stable output voltage and prevent any ripples in the circuit. The rectifier can be half wave or full wave depending on whether it rectifies one or both cycles of Alternating Voltage. The circuit for the Half and Full Wave rectifier is given as follows: Construct the above circuits on a breadboard. For the half wave rectifier, connect the terminals of CH1 and GND of PSLab on the input side and the terminals of CH2 and GND on the output side. The terminals of W1 and GND are also connected on the input side and they are used to generate a sine wave. Use the PSLab Desktop App and open the Waveform Generator in Control. Set the wave type of W1 to Sine and set the frequency at 100 Hz and magnitude to 10mV. Then go ahead and open the Oscilloscope. CH1 would display the input waveform and CH2 will display the output waveform and the plots can be observed. The plot obtained will have rectification in only half of the cycle. In order to obtain rectification in the complete cycle, the full wave rectifier is needed. For the full wave rectifier, the procedure is the same but an additional diode is used. Use an additional channel CH3 to plot the extra input. The plot obtained from the above steps would still have ripples and so a capacitor is placed in parallel to cancel this effect. Place a 100uF/330uF capacitor in parallel to the resistor RL and an additional 1 ohm resistor in the circuit. BJT Inverter Transistor has a lot of functions. The most common of them is its use as an amplifier. However, transistor can be used as a switch in a circuit i.e. as an inverter. The circuit for this experiment is shown below. For this experiment, it is recommended to use an external 5V DC supply like…

Continue ReadingElectronics Experiments with PSLab

SPI Communication in PSLab

PSLab supports communication using the Serial Peripheral Interface (SPI) protocol. The Desktop App as well as the Android App have the framework set-up to use this feature. SPI protocol is mainly used by a few sensors which can be connected to PSLab. For supporting SPI communication, the PSLab Communication library has a dedicated class defined for SPI. A brief overview of how SPI communication works and its advantages & limitations can be found here. The class dedicated for SPI communication with numerous methods defined in them. The methods required for a particular SPI sensor may differ slightly, however, in general most sensors utilise a certain common set of methods. The set of methods that are commonly used are listed below with their functions. In the setParameters method, the SPI parameters like Clock Polarity (CKP/CPOL), Clock Edge (CKE/CPHA), SPI modes (SMP) and other parameters like primary and secondary prescalar which are specific to the device used. Primary Prescaler (0,1,2,3) for 64MHz clock->(64:1,16:1,4:1,1:1) Secondary prescaler (0,1,..7)->(8:1,7:1,..1:1) The values of CKP/CPOL and CKE/CPHA needs to set using the following convention and according to our requirements. At CPOL=0 the base value of the clock is zero, i.e. the idle state is 0 and active state is 1. For CPHA=0, data is captured on the clock's rising edge (low→high transition) and data is changed at the falling edge (high→low transition). For CPHA=1, data is captured on the clock's falling edge (high→low transition) and data is changed at the rising edge (low→high transition). At CPOL=1 the base value of the clock is one (inversion of CPOL=0), i.e. the idle state is 1 and active state is 0. For CPHA=0, data is captured on the clock's falling edge (high→low transition) and data is changed at the rising edge (low→high transition). For CPHA=1, data is captured on the clock's rising edge (low→high transition) and data is changed at the falling edge (high→low transition). public void setParameters(int primaryPreScalar, int secondaryPreScalar, Integer CKE, Integer CKP, Integer SMP) throws IOException { if (CKE != null) this.CKE = CKE; if (CKP != null) this.CKP = CKP; if (SMP != null) this.SMP = SMP; packetHandler.sendByte(commandsProto.SPI_HEADER); packetHandler.sendByte(commandsProto.SET_SPI_PARAMETERS); packetHandler.sendByte(secondaryPreScalar | (primaryPreScalar << 3) | (this.CKE << 5) | (this.CKP << 6) | (this.SMP << 7)); packetHandler.getAcknowledgement(); }   The start method is responsible for sending the instruction to initiate the SPI communication and it takes the channel which will be used for communication as input. public void start(int channel) throws IOException { packetHandler.sendByte(commandsProto.SPI_HEADER); packetHandler.sendByte(commandsProto.START_SPI); packetHandler.sendByte(channel); }   The setCS method is responsible for selecting the slave with which the SPI communication has to be done. This feature of SPI communication is known as Chip Select (CS) or Slave Select (SS). A master can use multiple Chip/Slave Select pins for communication whereas a slave utilises just one pin as SPI is based on single master multiple slaves principle. The capacity of PSLab is limited to two slave devices at a time. public void setCS(String channel, int state) throws IOException { String[] chipSelect = new String[]{"CS1", "CS2"}; channel =…

Continue ReadingSPI Communication in PSLab

I2C Communication in PSLab

PSLab supports communication using the I2C protocol and both the Desktop App and the Android App have the framework set-up to use the I2C protocol. I2C protocol is mainly used by sensors which can be connected to PSLab. For supporting I2C communication, PSLab board has a separate block for I2C communication and has pins named 3.3V, GND, SCL and SDA. A brief overview of how I2C communication works and its advantages & limitations compared to SPI communication can be found here. The PSLab Python and Java communication libraries have a class dedicated for I2C communication with numerous methods defined in them. The methods required for a particular I2C sensor may differ, however, in general most sensors utilise a certain common set of methods. The set of methods that are commonly used are listed below with their functions. For utilising the methods, the I2C bus is first notified using the HEADER byte (it is common to all the methods) and then a byte to uniquely determine the method in use. The send method is used to send the data over the I2C bus. First the I2C bus is initialised and set to the correct slave address using I2C.start(address) followed by this method. The method takes the data to be sent as the argument. def send(self, data): try: self.H.__sendByte__(CP.I2C_HEADER) self.H.__sendByte__(CP.I2C_SEND) self.H.__sendByte__(data) # data byte return self.H.__get_ack__() >> 4 except Exception as ex: self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)   The read method reads a fixed number of bytes from the I2C slave. One can also use I2C.simpleRead(address,  numbytes) instead to read from the I2C slave. This method takes the length of the data to be read as argument.  It fetches length-1 bytes with acknowledge bits for each. def read(self, length): data = [] try: for a in range(length - 1): self.H.__sendByte__(CP.I2C_HEADER) self.H.__sendByte__(CP.I2C_READ_MORE) data.append(self.H.__getByte__()) self.H.__get_ack__() self.H.__sendByte__(CP.I2C_HEADER) self.H.__sendByte__(CP.I2C_READ_END) data.append(self.H.__getByte__()) self.H.__get_ack__() except Exception as ex: self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name) return data   The readBulk method reads the data from the I2C slave. This takes the I2C slave device address, the address of the device from which the data is to be read and the length of the data to be read as argument and the returns the bytes read in the form of a list. def readBulk(self, device_address, register_address, bytes_to_read): try: self.H.__sendByte__(CP.I2C_HEADER) self.H.__sendByte__(CP.I2C_READ_BULK) self.H.__sendByte__(device_address) self.H.__sendByte__(register_address) self.H.__sendByte__(bytes_to_read) data = self.H.fd.read(bytes_to_read) self.H.__get_ack__() try: return [ord(a) for a in data] except: print('Transaction failed') return False except Exception as ex: self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)   The writeBulk method writes the data to the I2C slave. It takes address of the particular I2C slave for which the data is to be written and the data to be written as arguments. def writeBulk(self, device_address, bytestream): try: self.H.__sendByte__(CP.I2C_HEADER) self.H.__sendByte__(CP.I2C_WRITE_BULK) self.H.__sendByte__(device_address) self.H.__sendByte__(len(bytestream)) for a in bytestream: self.H.__sendByte__(a) self.H.__get_ack__() except Exception as ex: self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)   The scan method scans the I2C port for connected devices which utilise I2C as a communication mode. It takes…

Continue ReadingI2C Communication in PSLab

Real time Sensor Data Analysis on PSLab Android

PSLab device has the capacity to connect plug and play sensors through the I2C bus. The sensors are capable of providing data in real time. So, the PSLab Android App and the Desktop app need to have the feature to fetch real time sensor values and display the same in the user interface along with plotting the values on a simple graph. The UI was made following the guidelines of Google’s Material Design and incorporating some ideas from the Science Journal app. Cards are used for making each section of the UI. There are segregated sections for real time updates and plotting where the real time data can be visualised. A methods for fetching the data are run continuously in the background which receive the data from the sensor and then update the screen. The following section denotes a small portion of the UI responsible for displaying the data on the screen continuously and are quite simple enough. There are a number of TextViews which are being constantly updated on the screen. Their number depends on the type and volume of data sent by the sensor. <TextView android:layout_width="wrap_content" android:layout_height="30dp" android:layout_gravity="start" android:text="@string/ax" android:textAlignment="textStart" android:textColor="@color/black" android:textSize="@dimen/textsize_edittext" android:textStyle="bold" /> <TextView android:id="@+id/tv_sensor_mpu6050_ax" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_gravity="start" android:textAlignment="textStart" android:textColor="@color/black" android:textSize="@dimen/textsize_edittext" android:textStyle="bold" />   The section here represents the portion of the UI responsible for displaying the graph. Like all other parts of the UI of PSLab Android, MPAndroidChart is being used here for plotting the graph. <LinearLayout android:layout_width="match_parent" android:layout_height="160dp" android:layout_marginTop="40dp"> <com.github.mikephil.charting.charts.LineChart android:id="@+id/chart_sensor_mpu6050" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000" /> </LinearLayout>   Since the updates needs to continuous, a process should be continuously run for updating the display of the data and the graph. There are a variety of options available in Android in this regard like using a Timer on the UI thread and keep updating the data continuously, using ASyncTask to run a process in the background etc. The issue with the former is that since all the processes i.e. fetching the data and updating the textviews & graph will run on the UI thread, the UI will become laggy. So, the developer team chose to use ASyncTask and make all the processes run in the background so that the UI thread functions smoothly. A new class SensorDataFetch which extends AsyncTask is defined and its object is created in a runnable and the use of runnable ensures that the thread is run continuously till the time the fragment is used by the user. scienceLab = ScienceLabCommon.scienceLab; i2c = scienceLab.i2c; try { MPU6050 = new MPU6050(i2c); } catch (IOException e) { e.printStackTrace(); } Runnable runnable = new Runnable() { @Override public void run() { while (true) { if (scienceLab.isConnected()) { try { sensorDataFetch = new SensorDataFetch(); } catch (IOException e) { e.printStackTrace(); } sensorDataFetch.execute(); } } } }; new Thread(runnable).start();   The following is the code for the ASyncTask created. There are two methods defined here doInBackground and onPostExecute which are responsible for fetching the data and updating the display respectively. The raw data is fetched using the getRaw…

Continue ReadingReal time Sensor Data Analysis on PSLab Android

Analyzing Sensor Data on PSLab

PSLab Android App and Desktop app have the functionality of reading data from the sensors. The raw sensor data received is in the form of a long string and needs to parsed to understand what the data actually conveys. The sensor data is unique in terms of volume of data sent, the units of measurement of the data etc., however none of this is reflected in the raw data. The blog describes how the sensor data received by the Android/Desktop app is parsed, interpreted and finally presented to the user for viewing. The image below displays the raw data sent by the sensors Fig: Raw Sensor data displayed below the Get Raw button In order to understand the data sent from the sensor, we need to understand what the sensor does. For example, HMC5883L is a 3-axis magnetometer and it returns the value of the magnetic field in the x, y & z axes in the order of nanoTeslas. Similarly, the DAC of PSLab - MCP4728 can also be used like other sensors, it returns the values of channels in millivolts. The sensor MPU6050 being 3-axes accelerometer & gyroscope which returns the values of acceleration & angular momentum of the x, y & z axes in their SI units respectively. Each sensor has a sensitivity value. The sensitivity of the sensor can be modified to adjust the accuracy of the data received. For PSLab, the data returned is a float number with each data point having 4 bytes of memory with the highest sensitivity. Although sensitivity is not a reliable indicator of the accuracy of the data. Each value received has a lot of trailing values after the decimal and it is evident that no sensor can possibly achieve accuracy that high, so the data after 2-3 decimal places is garbage and not taken into consideration. Some sensors are configurable up to a great extent like MPU6050 where limits can also be set on the range of data, volume of data sent etc. whereas some are not configurable and are just meant for sending the data at regular intervals. In order to parse the above data, if the sensor returns a single value, then the data is ready to be used. However, in most cases like above where the sensors return multiple values, the data stream can be divided into equal parts since each value occupies equal space and each value can be stored in different variables. The stored data has to be presented to the user in a better understandable format where it is clear that what each value represents. For example, in case of the 3 axes sensors, the data of each axis must be distinctly represented to the user. Shown below are the mock-ups of the sensor UIs in which each value has been distinctly represented.           Fig: Mock-ups for the sensor UIs (a) - HMC5883L (b) - MPU6050 Each UI has a card to display those values. These values are updated in…

Continue ReadingAnalyzing Sensor Data on PSLab

Creating Multiple Device Compatible Layouts in PSLab Android

The developer's goal is that PSLab Android App as an app should run smoothly on all the variety of Android devices out in the market. There are two aspects of it - the app should be able to support maximum number of Android versions possible which is related to the core software part and the other being the app should be able to generate the same user experience on all sizes of screens. This post focuses on the later. There are a whole range of android devices available in the market right from 4 inch mobile phones to 12 inch tablets and the range in the screen sizes is quite large. So, the challenge in front of app designers is to make the app compatible with the maximum  number of devices without doing any specific tweaks related to a particular resolution range. Android has its mechanism of scaling the app as per the screen size and it does a good job almost all the time, however, still there are cases where android fails to scale up or scale down the app leading to distorted layout of the app. This blog discusses some of the tricks that needs to be kept in mind while designing layouts that work independent of screen sizes. Avoid using absolute dimensions It is one of the most common things to keep in mind before starting any UI design. Use of absolute dimensions like px, inch etc. must be avoided every time as they are fixed in size and don’t scale up or scale down while screen sizes are changed. Instead relative dimensions like dp should be used which depend on the resolution and scale up or scale down. ( It’s a fair assumption that bigger screens will have better resolution compared to the smaller ones although exceptions do exist) . Ensure the use of correct layout/View group Since, android provides a variety of layouts like Linearlayout, Constrainedlayout, Relativelayout, Tablelayout and view groups like ScrollView, RecyclerView, ListView etc. it is often confusing to know which layout/viewgroup should be used. The following list gives a rough idea of when to use a particular layout or view group. Linearlayout - Mostly used for simple designs when the elements are stacked in ordered horizontal/vertical fashion and it needs explicit declaration of orientation. Relativelayout - Mostly used when the elements need to defined relative to the parent or the neighbouring elements. Since, the elements are relative, there is no need to define the orientation. Constraintlayout - It has all the features of Relativelayout and in addition a feature of adding constraints to the child elements or neighbouring elements. Tablelayout - Tablelayout is helpful to when all the views/widgets are arranged in an ordered fashion. All the above layouts can be used interchangeably most of the times, however, certain cases make some more favourable than others like when than views/ widgets are not present in an organised manner, it is better to stick to Linearlayout or Relativelayout. ListView - Used when the…

Continue ReadingCreating Multiple Device Compatible Layouts in PSLab Android