Showing posts with label Mouse. Show all posts
Showing posts with label Mouse. Show all posts

Sunday, July 01, 2018

ZeaMouse V2, USB Mice for the ZX81 & Spectrum Revisited: Part 2

Leave a Comment

The ZeaMouse version 2 firmware should take a USB mouse and have it function in a similar fashion to a Commodore 64s 1351 mouse. The 1351 had two modes of operation, an analogue mode and a digital compatibility mode. In digital mode a 1351s analogue movements are converted into digital signal for use on standard Atari style joystick port.

The trick to the converting an analogue like signal to a digital one is in the preservation of the proportional analogue mouse movement feel. Complicating matters is the host computer and the particular piece of software reading the joystick port at any given time.

In version one of the ZeaMouse I thought I'd got the mouse timings and movement about right. However at the time I only had a ZXPand equipt ZX81 for testing. Unfortunately what I though was working well was in reality only doing so for the ZX81. Thankfully I've acquired a ZX Spectrum Omni which has a Kempston compatible port, and so have been able to conduct more extensive testing this time around.

After about a month of testing I'm satisfied the mouse interface works just as well with the Spectrum (Kempston and Sinclair adapters) as a ZX81. Note that the Spectrums joystick ports should provide power on pin 5 else you'll need to power the mouse interface externally.

Proportional movement is simulated by keeping the joystick direction triggered for longer periods the more the mouse is moved in a constant direction. Getting the acceleration just right proved a little tricky. The mouse is also decelerated, but this happens at about twice the rate of acceleration.

The latest firmware ZeamMouse_V2_03.tar.gz is now avaliable for download, as always newer versions as they become avaliable are on the ZX81 Projects page.

To compile the ZeaMouse project a copy of the Circuits@Home Arduino USB Host Shield  library is also required. This is available from the Git Hub repository: https://github.com/felis/USB_Host_Shield


Using a USB Mouse in the 'The Artist 3'

See more entries for this project: Part 1Part 2

Read More

Saturday, May 12, 2018

ZeaMouse V2, USB Mice for the ZX81 & Spectrum Revisited: Part 1

Leave a Comment
A year ago I knocked up the ZeaMouse, a USB mouse interface for the ZXpand and ZX81. ZeaMouse is a USB to digital mouse expansion board built around an Adrunio USB host shield. A year on it seems like a good time to revisit the project and make some improvements.

Last time part of the fun was building a simple Arduino clone as part of the ZeaMouse. Unfortunately this kept the size of the end product much larger than it needed to be. This time an Arduino Pro Mini 3.3v has replaced the DIY Arduino, matching this with a USB Mini Host shield and some additional components on a home-brew shield sees significant reductions in interface size.

The USB Mini Host shield forms the core of the project and is designed to fit under an Arduino 3.3v Pro mini. The USB shield has all the abilities of it's bigger brother but does with some but comes with some power supply limitations. By default the combination of 3.3 volt Pro Mini and USB host  combination delivers 3.3 volts to an attached USB device. For some hardware the voltage may not be high enough, although all the USB mice (if a limited selection) I've tested have work without issue.

3.3v Arduino Pro Min, USB Shield and ZeaMouse V2 PCB.
The USB Host shield can be modified to deliver 5v to connected devices if required. Details of the conversion can be found on the Circuits@Home website. The modification bypasses the Arduino's 3.3v regulator, meaning that whatever is used to supply power to the RAW inputs must be rated a 5v or lower else you risk frying an attached USB device. The ZeaMouse is powered from the 5v lines on the digital joystick port, so the modification is fine for our purposes. (But check your Micro Computers Specs first).

I decided against using 4066 switching ICs on ZeaMouse V1 as it made designing the single sided PCB a lot simpler. This time, with design simplicity and ease of build-ability screams for the use of 4066s. With the Arduino Pro Mini operating at 3.3 volts and the ZX81 at 5 volts, 4066s provide a simple way of keeping these conflicting voltages separated.


ZeaMouse V2 Circuit Diagram
Although I got a couple of double sided test PCBs fabricated, the ZeaMouse boards are pretty much designed with home PCB making in mind. Only the bottom of the board really needs to be made up. There are a couple of via's must be connected with some straight wire on the top of the board should you choose to build a single sided PCB.

