[Arduino Series 11] Arduino turns into a game controller to control a Mecanum car

Dec 13, 2020 15:00 · 1171 words · 6 minute read back right rx yet left

I took two videos about the Mecanum car before The first video belongs to the fun science series, which explains more about physics In the second video, I rewrote the programme to become analog control and is closer to the maker series Since many people are interested in both episodes, so I continue this theme Everyone knows that Carlos likes to improve products I think the control with Apps doesn’t feel good I believe that many people have PS4 game controllers at home I wonder if there is a way to control the Mecanum car with it But why does this episode belong to the Arduino series? I’ll tell you later Just a reminder, if everyone likes the channel of Carlos the OrganMan Please click subscribe in the lower right corner If you want to be notified of new videos as soon as possible Please click the bell You are also welcome everyone to add likes and comments I just said that the purpose of this episode is to abandon Apps and use gamepad instead. From the previous episode, everyone knows that the Mecanum car uses HC-05 to receive Bluetooth messages First of all, we must know how the PS4 controller can communicate with HC05 After crawling on the Internet, I found that it doesn’t work The only way is to plug in the USB Host Shield on the Arduino Then plug in the Bluetooth Dongle on the expansion board To receive PS4 Bluetooth messages Very difficult, because CNC expansion board has already plugged in my Arduino How can one more USB Host Shield be plugged in I can only continue to browse other methods Sure enough, the sky is endless I found this thing! It turned out to be a Game pad expansion board and it is used with Arduino Adopt the same Joystick as PS4 but it does not have the 12 buttons of PS4, it only has two Joysticks Plug it in the Arduino and it becomes a small Joystick You can also plug HC05 next to it As long as this HC05 is set as Master, I can perfectly control my Mecanum car! I asked the seller for programming examples But he only gave me a circuit diagram Fortunately, I understand Turns out this is the remote control of a robotic arm Therefore, there are many servo pins on the diagram I am only interested in programming the left joystick, right joystick and Bluetooth It is clearly indicated that the left stick uses A0, A1, and the right stick uses A3, A2 It can be simple, first plug in the expansion board and USB connection then use four variables to represent A0, A1, A3, A2 Declare four more variables to store the read data Serial.begin(9600) is the baud rate of Serial Monitor In the main program, use analogRead to read data Multiply the value by 2501000 Then use the constraint function to control the value between 0-250 To match the programming of my Mecanum car The following sentences show the four values ​​on the Serial Monitor Upload the program first, then open the Serial Monitor The four values ​​are the X and Y axes on the left, and the X and Y axes on the right On the right: up, down, left, right On the left: up, down, left, right Very successful, all four values ​​are between 0-250 Set an HC05 as Master, then plug it in According to the circuit diagram, use Softwareserial to set D12 and D13 as RX and TX According to the previous Mecanum car programming, the joystick on the left only uses the X axis So I disabled all sentences on the left Y axis Only send out the three data of the left X axis, and the right X, Y axis You can use a power bank to power the joystick Or use 9V battery Set a piece of HC05 as Slave and connect it to Arduino to test the receiving Remember not to connect TX and RX yet Because you need to use these two pin when uploading This test program is a simplified version of the Mecanum car Using the same variables After receiving the Bluetooth data, it will display three values ​​through the Serial Monitor Connect TX and RX after uploading the program Two HC05, one is Master and the other is Slave, they will be automatically paired as soon as the power is connected Move the joystick, the value will change, which proves that Bluetooth is working Now that it’s so successful, I don’t mind designing and printing the box to install the joystick This is the bottom of the box, and there are screw holes for installing Arduino After designing, export for printing I designed the cover at the same time. There should be two large holes on the cover The size of these two holes must be very accurate, so as not to jam the joysticks Also export and print If you measure with a caliper when you design There should not be too many errors when finished The screw position should be very accurate Put the cover on, you can see that it fits very well Temporarily plug in the Bluetooth, during the test we cannot put on the cover yet Front, back, left, right Turn left, turn right Front left, back right, front right, back left All wheels rotate normally, trying on the ground Simple forward movement is fine But the rotating and “8” paths cannot be done I think the movement range of this joystick is too small The response is worse than using Apps If you have watch the video of Mecanum car V2.0, you know I used Apps Inventor to draw the Joystick The joystick is a circle, moving in a large canvas The movements of the circle will be transmitted to the Arduino Then use the Sin( ) function to calculate the correct speed of each wheel The rotating and “8” paths require fine adjustment of the speed of each wheel So using a mobile phone to control a Mecanum car seems more suitable This DIY Joystick may only be suitable for controlling simple movements Those who follow Carlos channel may find that I am busy a lot It seems that I spent a lot of time designing and printing wheels last time, but I bought them at the end.

09:38 - I bought an expansion board this time and spent time programming and trying it out At the end it seems to have successfully controlled the Mecanum car But is not as good as Apps Inventor You might think I’m too obtimistic Actually, I think the entire process of researching, designing, programming, and making is worthwhile Because the Gamepad made may not be suitable for Mecanum car But it can be used in many ways So I decided to put in the Bluetooth module, add a switch and battery to complete it, and use it in other situation If you like my video, please like, subscribe and share!.