PS/2 Mouse for Next non-ADB

Started by barcher174, December 21, 2013, 11:02:47 PM

Previous topic - Next topic

barcher174

It's ALIVE!



Still really buggy and choppy, but hopefully I'll have more details soon. It seemed like a good time since I'm seeing mice listed at $100 on ebay...

--
Brian

barcher174

Second iteration completed:



Tracking is now working well and both mouse buttons work as well. I found a mac 512k to PS/2 mouse conversion which helped with the X/Y tracking. Now I want to miniaturize this and stuff it into a PS/2 mouse.

barcher174

Ok last update of the evening. I was thinking to put the whole thing inside a ps/2 mouse, but then ran into the issue of what wire to use for the external connection. I'm thinking I will stick with an external adapter. I made a temporary version for now until I can get some additional parts.

--
Brian

gtnicol


Khashoggi

Nice work!

Microcontrollers make good glue.

Does the cursor track smoothly?

barcher174

It's an ATmega8 w/ arduino firmware. I had bought a bulk order on ebay a few years back and have been looking for problems to solve with them ever since. There are of course smaller footprint alternatives. The tracking is completely smooth now thanks to some code I lifted from here:

http://www.youtube.com/watch?v=KVvPGAEj-Zw

I have some PS/2 connectors on order so I can make an external adapter. I'll get everything cleaned up and documented when I have time. Overall it's maybe $10 in parts and less than an hour to make one of these.

--
Brian

barcher174

Ok, Here's a quick rundown.

First we need the pinout for the next mouse:

Next Mouse Connector:  
   
   6 7 8
  3 4   5
    1 2

6: Right Button 7: Left Button 8: GND
          3: XB  4: YA  5: YB
              1: +5V  2: XA

I chose to use an arduino for the uC. There is an existing PS/2 library located here:

http://playground.arduino.cc/ComponentLib/Ps2mouse

It's an older library, but still works fine with the newest IDE. When you are installing the lib, make sure you edit 'ps2.h' and replace "WProgram.h" with "Arduino.h". Other than that is should just work.

For more details on the PS/2 spec have a look here:
http://www.computer-engineering.org/ps2mouse/

The code is pretty simple. I started with the example code and then got simple movement working. I then found a completed code for a mac 512K here:
http://www.youtube.com/watch?v=KVvPGAEj-Zw

He was also using the same library so it was trivial to adapt his code to the Next based on what I already had found. Full Arduino code:

#include <ps2.h>

#define PIN_HORIZ_A 5
#define PIN_HORIZ_B 4
#define PIN_VERT_A  3
#define PIN_VERT_B  2
#define PIN_BUTTON_1 1
#define PIN_BUTTON_2 0
#define PIN_BUTTON_3 0

#define PIN_LED 13    

#define PIN_REAL_MOUSE_CLK 9
#define PIN_REAL_MOUSE_DTA 10

const uint8_t QuadratureEncoding[4] =
{
   0b00,
   0b01,
   0b11,
   0b10
};

PS2 realMouse(PIN_REAL_MOUSE_CLK, PIN_REAL_MOUSE_DTA);

uint8_t g_horizQuadStep = 0;
uint8_t g_vertQuadStep = 0;

void writeVerticalQuadratureOutputs();
void writeHorizontalQuadratureOutputs();

void mouseInit()
{
 realMouse.write(0xff);  // RST
 digitalWrite(PIN_LED, LOW);
 realMouse.read();
 realMouse.read();
 realMouse.read();
 realMouse.write(0xf0); // Remote.
 realMouse.read();
 delayMicroseconds(100);
}

void setup()
{
 pinMode(PIN_HORIZ_A, OUTPUT);
 pinMode(PIN_HORIZ_B, OUTPUT);
 pinMode(PIN_VERT_A, OUTPUT);
 pinMode(PIN_VERT_B, OUTPUT);
 pinMode(PIN_BUTTON_1, OUTPUT);
 pinMode(PIN_BUTTON_2, OUTPUT);
 pinMode(PIN_BUTTON_3, OUTPUT);
 pinMode(PIN_LED, OUTPUT);

 delay(100);
 
 cli(); // Disable interrupts, they interfere with our timing.
 
 digitalWrite(PIN_LED, HIGH);
 mouseInit();
 digitalWrite(PIN_LED, LOW);
}

void loop()
{
 char mstat;
 char mx;
 char my;
 boolean goingRight;
 boolean goingDown;
 
 realMouse.write(0xeb);
 realMouse.read();
 mstat = realMouse.read();
 mx = realMouse.read();
 my = realMouse.read();

 goingRight = mx > 0;
 goingDown = my > 0;
 mx = abs(mx);
 my = abs(my);
 
 while (mx > 0)
 {
   g_horizQuadStep += goingRight ? 1 : -1;
   writeHorizontalQuadratureOutputs();
   delayMicroseconds(100);
   mx --;
 }
 
 while (my > 0)
 {
   g_vertQuadStep += goingDown ? 1 : -1;
   writeVerticalQuadratureOutputs();
   delayMicroseconds(100);
   my --;
    digitalWrite(PIN_LED, 0);
 }

   digitalWrite(PIN_BUTTON_1, !(mstat & 0x01));
   digitalWrite(PIN_BUTTON_2, !(mstat & 0x02));
   digitalWrite(PIN_BUTTON_3, !(mstat & 0x04));
 

 digitalWrite(PIN_LED, mstat & 0b11);
}

void writeHorizontalQuadratureOutputs()
{
 uint8_t quadEncoding = QuadratureEncoding[g_horizQuadStep % 4];
 digitalWrite(PIN_HORIZ_A, quadEncoding & 1);
 digitalWrite(PIN_HORIZ_B, quadEncoding>>1 & 1);
}

