New Homepage Forums Basic I/O Shields Arduino & 1Sheeld GamePad control video game issue with syncing to arrow keys

This topic contains 11 replies, has 2 voices, and was last updated by avatar Amr 1 year, 3 months ago. This post has been viewed 296 times

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #136501
    avatarmsmallwood20
    Participant

    Hi, I pretty new to using 1Sheeld and Arduino, but I have followed some tutorials, microphone, and blinking, from different examples. But what I’m trying to do for my school project, is create a code that uses the gamepad feature from 1sheeld and controls a video game though arrow keys on a laptop. Although I have written the code, and the led lights attached to the 1Sheeld light up, from pressing the buttons on the gamepad, they don’t seem to syce to my laptop. The following code is what I have attached to the form.

    #136797
    avatarAmr
    Keymaster

    Hi,

    Since your LEDs light up according to the Gamepad buttons press then the issue isn’t from the Gamepade shield, but from the mapping between your Arduino and laptop.

    So, would you please try to connect a simple Arduino sketch which automatically sends the video game control commands like:
    void loop()
    {
    // code to move a video game up
    delay(500);
    // code to move a video game down
    delay(500);
    }

    And make sure it works fine then we can change the code to work with the Gamepad. Also, it would be helpful to send me the code you made.

    #137017
    avatarmsmallwood20
    Participant

    Hi Amr,

    This is the code that I have written when I tried to upload it originally it didn’t upload.

    #include <OneSheeld.h>
    #include <Keyboard.h>

    void setup()
    {
    OneSheeld.begin();
    Serial.begin(9600);
    Keyboard.begin();
    }

    void loop()
    {
    //up arrow
    if (GamePad.isUpPressed())
    {Keyboard.press(0xDA);}
    else
    {Keyboard.release(0xDA);}
    //Down arrow
    if(GamePad.isDownPressed())
    {Keyboard.press(0xD9);}
    else
    {Keyboard.release(0xD9);}
    //left arrow
    if(GamePad.isLeftPressed())
    {Keyboard.press(0xD8);}
    else
    {Keyboard.release(0xD9);}
    //right arrow
    if(GamePad.isRightPressed())
    {Keyboard.press(0xD7);}
    else
    {Keyboard.press(0xD7);}
    //delay(30);
    }

    #137112
    avatarAmr
    Keymaster

    Hi,

    Your code is missing the game pad #define line to be uploaded successfully, which is:
    #define CUSTOM_SETTINGS
    #define INCLUDE_GAMEPAD_SHIELD

    and you will write them at the beginning of the code.

    Also, 1Sheeld uses the same serial line that your arduino use to communicate with the pc so adding the Serial.begin(9600); with any Serial.print() functions will make a confliction and your 1Sheeld code will not run. You can use the Terminal Shield to act like a terminal/serial to your code instead of the serial monitor.

    I have added the gamepad codes and deleted the serial functions so here is the updated code .. try to upload it and let me know if it worked …

    Tip: I have noticed that you are using a keyboard library and if this library use the rx0,tx0 of your Arduino as a serial communication then you MUST use the 1Sheeld alt soft serial method so that you can free up the rx0,tx0 pins for the keyboard serial communication. Check this tutorial to know how you can make it:

    Arduino’s SoftwareSerial vs AltSoftSerial: Which library to use with 1Sheeld+ ?

    #137153
    avatarmsmallwood20
    Participant

    Hi Amr, I’ve tried the code that you provided and it gave me the following error below, Also, I tested out the website code and the led light attached lights up, however, I’m going to see if I can acquire jumpers to fit into the 1sheeld RX and TX pins as did the website pictures and program.

    “Multiple libraries were found for “Keyboard.h”
    Used: /home/builder/opt/libraries/latest/keyboard_1_0_2
    Not used: /home/builder/opt/libraries/latest/bluefairy_1_0_0
    Using library keyboard_1_0_2 at version 1.0.2 in folder: /home/builder/opt/libraries/latest/keyboard_1_0_2
    Using library HID at version 1.0 in folder: /home/builder/.arduino15/packages/arduino/hardware/avr/1.6.23/libraries/HID
    /tmp/ccBy66mc.ltrans1.ltrans.o: In function loop’:
    /tmp/129203869/GamePad/GamePad.ino:17: undefined reference to
    GamePad’
    /tmp/129203869/GamePad/GamePad.ino:22: undefined reference to GamePad’
    /tmp/129203869/GamePad/GamePad.ino:27: undefined reference to
    GamePad’
    /tmp/129203869/GamePad/GamePad.ino:32: undefined reference to `GamePad’
    collect2: error: ld returned 1 exit status
    exit status 1 ”

    #137315
    avatarAmr
    Keymaster

    Hey,

    This error means you have an unused library that has the same “Keyboard.h” file so you should delete this file from the pass:
    /home/builder/opt/libraries/latest/bluefairy_1_0_0

    #137370
    avatarmsmallwood20
    Participant

    Hi again,
    So I was using the online editor for Arduino, so deleting the library didn’t seem to be an option so I decided to try it again on the downloadable version of Arduino software. And came across another error, I looked through my C: drive folder where it was directing me and couldn’t find the file.

    “Arduino: 1.8.9 (Windows 10), Board: “Arduino Leonardo”
    C:\Users\MAYASM~1\AppData\Local\Temp\ccFeKWSU.ltrans1.ltrans.o: In function loop’:
    C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:16: undefined reference to
    GamePad’
    C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:21: undefined reference to GamePad’
    C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:26: undefined reference to
    GamePad’
    C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:31: undefined reference to `GamePad’
    collect2.exe: error: ld returned 1 exit status
    exit status 1
    Error compiling for board Arduino Leonardo.
    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    #137978
    avatarAmr
    Keymaster

    Hey,

    This error “undefined reference to `GamePad’” means that you didn’t install the 1Sheeld library OR you didn’t include the #define lines of the Gamepad shield which are:

    So, check the above and let me know what you got …

    #138021
    avatarmsmallwood20
    Participant

    Hi again,

    I got the code to work and it has successfully synced to my laptop, I had to redownload the 1Sheeld library!
    Thank you so much for your help! 🙂

    #138094
    avatarAmr
    Keymaster

    Great! Happy to know that you got it working now 🙂

    I like your project and have an idea for you .. what about sharing your project code & steps as a tutorial on hackster.io? It would be amazing and helpful to share what you have built with other makers and even get their opinions to get their insights and encouragement. If liked the idea, I can help you publishing it easily & quickly .. just let me know here …

    #138136
    avatarmsmallwood20
    Participant

    Hi again,

    I’m glad that you like the project and I would be glad to share it with others, I’m currently typing up a report and a presentation on how this project was developed over time, such as steps and errors that I faced for my class. So it would great to share it with others for different insights on the project its self.

    #144859
    avatarAmr
    Keymaster

    That’s great, yeah 🙂

    So, once finished your report and have the time to customize it for a tutorial-like blog, let me know and I will help you make it ..

    And may I ask you for a favor? Would you be able to take a minute of your time and review 1Sheeld on Amazon?

    https://www.amazon.com/1Sheeld-Arduino-shield-iOS-Android/product-reviews/B01GOE9XU8/ref=cm

    It would really help us in expanding our community and develop more features in the product.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.