Post

Graphical unit XY-4150

Recently I have found small graphical unit in the basement. I got it for Christmas when I was about 10 years old and I had a lot of fun with it. Graphical unit was connected to 8-bit personal computer ZX Spectrum and there was small program called superplott which was brain of the unit. Graphical unit had no any firmware and it was only able receive direct sigals for stepper motors. So superplott program was responsible for translating of some basic drawing commands to signals for stepper motors.

Graphical unit

I got the idea to connect this graphical unit to my raspberry pi. It meant two challenges. Graphical unit operates with 5 volts whereas raspberry pi operates with 3.3 volts. So the first question is how to connect these two devices. And the second challange was to create piece of software which will be able to draw basic graphical elements like lines, circles, text and so on.

Connecting graphical unit to raspberry pi

Lets see connector at graphical unit side. It has four pins for controlling pen, stepper motors, directions, one pin for reading whether graphical unit is ready for drawing and one ground pin.

Pin no.SignalDescription
1PENpen up / down
2STEPone step
3X/Yvertical / horiyontal move
4±direction
5READYsignal from graphical unit whether it is ready
6GNDground

Raspberry pi has GPIO connector which operates with 3.3V whereas graphical connector operaties with 5V. So if we connected graphical unit directly to raspberry gpio we would destroy it. For this reason it is necessary to build transistor inteface which will connect two devices.

RPi interface

Controlling program

Now when we have interface between graphical unit and raspberry done it is time to create controlling program. I decided to write controlling program in c to be fast enough and you can get it from here from github.

First we need to tell the program where is our graphical unit connected. In case of raspberry pi version 2 we will use GPIO interface version 2 and we will get pointer to our printer.

1
2
3
4
5
PRINTER *prn;
if ((prn = pr_create_printer(GPIO, "2")) == NULL) {
  fprintf(stderr, "Error: Cannot access port\n");
  return -1;
}

Next we need to inicialize it - make sure you have paper loaded to your graphical unit. Now we can inicialize it and get paper variable.

1
2
pr_init(prn);
POSITION paper = pr_get_max_position(prn);

Now we are ready for drawing. Drawing commands start with xy prefix and continue with command name - xy_mr is move relative, xy_vr is vector relative, xy_ma is move absolute, xy_va is vector absolute. All commands are described in api documentation.

This piece of code will draw rectangle representing boundary of drawing area on paper.

1
2
3
4
xy_vr(prn, paper.x, 0);
xy_vr(prn, 0,paper.y);
xy_vr(prn, -paper.x,0);
xy_vr(prn, 0,-paper.y);

Whole program example is here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include "printer.h"
#include "graph.h"
#include "text.h"

int main(int argc, char **argv) {

  PRINTER *prn;
  if ((prn = pr_create_printer(GPIO, "2")) == NULL) {
    fprintf(stderr, "Error: Cannot access port\n");
    return -1;
  }

  pr_init(prn);                   /* Initialization */
  POSITION paper = pr_get_max_position(prn);

  xy_vr(prn, paper.x, 0);         /* Vector Relative */
  xy_vr(prn, 0,paper.y);
  xy_vr(prn, -paper.x,0);
  xy_vr(prn, 0,-paper.y);
  xy_vr(prn, paper.x,paper.y);
  xy_mr(prn, 0,-paper.y);          /* Move Relative */
  xy_vr(prn, -paper.x,paper.y);

  xy_set_font_size(8);            /* Set Font Size */
  xy_set_text_angle(M_PI_2);      /* Set Text Orientation */
  xy_ma(prn, paper.x - 100, 100); /* Move Absolute */
  xy_vs(prn, 7);                  /* Velocity Set */
  xy_write(prn, "Hello World!");  /* Draw text */

  xy_hm(prn);                     /* Takes pen home */

  pr_close_printer(prn);
  return 0;
}

See api documentation and explore src/main.c from project repository for more examples.

The result of this project on youtube

Graphical unit is drawing

RPi is drawing

and it can also write text

RPi is typing

This post is licensed under CC BY 4.0 by the author.