void writeVerticalQuadratureOutputs()
{
 uint8_t quadEncoding = QuadratureEncoding[g_vertQuadStep % 4];
 digitalWrite(PIN_VERT_A, quadEncoding & 1);
 digitalWrite(PIN_VERT_B, quadEncoding>>1 & 1);
}

Note that the pin mapping is at the top of the file. Currently this is mapped to an ATMega8. In my case I have the cheaper model which only has a 4mhz internal oscillator. This is not sufficient. I ended up using an external 12mhz crystal and it gives perfect tracking results. So after the program is loaded to the uC just connect each uC pin to the corresponding  8 pin DIN connection. It's really as simple as that.

--
Brian

Rob Blessin Black Hole

Very cool kudos on this  !
Do you know if it is possible to convert an adb NeXT soundboard to work with non adb NeXT components in looking at the 2 there are very few differences , the reason I ask is I have a bunch of adb soundboxes and I think Gavin also has a cache of adb soundboards with next monitors going south and more non adb NeXT s than Adb it would give us a transition path to revive more NeXTs or can older NeXT rom code be upgraded to work with adb components .
I also have a few nonadb to serial mouse adaptors that work and a few NeXT roller mice .  
A way to bypass the NeXT soundboard altogether might work as well , I don't know if there would be a way to interface something like a raspberry pi with Ethernet and have the keyboard and mouse hooked up to the raspberry ...

I have a nice Batronix  rom burner and it software displays edits the code and am not sure what it would take to get any of this to work but am willing to help out. Best regards Rob Blessin
Rob Blessin President computerpowwow ebay  [email protected] http://www.blackholeinc.com
303-741-9998 Serving the NeXT Community  since 2/9/93

barcher174

Unfortunately a conversion like that is much more complicated. If we had that knowledge, we likely would remove the sound box completely. I have looked at the boards for ADB vs. non-ADB. It may be easier to modify the board directly. The difference seems to be a PLC and a cap from what gtnicol reported. If you could clone the PLC, the rest would just be some creative rework. Upgrading the Next ROMS would also be interesting, but way outside of my realm of knowledge to even start.

--
Brian

Rob Blessin Black Hole

Quote from: "barcher174"Unfortunately a conversion like that is much more complicated. If we had that knowledge, we likely would remove the sound box completely. I have looked at the boards for ADB vs. non-ADB. It may be easier to modify the board directly. The difference seems to be a PLC and a cap from what gtnicol reported. If you could clone the PLC, the rest would just be some creative rework. Upgrading the Next ROMS would also be interesting, but way outside of my realm of knowledge to even start.

--
Brian

I have several doa non adb sound boards so I'm wondering to test the theory we might be able to unsolder the Plc from a doa non adb board and move it to the adb board but we also would need an adb to non adb adaptor. I wondering if just making a male adb adaptor that plugs into the soundbox with a female nonadb receptor would work to connect a non adb keyboard and mouse to an adb soundbox with v74 rom chip on motherboard.
The monitor cables are different for adb and non adb.
Also you can unplug and non adb keyboard or mouse  while the system is powered on and plug it back in and it works whilst adb once unplugged requires unplugging the system from the wall and rebooting .
The theory on an alternative detached keyboard and mouse bypassing the soundbox is you can run the system headless as a print server so to test this have a monitor hooked up and if you can telnet in from another NeXT or just network and see it making changes on screen , I think I have copies of screencast and watchme which was used for dev training instructors computer cast it onto students and allowed access like mypc .... So them would a VMware install on a Mac or Openstep intel box be able to move a cursor and type on a black NeXT ? I'll give it a try after I catch up on orders or if someone knows please feel free to jump in.
The advantage would be you down the road if you have a NeXT computer and didn't have a the NeXT keyboard, NeXT mouse, NeXT soundbox , NeXT monitor, NeXT cable in theory you jump start it and look at it through the network obviously easier if already networked.
Other options if we look at the ports on the back I know hp for example has Ethernet based keyboards and mice on there PARISC box in fact I'm still looking for an hil keyboard and mouse .
Also 2 serial ports which I know a lot of people that tried to plug the keyboard and mouse in there , with drivers would that actually work?  lol me included that would be to easy. I know a serial mouse will work on a NeXT keyboard with the adaptor and now we have ps2 brilliant!
Would a dsp port keyboard and mouse solution work or even the printer port?
I'm sure we will figure it out !
Rob Blessin President computerpowwow ebay  [email protected] http://www.blackholeinc.com
303-741-9998 Serving the NeXT Community  since 2/9/93

gtnicol

I think we have enough knowledge to actually create a clone of the soundbox, and things like the F4 Discovery, Rasberry PI etc. have plenty of speed for prototyping (unlike the ATMEL or even PIC32). I just haven't had time to get into it.

I will experiment with swapping a later model ROM into a non-Turbo system to see if that will allow it to work with ADB peripherals.

Rob Blessin Black Hole

Quote from: "gtnicol"I think we have enough knowledge to actually create a clone of the soundbox, and things like the F4 Discovery, Rasberry PI etc. have plenty of speed for prototyping (unlike the ATMEL or even PIC32). I just haven't had time to get into it.

I will experiment with swapping a later model ROM into a non-Turbo system to see if that will allow it to work with ADB peripherals.

I tried swapping roms the v74 does not work in a color slab ,  I suspect the ics and turbo chip sets differ.
Rob Blessin President computerpowwow ebay  [email protected] http://www.blackholeinc.com
303-741-9998 Serving the NeXT Community  since 2/9/93