Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:43 19 Apr 2024 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 : Another Mouse Interface

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 10:48pm 04 Jun 2020
Copy link to clipboard 
Print this post

Seems like 'mites with mice is popular.

Here is the version I have been working on:
Youtube video

Mine is based on a PIC16F18313 microcontroller which translates the PS2 interface to serial. I chose 38400 baud for my prototype but maybe I'll add that as a changeable config.

Some mice with USB plugs work in PS2 mode also so that is the physical interface I chose.

Might I encourage the keepers of the new Maximite2 standard to consider adding this valuable interface? My microcontroller based version only requires 2 open drain bi-direction pins to communicate with the mouse and less than 1000 bytes of (very poorly compiled) object code to perform the translation. Those two pins might need to be 5 volt tolerant too.

This is also why I requested serial interrupts to fire when a particular character is received, a feature available in the Micromite and Micromite+.

The Armmite source code in the above video appears below. The mouse pointer is implemented with a custom font, which includes the pointer, a hand and an hourglass wait character. The display trickery involves blitting the region of the screen where the mouse pointer is to appear into a buffer and then "printing" the custom mouse character into the screen. Moving the mouse involves blitting the saved portion back to the screen to erase the mouse, performing any required screen updates and then repeating at the new location. (An apparent bug in the 'TEXT' command prevents the mouse pointer character from sliding off the bottom of the screen.)

' Micromite Mouse Demo Program
'  written by vegipete
'
' External hardware based on a PIC16F18313 microcontroller
' is used to convert PS2 mouse data to serial data.
' The external hardware can recognize a standard wheel mouse.
' Mouse data is ONLY sent when the mouse changes, to a
' maximum of 20 updates per second.
' The data format is an ASCII string of 16 characters:
' "LMR+000+000+000<\r>"
' L, M & R are the buttons, 1 when pressed, 0 when not
' +000 is the position change for each of x, y and z
' (z is the scroll wheel)
' Depending on the mouse, the displacement could range from
' +255 to -255
' On a mouse with no scroll wheel, those fields are zero.
'
' Note that SOME USB mice work in PS2 mode too and work
' just fine with the external hardware.

CLS
Dim integer mx, my, mz, newmouse
Dim integer mbl, mbm, mbr
Dim mxold, myold As integer
Dim dx, dy As float

Open "com4: 38400,256,mouseint,16" As #2

On error skip   ' allow error on next line
Blit close 1    ' ensure blit buffer is free

Text 150,15, "A Mouse and", "CT", 4
Text 150,40, "A Micromite", "CT", 4

Text 10,70, "With a special bit of",,2
Text 10,90, "interface hardware,",,2
Text 10,110, "both work together",,2
mx = 40 : my = 12
Text mx,130, "S",,2,,RGB(RED) : mx = mx + my
Text mx,130, "P",,2,,RGB(yellow) : mx = mx + my
Text mx,130, "E",,2,,RGB(cyan) : mx = mx + my
Text mx,130, "C",,2,,RGB(blue) : mx = mx + my
Text mx,130, "T",,2,,RGB(magenta) : mx = mx + my
Text mx,130, "A",,2,,RGB(green) : mx = mx + my
Text mx,130, "C",,2,,RGB(brown) : mx = mx + my
Text mx,130, "U",,2,,RGB(green) : mx = mx + my
Text mx,130, "L",,2,,RGB(magenta) : mx = mx + my
Text mx,130, "A",,2,,RGB(blue) : mx = mx + my
Text mx,130, "R",,2,,RGB(cyan) : mx = mx + my
Text mx,130, "L",,2,,RGB(yellow) : mx = mx + my
Text mx,130, "Y",,2,,RGB(RED) : mx = mx + my

mx = MM.HRes/2
my = MM.VRes/2
mz = 33
newmouse = 0

