Erratic mouse movement while Photon is plugged in


#1

Hi,

I was wondering if anyone could have a look at this problem. It is not a question about using an MUP9250 directly, but the weirdest thing I ever found whilst I went through the learning curve on my lonesome.

For info, I using a window 7 Ultimate machine. A photon, connected to an MPU9250 clone via i2c to experiment with motion detection.

Basically I’ve written a load of code which initially sets up the MPU9250 for Accel and Gyro, and accesses in Mag (AK8963).

There are tonne of register reads for debugging. Finally there are 3 subroutines which individually in turn read the accelerommeter, gyro, and mag data in turn, do some math and print the results. The delay before the subroutines call controls the speed of the output to a serial output.

As I was doing the learing, I found that for some reason when I was doing the read of the Mag data, without performing a complete register read, my computer would go absolutely mental. The mouse would bounce around all over the place I had no control, unless I unplugged the photon, and used Alt-Control-Del, then waited untill the mouse stopped jumping around and selected cancel to get back to the desk top. I could reflash the photon by using a USB psu, so the photon didn’t crash, or freeze up…itself. The speed of the demonic mouse action was related to the speed of the main loop.

After about 4 days of bashing my head against the ‘try-this, then-that’ approch of de-bugging I discovered that a tleast 2 out of three serial.print statements were to blame. If I '//'ed them out the code would run fine, if I leave them in, all hell broke loose. The code has loads of print statements, I’ve added others in, taken others away, but these three lines are causing the problem. And they have taken DAYS to track down as the casue. I thought it would be due to a variable type mis match or maths error, but trust me all I have to do is // these Serial.println() statements and everything is as expected. And it is a repeatable problem…

Has anyone experianced this before.

As it some 700 lines of code I will spare you just pasting it in, and I can not remember how to insert a code block in to this message system. None of the icons at the top of this message window look like they are the right ones. If your interested and can help then I will post the code upon request. I tried to uplad a txt file but that only allows pictures…

Thanks for thoughts.

Liam


#2

Try adding a 5-second delay before calling Serial.Begin in Setup() and see if that stops the Mouse issue on the PC.


#3

Your PC thinks the Photon is a Mouse. There are several threads.
Here’s one https://community.particle.io/t/issues-using-serial-debugging-mouse-moving/1200/18


#4

There’s this:

That one works for code (though it’s not formatted as nicely as the first option).

And a more recent, and probably best method, is sharing the application from the Web IDE so we can import it directly, including any libraries you’ve used. That way, we don’t have to guess.


As to the actual problem, like @Rftop mentioned, several threads already discuss the issue you’ve described. Have a look/search.


#5

Hi Moors,

Thanks for the tip on inserting code blocks.

I’ll take a look at the serial mouse issues. Seeing as it appears to be an issue it seems pointless uploading the code unless thats not the fix. No point taking up screen space for the hell of it.

Thanks

Liam


#6

The main thing to do about the mouse issue is to not hammer the serial output to the extreme :wink:
Limit your use of Serial.xxx() calls a bit (e.g. via delays) and see


#7

Hello Sruff,

I did notice that there was a relation ship between speed of the Serial calls and how mental my mouse went. But it meant I had to introduce delays of excess of 1200ms. And the really weired bit is was not happening unless three specific serial print calls were made, at about line 640-650. All I need to do was comment out there specific lines:-

Serial.println("X Axis Mag: ");
Serial.println(X_Mag_f, 4);
Serial.println("Y Axis Mag: ");
Serial.println(Y_Mag_f, 4);
Serial.print("Z Axis Mag: ");
Serial.println(Z_Mag_f, 4);

Its was lines 1, 3 and 5 that were casuing the problem, the print of the float varibles were fine. And there must have been 30 or so lines to be output to check the performance of the MPU9250. There were print statements before and after. The offending lines were printing plain text only. I’d be less perplexed if it was the varibles causing the issue. I’ve been messing around with the core/photon/electron now for years and never experianced this to my (now less reliable) memory.

I had to block out sections of code untill I could narrow it down. And It think it also transfered to my laptop.

Anyway I modified the registery and reinstated the offending lines and can loop though at 300ms fine.

Will have to check the laptop as well.

BTW Scruff and Moors… Just wanted to say thank you for you help and assistance not just in this instance, but in the past as well… You chaps have been much help to me several times in the past and to many others in this community… Just thought its worth saying thanks and your efforts noticed…

Thanks

Liam


#8

I just now remembered that there was some thread getting a bit deeper into it and outlining a way to prevent Windows from confusing the CDC for a HID mouse.
IIRC it’s some stupid switch in one of the related drivers but I can’t remember where I read that.


Found one thread
Issues using serial debugging (Mouse moving)


#9

Could it be because the beginning of the serial print statement there are X, Y, or Z coordinates labels and the driver is interpreting them as mouse positions? I could be way off but change the X, Y, and Z with something different and see if that changes anything.


#10

Hi RWB,

Interesting thoughts as to why these statememnts were giving trouble and not others.

I have applied the registery fix for now, becasue I don’t think it is unreasonable to want to start a statement with X, Y, or Z.

If I get a chance I will reverse the fix and test the hypophosis.

Liam


#11

Actually no, the serial mouse protocol does not care to issue human readable commands :wink:
So X,Y,Z would just be redundant bytes to be transfered.

If you want to learn about the (deprecated) serial mouse protocol you can read here
http://paulbourke.net/dataformats/serialmouse/