Current version of the OpenAuto Pro is 11
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GPIO Pin Mapping to AA Controls
#1
Where are the GPIO Pins mapped to AA Controls?



I have a working joystick to raise and drop pins but I need to know where to map the pins.



Thanks!
#2
Currently this has to be done by yourself.



We are working on script for this purpose. Stay tuned.
#3
Thanks!
I am not one to stand around and wait for an answerSmile...

Analog joystick connected to an arduino to pass the inputs to the pi via GPIO Pins.
I am in the process of writing the joystick service to control the OAP via the joystick.

This is the Python script,
Using the uinput package form here :http://tjjr.fi/sw/python-uinput/#download-and-install

Code:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import uinput
from time import sleep

GPIO.setmode(GPIO.BCM)

#define variables and pins
selectButton = 6
xAxisLeft = 26
xAxisRight = 16
yAxisUp = 13
yAxisDown = 12
counter = 0;
mode = 1;

#define Keyboard Device using uinput
device  = uinput.Device([
        uinput.KEY_N,
        uinput.KEY_V,
        uinput.KEY_F7,
        uinput.KEY_F8,
        uinput.KEY_ENTER,
        uinput.KEY_H,
        uinput.KEY_ESC,
        ])
time.sleep(2)


# normally 0 when connected 1
GPIO.setup(selectButton, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(xAxisLeft, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(xAxisRight, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(yAxisUp, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(yAxisDown, GPIO.IN, GPIO.PUD_DOWN)


def inputPinEvent(channel):
    try:
           if GPIO.input(selectButton):
               print("Select")
               device.emit_click(uinput.KEY_ENTER)
           elif GPIO.input(xAxisLeft) and GPIO.input(yAxisUp):
               print("Up/Left - ESCAPE")
               device.emit_click(uinput.KEY_ESC)
           elif GPIO.input(xAxisRight) and GPIO.input(yAxisUp):
               print("Up/Right - HOME")
               device.emit_click(uinput.KEY_H)
           elif GPIO.input(xAxisLeft) and GPIO.input(yAxisDown):
               print("Down/Left")
           elif GPIO.input(xAxisRight) and GPIO.input(yAxisDown):
               print("Down/Right")
           elif GPIO.input(xAxisLeft):
               print("Previous Track")
               device.emit_click(uinput.KEY_V)
           elif GPIO.input(xAxisRight):
               print("Next Track")
               device.emit_click(uinput.KEY_N)
           elif GPIO.input(yAxisUp):
               print("Volume Up")
               device.emit_click(uinput.KEY_F8)
           elif GPIO.input(yAxisDown):
               print("Volume Down")
               print("Volume Down")
               device.emit_click(uinput.KEY_F7)
           else:
               print("inputPinEvent - Else")

           time.sleep(0.125);

    except Exception as e:
       print("Exception Detected.")
       print(e)
       GPIO.cleanup()

GPIO.add_event_detect(selectButton, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(xAxisLeft, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(xAxisRight, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(yAxisUp, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(yAxisDown, GPIO.RISING, callback=inputPinEvent, bouncetime=10)

print("GPIO Event Monitor for Joystick Input")
try:
  while(True):
    time.sleep(.25)
except KeyboardInterrupt:
    GPIO.cleanup()
    print("Exiting")


Currently I am passing the inputs successfully.
I am in the process of polishing the python script for making it a service.

DM me if you like to get the system diagrams and such.


Attached Files
.png   Head Unit Diagram SMALL.png (Size: 128.44 KB / Downloads: 1,071)
#4
Great! This is exactly how we will do that Wink No need to waiting for us.



What kind of joystick are you using?
#5
Its a standard Adafruit Analog Joystick.
I am using the Arduino board as my analog to Digital converter because it allows me to do so much more than just an ADC for the pi would.
There is a company that makes Thumb joystick for situations where it had to be IP65/68 compliant at about 35 to 200 dollars per joystick.
At this point I have converted the script I mentioned to a service and it works flawlessly.

Using 5 GPIO inputs to the pi from the Arduino I am able to pass 16 different functions.
Pins 1 - 4 are BitaA throug D and Bit E is a signal Bit to let the Pi know there is a button pressed.
ThePi Reads the GPIOS as bits and Adds them up in binary to determine the button pressed.
So BitA is 0/1, BitB is 0/2, BitC is 0/4 BitD is 0/8.
Wehen BitE goes high the routing clears the input variable and sets it to 0.
Then the input variable adds up the values of the GPIO Pins that are high and returns an integer from o to 15.

I have now integrated this Handlebar control to my OAP using the Arduino as the ADC and the Pi can see the buttons pressed.
[/url]
https://www.crutchfield.com/S-45Sx8m64vg...FOEALw_wcB

This Control takes in 12V GND and has one output wire. The output is a resistance Ladder which reads as resistance to ground from the arduino.

By using the python service script I can now do volume up and down, track next / previous and with the mode button I will be able to change the functions of the buttons. I am planning on giving audible feedback when the mode button is pressed to execute navigation or other functions.
The power button will be used to shut down the pi from the arduino when pressed longer than 10 seconds. if pressed for less than that it will become the enter key on OAP.

This is the joystick I am using [url=</s>https://www.adafruit.com/product/512<e>]https://www.adafruit.com/product/512

The Joystick service give me Volume UP/DN, Track Next/Prev and select button that can be used as power on off for the pi when pressed longer than 10 seconds. By moving the joystick in diagonal manner I can add 4 additional commands to the joystick as UP/Left, UP/Right, Dn/Left, Dn/Right, so total of 9 commands can be obtained form the joystick including select.

Keep in mind that on the Mega2560 board I am using I have had to make the arduino input pins INPUT_PULLUP to make the pins give me steady readings instead of erratic. This is very useful when reading ladder resistance controls such as the handlebar control I used.

The arduino board does more than just the handlebar controls, it also controls power up and down of OAP/Pi and controls the remote output pin to turn on and off the amplifiers.

When I get home today I will post an update to what I have completed.
Maybe a video.

One thing I would like to see is the control scheme changed to be context sensitive. So if I am on the AA screen the buttons do volume and track select but by pressing mode or based on where the screen is currently operating it may make those same controls navigation and such.
#6
The RPI is missing ADC. Maybe in version 4 they will introduce it Wink



This joystick is great, however the price.. :?



You have done great job with this GPIO conversion. Congrats 8-)
#7
(02-01-2019, 11:22 PM)PlasmaFlow Wrote: Thanks!
I am not one to stand around and wait for an answerSmile...

Analog joystick connected to an arduino to pass the inputs to the pi via GPIO Pins.
I am in the process of writing the joystick service to control the OAP via the joystick.

This is the Python script,
Using the uinput package form here :http://tjjr.fi/sw/python-uinput/#download-and-install

Code:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import uinput
from time import sleep

GPIO.setmode(GPIO.BCM)

#define variables and pins
selectButton = 6
xAxisLeft = 26
xAxisRight = 16
yAxisUp = 13
yAxisDown = 12
counter = 0;
mode = 1;

#define Keyboard Device using uinput
device  = uinput.Device([
        uinput.KEY_N,
        uinput.KEY_V,
        uinput.KEY_F7,
        uinput.KEY_F8,
        uinput.KEY_ENTER,
        uinput.KEY_H,
        uinput.KEY_ESC,
        ])
time.sleep(2)


# normally 0 when connected 1
GPIO.setup(selectButton, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(xAxisLeft, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(xAxisRight, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(yAxisUp, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(yAxisDown, GPIO.IN, GPIO.PUD_DOWN)


def inputPinEvent(channel):
    try:
           if GPIO.input(selectButton):
               print("Select")
               device.emit_click(uinput.KEY_ENTER)
           elif GPIO.input(xAxisLeft) and GPIO.input(yAxisUp):
               print("Up/Left - ESCAPE")
               device.emit_click(uinput.KEY_ESC)
           elif GPIO.input(xAxisRight) and GPIO.input(yAxisUp):
               print("Up/Right - HOME")
               device.emit_click(uinput.KEY_H)
           elif GPIO.input(xAxisLeft) and GPIO.input(yAxisDown):
               print("Down/Left")
           elif GPIO.input(xAxisRight) and GPIO.input(yAxisDown):
               print("Down/Right")
           elif GPIO.input(xAxisLeft):
               print("Previous Track")
               device.emit_click(uinput.KEY_V)
           elif GPIO.input(xAxisRight):
               print("Next Track")
               device.emit_click(uinput.KEY_N)
           elif GPIO.input(yAxisUp):
               print("Volume Up")
               device.emit_click(uinput.KEY_F8)
           elif GPIO.input(yAxisDown):
               print("Volume Down")
               print("Volume Down")
               device.emit_click(uinput.KEY_F7)
           else:
               print("inputPinEvent - Else")

           time.sleep(0.125);

    except Exception as e:
       print("Exception Detected.")
       print(e)
       GPIO.cleanup()

GPIO.add_event_detect(selectButton, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(xAxisLeft, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(xAxisRight, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(yAxisUp, GPIO.RISING, callback=inputPinEvent, bouncetime=10)
GPIO.add_event_detect(yAxisDown, GPIO.RISING, callback=inputPinEvent, bouncetime=10)

print("GPIO Event Monitor for Joystick Input")
try:
  while(True):
    time.sleep(.25)
except KeyboardInterrupt:
    GPIO.cleanup()
    print("Exiting")


Currently I am passing the inputs successfully.
I am in the process of polishing the python script for making it a service.

DM me if you like to get the system diagrams and such.

Hi my friend,

I bought an arduino nano. There is no problem on arduino side. I'm writing command to serial. Arduino connected to the USB of raspberry.

In raspberry I can read the serial. And I'm successfully getting message from arduino.

I'm trying to simulate keypress with uinput library.

It was working successfully. But now I'm getting uinput device permission denied.

And I cant add this script as service.

How did you successfully? I'm tried all in internet about adding service. But I failed.

Can you create a thread about this operations? This will very helpfull for many users.

I can help you for document If you need help to reduce time for thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)