I use Raspberry 3 PI b+ model which is installed with Raspbian OS.
My pressure sensor is FSR-406 with MCP3008 ADC, and I connected these components based on below diagram
https://es.mathworks.com/help/supportpk ... meter.html
and that is my code
Code: Select all
import spidev, time, sys, os
from subprocess import Popen
import subprocess as sp
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
def analog_read(channel):
r = spi.xfer2([1, (0x08 + channel) << 4, 0])
adc_out = ((r[1]&0x03) << 8) + r[2]
return adc_out
video1 = ('/home/pi/Videos/sample1.mp4')
video2 = ('/home/pi/Videos/sample2.mp4')
while True:
reading = analog_read(1)
time.sleep(1)
if (reading <= 20):
zone = 1
elif (reading > 20):
zone = 2
if (zone == 1):
Popen(['/usr/bin/omxplayer', '--display', '0', video1])
if (zone == 2):
Popen(['/usr/bin/omxplayer', '--display', '0', video2])
First of all, I though this sensor can detect continuous force, but when I got the output data, this sensor only can detect the force at the moment.
For example, the trigger system should be operated like.. when someone sit on the sensor, the sensor detects the person's wight during siting, then this system play 'video2', and when the person stands up, the sensor's output will be zero or under 20, then play video1. But When I try to run the program, this sensor only detect as someone sit the sensor at the moment, and directly the output became zero. So I wonder, why this sensor only can detect the moment force? Am I wrong something?
Secondly, I made a 'while loop' for continuously playing video1 and 2 depend on the situation, but problem is that same video will start to play every second under own specific condition.
For example, I gave a condition like as 'if (reading <= 20): zone = 1 ....... if (zone == 1): Popen(['/usr/bin/omxplayer', '--display', '0', video1])' but when output data is under 20 situation, this program trigger to play 'video1' in every second. Opposite situation is also same (Over 20 with video2). Can you give me some solution for making that keeping the play 'video1' until the output data is over 20?
Sorry about too long and massive sentences but I am a beginner so If you have any suggestions, I would greatly appreciate it! Thanks!