The PSLab Android App as of now supports quite a few sensors. Sensors are an essential part of many science experiments and therefore PSLab has a feature to support plug & play sensors. The list of sensors supported by PSLab can be found here.
- AD7718 – 24-bit 10-channel Low voltage Low power Sigma Delta ADC
- AD9833 – Low Power Programmable Waveform generator
- ADS1115 – Low Power 16 bit ADC
- BH1750 – Light Intensity sensor
- BMP180 – Digital Pressure Sensor
- HMC5883L – 3-axis digital magnetometer
- MF522 – RFID Reader
- MLX90614 – Infrared thermometer
- MPU6050 – Accelerometer & gyroscope
- MPU925x – Accelerometer & gyroscope
- SHT21 – Humidity sensor
- SSD1306 – Control for LED matrix
- Sx1276 – Low Power Long range Transceiver
- TSL2561 – Digital Luminosity Sensor
All the sensors except Sx1276 communicate using the I2C protocol whereas the Sx1276 uses the SPI protocol for communication. There is a dedicated set of ports on the PSLab board for the communication under the label I2C with the ports named 3.3V, GND, SCL & SDA.
Fig; PSLab board sketch
Any I2C sensor has ports named 3.3V/VCC, GND, SCL, SDA at least along with some other ports in some sensors. The connections are as follows:
- 3.3V on PSLab – 3.3V/VCC on sensor
- GND on PSLab – GND on sensor
- SCL on PSLab – SCL on sensor
- SDA on PSLab – SDA on sensor
The diagram here shows the connections
For using the sensors with the Android App, there is a dedicated I2C library written in communication in Java for the communication. Each sensor has its own specific set of functionalities and therefore has its own library file. However, all these sensors share some common features like each one of them has a getRaw method which fetches the raw sensor data. For getting the data from a sensor, the sensor is initially connected to the PSLab board.
The following piece of code is responsible for detecting any devices that are connected to the PSLab board through the I2C bus. Each sensor has it’s own unique address and can be identified using it. So, the AutoScan function returns the addresses of all the connected sensors and the sensors can be uniquely identified using those addresses.
As per the addresses fetched, the sensor library corresponding to that particular sensor can be imported and the getRaw method can be called. The getRaw method will return the raw sensor data. For example here is the getRaw method of ADS1115.
Here the raw data is returned in the form of voltages in mV.
Similarly, the other sensors return some values like luminosity sensor TSL2561 returns values of luminosity in Lux, the accelerometer & gyroscope MPU6050 returns the angles of the 3-axes.
In order to initiate the process of getting raw data from the sensor in Sensor Activity, the object for the sensor is created and the method of getRaw is called. The following is the implementation for ADS1115. The rest of the sensors also have an implementation similar to this. There are try-catch statements in the code to handle some of the exceptions thrown during process of method calls.
- Sensor implementation in PSLab Python repository – https://github.com/fossasia/pslab-python/tree/development/PSL/SENSORS
- Using the sensors with Arduino in case you have worked with Arduino before – The basic connections are same as PSLab http://www.instructables.com/id/Arduino-MPU-6050-Getting-It-to-Work/