Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:44 05 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PS2 mouse to HobbyTronics emulator

     Page 3 of 5    
Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 08:39pm 18 Dec 2020
Copy link to clipboard 
Print this post

Dual mode can be a problem. The pull-ups are worth a try but I think those extra 2 buttons are the problem.
I think I have details on the Microsoft extensions so might be able to cater for them. (by ignoring the extra buttons)

RE the resolution change. I didn't allow for changing that except during a full reset.

SUB initmouse res
 'I2C2 OPEN 100,1000
 I2C2 WRITE 41,0,3,20,INT(MM.HRES \ 256),INT(MM.HRES MOD 256)
 I2C2 WRITE 41,0,3,20,INT(MM.HRES \ 256),INT(MM.HRES MOD 256)
 I2C2 WRITE 41,0,3,22,INT(MM.VRES \ 256),INT(MM.VRES MOD 256)
 I2C2 WRITE 41,0,3,24,INT(MM.HRES \ 512),INT((MM.HRES\2) MOD 256)
 I2C2 WRITE 41,0,3,26,INT(MM.VRES \ 512),INT((MM.VRES\2) MOD 256)
 I2C2 WRITE 41,0,2,28,res
END SUB


should do the job for now

Jim
Edited 2020-12-19 06:42 by TassyJim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 09:48pm 18 Dec 2020
Copy link to clipboard 
Print this post

Jim, I did a hard deep dive in my storage and borrowed a few other PS/2 mice and without exception, all of the 15 optical mice I tried will not work and half of them never even light up. I have my reset button installed and that does not help.  The activity light on the NANO just flashes once and then stops on all of the opticals.  I only have those two ball mice and they work.   7 MS dual-type mice do not work. My favorite Keytronics optical does not work. Three other generic optical mice(all different off brands)do not work and in every case, they show the on flash on the activity light.  During your testing did you have any optical mice and am I just having bad luck with the opticals I can get my hands on. I got 2 ebay opticals today and they of course do not work. (the mice that do work are ancient so I wanted a newer one)  I have tested all of the mice on a Windows PC and they all work. So, at least I have one ball mouse that has a wheel that works. I am weird about having only one device to depend on.  I always keep spares of important peripherals.   Just hope this info is of some use.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 12:47am 19 Dec 2020
Copy link to clipboard 
Print this post

Are you sure that you have 5V going to the mice?

My optical mice work OK.
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 05:32am 19 Dec 2020
Copy link to clipboard 
Print this post

  TassyJim said  Are you sure that you have 5V going to the mice?

My optical mice work OK.
I checked all the contacts and I get continuity to them all.  I double-check the pinout and I have the 5v going to common pin of 5V, but if that was not connected could the ball mice ever work?  I do get the sensor LED on half of the optical mice so they are getting 5V. The behavior from the NANO for a functioning mouse is a rapid flashing light is that correct? I am not sure why this is happening. I wonder How loose of a standard the PS/2 Mouse protocol is.  Thanks for indulging me on this.  I am just ecstatic that I got it to work at all.  Have a great one.
Edited 2020-12-19 16:16 by mclout999
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 06:41am 19 Dec 2020
Copy link to clipboard 
Print this post

Connect the Arduino IDE and open the serial monitor.(Tools menu)
Set the baud rate to 19200

With the mouse stationary and the CMM2 not running a program,one LED will be rapidly flashing.
That will flash at the serial rate but there will be nothing on the monitor if the mouse is stationary.
Move the mouse and the other LED will flash indicating serial data being sent and data should appear on the serial monitor.

With the mouse test program running, there will be no serial data and the activity LED flashes much faster. So fast that it appears ON.
The serial data LED will stay off.

Once you have the serial monitor mastered, I can do some debugging.

The PS/2 code is not my work but it does successfully interrogate my wheel mouse and recognize the wheel data so should work.

Jim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 07:16am 19 Dec 2020
Copy link to clipboard 
Print this post

  Quote  Connect the Arduino IDE and open the serial monitor.(Tools menu)
Set the baud rate to 19200
Do you mean over the USB connection.  I do not have a TTL to USB device yet.  I will also have to disconnect the 5V from the CMM2 correct?  what should I be looking for on the output of the none working mice?  I do not know id I am equipped to figure this out.  I will try.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 08:47am 19 Dec 2020
Copy link to clipboard 
Print this post

