Automate B-Spec with an Arudino Development Board

  • Thread starter deba94
  • 19 comments
  • 6,393 views
640
Canada
Ontario
Abread
After seeing the interest people put into the automated A-Spec grinding, I thought I'd share my B-Spec grinding method done with the Arduino Uno (as a matter of fact, this works for A-Spec as well).

NOTE: This will only work for the Arduino Uno (tested) and possibly the Arduino Mega 2560. The Uno and (if I recall correctly, the Mega 2560) differ(s) from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega8U2 programmed as a USB-to-serial converter. This allows the board to be seen as a HID by flashing the Atmega8U2 with a custom hex file.

What you'll need:

Hardware:
Arduino Uno (or Mega 2560) x1
Usb cable x1
Wire about an inch long and stripped on both ends x2

Software:
Arduino IDE
AND
Flip Programmer (windows only)
OR
MacPorts & dfu-programmer ("sudo port install dfu-programmer") (mac only)
OR
dfu-programmer (grab it from your distro's repos) (linux only)
AND
My big-bag-o-fun

PS3:
Copy of GT5
Red Bull x2010 (any version)

Start off by uploading this sketch to your Arduino:
Code:
/*

Keyboard sketch
by Andrew McDaniel 
Tweaked by deba94

Copyright (c) 2010 Andrew McDaniel
Copyright (c) 2011 deba94

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/*
When we send data to the keyboard driver, it has to be
scancodes, not ascii characters. Refer to the AVR keyboard
source code to obtain the scancodes. 
*/

// meaningful constants for GT5
byte SC_SPACE = 0x2c;
byte SC_ENTER = 0x28;
byte SC_ESCAPE = 0x29;
byte SC_ESC = 0x29;
byte SC_RIGHT_ARROW = 0xef;
byte SC_LEFT_ARROW = 0x50;
byte SC_DOWN_ARROW = 0x51;
byte SC_UP_ARROW = 0x52;

void setup()
{
  delay(6000); //  Give the keyboard driver time to boot
  Serial.begin(9600);
}

void loop()
{
  sendSCByte(SC_ENTER); //accepts on screens that need accepting
  sendSCByte(SC_DOWN_ARROW); //moves down once to get past the driver progression screen

}

void sendSCByte(byte byteToSend)
{
  // This function sends single scancode bytes.
  Serial.print(byteToSend);
  delay(25);
}
Now, you'll need to throw your UNO into DFU mode. To do this, (while your Arduino is plugged into USB) use one of the short wires to bridge two points on the back of the board near the map of Italy (just below). With that in place (hold it down with tape if you'd like) use the other wire to bridge the the two points seen here:
Uno-front-DFU-reset.png.resized.jpeg


If done correctly, your UNO should now be in DFU mode. (Confirm this by checking the list of serial ports. The serial port for your board should no longer show up.)

Now, flash the 8u2!

Windows: Open flip, load the hex, select at90usb82 and flash away.
OS X/Linux:
Code:
cd <PATH>/UNOPS3/
sudo dfu-programmer at90usb82 erase
sudo dfu-programmer at90usb82 flash keyboard.hex
sudo dfu-programmer at90usb82 reset
Now unplug the board and plug it back in. Careful though! It'll start typing exactly 6 seconds after the board receives power. Open notepad/gedit/emacs or something.

Go hook it up to the ps3! Fire up B-Spec and go to either Extreme Series > Dream car championship > circuit de la sarthe (best for farming XP) or Extreme Series > American Championship > Laguna Seca (best for farming money).

The UNO will alternate between sending the "return" key and the "down" key, so you can simply walk away and come back whenever you want to collect your winnings.

Enjoy.

Credits:
to A.McD and ant.b from the arduino forums for the base code.
to Dean Camera for LUFA-lib.

Note (Vista/7 64-bit Users Only): Windows nags about unsigned drivers, and that's what Atmel provides with their Flip programmer.
To circumvent this:
Right click "Computer" and select manage. Select device manager. While the UNO is in DFU mode, right click "UNO DFU" and select update driver. Select "Location on my hard drive" (not exactly sure of all the specific names as I do not use windows). Now download this and extract it somewhere. Type the path to the files into the path box for the driver. Follow the rest of the steps normally and all should be well.

Videos:
http://dl.dropbox.com/u/1016943/1300560860.mov
http://dl.dropbox.com/u/1016943/1300575149.mov
 
Last edited:
The Arduino development board is an inexpensive way to do just about anything you could imagine with software/hardware.

A good explanation can be found here.

If you're into electronics, or computer programming, developing with an arduino is a fun way to waste time ;)
 
I've done the same thing but with a Sparkfun UBW http://www.sparkfun.com/products/762 purely for the A-Spec grinding as I didn't have a spare keyboard lying about and figured it was easier just to setup a virtual USB HID Keyboard that would spam enter with my spare UBW.

I've attached my hex and code for the UBW (it is a modified HID Keyboard demo from Microchip) just flash it to your UBW then open notepad and connect it to your PC and the cursor should fly down the screen. Once you are ready setup your rubber banded controller in the dreamcar event with the X2010 and plug the UBW in usb slot 1 or 2 and the races will auto restart at the end of each event.

Enjoy! :dopey:
 

