In order to start catching in a more exciting way, some simple steps needs to be taken. First the Arduino Pokéball works by using the accelerometer in the 101 board to sense that it's been thrown, then using the bluetooth on the board, the 101 sends the info to the Arduino PokeBall app on the phone.
Now in the app, when the “Toss mode” is on the app looks for any changes in the values that are being sent to it over the bluetooth. If the value is changed it means the Arduino been thrown.
When the value is changed, the app creates a text file and write the value into it, modifying the text file. That's all the Arduino PokeBall app does.
Running in the background of all of this, there is another app Tasker. Tasker is monitoring the same text file the app writes to, and when the file is modified Tasker sets up a “Task”, an action, that runs a small line of code. The code line is a “Shell command” containing the following code: input swipe 550 1650 550 900 200.
This code makes a swipe gesture from coordinates 550 ,1650 to 550, 900 the phone screen simulating a real swipe.
This fake swipe is what tosses the ball in Pokémon Go. These coordinates fit right on top of the ball during the catching phase in the game.
So for everything to come together have the Arduino PokeBall app connected to the Arduino 101 running with the tossing code, have the Toss mode active (the mode last for 5 mins) and the Tasker-app ready in the background, now start Pokémon Go. Now catch 'em all with style!
If you already have a rooted phone skip this section.
This project requires a rooted Android phone to work. For those who don't know; rooting a phone gives you extra control over your phone . But take note, rooting your phone may void your warranty and might, in some cases, render the phone useless.
But if you do want to root your phone, start by looking up guides for how to root your phone model.
When your phone is rooted, double check that it's ready with a root checking app like this one: Root Checker
Before any coding is needed you need to figure out what coordinates on your phone fit right over the pokéball in the game. Easiest way to check them, is by activating the developer options on your phone and turn on “Pointer location”. Now you will be able to see the coordinates of the touches at the top of the screen. Write down the two set of coordinates that will make a fitting swipe to flick the ball on your phone. Keep the “Pointer location” on for now, it will be useful for testing.
Download the Tasker app and create a new task. Name it and Select Action Category. Pick Code, then Run Shell. Under “Command” write “input swipe” and your two sets of coordinates, add a 200 to the end. Make sure to check the “Use Root” checkbox. You can test your task by clicking the play button in the lower left corner. If you see the “Pointer location” updating and drawing a line that fits your coordinates it’s working as intended. This part was inspired by Useless Duck Company's similar idea.
The Arduino code is based of the example CallbackLED for the CurieBLE library and the ShockDetect from the CurieIMU library. The code also used some features from the Education shield library.
Before changing anything in both this code and the android code later on, I recommend to read up about how Bluetooth low energy and GATT works, particularly how GATT services and GATT characteristic functions.
As the MDF casing used in the first video was damaged during testing, a colleague created a 3d print for a pokéball that can host the arduino and the power supply. The files for the pokéball is provided further down.
Besides the case, all you need to do is to connect the 9v battery to the board though the 9V to Barrel Jack Connector, to make the connector fit inside the case, remove the black casing on the jack. Also remove the black casing around the dc jack to make it stick out less or just plugin the 9v battery directly into the Vin and ground pin.
Would recommend you to screw or glue the 101 board to the ball.
The code for the Arduino Pokéball based off the BluetoothLeGatt sample provided with Android Studio.
Added some functions to connect to the GATT service and characteristic of that use setup in the Arduino code. In DeviceControlActivity.java, we have an AsyncTask that starts when clicking the “Start Toss mode” button. AsyncTask is basic background thread, that here is used to read what the bluetooth is sending once per second for 5 minutes.
The data from the bluetooth ends up in the displayData method where, if its not empty, is sent to the saveFile method. If you like to skip the Tasker app, some commented code in displayData does the same Shell command that was set up in Tasker.
With the saveFile method, we first check if the data has been updated, and if so the file_name.txt file is updated with the new data. If it's the first time the app is running on that phone, the app creates the txt file. Also note that the phone used for my setup has a SD card, so if yours only has an internal memory should be a bit different. Read about it here
After setting up the app on your phone, connect it to the 101 board running the pokéball code and start the “Toss mode”. Test it out by shaking the board around a bit. There are several Logs in the app code, under the TEST tag you should find help with eventual errors.
Now, go back to the Tasker app.
Go to the Profiles tab and create a new profile. Pick Event → File → “File Modified”. Click on the Magnifying glass icon to open a file navigator, find the txt file that was created by the Pokéball app, this should be in folder the file navigator started at. Pick the txt file and go back a step in Tasker. Now you should be prompted to pick a task, so pick the toss task you created earlier.
Next test so everything is ready by starting the toss mode again, and shake the board. You should get a small Toast, saying that Tasker has been granted certain permissions, and the “Pointer location” should show that a swipe has been made.
If everything works as intended you can turn off the “Pointer location” setting.
Now start Pokémon Go. Now catch 'em all with style!
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!