Ok, I figured it out and disconnected the CMM2 pin 2 from Nano and connected via USB.  On the ball mice, I get very clean and readable stings on the serial monitor only if no program is running.  When I start your demo the output to the monitor drops till I exit your test.  Strangely my new optical mouse will sometimes work if the NANO is powered by the PC USB cable and not the CMM2.  I switched it back to pin 2 on CMM2 and it never works. It does seem to be a power issue. ON that mouse I randomly get sensor LED or not but it never works either way on CMM2 Power.  I am thinking of setting up a 5V external supply and bypassing the CMM2 altogether and see how that works.  I just disconnect the 5V from the CMM2 right but do I need to remove the groud as well.  I will await your input on that because I think messing about with an external power supply could be trouble if I am not sure.  I also swapped out the NANO for the other one I got and get the same issues.  I just thought of something.  Could it be that motherboard header I used to make my device.  It is a 2 port stacked one for a PC MB.  I check to see that there were are no additional components on the PCB I cut off of the MB. but do they ever use resistors inside the stacked header?  I am going to check that there is no resistance on each pin to the pigtails I soldered on to them.

Edit: I tested the resistance on each pin and they all have a 3 to 5 ohm. I'm stumped and it is 3am so I am done for the day.
Edited 2020-12-19 19:18 by mclout999
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 08:20pm 19 Dec 2020
Copy link to clipboard 
Print this post

  Quote  Ok, I figured it out and disconnected the CMM2 pin 2 from Nano and connected via USB.  On the ball mice, I get very clean and readable stings on the serial monitor only if no program is running.  When I start your demo the output to the monitor drops till I exit your test.

That is correct. Serial only happens when the I2C is NOT polling the device.
It should also only happen with a change or movement.


  Quote  Strangely my new optical mouse will sometimes work if the NANO is powered by the PC USB cable and not the CMM2.  I switched it back to pin 2 on CMM2 and it never works. It does seem to be a power issue.


I think you are right. It is a power issue.
The mice need a good 5V supply.

  Quote  Could it be that motherboard header I used to make my device.  It is a 2 port stacked one for a PC MB.  I check to see that there were are no additional components on the PCB I cut off of the MB.

If you have some motherboard attached to the header, you might have some of the lines shorted. The IDE pins that are used for ground on the PC will be different to the ones on the CMM2. That could result in heavy load on the CMM2 side and lower the voltages a bit.
A big no-no is using an 80 wire IDE cable. That will certainly short out a lot of the lines.