GUI BARGAUGE #1, 300,20,10,200,RGB(GREEN),0,0,200
CtrlVal(#1) = mz
GUI LED #2, "", 110,175,10,RGB(RED)
Text 110,190, "Left", "CT", 1
CtrlVal(#2) = mbl
GUI LED #3, "", 160,175,10,RGB(BLUE)
Text 160,190, "Middle", "CT", 1
CtrlVal(#3) = mbm
GUI LED #4, "", 210,175,10,RGB(GREEN)
Text 210,190, "Right", "CT", 1
CtrlVal(#4) = mbr

CursorOn

Do
 If newmouse Then
   'The screen should not be updated while the cursor is displayed
   CursorOff
   CtrlVal(#1) = mz
   CtrlVal(#2) = mbl
   CtrlVal(#3) = mbm
   CtrlVal(#4) = mbr
   CursorOn
   newmouse = 0
 EndIf
 Pause 25
Loop

End

' Routine called when a new data string is received from the mouse
Sub mouseint
 Local dx,dy,dz
 Local string dm$ length 32
 mbl = Val(Input$(1,#2))     ' left button
 mbm = Val(Input$(1,#2))     ' middle button
 mbr = Val(Input$(1,#2))     ' right button
 dx = Val(Input$(4,#2))      ' x movement
 dy = Val(Input$(4,#2))      ' y movement
 dz = Val(Input$(4,#2))      ' z (wheel) movement
 dm$ = Input$(8,#2)          ' read any left over junk

 mx = mx + dx
 If mx < 0 Then mx = 0
 If mx > MM.HRes-2 Then mx = MM.HRes-2
 my = my - dy
 If my < 0 Then my = 0
 If my > MM.VRes-24 Then my = MM.VRes-24
 'Note: can't go to bottom of screen because of bug in text command
 mz = mz + dz
 If mz < 0 Then mz = 0
 If mz > 200 Then mz = 200

 newmouse = 1
End Sub

' Move cursor to (new) mx,my
Sub CursorMove
 CursorOff
 CursorOn
End Sub

' Save screen and paint cursor at mx,my
Sub CursorOn
 Blit read 1,mx,my,14,20   ' save background
 mxold = mx : myold = my   ' save location of saved background
 Text mx,my," ",,10,,,-1   ' paint the cursor
End Sub

' Remove the cursor from the screen and restore screen
Sub CursorOff
 Blit write 1,mxold,myold,14,20  ' restore background
 On error skip   ' allow error on next line
 Blit close 1    ' free up the blit buffer for next time
End Sub

' CursorFont20x24
DefineFont #10
 04201814 00040000 05006000 00480000 42004004 00100400 04048040 04204000
 08400001 44800F04 00A40480 12064052 00200100 0000000C 00000000 00000000
 30000000 00800400 80040048 04004800 C04900E0 49009304 44927428 004424C0
 10040042 04004100 80400008 80000408 01020840 03102000 000000FF FF070000
 070140F0 0220F0FF 20200002 202A0202 88004411 00100480 10040022 10808800
 20000204 2A024221 07522520 0140F0FF 00F0FF07 00000000 FF070000 070140F0
 0220F0FF 20200002 202A0202 88004411 00100480 10040022 10808800 20000204
 2A024221 07522520 0140F0FF 00F0FF07 00000000 00000000
End DefineFont
>


Enjoy!
Visit Vegipete's *Mite Library for cool programs.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5882
Posted: 12:13am 05 Jun 2020
Copy link to clipboard 
Print this post

It's good to see another version.
With all the different mice running around, there is sure to one version that woks with each mouse.

Jim
VK7JH
MMedit   MMBasic Help
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 372
Posted: 07:21pm 17 Feb 2023
Copy link to clipboard 
Print this post

Ahh... I know I am ressurrecting an old post, but the whole mouse topic won't let me sleep.

I am wondering if it is possible to use this approach with the picoMite VGA. I have lots of PS/2 mice flying around and all the hardware for an PS/2 to Serial adaptor which translates PS/2 code to serial. With that via a level shifter to some picoMite Serial ports it should be no problem, or I am missing something?

Since we got all the good stuff Peter is working on (now an even better colour edit mode) I feel what's really left is the option of a mouse. Is is perfectly fine if it is not possible via "native" PS/2 .. but with this workaround?

Let me know your thoughts  

Greetings
Daniel
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1639
Posted: 09:40pm 17 Feb 2023
Copy link to clipboard 
Print this post

Could I use my non vga picomite with touch screen to communicate fast x,y info to vga picomite please? Just to see. seems an idea. glcd buttons would be useful. serial?
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3649
Posted: 10:00pm 17 Feb 2023
Copy link to clipboard 
Print this post

  stanleyella said  Could I use my non vga picomite with touch screen to communicate fast x,y info to vga picomite please? Just to see. seems an idea. glcd buttons would be useful. serial?

Yes just connect them to each other and send the data across.

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 10:03pm 17 Feb 2023
Copy link to clipboard 
Print this post

What you can't do is run a LCD and/or touch display and a VGA display on the same PicoMite.

Also, bear in mind the graphics limitations of the PicoMite VGA implementation if you want to use a cursor. Only Mode 2 has true colour capability.
Edited 2023-02-18 08:09 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1639
Posted: 11:08pm 17 Feb 2023
Copy link to clipboard 
Print this post

I meant a lcd picomite connected to another vga picomite.I got a touch lcd on vero and a breadboard vga. What do the 3 pads at the end do? What serial comm would be easiest/best i2c? It's just a thought. picomite is cheap enough to use 2 for a hobby idea.
picomite glcd touch is accurate and could be a keypad control for a vga display but only thinking of games.
I got a 2 pot x/y joystick that I could use a-d to read but again can't really think of a use... missile command?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 08:00am 18 Feb 2023
Copy link to clipboard 
Print this post

The three end pads are debug connectors - low level stuff that's not supported in MMBasic.

You can link two (or more) PicoMites but there are no standards. You could use I2C, SPI or (easier than either) a COM port. The protocol and what data is sent is your design!

You could write a program that simulates a PS/2 keyboard. That way you can send any characters you like in response to button presses or whatever and it's already decoded by a standard PicoMite. Don't ask me how though. :)

It's a lot easier to simply get a PicoGAME set up and use joysticks (digital or analogue) or game pads though. After all, I designed it as a VGA games platform. :)  Tom and Volhout have done some hard work in getting joystick and game pad handling sorted out for it. You can even put your little darling in a posh case after. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1639
Posted: 04:12pm 18 Feb 2023
Copy link to clipboard 
Print this post

is this picoGAME? http://www.picogame.com
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 04:59pm 18 Feb 2023
Copy link to clipboard 
Print this post

Nope. Similar name (but not logo) and no relation. :)  They don't do hardware.

Follow the "my PCB designs in my sig
Mixtel90'sPCBs / PicoGAME 20 Construction Pack.zip

Everything is in there, including gerber files.
Edited 2023-02-19 03:02 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 372
Posted: 12:43pm 19 Feb 2023
Copy link to clipboard 
Print this post

  Amnesie said  Ahh... I know I am ressurrecting an old post, but the whole mouse topic won't let me sleep.

I am wondering if it is possible to use this approach with the picoMite VGA. I have lots of PS/2 mice flying around and all the hardware for an PS/2 to Serial adaptor which translates PS/2 code to serial. With that via a level shifter to some picoMite Serial ports it should be no problem, or I am missing something?

Since we got all the good stuff Peter is working on (now an even better colour edit mode) I feel what's really left is the option of a mouse. Is is perfectly fine if it is not possible via "native" PS/2 .. but with this workaround?

Let me know your thoughts  

Greetings
Daniel


*Push...*
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 01:47pm 19 Feb 2023
Copy link to clipboard 
Print this post

Why not try it?
You'll need a PS/2 to serial converter of some sort then you can watch the COM port with a PicoMite.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1639
Posted: 02:43pm 19 Feb 2023
Copy link to clipboard 
Print this post

If you want to use a mouse for editing, saving, running mmbasic then the mmedit for win is sorted already. Getting a non win mouse to work with the picomite inbuilt editor.. how to integrate it?
Using a mouse with own program different job.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024