Question: Fill in missing lines of code for python. A Program to measure force using the Force - Sensitive Resistor ( FSR 4

Fill in missing lines of code for python. """A Program to measure force using the
Force-Sensitive Resistor (FSR 402) by Interlink Electronics"""
"""A FSR is a variable resistor that changes its resistance
in proportion to the force applied. FSR 402 is a cheap
FSR and not highly accurate"""
#import time
from time import sleep
#Import Serial Programmable Interface module from the Adafruit SPI library
import Adafruit_GPIO.SPI as SPI
#Import the MCP3008 module from the Adafruit library
import Adafruit_MCP3008
#Import GPIO library
import RPi.GPIO as io
#Define SPI Port and Device Identifiers
spiPort =0
#SPI Device Identifier
spiDevice =0
#Analog To Digital Object Global Variable
adc =0
#Channel Number to which the FSR is connected
chnFSR =0
"""A callback method to be called when the pushbutton is pressed
The callback method should measure the channel 0"""
def MeasureForce(channel):
"""Variable to store the dynamic resistance of FSR
initialized to the upper limit value"""
R1=0.0
#Resistance in Series with FSR:
R2=10000.0
#Valid Maximum Force Sensor Resistance
MaxR1=30000.0
#Force Variable
F =0.0
#Define the maximum decimal value that can be measured on Channel 0 of the ADC
MaxRawValue =1023
"""Define the reference value of the input voltage signal connected
to Channel 0 of the ADC"""
RefVolt =3.3
"""Variables to store the raw and corresponding values of the voltage
measured at Channel 0 of the ADC"""
rawValue =0 #Variable to store the raw value of the signal input to Channel 0
VoltageSum =0.0 #Variable to store the sum of twenty five analog samples
AverageVoltage =0.0 #Variable to store the average of twenty-five analog samples
"""Sampling twenty-five values over a period of 2.5 seconds
and storing sum of the twenty five samples in the variable VoltageSum"""
Samples =25
for sample in range(Samples):
"""Read the raw value from the Channel 0 using the chnFSR variable
and adc object, and store in variable rawValue"""
"""Convert the rawValue to its corresponding analog Voltage using the
RefValue and add it to the VoltageSum variable"""
#Sleep for appropriate time to perform 25 samples approximately in 2.5 seconds
#Compute the average of the twenty-five samples and store in AverageVoltage
#Display the Average Voltage matching the sample format
"""Compute the resistance R1 of the Force Sensor using the Voltage divider formulae,
the RefVolt, Average Voltage and R2"""
#Display the Force Sensing Resistor value matching the sample format
"""Compute the corresponding force using the straight line equations
only if the measured resistance of the FSR is less than or equal to 30,000 ohms"""
"""You should first implement an if-else to check whether the measured resistance
is less than 30kohms, and then inside the if condition implement
three if conditions corresponding to the three line segements"""
if __name__=='__main__':
btnMeasureForce =26
io.setmode(io.BCM)
#Instantiate a ADC object using the global variable adc, spiPort, and spiDevice
"""setup the push button using the variable btnMeasureForce
connected to GPIO26"""
"""setup the OS to detect an edge event at GPIO26 with the
callback method MeaureForce"""
input('Press Pushbutton to start measuring Force
or press any key to exit')
print('Exiting the program')
io.cleanup()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!