Building the interface is straight forward. The hardest part is probably soldering the Pro Mini and the USB shield together. Constructing ZeaMouse shield itself is a breeze, and will only take about 20 minutes maximum.

Other than two 4066s, the only other components required are pin headers and IC sockets, although all of these are optional. The Arduino and USB Host along with the ICs could be soldered directly to the shield PCB. The only required header is J4, used to enable or disable RS232 communication with the ZXpand. J4 should be left open if using the ZeaMouse on any micro computer other than a ZX81.

ZeaMouse v2 Shield completed.
The connection pads or pin headers on the far end of the shield board should be wired up to an Atari joystick cable or DB9 socket. I had a cable from a broken controller to hand; care needs to be taken re-purposing cables for fear of sending 5 volts down the wrong line. The TX serial out is the one non-standard connection, it's specifically for the ZXpand+, and should be routed to RX on the ZXpand+.

ZeaMouse v2 interface for the ZX81 & ZXpand / ZX81, the ZX Spectrum and other 8 bit micros
Next time I'll cover the firmware and take a look at the mouse in action. No need to wait until then if you're keen to get going; All the files and firmware required to build the interface are a already available on the ZX81 Projects and Programs to Download Page.

See more entries for this project: Part 1Part 2
Read More

Saturday, June 10, 2017

USB Mouse For The ZX81 And ZXpand (Part 2)

Leave a Comment
It's been a while since the first part of this article, some exciting developments happened to the ZXpand in between and I wanted to test the interfaces functionality out on the brand new ZXpand+ hardware before posting. I've also given the interface a little moniker, "ZeaMouse". Anyway, enough fluffing around, down to the specifics.

As previously mentioned (in Part 1: USB Mouse For The ZX81 And ZXpand), the USB mouse interface relies on normal Atari digital joystick inputs as found on the ZXpand. Since that time, Charlie Robson unleashed the new ZXpand+ into the ZX81 world. With this comes some potential options, in particular a TTL serial port has been included on the ZXpand+ IDC header, this may be of use for sending proportional mouse data, promising true mouse functionality.

For now though, the Mouse interface maintains full compatibility with the original ZXpand while also making allowances for serial connection to the ZXpand+, connections  that will be used at a later date. Of note for those intending to use the interface on other Micro computers, the serial tracks on the ZeaMouse interfaces IDC header may need to be cut (or removed) in order to avoid potential damage to that Micro or the Interface itself.

ZeaMouse Firmware


Some things end up being a lot less complicated than you'd imagined they would be. The coding behind reading the mouse and passing directions to the ZXpands digital joystick port was one of those things. That's definitely a credit to those behind the USB host shield.

There is nothing overly complex in the code. Mouse movement tracked by time, if XY mouse movement is detected the appropriate joystick pin is set to OUTPUT, a debounce timeout then set to 15, milliseconds providing enough time for a 'button press' to be registered by the ZXpand. While mouse movement continues in the same direction the debounce timings are updated. Mouse button 1 and 2 are both setup to work as a standard joystick button press.

A regular Atari Joystick can be attached to the semi-pass-though port. Joystick movement is given priority and should override incidental mouse movements while using a joystick. The exception to this is where a mouse button is pressed as tracking mouse presses relies on the button being released again to clear the OUTPUT.

A large scope exists for future additions to the code. Provisions for USB joysticks and keyboards (with limited functionality) could also be added with some extra effort. As it is possible to attach the USB shield to a USB hub, allowances for multiple devices to be connected at the same time could also be made. Depending on updates to the ZXpand+ itself, and how the TTL serial lines are read, all manner of interfacing options could become available.

The Arduino Code Files can be found here: ZeaMouse_Arduino.tar.gz

ZeaMouse plugged into the ZXpand+ using a (delightful rainbow (thanks Charlie)) IDC cable, with USB mouse and Digital Joystick connected.


Programing the ATmega328P  / Arduino


Ideally it's easiest to purchase an ATmega328P IC with the Arduino boot loader pre-installed, these can be sourced quite easily. I recommend purchasing a kit that comes with the required crystal, such as this kit from Jaycar: ATMEGA328P MCU IC with Arduino UNO Bootloader and 16MHz Crystal (or a cheaper version from your favourite Chinese supplier).

