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 Amr 1 year, 9 months ago. This post has been viewed 322 times
-
AuthorPosts
-
April 12, 2019 at 5:30 PM #136501
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.
April 14, 2019 at 3:41 PM #136797Hi,
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.
April 16, 2019 at 1:21 AM #137017Hi 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);
}April 16, 2019 at 4:30 PM #137112Hi,
Your code is missing the game pad #define line to be uploaded successfully, which is:
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_SHIELDand 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 …
C++123456789101112131415161718192021222324252627282930313233343536#define CUSTOM_SETTINGS#define INCLUDE_GAMEPAD_SHIELD#include <OneSheeld.h>#include <Keyboard.h>void setup(){OneSheeld.begin();Keyboard.begin();}void loop(){//up arrowif (GamePad.isUpPressed()){Keyboard.press(0xDA);}else{Keyboard.release(0xDA);}//Down arrowif(GamePad.isDownPressed()){Keyboard.press(0xD9);}else{Keyboard.release(0xD9);}//left arrowif(GamePad.isLeftPressed()){Keyboard.press(0xD8);}else{Keyboard.release(0xD9);}//right arrowif(GamePad.isRightPressed()){Keyboard.press(0xD7);}else{Keyboard.press(0xD7);}//delay(30);}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+ ?
April 16, 2019 at 9:23 PM #137153Hi 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 functionloop’:
GamePad’
/tmp/129203869/GamePad/GamePad.ino:17: undefined reference to
/tmp/129203869/GamePad/GamePad.ino:22: undefined reference toGamePad’
GamePad’
/tmp/129203869/GamePad/GamePad.ino:27: undefined reference to
/tmp/129203869/GamePad/GamePad.ino:32: undefined reference to `GamePad’
collect2: error: ld returned 1 exit status
exit status 1 ”April 17, 2019 at 9:46 PM #137315Hey,
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_0April 18, 2019 at 1:33 AM #137370Hi 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 functionloop’:
GamePad’
C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:16: undefined reference to
C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:21: undefined reference toGamePad’
GamePad’
C:\Users\Maya Smallwood\Desktop\Project\GamePad/GamePad.ino:26: undefined reference to
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.
”April 21, 2019 at 6:32 PM #137978Hey,
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:
C++12#define CUSTOM_SETTINGS#define INCLUDE_GAMEPAD_SHIELDSo, check the above and let me know what you got …
April 22, 2019 at 12:47 AM #138021Hi 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! 🙂April 22, 2019 at 1:42 PM #138094Great! 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 …
April 22, 2019 at 5:18 PM #138136Hi 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.
April 29, 2019 at 3:20 PM #144859That’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.
-
AuthorPosts
You must be logged in to reply to this topic.