Using Sensors with PSLab Android App
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. public ArrayList<Integer> scan(Integer frequency) throws IOException { if (frequency == null) frequency = 100000; config(frequency); ArrayList<Integer> addresses = new ArrayList<>(); for (int i = 0; i < 128; i++) { int x = start(i, 0); if ((x & 1) == 0) { addresses.add(i); } stop(); } return 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. public int[] getRaw() throws IOException, InterruptedException { String chan = typeSelection.get(channel); if (channel.contains("UNI")) return new int[]{(int) readADCSingleEnded(Integer.parseInt(chan))}; else if (channel.contains("DIF")) return new int[]{readADCDifferential(chan)}; return new int[0]; } Here the raw data is returned in the form of voltages in mV. Similarly, the…
