I created a library called gamepad-ble to use a Bluetooth Low-Energy (BLE) gamepad to control your Particle project.
Right now, the library works with the Xbox Wireless Controller (the 3 button model). It's the only BLE gamepad I found. All other wireless gamepads (Playstation, Nintendo, 8bitdo) all use Bluetooth classic which isn't supported by Particle devices.
The Xbox controller pairs with the Photon 2, but I'm getting an error when pairing with an Argon or Boron, so the library is for Photon 2 only for now.
For fun, here's the project I'm using this in. I turned my kids' PowerWheel into a remote controlled drift car driven by a 5' tall skeleton for Halloween. Spooky!
Very cool.
I imagine the Photon2 replaced switches for forward and reverse.
What's involved for the steering, stepper motor?
Thanks for sharing, especially the BLE code.
Just driving it around during the day made the neighborhood kids nervous so imagine during Halloween night after I add some red LEDs.
I used a big motor controller for the wheel motors so I can do soft start and drive slowly. For the steering, I 3D printed a gear sprocket that is connected by a chain to a REV Robotics motor that has an integrated encoder. There's a control loop in software to make the steering follow the joystick. The wheels return to the center when the joystick is released.
Every year my son does some sort of electronics trick or treat thing. Last year was a slide with lights and sound playing etc. he wanted to make a train track this year and have it come out around the corner. This is so much better/easier and way cooler! We might just replicate exactly your project instead.
Old and unused kids car.
Particle Photon 2:
Xbox controller:
And the fun begins! The controller boards arrive tomorrow. That’s when we can really start hacking. This should be a fun project for my 12 year old and I between now and Halloween.
@jvanier - I started the project briefly tonight with my son. Step 1 was having him load your XBOX controller test code. I then had him wire it up to a basic LED and to turn the LED on based on how much one of the left or right triggers were pressed. To see his excitement and joy on his face knowing he's controlling it all through an Xbox controller was very cool and this is just the LED much less a souped-up power wheels car.
I had a couple of quick questions regarding wiring to the wheel driver board 7A/160W. Can you elaborate a bit on how you wired that up?
I assume motor #1 was one wheel and motor #2 was the other wheel correct?
If so, then I assume the Wheel PWM output was wired/jumper between both ENA1 and ENA2 and same goes for the EN pins for each motor such that both motors always worked together?
What about the IN1 and IN2 pins on the 7A-160W? I see you have it called out as
Wheels reverse: S4
From what I can tell from the spec sheet/tutorial on the 7A-160W motor to get it to go forward using PWM IN1 = 1 and IN0 = 0 and then for reverse using PWM IN1=0 and IN2 = 1. From what I can tell you used only 1 digital output for the wheels but the controller is expecting 2 for the logic controller. Was curios how that was done. I could likely wire up another digital output and update the code but was hoping to first replicate your example.
Unit testing is complete… we are now able to control the wheels and the steering wheel independently via the Xbox controller. Next few days we will likely tie it altogether, solder the wires onto a protoboard and get this thing driving fully remote. Plenty of time before Halloween to add LEDs and sound of some sort.
Turning the wheels took a bit of 3D modeling and printing. What was nice is the Rev Robotics site includes all of their components including gears with full step files to download. It includes a wide range of gear ratios and the motors itself. So spending a little time in Fusion 360 to fabricate a bracket and modify the gear to fit over the steering wheel shaft we should be good to go. I printed it in ASA with 85% infill so I think it'll be strong enough.
Only issue I’m having is the Photon2 itself seemingly locks up for no apparent reason. When this happens the status LED locks (stops breathing, doesn’t blink, just locks in on some random brightness) and the Xbox controller drops. Seems to happen after 2-5 minutes or so. I thought it was the “boot” pin issue on the P2 but I am guessing it’s something else.
I didn’t didn’t try and isolate it yet but will eventually have to figure out what that issue is. Not sure if it's something back feeding a GPIO pin causing it or the firmware itself. I'll need to investigate further.
@jvanier - I noticed you have some ferrite chokes on the power wires to the wheel motors. Was this included or something you added in response to encountering some issues?
Hey Jeff, it could be that you are hitting an issue with BLE where BLE APIs cannot be called from BLE handlers or a sort of logging issue I'm experiencing as well.
Now, did you add any calls to BLE, example BLE.peerConnected() from loop, maybe for serial logging reasons?
If so, try removing it.
Thanks for the guidance @gusgonnet. I did try turning serial logging off but that didn't seem to do anything. To be honest, this is my first time playing with BLE so I'm just using the library and source code as is with minimal modifications. Once it's operational, I may dive in and take a closure look. In my quick peek, the library does not use BLE.peerConnected() in loop.
Alright... I think I figured it out. I was wiring it up per this picture. In particular it indicated "Direction Power" was 3V3.
However, per the motor driver speed controller description... the 5V pin is actually to supply a host controller at 250mA. Therefore, the board itself produces it's own 5V power.
So I was actually back feeding 5V on the 3V3 side of the P2. Obviously this is not ideal and is what caused the P2 from locking up. Thankfully I didn't smoke anything.
I was hoping I could then use this to power the Photon2 but turns out 250mA isn't enough juice for it and it keeps browning out. So for now, I'm still powering it via it's own LiPo battery. Maybe it can power the wheel driver board instead. That'll be tomorrow's project.
Standard driving mode is done and seems to be working well:
Now we get to move on to painting this, maybe some LED lights, maybe an LED headlight/strobe, likely a horn or music of some sort. Secure the skeleton in place, etc.
We also tested mounting a go pro camera on the front and use “Live View” to drive the car and record video from the cars perspective. Should make for some fun videos during trick or treating day.