Tuesday, December 11, 2012

CGCOLORMAX1 Serial I/O Example


Two serial ports are available on the CGMMSTICK1 and CGCOLORMAX1 for asynchronous serial communications.
MMIDE can again be used to demonstrate serial communication.
This example uses the CGCOLORMAX1, since it has on-board RS232 circuitry.

OK bear with me here. There are a lot of pin numbers that need to be kept straight.
From the Maximite manual:
COM1: uses pin 15 for receive data (data in) and pin 16 for transmit data (data out). If flow control is specified pin 17 will be used for RTS (receive flow control – it is an output) and pin 18 will be CTS (transmit flow control – it is an input).
COM2: uses pin 19 for receive data (data in) and pin 20 for transmit data (data out) in the monochrome Maximite and D0 for receive data and pin D1 for transmit data on the Colour Maximite.
We will use COM1 on the CGCOLORMAX1for this example.
The MMBasic firmware transmits data out of the Maximite on what the software refers to as I/O Pin 16. I/O Pin 16 is located on the CGCOLORMAX1 on J9 (and J9a). If you count pins from the square pin (1) on J9 and zig zag back and forth on that connector then I/O Pin 16 is located on that connector's 14th pin. On the hardware picture above I connected to J9.14 with a blue wire.
This TX signal needs to go to the RS232 circuit connector on the CGCOLORMAX1. This would be J10, along the edge of the printed circuit board. The blue wire needs to connect to pin 7 on J10. The circuit converts this TX signal to RS232 voltage levels and the TX signal then appears on J12, pin 6. This is connected to a PC serial port RS232 input via the 2nd blue wire.
The PC receives this signal from the CGCOLORMAX1 and transmits a reply to the receive circuit via a white wire connected to J12 pin 5. The RS232 circuit on the CGCOLORMAX1 converts the voltage level to something safe for the CGCOLORMAX1 and that received signal appears on J10, pin 6.
A white wire connects the J10 pin 6 signal to J9 (or J9a) Pin 12. That pin is associated with software I/O Pin 15 to receive the date.
Whew! Did you follow all of that?
A serial port application on the PC is set to the right baud (in this case 1200) to match that of the MMIDE applet.

The MMIDE applet communicates with the PC through the hardware described above.
The “Open 1” button sends the command:
OPEN “COM1:1200, 256” AS #1
to the CGCOLORMAX1 to open the serial port.
The text string that you type in the send text area is sent to the serial port when the “Send” button is pushed.
PRINT #1, “This is a test”
“This is a test” is then sent out the serial port of the CGCOLORMAX1 to the PC.
A string typed in the serial port application on the PC is received by the CGCOLORMAX1 into the serial buffer. Pressing the “Get” button sends a command from MMIDE to the CGCOLORMAX1 to get stuff out of it's buffer and then MMIDE displays it.


Purchase a CGMMSTICK1 Download of Maximite Integrated Development Environment: MMIDE

CGMMSTICK Vacuum Fluorescent Display Example


I've had a couple of these display modules setting around for a while. They have a 10-pin connector, not the 'normal' 14 that an LCD module has. I also don't have a data sheet for the display, but a couple of old data sheets for different displays. Every time I bump into the modules in my box of stuff I wonder what they look like when activated.


I decided to wire up the display to a CGMMSTICK1 to test them. It is a 5V display, so I used OC outputs pulled to 5V through a 10k resistor. The display has a reset line, data in, and clock. Data is most significant bit first.
Pins 2, 4, 6, 8, 10 are ground
Pin 1 +5V
Pin 3 clock
Pin 5 data
Pin 7 reset




The value that it takes to write "A" is 1, "B" is 2. This doesn't follow ASCII. Below is the code I used to test the display:
' VFD test code


' I/O init
' Open collector data
SETPIN 12, 9 : PIN(12) = 1

' Open collector clock
SETPIN 13, 9 : PIN(13) = 0

' Open collector reset
SETPIN 15, 9 : PIN(15) = 1


