1

I've managed to connect a IR sensor to GPIO pin 23 and get LIRC to work with one of my remote controls. I've also set irexec up to launch a bash-script that drives motors (connected via open collectors):

#!/bin/bash

gpio -g mode 4 out
gpio -g mode 7 out

function forward {
        gpio -g write 4 1
        gpio -g write 7 1
}

function left {
        gpio -g write 4 0
        gpio -g write 7 1
}

function right {
        gpio -g write 4 1
        gpio -g write 7 0
}

function stop {
        gpio -g write 4 0
        gpio -g write 7 0
}

case $1 in
    "forward")
        forward
        ;;
    "left")
        left
        ;;
    "right")
        right
        ;;
    "stop")
        stop
        ;;
esac

Now, the problem is, after the first key press on the remote control, the motors start to spin but LIRC stops receiving any signals.

I assume writing to pins other than 23 causes the 23rd pin to be lost for lirc_rpi?

6
  • It sounds like electrical interference. Lirc shouldn't care about what is happening on the other gpios. How are you driving the motors? Via a motor driver board or your own circuitry?
    – joan
    Commented Nov 22, 2014 at 12:20
  • Nice to see you again @joan! The motors are connected to open collector ports on a Gertboard. The thing is, when I stop the motors running ./motors.sh stop directly, the IR is still not working. I tried reloading the kernel module, to no avail. mode2 reports silence.
    – katspaugh
    Commented Nov 22, 2014 at 12:52
  • Perhaps the script isn't returning control to Lirc. Does Lirc still stop responding if you comment out the gpio -g calls or pass a parameter other than forward/left/right/stop?
    – joan
    Commented Nov 22, 2014 at 12:57
  • @joan you might be right, I'll also try to launch the script with & in the end.
    – katspaugh
    Commented Nov 22, 2014 at 16:57
  • Nope, launching the script to background isn't helping.
    – katspaugh
    Commented Nov 24, 2014 at 9:23

1 Answer 1

1

I think you need to read a character from keyboard like this.

#!/bin/bash
a=`stty -icanon ; dd bs=1 count=1 2>/dev/null`

gpio -g mode 4 out
gpio -g mode 7 out

function forward {
        gpio -g write 4 1
        gpio -g write 7 1
}

function left {

        gpio -g write 4 0
        gpio -g write 7 1
}

function right {

        gpio -g write 4 1
        gpio -g write 7 0
}

function stop {

        gpio -g write 4 0
        gpio -g write 7 0
}

case $a in

    "f")
        forward
        ;;

    "l")
        left
        ;;

    "r")
        right
        ;;

    "s")
        stop
        ;;

esac

I hope that help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.