Attachments

  • USB Device - HID - Keyboard- C18 - UBW.rar
    5.9 KB · Views: 38
Eq
I've done the same thing but with a Sparkfun UBW http://www.sparkfun.com/products/762 purely for the A-Spec grinding as I didn't have a spare keyboard lying about and figured it was easier just to setup a virtual USB HID Keyboard that would spam enter with my spare UBW.

I've attached my hex and code for the UBW (it is a modified HID Keyboard demo from Microchip) just flash it to your UBW then open notepad and connect it to your PC and the cursor should fly down the screen. Once you are ready setup your rubber banded controller in the dreamcar event with the X2010 and plug the UBW in usb slot 1 or 2 and the races will auto restart at the end of each event.

Enjoy! :dopey:

That hex works for me
Thanks Eq
Could you post a hex with the enter down sequence for B spec grinding?
 
Hi Cvader,

I'll tale a look at deba94's code and see if I can get it to work for the UBW. If it works i'll post it up here as that would be a great for some big money b-spec events not to mention the coaching of the bob. At present I use the device as is for b-spec which is great for coaching but can't "re-start" the race :(

Will let you know how I go :)

Eq

That hex works for me
Thanks Eq
Could you post a hex with the enter down sequence for B spec grinding?
 
Hey Cvader,

I've updated the code to include the down arrow required for B-SPEC grinding. Also a big thanks to deba94 that down arrow was exactly what I needed for getting around the damn driver selection screen.

Also, this time i've included the code as it was missing from my last upload.

As per my original message this is for a Sparkfun UBW but should work on any UBW device.

Enjoy your A-SPEC and B-SPEC grinding everyone :-)
 

Attachments

  • HID_UBW_GT5_ASPEC_BSPEC-EQ.rar
    49.1 KB · Views: 27
pretty cool. obviously it's significantly more expensive, but do you think one could get the arudino bluetooth, then somehow set it up so you just leave the arudino in a box or something near the ps3 and it just works? my wife simply won't let me have all kinds of stuff (particularly bare boards) plugged into the ps3 lol.
 
That's all pretty neat stuff. If it wasn't for automated remote racing, I'm sure I'd get into this.
 
Works like a charm!
Thanks again Eq

I setup the indy b-spec event this morning and left it running for my work day to see which nets more CR over the 8hrs. I know that the A-SPEC event will net me around 6 million CR for 8hrs so it will be interesting to see what B-SPEC comes up with. Oh, for that period I leveled up from 30 to 32 in A-SPEC.

I'm also going to try to mod the code a little to see if I can get it to automate a B-SPEC championship event so you don't have to manually select the next race now that would be cool.. :-)
 
Nice work Eq :)

Automating championships seems interesting, there surely would be a much higher payout. If I had to guess though, I'd think a timer would be required to know when to move right and select the next race.

I'll take a look as well soon ;)
 
After taking a look, Enter + Down works fine up until the championship/cup is over.
After the final race, you're left with a screen that defaults on the "watch replay button" which is two presses of "Right" away from exit -- or one press of circle. After that, Enter+Down works again.

Now to find the perfect pattern...
 
After taking a look, Enter + Down works fine up until the championship/cup is over.
After the final race, you're left with a screen that defaults on the "watch replay button" which is two presses of "Right" away from exit -- or one press of circle. After that, Enter+Down works again.

Now to find the perfect pattern...

Interesting! I'm still at work so haven't had a chance to look.. sounds like a programming plan for this evening while the PS3 is grinding me more free credits :)
 
Hey Deba94,

I just found this thread on the Arduino which I think will give you the information you need to setup the "complete" automation with oil changes, etc..

http://forums.hackaday.com/viewtopic.php?f=3&t=150

Let me know if this helps, i'm going to try and adapt the delay codes to the UBW and see how I go :-)

After seeing the interest people put into the automated A-Spec grinding, I thought I'd share my B-Spec grinding method done with the Arduino Uno (as a matter of fact, this works for A-Spec as well)....... TRUNCATED
 
I've got the Uno programmed so that in notepad, it flys down the screen. When I plug it into my PS3, I can't figure out how to assign it as the active controller. Any suggestions?
 
Well, while programming micro-controllers is fun, this is another approach:

1. Connect a keyboard or a numpad to the PS3
2. Start a B-spec race, give first instruction to slow down EDIT: also don't forget to set the pit strategy
3. Put PS3 controller or something else that is heavy enough on the <Return> key

I've been doing the lvl26 endurance race for about 2 hours now (currently on lap 101) and my bob has been in the lead ever since the start.

Enjoy! :)

PS. I'm just saying this in case you guys missed the obvious (i've seen ppl building stuff in wood or lego just to repeatedly press the X button).
 
Last edited:
Well, while programming micro-controllers is fun, this is another approach:

1. Connect a keyboard or a numpad to the PS3
2. Start a B-spec race, give first instruction to slow down
3. Put PS3 controller or something else that is heavy enough on the <Return> key

I've been doing the lvl26 endurance race for about 2 hours now (currently on lap 101) and my bob has been in the lead ever since the start.

Enjoy! :)

PS. I'm just saying this in cased you guys missed the obvious (i've seen ppl building stuff in wood or lego just to repeatedly press the X button).

But you can't start a new race with just the <Return> key, or?
 
Back