' Values for characters
_A = 1 : _B = 2 : _C = 3 : _D = 4 : _E = 5
_F = 6 : _G = 7 : _H = 8 : _I = 9 : _J = 10

_K = 11 : _L = 12 : _M = 13 : _N = 14 : _O = 15
_P = 16 : _Q = 17 : _R = 18 : _S = 19 : _T = 20
_U = 21 : _V = 22 : _W = 23 : _X = 24 : _Y = 25 : _Z = 26


_AT = 0 : _SPACE = 32

_ZERO = 48 : _ONE = 49 : _TWO = 50 : _THREE = 51
_FOUR = 52 : _FIVE = 53 : _SIX = 54 : _SEVEN = 55
_EIGHT = 56 : _NINE = 57



' Initialize and display message
VFDRESET

VFDDATA _SPACE
VFDDATA _C
VFDDATA _I
VFDDATA _R
VFDDATA _C
VFDDATA _U
VFDDATA _I
VFDDATA _T
VFDDATA _SPACE
VFDDATA _G
VFDDATA _I
VFDDATA _Z
VFDDATA _M
VFDDATA _O
VFDDATA _S
VFDDATA _SPACE

END


' VFD display reset routine
Sub VFDRESET

' pulse the reset line
PIN(15) = 1 : PAUSE 1
PIN(15) = 0 : PAUSE 1
PIN(15) = 1 : PAUSE 1

' Clear the display
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
VFDDATA &h20
' Turn display on
VFDDATA &hFF

End Sub

' Write data to display, MSB first
Sub VFDDATA (valu)

PIN(13) = 1

PIN(12) = valu AND &B10000000
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B01000000
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00100000
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00010000
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00001000
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00000100
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00000010
PIN(13) = 0 : PIN(13) = 1

PIN(12) = valu AND &B00000001
PIN(13) = 0 : PIN(13) = 1

End Sub




And the result:


Purchase a CGMMSTICK1 Download of Maximite Integrated Development Environment: MMIDE

CGMMSTICK LCD Interface Example


