Go Down

Topic: Connecting an USB Joystick to Arduino Nano / Gravitech Shield (Read 1 time) previous topic - next topic

schnorz

Hello to the Comnunity,

Is there any way to connect a USB Joystick with the Arduino Nano?
There is a USB host shield from Gravitech but I cannot find any example where somebody actually made it work and it does not work for me, too.
I tried to remap the pins, too,  with absolutely no success.
Is there anybody with a working setup who can give me some directions? I would like to make sure I did not get a broken board.


Thank you in Advance!

ballscrewbob

#1
Feb 02, 2017, 02:27 am Last Edit: Feb 02, 2017, 02:29 am by Ballscrewbob
I think you might need this HERE

Took me a few tries to find but it was linked from a review of the board.

Found the review HERE btw
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

schnorz

Hi Ballscrewbob,

yes, this is what reportedly is required to run the shield, Gravitech says so, too. However, I am not able to establish any connection to the shield with this library. Also, the author of the library states, that the shield is not even compatible with his code, see this post.

So again, does anybody actually own this shield and made it work?

Amorth31

Hi Schnorz and the Community,

Did you finally manage to make the thing work?
I've got exactly the same configuration: Arduino Nano and Gravitech shield (HERE)

I can't make the shield works: Usb.Init() fails... I tried to remap the pin D10 to D8 in the library as well for the chip selection.


Please could anyone help me/us?

Thank you very much in advance,
See you

gdsports

I have used an Arduino Pro Mini 3.3V with a USB host mini board. The boards stack so it is very compact.

The links to buy boards no longer work from circuitsathome.com but USB host clone boards are available.


Amorth31

Thank you gdsports, but I would like try with my current configuration :)
If I find out it's not possible at all I might reconsider my boards and buy new ones but it's kind of a waste of money  :(

Thank you for your answer anyway, I keep that in mind if I decide to change my hardware configuration!

jfreise

Would your situation work if you had to connect the joystick to a host computer instead? I use dual T1600 joysticks to fly my drone.

It uses a python script that implements pygame and pyserial that looks like this

Code: [Select]

import pygame
import serial
import time
ser = serial.Serial(
    port='/dev/cu.usbmodem1421',
    baudrate=4000000,
    bytesize=8
)

pygame.init()

def remap(value, oldMin, oldMax, newMin, newMax):
    oldRange = (oldMax - oldMin) 
    newRange = (newMax - newMin) 
    return  chr(int(((((value - oldMin) * newRange) / oldRange) + newMin)))

def main():
    jstick = []
    data = []
    aux1 = 0;
    aux2 = 0;
    oldAux1 = 0;
    oldAux2 = 0;
    beenPressed1 = 0;
    beenPressed2 = 0;
   
    print "helloworld"
    for i in range(0, pygame.joystick.get_count()):
        jstick.append(pygame.joystick.Joystick(i))
        jstick[i].init()
        print "Detected Joystick '", jstick[i].get_name(),"'"

    while True:
        if (ser.in_waiting>0):
           
            ser.reset_input_buffer();
            pygame.event.pump()

            aux1 = jstick[1].get_button(0);
            aux2 = jstick[0].get_button(0);

            if(aux1 and not(oldAux1)):
                beenPressed1 = not(beenPressed1);   

            if(aux2 and not(oldAux2)):
                beenPressed2 = not(beenPressed2); 
           
            data = bytearray([remap(jstick[0].get_axis(1), -1, 1, 255, 0), remap(jstick[0].get_axis(0), -1, 1, 0, 255),remap(jstick[1].get_axis(1), -1, 1, 255, 0),remap(jstick[1].get_axis(0), -1, 1, 0, 255),beenPressed1,beenPressed2])                         
            oldAux1 = aux1;
            oldAux2 = aux2;
            ser.write(data)
   
if __name__ == '__main__':
   main()





my Arduino loop looks like this

Code: [Select]


void loop()
{
  while (Serial.available()<channels) {} // Wait 'till there are 9 Bytes waiting
  for(int n=0; n<channels; n++)
    bytes[n] = Serial.read(); // Then: Get them.
   
  Serial.write('A'); //tell python we received data
  data.pitch = bytes[0];
  data.roll  = bytes[1];
  data.throttle  = bytes[2];
  data.yaw = bytes[3];
  data.AUX1 = bytes[4];
  data.AUX2 = bytes[5];
 
  printValues(data);
 
  radio.write(&data, sizeof(MyData));
}


Amorth31

So if I understood correctly you somehow connect the Arduino on the drone to the computer (Bluetooth / Wifi?) and then you use whatever the joystick you want on your computer then send the controls to the Arduino right?

It could work but I would have to buy a Bluetooth dongle to allow communication between my computer/arduino and it will surely be the same problem... "How can I make my USB shield connection work?"  :)

Currently what I'm trying to do is to read Tx/Rx data of a little USB stick (it's not a flash drive but a proper "antenna" paired to the joystick, the kind of wireless joystick used for PS3 but not via bluetooth).

Thanks for helping by the way, I really appreciate :)


jfreise

I serially send the data to one Arduino I have hardwired. That Arduino then sends the data over radio using an nrf24 module which is received by a second Arduino that also has an nrf24 module.

If your setup is stationary you wouldn't need the second Arduino, you could just use a USB cable from your computer. 


I like visual to help me explain

in my case my setup looks like this

Python->USB->arduino->radio->arduino->..->motors


your setup could easily be like this

Python->USB->arduino->whatever you want

Amorth31

To be consistent with your setup visual, mine would look like this:

Joystick -> USB stick paired with the joystick (wireless connection) -> USB host shield (the stick is embedded on the flying drone) -> Arduino -> motors or whatever

Your setup would work but would require buying a second arduino and RF transmitter. I think it's a shame because on the paper my current configuration should work  :)  The only thing preventing me to do so is that I have problems powering and reading the USB stick on this host shield (although the shield is powered on).

I'm open to any suggestion :) For now I'll try to understand why the stick is not powered on.

Thank you very much for your time!

Go Up