Other languages

send thermistor temp down gpio pins

1 543
hey guys.
my pic programmer guy has finaly finished the coding of my chip. i have asked him to send the thermister from my own pcb down the gpio pin of the banana pi.
i know that its a digital pin but that was the only pin that was linked to the pic chip, so i told him to convert the temperature into a time function so if the temp is 35.4c then he would make the gpio active for 354ms and then inactive for 1 second.

anyway i tried to make a bash script to read these delays and im failing.
it seems that i cannot read the pins that fast with my code.

instead of the expected millisecond count of around 300 im actualy getting between 1-3
could you explain to me whats wrong.

here is my code.
  1. #!/bin/bash
  2. gpio mode 1 in

  3. COUNTER=0
  4. Timeout=0

  5.          while gpio read 1 ; do
  6.                 sleep 0.001
  7.                 if [ $Timeout -gt 2000 ]; then
  8.                         echo "error $Timeout"
  9.                         exit 1
  10.                 fi

  11.                 Timeout=$((Timeout+1))
  12.          done

  13. Timeout=0

  14.          while gpio read 0 ; do
  15.                 sleep 0.001
  16.                                 if [ $Timeout -gt 2000 ]; then
  17.                         echo "error $Timeout"
  18.                         exit 1
  19.                 fi
  20.                 Timeout=$((Timeout+1))
  21.          done

  22. Timeout=0

  23.          while gpio read 1 ; do
  24.                 sleep 0.001
  27.                 if [ $Timeout -gt 2000 ]; then
  28.                         echo "error $Timeout"
  29.                         exit 1
  30.                 fi

  31.                 Timeout=$((Timeout+1))
  33.          done

  34. echo $Timeout
Copy the Code

the first while loop is to wait untill the 1 second inactive pin
the second loop is to wait until the pin becomes active once again
and finaly the last loop will count the milliseconds until that pin becomes inactive

You have to log in before you can reply Login | Sign Up

Points Rules