The Direct I/O page of MMIDE can also be used to test out an LCD display. In this example an LCD display is interfaced to the first ten (Pins 1-10 from MMBasic's perspective) and clicking the “Write” button in the 8-bit LCD Applet will write the text string that is in the text box above the button.
The LCD is wired as follows:
Pin 1 (11 on the connector) connects to the LCD data/control line.
Pin 2 connects to the LCD enable line.
The LCS read/write line is connected to ground. Ground and 5V power the LCD.
Pins 3-10 connect to the LCD D0-D7 data lines.

Prior to writing the text to the LCD, the applet writes the command sequence of &h33, &h33, &h38, &h0C, &h01. The LCD data sheet will help you understand the commands.






Purchase a CGMMSTICK1 Download of Maximite Integrated Development Environment: MMIDE


Monday, January 30, 2012

Maximite Input Example

Simple input is pretty simple to test using MMIDE. All of the 20 pins of the CGMMSTICK1 can be set to be digital inputs. To test a simple button input, just use this testing facility.

All 20 of the CGMMSTICK1 lines can be controlled for testing.

CGMMSTICK1 button input.

A simple button input for the CGMMSTICK1 would use a 10 kilo ohm resistor to pull the input line (in this case MMBasic pin 20) high, then the button press would short the line low.

Testing the input.


With the right pin set to “Digital Input” both states of the button can be tested using MMIDE to do the work. In the picture above the red square and value of 1 indicate that the button is not pushed – the resistor is pulling the input line high.


Purchase a CGMMSTICK1

Download of Maximite Integrated Development Environment: MMIDE

Maximite Sound Example

The Maximite can make sound using the 'SOUND' command. The SOUND command accepts a frequency to play for the sound and a duration to play that sound.

MMIDE has an Applet that plays Ode to Joy.

On the CGMMSTICK1 the audio connection is NOT on J1 along with all of the port lines. Instead it is at the top of the board on an unpopulated header named J5.

On J5 the top connection is ground, the bottom (square) hole is the audio line.

If you have a small amplifier, you can connect the amp to these two lines and run the Ode to Joy Applet that is in MMIDE.

CGMMSTICK1 audio connection.
Using the Ode to Joy Applet in MMIDE to play a tune.


The Ode to Joy Applet downloads a MMBasic program to the CGMMSTICK1 and then runs that program. Below is the program that is sent. You might notice that there is a test for data where the frequency could be 0. If the frequency is 0 no note is played, just a delay.

I asked my 15 year old son to write this program. He used a frequency/note chart to get the frequencies right, but the notes for Ode to Joy were in his head – he didn't have to look them up.

His frequency table was a little bit different than the table that I reproduced after the program below.

10 FOR a=1 TO 65
20 READ fr,du
30 IF fr=0 THEN
40 PAUSE du
50 ELSE
60 SOUND fr,du
70 ENDIF
80 PAUSE du
90 PAUSE 30
100 NEXT a
110 DATA 493.88,300,493.88,300
120 DATA 523.25,300,587.33,300
130 DATA 587.33,300,523.25,300
140 DATA 493.88,300,440.00,300
150 DATA 392.00,300,392.00,300
160 DATA 440.00,300,493.88,300
170 DATA 493.88,450,440.00,200
180 DATA 440.00,300
190 DATA 0,200
200 DATA 493.88,300,493.88,300
210 DATA 523.25,300,587.33,300
220 DATA 587.33,300,523.25,300
230 DATA 493.88,300,440.00,300
240 DATA 392.00,300,392.00,300
250 DATA 440.00,300,493.88,300
260 DATA 440.00,450,392.00,200
270 DATA 392.00,300
280 DATA 0,200
290 DATA 440.00,300,440.00,300
300 DATA 493.88,300,392.00,300
310 DATA 440.00,300,493.88,150
320 DATA 523.25,150,493.88,300
330 DATA 392.00,300,440.00,300
340 DATA 493.88,150,523.25,150
350 DATA 493.88,300,440.00,300
360 DATA 392.00,300,440.00,300
370 DATA 293.66,550
380 DATA 0,200
390 DATA 493.88,300,493.88,300
400 DATA 523.25,300,587.33,300
410 DATA 587.33,300,523.25,300
420 DATA 493.88,300,440.00,300
430 DATA 392.00,300,392.00,300
440 DATA 440.00,300,493.88,300
450 DATA 440.00,450,392.00,200
460 DATA 392.00,300



Note/Frequency Table for SOUND command
Note Frequency
C 16.4
C sharp / D flat 17.3
D 18.4
D sharp / E flat 19.5
E 20.6
F 21.8
F sharp / G flat 23.1
G 24.5
G sharp / A flat 26
A 27.5
A sharp / B flat 29.1
B 30.9
C 32.7
C sharp / D flat 34.7
D 36.7
D sharp / E flat 38.9
E 41.2
F 43.7
F sharp / G flat 46.3
G 49
G sharp / A flat 51.9
A 55
A sharp / B flat 58.3
B 61.7
C 65.4
C sharp / D flat 69.3
D 73.4
D sharp / E flat 77.8
E 82.4
F 87.3
F sharp / G flat 92.5
G 98
G sharp / A flat 104
A 110
A sharp / B flat 117
B 123
C 131
C sharp / D flat 139
D 147
D sharp / E flat 156
E 165
F 175
F sharp / G flat 185
G 196
G sharp / A flat 208
A 220
A sharp / B flat 233
B 247
C 262
C sharp / D flat 277
D 294
D sharp / E flat 311
E 330
F 349
F sharp / G flat 370
G 392
G sharp / A flat 415
A 440
A sharp / B flat 466
B 494
C 523
C sharp / D flat 554
D 587
D sharp / E flat 622
E 659
F 698
F sharp / G flat 740
G 784
G sharp / A flat 831
A 880
A sharp / B flat 932
B 988
C 1047
C sharp / D flat 1109
D 1175
D sharp / E flat 1245
E 1319
F 1397
F sharp / G flat 1480
G 1568
G sharp / A flat 1661
A 1760
A sharp / B flat 1865
B 1976
C 2093
C sharp / D flat 2217
D 2349
D sharp / E flat 2489
E 2637
F 2794
F sharp / G flat 2960
G 3136
G sharp / A flat 3322
A 3520
A sharp / B flat 3729
B 3951





Purchase a CGMMSTICK1

Download of Maximite Integrated Development Environment: MMIDE

Maximite LED Control Example

Using MMIDE it is pretty easy to set up a large group of pins to drive LEDs. The “Scroll LEDs Applet” on the Direct I/O page of MMIDE groups all 20 lines into two groups of 10. The groups can be scrolled separately.

Behind the scenes the applet code sets all of the lines to be outputs. It then lights the LEDs one by one from left to right. Then the applet turns the LEDs off one by one from right to left.

Using the MMIDE Scroll LEDS Applet to test a group of LEDs.

Solderless breadboard setup for demonstration.

The ten LEDs are contained in a single package. Plugged into the solderless breadboard you can see that they connect on one side to pins 21-30 of J1 which means that they are controlled by MMBasic commands as pins 11-20. Current-limiting resistors (330 ohm) tie the LEDs to ground.

Setting those 10 lines to output and then turning each line on and off will turn each LED on and off.

60% power remaining on warp drive.

The Scroll LEDs Applet will light the LEDs from left to right when the “11-20” button is pressed.

Setting the applet aside, you can write a MMBasic program to control these LEDs, too. This example code will light and extinguish the LEDs randomly.

Using MMIDE to enter some code to control the LEDs

Code can be entered to the CGMMSTICK1 using the MMBasic page of MMIDE. The following code will flash the LEDs randomly.

10 For a = 11 To 20
20 SetPin a, 8
30 Next a
40 a = 11 + Fix(Rnd(0) * 10)
50 b = 11 + Fix(Rnd(0) * 10)
60 Pin(a) = 1
70 Pin(b) = 0
80 Pause 50
90 GoTo 40

MMBasic lines 10, 20, and 30 loop to set the I/O pins 11-20 to output.

MMBasic line 40 establishes a random pin to turn on. Rnd(0) generates a random value between 0 and 1 that is multiplied by 10 to get a random number between 1 and 10. “Fix” cleans up the number by removing the fraction. The number is offset by 11 to finally be a random number between 11 and 20 for pins 11-20.

MMBasic line 50 does the same thing for a random line to turn off.

60 and 70 turn off and on these lines respectively. MMBasic line 80 pauses for a twentieth of a second before line 90 forces the whole thing to repeat.

When run, the program turns the 10 LEDs on and off randomly.



Purchase a CGMMSTICK1

Download of Maximite Integrated Development Environment: MMIDE

Maximite Hardware Interface Example

Using the CGMMSTICK1 might be very familiar or easy to understand for you, or you might be very new to all of this. Don't worry about the first examples here if you are new to all of this. This document does assume that you have some hobbyist-level familiarity with electronics and also familiarity with the BASIC language. However, by the end of this document, you should be familiar enough with the workings of the CGMMSTICK1 to feel confident that you will be able to program and utilize the CGMMSTICK1.

Before getting into greater detail on the Maximite hardware, software, and the workings of the CGMMSTICK1, I'd like to whet your appetite for the Maximite with a simple example.

Misc interfacing using the prototype for the CGMMSTICK1. The prototype pictured here was used for a lot of the initial CGMMSTICK1 testing.

It is easy to plug the CGMMSTICK1 into a white solderless breadboard and connect a USB cable to a PC to control the Maximite. This example demonstrates connecting an LED to one of the interface lines of the CGMMSTICK1.

This introductory example uses a program that runs on PC/Linux/Mac as an aid to CGMMSTICK1 project development. The MMIDE program uses the serial port that is created when you connect the CGMMSTICK1 to your computer. MMIDE can be used as a terminal, as a way to transfer files, and to assist in hardware/software development.

CGMMSTICK1 mounted in positions 1-30 of the author's solderless breadboard.

The picture shows a solderless breadboard that is set up with the CGMMSTICK1. The CGMMSTICK1 is plugged in to the solderless breadboard so that the numbered pins correspond to the numbers on the long connector. The 20 input/output lines of the CGMMSTICK1 are the connections on the right side. Ground, 3.3 volt, and 5 volt connections are some of the remaining pins on the right.

The electrical hardware used for this very simple example is a single LED and 330 ohm resistor. One CGMMSTICK1 output line is connected to the LED, and the resistor connects the other end of the LED to ground.

LED connected between I/O line #20 and a resistor (330 ohm) that goes to ground.

The picture shows the solderless breadboard with the LED example circuit. The I/O pin chosen was pin 20, the connection farthest to the right on the CGMMSTICK1. The breadboard is set up so that ground runs along the blue bus bar.

MMIDE - Select serial port and then click the Direct I/O page.

Normally your developed BASIC code would be run to turn this LED on and off. But before doing that, the MMIDE development tool can be used to verify the LED circuit. Run MMIDE and select the appropriate serial port for the CGMMSTICK1. Select the page tab to select the Direct I/O page.

Use the Blink LED Applet to test the LED that you have connected.

On the Direct I/O page you can see a little application called the “Blink LED Applet”. There are only two things to do to run this applet. First you select the I/O port connected to the LED. The little applet defaults to I/O pin #1, but can be changed to any of the 20 I/O pins.

In this example the I/O port used for the LED is port #20. Port #1 is the default when you first run the program, just select “20” from the drop-down menu.

After you have selected the port, press the “Blink” button. Your LED should start blinking. If it doesn't, recheck your circuit. One common problem is a reversed LED – just flip it around.

If you press the “Blink” button a second time, the LED blinking will cease. MMIDE sends commands directly to the CGMMSTICK1 in order to make this little applet work. The applet sets the port line to be an output port, and then sends commands to turn that line on and off over and over. When done, make sure that you turn the blinking LED off.

I'll mention again here that you might have wired up the LED circuit and could be clicking along with these instructions if you already have the CGMMSTICK1 and drivers installed, or you might just be reading along to see what this version of a Maximite can do. The setup/installation process will be talked about in more detail later.

So you've just tethered the CGMMSTICK1 to your computer, added a simple LED circuit to it, and controlled that LED with MMIDE. But now what? Isn't the little Maximite supposed to be the brains, not a big old computer running MMIDE? It is. And to make it the brains, all you have to add is some BASIC code that you write and then run on the CGMMSTICK1.

LED blinking BASIC program

If you return to the MMIDE page tab that says “MMBasic” you will be connected to the Maximite in a mode where you can type in your BASIC programs. This BASIC program in this example will do essentially the same thing as the MMIDE Applet did. Here is the program for you to enter:

10 SETPIN 20, 8
20 PIN(20) = 1
30 PAUSE 200
40 PIN(20) = 0
50 PAUSE 200
60 GOTO 20

You can run the program by entering the command “RUN” or you can click the green Run button. If you have entered the program correctly, the LED should be blinking while the program is running.

You can stop the blinking by typing Control-C or by clicking the red Stop button in MMIDE.

You can look up the commands in the program to see in detail what the program does at each step. In short, the program does about the same thing that the MMIDE “Blink LED Applet” does. The BASIC program sets the line (20) to be an output line, turns the line on, waits a little, turns the line off, waits a little, and then repeats.

This program can be saved to memory on the CGMMSTICK1 to be run again later. It can even be made to run automatically when the CGMMSTICK1 is powered up, so you would then have a fancy and overly sophisticated LED blinker. This fancy and overly sophisticated LED blinker has given you a good taste of what the CGMMSTICK1 Maximite can do.




Purchase a CGMMSTICK1

Download of Maximite Integrated Development Environment: MMIDE