0

I am working on a remote controlled vehicle based project. I am using a PS3 bluetooth controller for this purpose & am facing the problem described below. Any help would be appreciated.

Basically, the motors are connected to the MEGA which is connected to a USB Host Shield. A bluetooth dongle is connected to the shield. This dongle & shield enable MEGA to communicate with PS3 wirelessly. I am using the USB Host 2.0 library available for Arduino on GitHub.

My code to take input from the PS3 is as follows:

USB.Task();
if ( PS3.PS3Connected || PS3.PS3NavigationConnected )
{
    if ( PS3.getAnalogButton(UP) )
        Serial.println("UP");
    if ( PS3.getAnalogButton(DOWN) )
        Serial.println("DOWN");
    if ( PS3.getAnalogButton(LEFT) )
        Serial.println("LEFT");
    if ( PS3.getAnalogButton(RIGHT) )
        Serial.println("RIGHT");
}

This is the code inside loop(). If anyone is wondering why getAnalogButton is used instead of getButtonClick, the reason is to enable the vehicle to move ahead as long as UP is pressed & so on. This was an improvisation on our part.

As can be seen, the function prints UP, DOWN, LEFT or RIGHT as long as they are pressed continuously. The problem is that it works perfect for a while. But then, it enters an infinite loop & stops taking input from the PS3.

Basically, the input is like

UP
UP
UP
UP
UP
UP
UP
.....
LEFT
LEFT
LEFT
// At this point it hangs without printing any further inputs.

Can someone help tackle this problem? It is essential for us to move the vehicle as long as the buttons are pressed & stop when button is released. Unfortunately, there is no feature to detect PRESSED or RELEASED state for PS3. Any help would mean a lot.

Also, we initially thought that the hang was because of overflowing the serial input. So, we removed all Serial messages & tested with LEDs. But, the same problem is still faced.

  • I think the most precise answer you can get is "Something is blocking your loop". If you want more help, you'll have to share more information. For instance, what else is there in your program? Which library are you using? Can you understand what is the function blocking everything (I mean, does the USB.task hang or the checks are failing?)? Moreover the title and the text are different: are you actually experiencing lag or it hangs? – frarugi87 Dec 13 '17 at 11:36
  • Depending on how you are reading the serial data, there might be a read buffer that's getting full and not getting purged. I had this when using SoftwareSerial on a recent project. I don't have the code handy, and my Google-fu is failing me on finding the same solution, but I had to "redeclare" a SoftwareSerial buffer variable on each loop. I'll try to remember to look this up after work tonight, because I know what I said isn't clear. – computercarguy Dec 13 '17 at 15:28
  • What other details would it take to answer the question??? @frarugi87 Let me know. I'll provide those straight away. – Samagra Singh Tomar Dec 14 '17 at 0:44
  • The same goes for you too @computercarguy – Samagra Singh Tomar Dec 14 '17 at 0:44
  • You need to figure out where it is hanging, if it is even doing so - a fairly likely possibility could be the BT connection dropping at which point your posted code would seemingly do nothing. – Chris Stratton Dec 14 '17 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.