The ATmega328P chip (with boot loader) will require sketch / code / firmware, this must be programmed outside of the USB joystick interface. To do this an Arduino UNO can be used, simply swap out the existing IC in the UNO, insert and program the new one, then transferring that to the interface.

Required Components


All components should be easily obtainable, there is nothing remotely exotic required to build the ZeaMouse. In addition to the construction components listed in the Main Contruction Shopping List, you will also need a USB host Shield.  Along with a 10 pin IDC cable (which may be split from a larger cable), cut to the length you require, proably not shorter that 10cm. 1 or 2 10 pin IDC sockets and or a 9 Pin D-SUB DB9 Female IDC Connector. The configuration of these cables is dependent on variant of ZXpand being used.
IDC Cables: Top Cable for ZXpand+, Bottom Cable for ZXpand.

You may be able to purchase IDC cables pre-made, however if manufacturing at home there is a nice video on how to make IDC (ribbon) cables over on YouTube thanks to The University of Manchester. The main thing to remember when building a cable is that pin 1 on 1 socket should always go to pin 1 on socket 2.

All parts required to build the actual ZeaMouse interface are listed in the table below.

Main Contruction Shopping List (Excluding the PCB & USB Shield)

Amount Part Type Properties
2 Capacitor variant pth2; package cap-pth-small2
1 Ceramic Capacitor package 200 mil [THT, multilayer]; capacitance 100nF; voltage 6.3V
1 Capacitor Polarized variant pth2; package cpol-radial-10uf-25v
1 Capacitor Polarized variant pth1; package cpol-radial-100uf-25v
5 Diode variant pth; package diode-1n4001
1 MICROCONTROLLER variant kit; package dil28-3-simon-kit; chip atmega8
1 AVR ISP 6 Pin variant pth; package 2x3; pins 6
1 10 Pin IDC Header variant variant 2; row double; package THT; pins 10; form ♂ (shrouded male); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
1 Ardunio_Power_Header_8_Pins variant variant 3; row single; package THT; pins 8; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
1 Ardunio_Analog_Header_6_Pins variant variant 4; row single; package THT; pins 6; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
1 Ardunio_Digital_Header_10_Pins variant variant 5; row single; package THT; pins 10; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
1 Ardunio_Digital_Header_8_Pins variant variant 6; row single; package THT; pins 8; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
1Bucket DB9 Solder Bucket DB9
1 Red (633nm) LED package 3 mm [THT]; color Red (633nm); leg yes
1 10kΩ Resistor package THT; tolerance ±5%; bands 4; pin spacing 400 mil; resistance 10kΩ
1 220Ω Resistor package THT; tolerance ±5%; bands 4; pin spacing 400 mil; resistance 220Ω
1 Voltage Regulator - 3.3V package TO220 [THT]; voltage 3.3V; part # LM2936
1 Crystal package THT; frequency 16 Mhz; pin spacing 5.08mm; type crystal
1 Crystal package THT; frequency 16 Mhz; pin spacing 5.08mm; type crystal


ZeaMouse Board Assembly


ZeaMouse PCB Layout
All the files required files for ordering a PCB from a fabrication house, or for rolling your own board are contained in the ZeaMouse_Fritzing.tar.gz file. 

As mentioned in Part 1 of the USB Mouse For The ZX81 And ZXpand blog post, the mouse interface PCB is designed to allow easy one sided home fabrication, as well as double sided construction for the more adventurous, or ordering from fabrication houses.

The underside of the PCB is all that needs to be printed, with the top side consisting of only straight tracks and vias that can be linked with copper wire if you choose the one sided method. Linking wires are highlighted in red on the PCB layout figure / image.

All components are of the through hole variety for easy assembly, and there are not a great many of them. The only really tricky part in the whole process is attaching the solder bucket DB9 joystick socket. I used this particular part to save space and keep the interface an acceptable size. In attaching the DB9 connector to the PCB, I first soldered pin cutoffs from the long Ardunio Headers to the solder pads / buckets of the DB9, then inserted the pins through the PCB for soldering to the board. You could also use Generic male header pins in a similar fashion.