If you power the mouse separately (which is what we are doing by having the Arduino USB cable attached, you do need to keep the ground connected to the CMM2 as well as the two I2C lines.
As there are only 3 or 4 wires to connect, I would use a few DuPont jumpers rather than the IDE header.

  Quote  Edit: I tested the resistance on each pin and they all have a 3 to 5 ohm.
This is likely to be the resistance of your meter leads. Measuring low resistance can get tricky.

We are making progress. Light at the end of the tunnel even.

Jim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 12:16am 20 Dec 2020
Copy link to clipboard 
Print this post

I am using an IDE cable cut off and the relevant pins pulled out with pigtails soldered on to insert into the breadboard I am using.  So, I should discard the IDE cable altogether? The only PS/2 port I have is trimmed from an MB like I said and I guessed from the meter readings that there were no resistors in line like you said the Ohm readings are consistent with that and that is why I was giving up for the night.  My concern is that it would be very finicky to have just a few Dupont connectors on there.  I like having the full 80 pin header to key and stabilize the connections.  could I just trim off all the other wires!  Right now I just have them folded back and am using them as a strain relief for my Franking mouse box.(see my Pic from before)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 01:45am 20 Dec 2020
Copy link to clipboard 
Print this post

So the motherboard header is the PS/2 one, not the IDE as I thought.
That should be OK.

Using an IDE cable is good provided it is 40way and not the newer 80 way cable.
The 80 way cable still goes to a 40 way connector but does strange things internally.

For now I would ignore the mice that are USB/PS2 combos.

Jim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 03:18am 20 Dec 2020
Copy link to clipboard 
Print this post

  Quote  Using an IDE cable is good provided it is 40way and not the newer 80 way cable.
The 80 way cable still goes to a 40 way connector but does strange things internally.
The IDE cable I used I think is 40 way. I do not think I have any 80 conductors cables and I have HUNDREDS of the 40.(custom PC builder and IT consultant for 30+ years)

I had no other PS/2 ports so I Just trimmed around a double stack header from a DOA motherboard.  I Just am not going to be getting anything from china right now.  They are all starting to just refund me for all the parts that are never likely to get here. I can't find any local parts supplier and If I go with "Reputable" vendors like mouser and the like I will not be affording it.

What do you think the power issue is with my setup then, because I am not seeing it.  And yes the dual function mice are not an important issue.  To see that new optical mouse work but only while powered by my PC is frustrating.  Oh well, I have the one fully functional ball mouse and that should be enough for now.  Thank you once again for all your help.
Edited 2020-12-20 13:19 by mclout999
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 04:28am 21 Dec 2020
Copy link to clipboard 
Print this post

  Quote  What do you think the power issue is with my setup then, because I am not seeing it. To see that new optical mouse work but only while powered by my PC is frustrating.

Can you measure the voltage on the %v pins and compare the two sources.

The attached code has a few changes in the way it initialises the mouse.
The mouse is only initialised during bootup so if you switch from mouse to joystick, you will need to press reset.
I am still learning what works in the background and what doesn't with the Arduino

It 'might' make a difference.

The code to change mouse speed is now working with the one line:
I2C2 WRITE 41,1,2,28,speed


If you have the Arduino serial monitor open when you load the firmware or do a reset on the nano. you will see
mouseOK 40,399

The numbers will vary a bit and I am interested in what you get with the various mice.
The first number is how long it takes for the mouse to do a reset and the second number is the time to initialise the mouse.

HT_mouse1.zip

Jim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 09:35am 21 Dec 2020
Copy link to clipboard 
Print this post

Thanks, Jim.  I will be having surgery today(diagnostic issue) so I will get back to this in a day or so, I hope.  I really appreciate the help. I will do all of the diagnostic and will test each mouse that did not work and will compile a list of outcomes.  Just so I do not screw up on the V test.  I measure ground and 5V on NANO pins with power applied by both methods right?
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 10:13am 21 Dec 2020
Copy link to clipboard 
Print this post

I am waiting on my medical transport so I tested the voltage on NANO pins and got 4.90V on CMM2 power and only 4.6V on USB but very odd to me the CMM2 powered up on USB power with its power switch turned off.(I did pull the 5V pin from CMM2 when using the USB)  That does not seem right, or does it?! I flashed the new NANO software and made sure it still works but an optical one still does not.  I will get back to this. Thanks.
Edited 2020-12-21 22:54 by mclout999
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4248
Posted: 07:16pm 21 Dec 2020
Copy link to clipboard 
Print this post

Well my first attempt was an unmitigated failure.

Initially ALL the LEDs on the Nano were flashing madly, so I poked it a few times without as far as I can tell changing any of the wiring, then the LEDs stopped flashing and the optical mouse light was red, but the mouse wasn't working, more poking ensued, the mouse light went out and the Nano power light dimmed. I now have a nano which won't power properly from USB (dim power light) but if powered externally through its Vin can still be programmed by USB - I'm assuming it's fritzed and not repairable by such as me.

It's possible that this can be put down to a crappy Chinese Nano, but I wouldn't exclude user incompetence

Hopefully haven't blown anything on the CMM2 during this escapade.

Am I correct that in normal operation:

- the CMM2 (pin 2) is providing Vcc to the PS/2 port
- the Nano needs powering by USB or an external 5V supply (and not the CMM2)

I'm still not sure I understand the jumper on pin 27 of the Nano, when you close that presumably you should power-off the CMM2 so as not to tie their power supplies? Shouldn't it be a toggle instead to control whether the PS/2 gets its power from Nano pin 27 or CMM2 pin 2 ?

Merry Christmas,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 09:38pm 21 Dec 2020
Copy link to clipboard 
Print this post

In normal use , the nano is supplied through it's 5V pin 27 from the CMM2.
You could also power it through it's Vin pin with a ~9V source.
If you have the USB programming cable attached, you will be powering the nano from the USB supply.
If you do power it from anything other than the CMM2, the jumper on pin 27 should be open to prevent feeding the CMM2 from the external source.

So, while I am playing with the code, I leave the pin27 jumper off and keep the nano powered from the PC.

Once I have stopped playing, I will remove the USB cable and reconnect the jumper to power the nano from the CMM2.

If you are playing with the CMM2 shutdown and relying on the serial monitor only, you will need to power the PS/2 from the nano instead of the CMM2.
If that is likely, the jumper would be better placed in the line going to pin 2 of the CMM2 instead of pin 27 on the nano.
Either place would do the job of keeping the supplies isolated.

A word about the latest code.
It will sometimes fail to detect the mouse on startup.
I know the reason and will amend the code shortly.
The CMM2 firmware needs the mouse close to stationary for a number of (5) reads and I only keep it still for one read. Easy fixed.

  Quote  Initially ALL the LEDs on the Nano were flashing madly,

Standard nano startup.

Jim
VK7JH
MMedit
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4248
Posted: 11:14pm 21 Dec 2020
Copy link to clipboard 
Print this post

Thanks for the additional information Jim - I'm still not sure what I did wrong. Will probably start again tomorrow with just a Nano and the mouse and see what I can learn through the serial monitor.

  TassyJim said  
  thwill said  Initially ALL the LEDs on the Nano were flashing madly,

Standard nano startup.


Really? that isn't what I've observed in my extensive (just kidding) 2 evenings of play. I'm talking about the TX and RX LEDs as well as the Power and L.

Best wishes,

Tom
Edited 2020-12-22 10:22 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6213
Posted: 01:11am 22 Dec 2020
Copy link to clipboard 
Print this post

This update holds the mouse steady for a while during configuration so MMBasic doesn't get annoyed.

HT_mouse1.zip

I still observe the occasional time when the I2C doesn't send an ACK during the setup dialog causing the "Mouse not connected" error.

I am not sure why so will dig deeper.

During setup, MMBasic sends 4 pairs of data followed by a single byte
Most of the time, all the data is received OK but occasionally, the second or 3rd pair don't get the required ACK so MMBasic aborts.

A second run of the MMBasic program will run OK and once running there are no issues.


  Quote   I'm talking about the TX and RX LEDs as well as the Power and L.

You're right, the power LED shouldn't be dancing. The other LEDs get excited during programming and in use depending on the current state.

It is possible that the internal pullups on the PS/2 clk and data lines are not strong enough for some mice so external 10k between the lines and 5V are worth a try.
I only have 3 different types of PS/2 mouse and they all work without the external pullups so it's difficult to investigate further.

Jim
VK7JH
MMedit
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 482
Posted: 11:27pm 22 Dec 2020
Copy link to clipboard 
Print this post

  Quote  This update holds the mouse steady for a while during configuration so MMBasic doesn't get annoyed.

HT_mouse1.zip


Jim!!!!! This version works with some of my optical mice!!!!!!!!!  Thanks for your diligence. It works every time and is consistent. Two do not work but that is not bad.   Just for info, the MS duel mice do not. This is very nice news.  Thanks.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4248
Posted: 11:30pm 22 Dec 2020
Copy link to clipboard 
Print this post

  TassyJim said  
  Quote   I'm talking about the TX and RX LEDs as well as the Power and L.

You're right, the power LED shouldn't be dancing. The other LEDs get excited during programming and in use depending on the current state.


OK, I understand now, you confused me by saying "Standard nano startup", which I interpreted to mean something that happens anytime the nano gets power. Whereas I now believe you meant standard when the nano is being programmed. I hadn't noticed this when using the Blink program because it happens so quickly and with your mouse program I only successfully loaded it once before my original Nano gave up on me / I broke the Nano - looks like it was the SMD shottky diode because it started powering properly again after I removed that and bodged a through hole 1N4148 in its place.

  Quote  It is possible that the internal pullups on the PS/2 clk and data lines are not strong enough for some mice so external 10k between the lines and 5V are worth a try.
I only have 3 different types of PS/2 mouse and they all work without the external pullups so it's difficult to investigate further.


Using:
- a new (albeit cheap Chinese) unbodged Nano
- a new Genius DX-110 PS/2 mouse (my only PS/2 mouse)
- no CMM2 connected

then the HT_mouse program "hangs" for me in PS2Mouse::readData() when doing data.wheel = readByte().

If I comment this out then I can see from the Serial Monitor that the three buttons (left, right & wheel) are working, but x & y stay steadily fixed at 400, 300. The TX and L LED's are flashing rapidly thoughout (green & orange respectively.)

This happens with and without the 10k pullups.

Any advice ? - I'm comfortable changing the code and reporting back, but if it comes to poking things with an oscilloscope I only have a toy DSO138.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
     Page 3 of 5    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025