Assembly List

Label Part Type Properties
C1 Capacitor variant pth2; package cap-pth-small2
C2 Capacitor variant pth2; package cap-pth-small2
C3 Ceramic Capacitor package 200 mil [THT, multilayer]; capacitance 100nF; voltage 6.3V
C4 Capacitor Polarized variant pth2; package cpol-radial-10uf-25v
C5 Capacitor Polarized variant pth1; package cpol-radial-100uf-25v
D1 Diode variant pth; package diode-1n4001
D2 Diode variant pth; package diode-1n4001
D3 Diode variant pth; package diode-1n4001
D4 Diode variant pth; package diode-1n4001
D5 Diode variant pth; package diode-1n4001
IC1 MICROCONTROLLER variant kit; package dil28-3-simon-kit; chip atmega8
J1 AVR ISP 6 Pin variant pth; package 2x3; pins 6
J2 Atari Joystick IDC variant variant 2; row double; package THT; pins 10; form ♂ (shrouded male); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
J3 Ardunio_Power_Header_8_Pins variant variant 3; row single; package THT; pins 8; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
J5 Ardunio_Analog_Header_6_Pins variant variant 4; row single; package THT; pins 6; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
J6 Ardunio_Digital_Header_10_Pins variant variant 5; row single; package THT; pins 10; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
J7 Ardunio_Digital_Header_8_Pins variant variant 6; row single; package THT; pins 8; form ♀ (female); pin spacing 0.1in (2.54mm); hole size 1.0mm,0.508mm
J8 Generic male header - 5 pins Solder Bucket DB9, top row: See article for attachment guide
J9 Generic male header - 4 pins Solder Bucket DB9, bottom row: See article for attachment guide
LED1 Red (633nm) LED package 3 mm [THT]; color Red (633nm); leg yes
R1 10kΩ Resistor package THT; tolerance ±5%; bands 4; pin spacing 400 mil; resistance 10kΩ
R2 220Ω Resistor package THT; tolerance ±5%; bands 4; pin spacing 400 mil; resistance 220Ω
U1 Voltage Regulator - 3.3V package TO220 [THT]; voltage 3.3V; part # LM2936
XTAL1 Crystal package THT; frequency 16 Mhz; pin spacing 5.08mm; type crystal


Go Forth and Build


That's it for the moment, so go forth and build the ZeaMouse. I'll be updating and adding features to the firmware over the coming months, and hopefully some specifically ZXpand+ only enhancements that take advantage of the new hardware, so come back every now and again to check for that. As always feedback and suggestions are more than welcomed.

Read More

Monday, April 24, 2017

USB Mouse for the ZX81 and ZXpand (Part 1)

Leave a Comment
A USB mouse on a ZX81 sounds a little mad and yet given the wealth of plug and play electronics available in 2017, it's a comparatively painless task to implement. To be clear I'm talking about a digital mouse, one that uses an Atari style joystick port, where proportional mouse movements are converted to digital signals.

Why a digital mouse? While not being a true proportional mouse implantation, it is a path taken by at least one 8bit computer, the Commodore 64 and it's 1351 Mouse back in the 1980s. As an added bonus this also means the mouse interface should work on all 8bit systems that support the Atari protocol. At the end of the day it's smarter to build on an existing solid and supported base such as Charlie Robsons'  ZXpand with its digital joystick implementation, than it is to implement a non supported (by existing software) standalone proportional mouse interface; at least for now.

So now it's down to how to get this thing to work, and my prototyping weapon of choice is an Arduino UNO armed with a USB host shield. The USB host shield really is the key to the project, it comes with an extensive Arduino / C++ library ready to plug in, leaving the casual developer or hobbiest free to solve other non-USB related hardware and software puzzles.


Stage 1: Getting a Test up and Running


Testing a 4006 IC vs a Diode
As we will be leveraging the ZXpands joystick port for interfacing our mouse (and Adruino) with, we need to trigger all mouse movements by simulating joystick button presses. To achieve this the correct signal lines on the joystick port must be pulled low (pulled to ground). We also need to insure that we don't unduly damage the ZX81 / ZXpand in the process of doing so. Ideally we'd wish to partially electrically separate the Arduino from the ZXpand (partially, as we will eventually be drawing power from the joystick port), so that unintentional voltage are not shot in the wrong direction, particularly during testing phase. There are numerous ways ways to achieve this, I tested 2 options.

Option 1: Use Some Diodes.  Diodes can be placed with the cathode to Arduino output pins, and anodes to the joystick port lines. Our Arduino can then set the input to 0v when we wish to trigger a simulated push button action, and there will be no possibility of feeding +5v back to the ZXpand / ZX81.

Option 2: Use a 4066 IC bilateral Switch. This is the slightly more complicated method, though not by much. A bilateral switch can be used to act as Joystick buttons. Power is applied to the IC switch and 2 connected lines are switched on, much in the same way a relay works. There is an easy to follow tutorial to be found on the subject at Brainy Bits. Th e main downside to this method is that in order to trigger the 5 required buttons on the joystick port (up, down, left, right and fire), we would need 2 ICs and all that extra routing on a PCB that that would require.

I wired up the 4066 IC switch for one input and implemented the diode method on an other input, needles to say both of the above variations worked, producing the same results of simulating a button press / movement on the ZXpand Joystick port. I decided to go with the diode method for ease of implementation. If however we were in a position were we might be dealing with different voltage levels, such as a Teensy or Pro Micro with 3.3volts and the ZX81 with 5volts, the switch would be the better option here.


Stage 2: A DIY Cut-down Arduino Clone


If one of the aims of this project is to make something a little more permanent, then using a Uno for the end solution is not the ideal. I could just design a simple shield for the UNO, however the USB host shield will still be required, and with the addition of an extra shield on top, would leave the whole project a little unwieldy for what it actually achieves.

It seems apt to mention here before proceeding, there is such a beast as a Adruino UNO and USB host in one easy to use package. Freetronics makes the USBDroid, this could be a perfect solution for proof of concept stages, however to use this in a semi-permanent ZX81 mouse interface seems a bit of a waste.

Bare-bones Breadboard Arduino (and shiny lights)
Anyways, the last little blurb aside, the intention is to mount a USB shield on a Arduino clone board, one with all the other required elements built in. All parts, from the diodes to connectors for the the joystick port and a through port for an actual digital joystick. As I've never built one of these before, I thought it best to build a bare-bones cut down Arduino on a breadboard first, then hook that up a USB shield for some more testing.

At the risk of sounding like a paid advocate for Freetronics, I used their easy to follow Tutorial - build your own "breadboard Arduino", as the basis for the rest of the design. The rest of the design consisting of connecting to USB host shield and the ZXpands joystick port.

There are a number of Arduino pins that must be connected to the USB shield, INT, SS, SCK, MOSI, MISO and RESET. Also required are  a 5v power source (which we will eventually tap from the ZXpands joystick port) and a 3.3v input. To generate the 3.3v a down voltage regulator circuit needs to be added to the end design.

For full details on the USB Host Shield, there is an extensive manual and resources available on the Circuits at Home website. I can't recommend that highly enough.

Stage 3: Build a Prototype Mouse Interface PCB


Mouse PCB. Note the USB Host Shield Mounts on Top.
Lastly on the hardware side of thing I wanted to build a demo PCB board to bring everything together. I employed the help of Fritzing for the PCB design. Fritzing is not the most feature rich of programs, however it is approachable and presents a low learning curve to the casual user, perfect for these small projects.

I wanted the end PCB to be easily producible and assemblable at home. As such I designed the board to be primarily one sided, any tracks that had to be placed on the topside are straight. The final (or ongoing) Fritzing files will be available for download. if anybody plans to make the PCB at home, only the bottom layer needs to be etched and copper wire strands can be used for the linking via's. If preferred, the boards can be fully double sided for usage by PCB fabrication houses or the DIY experts.

I've covered the home PCB making process I use in a previous article back when I first started this blog. If you're interested refer to Creating A PCB For Mounting The Keyboard Controller.


Next Time: Software and Other Bits


Coming up in Part 2, I'll look into the software side of the project, post the schematics, code and parts list for building the ZX81 USB mouse interface. For now feel free to have one or more views of the teaser video on You Tube.






Read More