Type in Game: PONG! (or, something close)

WP_20160911_21_48_56_Pro (3)Today’s type in game for HB Tiny Basic is a PONG! variant.  I cannot take full credit for this one, I found the original on a Japanese educational site devoted to teaching microcontroller programming, using Half-Byte’s Tiny Basic(!) (a variation of it, anyway) and for basic electronics.  The original was written in a variant of HB Tiny Basic and also used a 10k potentiometer for the controller.  I fixed a couple of bugs, got it to work with Nunchuk AND squeezed into a somewhat smaller memory footprint.

The game has a little bit of intelligence, it does a decent job of trying to guess where the ball will go, but, it is not perfect and it is possible to win the game.  There are some nice uses of the language, such as trying to include something like an OR statement when figuring out where the ball is going and takes advantage of an undocumented ‘feature’ of LINE: if you specify ‘2’ as the ‘color’ parameter, it simply inverses the pixels in the line.  This eliminates the need for multiple statements to draw and erase the paddles.  Quite clever.

Gameplay is super simple: the computer ALWAYS serves, the score goes to nine and stops. You are always on the right. You use the thumb stick up and down to control your paddle.

Weird things are likely to happen, it is not perfect and there’s no more room for improvement (challenge?)

Anyway, have fun!

10 CLS:A=0:B=0:W=48:H=32
30 BOX 0,0,W,H,1
40 U=H/2-3:V=U
50 LINE W-5,U,W-5,U+5,2:LINE 4,V,4,V+5,2
60 CURSOR 8,1:? A:IF A=9 STOP
70 CURSOR 3,1:? B:IF B=9 STOP
80 D=1:E=1:IF (U+V)&1 E=-1
90 X=5:Y=V+3:SET X,Y
100 C=50
110 IF C>0 C=C-1:GOTO 240
120 RESET X,Y
130 X=X+D
140 IF X=0 A=A+1:GOTO 60
150 IF X=W B=B+1:GOTO 60
160 IF X=W-6 IF Y>=U IF Y<=U+6 D=-D:TONE 440,100
170 IF X=5 IF Y>=V IF Y<=V+6 D=-D:TONE 440,100
180 Y=Y+E
190 IF Y=1 E=-E
200 IF Y=H-1 E=-E
210 IF X=W-6 IF Y=U IF E=1 E=-1
220 IF X=W-6 IF Y=U+5 IF E=-1 E=1
230 SET X,Y
240 LINE W-5,U,W-5,U+5,2
250 U=H-2-PAD(1)/8
260 IF U<0 U=0
270 IF U>H-6 U=H-6
280 LINE W-5,U,W-5,U+5,2:LINE 4,V,4,V+5,2
300 IF D=1 GOTO 370
310 IF X>=28 GOTO 370
320 IF X=27 IF A<=B GOTO 370
330 IF E=1 Q=Y+X-4:IF Q>=H Q=32-H
340 IF E=0 Q=Y-X+4:IF Q<0 Q=-Q
350 IF Q<V+3 IF V>1 V=V-1
360 IF Q>V+3 IF V<25 V=V+1
370 LINE 4,V,4,V+5,2
380 RESET X,Y
400 DELAY 20:GOTO 110

Retro Computer: Arduino Pro Mini stuffed in a keyboard

WP_20150325_16_25_02_ProSo, during the Half-Byte Console project, I purchased quite a few PS/2 style PC keyboards.  Since the project is pretty much over, I have a few of these keyboards still. They are actually fairly decent keyboards for the price.  Well, I had envisioned a future Half-Byte Computer living in something like a keyboard, like the old Commodore 64 or Vic 20.  So, I set out to build one.

I wanted to use one of my Half-Byte Console boards, alas, though, it is too big. Since I ordered a truckload of Arduino Mini Pro’s, and they are really small, I used one of them.

The first thing I had to do was figure out what I wanted in this thing and where to put the parts.WP_20150325_15_44_57_Pro

I grabbed one of the keyboards and took it apart. It is really simple, a standard membrane matrix with full travel keys.  However, even though it is a full size keyboard. there isn’t much room inside.  However, there’s enough for the mini pro, wires and not much else.  I had to cut holes for the power connector and video out.

WP_20150325_15_44_49_ProWhat I was not going to do this iteration was include sound, nunchuck or FTDI connectors.  That can all come later. I’m putting HB Tiny Basic  on the this one, so I won’t need to be programming it often. The nunchuck will be easy enough to add later, as will sound. Just not that industrious at the moment.

I cut the cable from the keyboard as the pc board inside is marked and easily accessible.  I wired it directly to the pro mini: data to pin 5 and clock to pin 4.

I decided to put the video jack on the left side,  but first had to cut a hole for the connector.WP_20150325_16_24_37_Pro  Next, I put the power jack on the bottom, where the keyboard’s cable came out. I had to enlarge that opening and super glue the connector.  Next, I wired up the video out jack and the two resistors (470 ohm and 1kohm) to the pro mini (470 ohm to pin  9 and 1k to pin 7 see my previous postings on the video out subject.)  Then the power was wired up and I tested the whole thing.  Amazingly, it worked.  It took two attempts at laying out the wire and board to get the case to  go back together and for all of the keys to work. 

WP_20150325_16_20_05_ProI now have my true retro computer, complete with Tiny Basic and blocky graphics.  Truly, an awe inspiring device.  Yep. Awe inspiring.

NOTE: yes, the wiring  is a bit sloppy, but I’m no Ben Heckendorn and this was for me.  I will clean it up when I add the other connectors.

It’s here! Half-Byte Tiny Basic 2 for Arduino and compatibles

It’s back! Better than ever. Yes, that’s right, Half-Byte Tiny Basic 2 for Arduino.  The first was so good, there just had to be a follow up.  And this version has even more fun stuff like new graphics functionality like ARC and CROSSHAIRS.  New math in SIN and COS.  Enhanced LIST statement and more.  Read on for more on the new goodies.

Tiny Basic weather?

WP_20140826_22_20_46_ProWell, yes and no. Yes in that support for the DHT-11 temperature and humidity sensor has been included. No, it won’t generate satellite images or predict snow storms. But, if you have a project where you need to capture the temperature and/or humidity, this will work.  Temperature is returned in either Celsius or Fahrenheit.  TEMP( 0 ) will return the temperature in Celsius and TEMP( 1 ) will return it in Fahrenheit. HUMIDITY with any value parameter will return the relative humidity.

EXAMPLE:

100 CLS
110 PRINT “Temperature: “, TEMP( 0 ),”C”
120 PRINT “Relative Humidity: “,HUMIDITY( 0 ),”%”
130 DELAY 4000
140 GOTO 100

New Graphics Functions

POLY

Poly will draw an abnormal circle. It is abnormal because the sides will not be ‘normal’. They will be straight lines IF the radius is small. As the radius gets larger, the circle looks more normal, then it begins to ‘explode’. Poly gives nice random like patterns or explosions for games.

POLY start_x, start_y, radius, points, color
Where start_x and start_y are the screen position to draw the poly;
Radius is width of the circle;
Points is the size of the ‘sides’ of the circle;
Color is black or white
100 CLS: CENTER: PRINT “EXPLODING”
110 R=RND(20): P=RND(15)
120 POLY 40,20,R,P,1
130 DELAY 100
150 POLY 40,20,R,P,0
160 DELAY 100
170 GOTO 110

 

INVERT

One thing you can do to get a user’s attention is to flash the screen. Tiny Basic allows you to do this quickly, by using the INVERT statement. It takes no parameters and its syntax is simply:

INVERT
100 CLS
110 CURSOR 3,2
120 PRINT “TO CONTINUE WITH”
130 CURSOR 3,3
140 PRINT “PROCESSING, PRESS C”;
150 A=INKEY(0)
160 IF A=67 GOTO 210
170 INVERT
180 DELAY 500
190 GOTO 150

210 #CONTINUE…

Starting at line 150, we wait for a key to be pressed. If it is C, goto 210 else, we invert the screen, wait a half second and do it again. If there is no delay, the screen would be just obnoxious. Inserting a delay slows it down a bit.

 

CROSSHAIRS

Crosshairs draws a graphical ‘t’ on screen. The ‘t’ can be controlled to be tight and small or apart and big. This is useful for creating crosshairs on screen for shoot them up game, driving game or some other type of game. Or, use it for art.

 

ARC

ARC draws a partial circle, a PIE piece.
ARC has eight parameters:
Start x, start y, radius, angle, end radius, color, pie, fill
Start x and y are center point
Radius is just that
Angle is the angle of the arc
End radius is the end point
Color is 0 or 1 for black or white
Pie is 0 or 1
Fill is 0 or 1 and will fill the arc or leave it open

WP_20140930_22_18_20_Pro

CENTER

CENTER will start PRINTing at the center point of a line

LIST

The LIST statement has been enhanced.  You can now list a single line, five lines or the entire program.

LIST by itself lists the whole program
LIST number- will list the program starting at number and go for five lines
LIST number. will list just that line.

MATH

COSine and SINe have been added.

a=COS( x )
b=SIN( y )
The functions were contributed by reader Jim F – Calgary Alberta Canada , thanks Jim!

OTHER STUFF

The overall interpreter is a bit speedier as there have been some optimizations and I was able to cut a lot of redundant code out. Because the functions added some RAM overhead, I lost about 30 bytes, so usable memory is around 970 or so bytes.  This is plenty for small games, control applications and for learning. It is also enough for great demos too.  If you use this on a Mega, then you will have a lot more memory. Just remember, you will need to change the pins used at the top of the code (for nunchuck, TV OUT, sound and the DHT-11 if you use that.)

To run Tiny Basic on your Arduino, download the package below. Put the Half-Byte Tiny Basic files in your Arduino directory. The TV OUT and DHT-11 libraries need to be imported into your IDE. Please follow the procedure for importing libraries. The Fonts need to go in the the TVOut font directory.  Next, open the Half-Byte Tiny Basic in your IDE and then compile and upload to your Arduino.

DOWNLOAD IT

You can download all files to install Tiny Basic 2 on your Arduino here. Tiny Basic 2  manual is here.

101_3353

Hacking the Half-Byte Console and Tiny Basic v2 (or, making Tiny Basic tell me the temperature)

WP_20140826_22_19_55_ProI had one main goal in mind when I designed the Half-Byte Console: to bring together parent and child in a learning experience. Now that the console is a reality and a few are out in the wild, I want it to do other things.  So, I thought ‘what can this do that isn’t expensive and would be easy to add to the Tiny Basic as well?’

Looking around my office, I see a DHT-11 temperature and humidity sensor. Ah ha! These are cheap, just a few dollars each.  They are also easy to access in code and, with only three pins, easy to connect.  So, this is the Half-Byte Console’s first hack: measuring indoor environment.

The DHT-11 has three pins: +5, data and Ground (-).  I chose to use D5 on the console as it is safe to use and won’t interfere with video or the keyboard.  Plus, it is easy to get to on the board. I loaded the example sketch and changed the pin reference to make sure it worked. It did. WP_20140826_22_20_22_Pro

Next, I added support for the sensor to Tiny Basic.  I am working on Version 2 and this support will be part of that release (which should be ready very soon.)

Support comes in the form of two functions:

  • x=Temp(1)
  • x=Humidity (1)

The parameter for Temp actually has meaning: if the parameter is a zero, the temperature is returned as Celsius. If it is a 1, it is returned as Fahrenheit. Any non-zero parameter defaults to Fahrenheit.WP_20140826_22_20_46_Pro

So, now the console can do something useful.  I’m anxious to get the release of Tiny Basic out and see what you all can do with this new functionality.  I am going to post more on the new features of Tiny Basic (hint…more graphics, LIST is fixed…)

In the mean time, if you have any suggestions for Tiny Basic, please let me know in the comments.

Half-Byte Console, now available

We have kits and an assembled and tested unit for sale on our eBay store.

For information on the Programmer’s Kit, click here.

For information on Half-Byte Tiny Basic, click here.

For sample HB Tiny Basic code, click here.

Half-Byte Tiny Basic is now available!

101_3346Half-Byte Tiny Basic is now complete. It supports 80×48 graphic resolution, 20 by 8 lines of text using a 4 x 6 bit character set. Audio generation via 16384 tones from a single channel. Graphical support in the form of Line, Box, Set, Reset, Circle and Shift statements and the Get function. 16 bit integer math is supported. Direct hardware access via the DWrite, AWrite statements and ARead and DRead functions. Serial port access via the SPrint and Echo statements as well as the IN function. You have access to all of the I/O pins of the 328p controller chip, the heart of the Arduino UNO and the Half-Byte Console.  The Wii Nunchuck and Classic Controller are supported via the PAD function.  LImited string handling can be accomplished (but there is no native string support.)

WP_20140701_018 (2)Functions include ABS, CHR, RND and INKEY.

Half-Byte Tiny Basic harkens back to the early days of home computing when memory was low and very expensive. Video capability was primitive (as it is, admittedly, here) and mass storage was non-existent. You only have one thousand bytes memory available for your Basic program. Half-Byte Tiny Basic is based on a version of 68000 Tiny Basic written by Mike Field. This version is optimized and specifically developed for on board development using a PS/2 keyboard and the TVOut Arduino library. And it is ideal for teaching the basics of computer programming. It is easy to learn and easy to use.WP_20140701_007

Since the Half-Byte Console is a very simple device, many shortcuts (as in the early days) had to be taken. For instance, memory is at a premium and that is why the resolution is low and the font is cramped. There is no fancy integrated development environment, heck, there isn’t a real editor: you make a mistake on a line, you type it in again. The LIST WP_20140701_027 (2)command is very primitive: LIST will type out the whole program, LIST <line number> begins typing out the program starting at <line number> while LIST <line number>- will type out JUST that line.  You can only SAVE one program as there is currently no mass storage (but, I am working on a better solution, stay tuned!)

Half-Byte Tiny Basic is not perfect, but is works well and is a great tool for teaching. Best of all, you can download it for free.  A short document explaining the commands,statements and functions is included. You get the source code and the documentation all for free.  A nicer book/manual will soon be available for a small cost. The book written so that someone with no experience can pick it up, read and follow it to gain a basic understanding of how to write a program and get it to work. This book will also be part of the Programmer’s kit for the Half-Byte Console.

SAMPLE CODE

Here are a few pieces of sample code:

Kaliedoscope 3

100 CLS
110 X=RND(79)
120 Y=RND(47)
130 P=RND(79)
140 Q=RND(47)
150 SET X,Y
160 SET 79-X,Y
170 SET 79-X,47-Y
180 SET X,47-Y
190 RESET P,Q
200 RESET 79-P,Q
210 RESET 79-P,47-Q
220 RESET P,47-Q
230 Z=RND(100)
240 R=RND(20)
250 IF Z>92 CIRCLE 40,24,R,1
260 IF Z>92 FOR I=1 TO R
270 IF Z>92 CIRCLE 40,24,I,0
280 IF Z>92 NEXT I
290 GOTO 110

Half-Byte Demo

100 CLS
110 FOR K=0 TO 4
120 CURSOR K,3
130 PRINT ” Half-“
140 CURSOR 14-K,3
150 PRINT “Byte “
152 DELAY 1000
160 NEXT K
170 FOR R=1 TO 20
180 CIRCLE 38,21,R,1
184 DELAY 50
186 CIRCLE 38,21,R-1,0
190 NEXT R
195 CIRCLE 38,21,R-1,0
197 DELAY 1000
199 X=7
200 A=67:GOSUB 900
210 A=79:GOSUB 900
220 A=78:GOSUB 900
230 A=83:GOSUB 900
240 A=79:GOSUB 900
250 A=76:GOSUB 900
260 A=69:GOSUB 900
400 GOTO 100
900 FOR Y=0 TO 6
910 CURSOR X,Y
920 PRINT CHR(A);
930 DELAY 250
940 CURSOR X,Y
950 PRINT ” “;
960 NEXT Y
970 CURSOR X,7
980 PRINT CHR(A);
985 X=X+1
990 RETURN

You can download a PDF of the Half-Byte Tiny Basic Guide here.

You can download a ZIP file with the Half-Byte Tiny Basic source, Guide and some example code from here.

You can download the Half-Byte serial terminal for Arduino here.

The serial terminal runs on another Half-Byte Console or Arduino that has the Video and Audio output modifications and runs TVOut. Connect the two devices using TX,RX and GND pins. This allows you to use the serial terminal as an output device, providing a second screen to your console. The terminal provides 128×96 graphics and 22×16 lines of text. The terminal software interprets special code for clear screen, set pixel, reset pixel and box.

PLEASE NOTE:

Half-Byte Tiny Basic Copyright (c) 2014 George Gray

Arduino Tiny Basic Copyright © 2011 Mike Field

TVOut Library Copyright© 2010 Myles Metzer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be  included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

From design to built: the Half-Byte Console

IMG_4376For years, I yearned to build my own computer and, recently, as I have written here, I did. Only, this time, the computer I built was not someone else’s design, but my own. Now, for some, that’s not a big deal. For me, not being an engineer, it is big. 

Last fall, I had built an Arduino, copying someone’s schematic. It worked and worked well. I got to playing around with Arduino more and more, discovering the video and audio capability and the ability to code for this thing, rather easily, just got me more and more intrigued.

I worked on a port of Tiny Basic, nearly rewriting the wonderful Mike Field Tiny Basic for Arduino. I’ve added a ton of features-graphics, audio (ok, beeps), hardware support…etc. And I’ve optimized it to not only work with a PS/2 Keyboard and video, but it also gives you nearly 1k of RAM to use for your Tiny Basic programs. That may not sound like much, but there is a surprising amount of things you can with ‘only a k’ of RAM.

So, now I have this nifty little computer, that is not only a throwback to the home computers of the 1970’s, it is also fun to build and program.

As I am using the TVOut Arduino library un altered, pretty much any program or game that uses this library and a 328p compatible Arduino will work on the console.

So, how did I design this thing?

hbc1I downloaded the Fritzing schematic/pc board/breadboard designer package. It is free and you can generate industry acceptable ‘gerber’ files that can then be used to create a professional look printed circuit board.

I studied the basic circuitry for a 328p based Arduino compatible microcontroller. Turns out, it’s really simple. With encouragement from my wife, son and friends, I set out to design something and then turn into a product.

I had to decide what was going into the computer, what features. Well, the idea I had was that this be a fun project for parents and children to do together. Mom or Dad do thbackpice soldering and the kids help with inserting the parts and then programming the computer.  Games had to be a priority. So, the Wii Nunchuck became the controller. Unfortunately, only one is supported, due to the way it works.  (I have since discovered a way to allow more than one. That will be in the next version.) Video and sound have to be there. We need to be small and somewhat expandable.

BLACK_6_5_2014 6_03_05 PMMy first prototype looked great. I built it up on a proto board and it worked fine.  My proto, however, didn’t fully replicated my design.  After building it, I made changed to the design, but did not reflect them all on the proto. I realized, later, I should have.

So, I finish up my design, run the rules check and it passes. I study it for several days before sending it off to Fritzing to have one board made. That was expensive…forty dollars for the one board. Wow, there’s no way I can ‘mass’ produce these things at that price.  So, I search and search for a cheap fab house.  That search lasted a couple of months.  In the mean time, the board arrives, I photograph it and then put it together.  I solder the last connector and plug in the 328 chip.  Insert the power and…viola! NOTHING.  Scratching my head, I check my work and try again. Nothing happens.  I study the power circuit. I check voltage. NOTHING.XANDER - WIN_20140326_212243

Hmmm…So, I check polarity of the connector and…BINGO! The pins are backward.  This is where my inexperience with Fritzing comes in.  I misread the symbol. Damn. So, I cut the traces, solder jumper wire and try again.

This time, the Tiny Basic welcome message displays. Success! So, I wire up the keyboard because I realized that I also had the PS/2 connector wrong.  So, after correcting my mistakes with Fritzing, I get down to ‘burning in’ the board.  I run battery life tests (12 hours running constant random graphics, not too bad as it is also generating video) and communications test. Everything working great, even the Wii Nunchuck works fine.  Now, I have to find cheap components and a fab house.

Finding the components was easy, for the most part. No one dealer  had everything.  Weird how PS/2 keyboard connectors and board mounted RCA phone jacks are hard to find now.

101_3326During my experimenting and eBay purchasing, I struck up a relationship with a Chinese vendor.  I inquired about fabbing the boards and they could do it really inexpensively. So, that made this possible.  I finished up revising and cleaning up my design. I checked, rechecked and double checked. It’s going to be perfect.  Off it went to the fab.  I buy parts.  The parts begin showing up. Not too long after the parts started to roll in, but the boards did too.

My, were they pretty.

101_3346I grabbed one of the blank boards and photograph it. Then, as with the first, I build it up. Plug it in and…it worked! First time. Whew!  Finally, it works. Well…not so fast.  Everything worked but the bloody Nunchuck. My heart sinks.  Upon close examination, I see that, while I had put the labels to the connector pins correctly, I neglected to re-arrange the ground and 3.3 volt pins.  Man. I have hundreds of these boards. What the hell am I going to do?

Ah…I’ll correct the issue on the Solarbotics made Nunchucky adaptor board.  So, I fix the problem on the adapter and try. It works!  Awesome. IMG_4386

Now, I have a nice design that works. It has audio, video, game controller (that you can unplug from the main board) and it can talk, via serial, to other devices. 

I have a ton of ideas for follow up accessories, the first of which is the PS/2 keyboard and Tiny Basic programmers kit.  The standard kit is just the console, Nunchuck adapter and a 9volt battery clip. The programmers kit is the standard kit, plus a PS/2 connector, Tiny Basic in the 328, A Learn to Program with Tiny Basic manual and either a PS/2 Keyboard OR a USB to PS/2 keyboard adapter. I am also working on a real time clock, Bluetooth connectivity and an experimenters kit. 

This has been a fun project and one I thought I’d never do.  I’m a programmer,not a hardware engineer. And, anything more complicated will, likely, require a real engineer. But, in the mean time, I have more projects like this. 

IMG_4394The console and Tiny Basic will be licensed as the original works are, I will post that later.  I will post the source code for Tiny Basic, the schematic, parts list and Fritzing files.  I will be selling the blank boards and the two aforementioned kits with printed documentation very soon.

In the mean time, if you want a blank board, I am selling them now.  Go to the Half-Byte eBay store and pick one up.

Bluetooth Communication for the Half-Byte Console (or how to make your HC-06 work)

WP_20140619_007Wireless transmission of data is mostly preferable to using physical connections and, in the Arduino world, it is no different. If you want a network of sensors or need to have several microcontrollers communicate with each other or a PC, you may not be able wire them together. Fortunately, there are several wireless alternatives that are simple and inexpensive.

While scouting eBay and other sources for parts for the Half-Byte Console, I found these cheap, simple and cute little Bluetooth modules. They also happen to work with the serial connection on your Arduino. If you decide to use the standard serial pins (RX/TX) then coding the module is a no brainer: just use Serial.Write, Serial.Print, etc. to send data or Serial.Read(), etc. to get data. If you need to use other pins, use SoftwareSerial.  It really is that simple.

The particular module I have is the JY-MCU BT-Board v1.02pro (HC-06).  It was $4.99 on eBay.

Wiring it up was simple: WP_20140619_014

  • RX->TX
  • TX->RX
  • GND->GND
  • VCC->+5v

When the module is powered up, and found by another Bluetooth enabled device, it shows as ‘HC 06’.  The key is ‘1234’.  Once the device pairs with the HC-06, you are now ready to communicate. On a PC, you’ll need some kind of terminal app that can access a virtual serial port or Bluetooth directly. I found a Windows 8 Modern Appbtserialterm called Bluetooth Serial Terminal and it works great (it is also free from the Windows App Store.) The application is very simple, there’s no real setup as it detects BT devices and configures itself accordingly.

The module defaults to 9600baud, which is a bit slow, but you can reconfigure it. I chose to leave it at the default since the particular application I have in mind will not require more than that.  I’ll spare the dirty details of configuring the module and leave it to ‘Stan’ at the 42bots blog.

Since the module is serial, it works with Arduino Tiny Basic.  As long as you keep it on the RX/TX pins, you can use the built-in Tiny Basic serial statements to talk to and send data over bluetooth.

SPRINT “Hey ma, I’m on Bluetooth now!”

will send that sentence over Bluetooth and be displayed on the BT enabled device. You can IN( 0 ) to receive data from the module. It is very simple.

WP_20140619_011This little module, coupled with an Arduino Pro Mini and some sensors would make a cool little environmental (one use) device. No screen would be needed, which brings cost way down. Instead, you could use your BT enabled phone or tablet and when it gets near the device, they auto pair and you can open up your terminal or, perhaps, dedicated app and get the data streamed to you. I envision, under Windows 8 or Windows Phone 8, having a live tile that would display this data for you. 

It also opens up some cool game ideas. Awhile back, I wrote of using Basic Stamps to create a meshed Star Trek like game.  These little BT modules could make that really easy to do.  There are always possibilities.

I am really impressed with this little module. It was super simple and really cheap and, it just works.

For a cheap, simple and effective means for wireless data in your Arduino projects, these little gems seem to be the way to go.

The archive. Confetti. Type in programs. Read.

syncmagAs part of putting together a package of materials for Half-Byte Tiny Basic, I came across several gems that either reminded me of my early computing days or are cool enough for me to write about.

One such site is the Internet Archive. (The link takes you to the magazine rack. From there, use the search bar near the top of the page, and search for, say, ‘Byte’. Or computer magazines.)

Now, this site has a treasure trove of material, including the Way-Back machine. The Way-Back machine allows you to enter a URL and then see it in various incarnation through the years. It’s really interesting to see how the Internet and web design have developed. But, that’s not what caught my eye, as cool as that is.

No, it was the site’s collection of magazines, specifically, computer magazines. You can download scanned images of whole magazines, going back to the mid 1970’s.  I remember quite a few and even had many of them. At one point, I had the first ten years of Byte Magazine, THE computer magazine of the 1970’s and ‘80s.

Now, the magazines I was looking for, Dr Dobb’s (another one that I had the first seven years worth, but, no longer) Journal and a bunch of Sinclair ZX related magazines. Unfortunately, CMP has Dr Dobbs, so you won’t find it here, however, you will find Byte and a whole slew of Tandy, Commodore, Atari and, of course, Sinclair related magazines.

The quality of the scans various widely. Some are really nicely done and care taken to line them up correctly, etc. BUT…some were not cared for very well. But, hey, they ARE scanned and there’s no charge to download them, so…all considered, it is a treasure trove that I’ll not complain about.

So, I did find a few things that I was looking for, namely some type-in BASIC programs.  I am putting together a booklet of short type-in programs-games-to use on the Half-Byte Console and Tiny Basic. And, the Sinclair flavour of BASIC is close and the ZX-81 lunarzx81specs are very close to the Half-Byte Console, so the conversion is pretty easy. I will also be writing about such a conversion process. The downside is that there are few examples of Tiny Basic software, or other BASIC for that matter.  Type in software is a thing of the past and pre-dates the Internet. 

I certainly remember the thrill of getting my next issue of Computer Shopper, Compute! or Sync Magazine and anxiously looking at the type in games or utilities and converting them to whatever computer I wanted to use them on.  I had my ZX-81, my TRS-80 Color Computer and, eventually, a Xerox 820 that ran CP/M and several flavors of Basic. Of course, the 32k Extended Microsoft Basic was my favorite, but the Xerox had no graphics, so I spent a lot of time on the ZX or the CoCo. 

Typing in games was great. I got to learn what the program did, hone my typing skills and felt accomplished when I typed that last line, saved and then type RUN.  Inevitably, of course, I would have made a mistake and would have to fix it. Sometimes, I made no mistake-the listing was just wrong. Other times, I made a mistake converting the code and would have to correct it. Sometimes, that took minutes. Other times…DAYS. Oh my. I remember one game that took me hours to type in on my CoCo. I had an original CoCo, which had a crummy key board. UGH.  I hated that thing.  Never replaced it though.  Should have. 

Anyway, I get through typing in this game. Saved it on two different tapes, just to make sure. I type RUN, press RETURN and…nothing.  The damned computer hung.  I had to TURN IT OFF! Now, this meant re-loading the game and trying to figure out why it choked.  Loading anything from a tape was a laborious and risky task.  Will it load? You pray, even if you don’t believe, you pray that the Tape Gods are  favorable to you today and will allow the software to load.  Fortunately, I had not upset the Tape Gods and all was good.  I figured out that I had reversed two numbers that were in some MACHINE CODE that was getting POKED into memory and run.  So, I fix that.  Re-save. On three tapes, this time. I want to be safe.

I type RUN.

Boom! Confetti!

It started. 

I followed the directions and pressed the space bar to start the game.

Boom! No Jimmy Johnson. No Confetti. Only a damned Syntax Error and that stupid multi-colored cursor blink at me.

This problem, a multi-statement line where I left out a bloody colon in the middle of the line. That…took a week to find.  I ended up just retyping the line. Three times! I mistyped that same line two different times. The third time was the charm.  This time, there was confetti. And, it was good.

Ah, those were the days. ‘Free’ and open source software before it was called that. Well, not totally free. You still had to buy the magazine.

So, sit right back my friends, you are sure to get a smile…or a chuckle. Once the console is out of the door, expect to see a few type in games or utilities on these pages from time to time.

HALFBYTE Console Tiny BASIC update

XANDER - WIN_20140222_110454 (2)The HalfByte Console is nearly complete. The hardware design is pretty much done and a prototype built. It is a fairly simple ATMega328 based computer with audio and video out, Wii Nunchuck interface (the Wii Classic Controller also works), PS/2 Keyboard support and will run off of battery, wall wart or can be powered via FTDI.  It is pretty small, about the size of an Arduino UNO. It is designed to be easy to use and build. (The console featured in the photo above is the first prototype and is not the final design. The final prototype is not presentable here, this one looks nicer.)

One of the goals of the console is to aid in learning to program.  For now, this can be done in two ways: standard Arduino IDE or on console via Tiny Basic.

Yes, Tiny Basic. 

I have adapted the wonderful little version of Tiny Basic from Mike Field.  I did this for the XGamestation and have done it for the HalfByte Console as well. This version of the language supports graphics, low level hardware access and the Nunchuck. It is standard Tiny Basic in every other aspect: integer variables, single letter variables, line numbers, GOTO, small memory footprint and is easy to learn. It makes the perfect introduction to programming.

Because the 328 is limited, RAM wise AND the video takes up most of that RAM, we are left with only 726 bytes of memory to use for programming. The 52 bytes for variable storage and stack already have RAM dedicated, so you do not need to factor that in.  As such, the big feature I wanted to include, SD Card support, could not be done.  To implement FAT16, you need a 512 byte buffer and we simply do not have that, so, for now, EEPROM is used to store a program. Again, memory issues only allow for ONE saved program.  Since RAM is low anyway, we can fit it in the 1k EEPROM space we have.  And, remember, this is more of a learning tool than a ‘serious’ development platform.  The console can, of course, be programmed for games and other applications outside of Tiny Basic and there are a lot of really clever games that utilize the TV OUT library.

So, what can we do with Tiny Basic? Well, even with these limitations, a lot.  Throw some motors on the console and control them with Tiny Basic.  Add some LED’s and make them blink.  Create small, clever games.  Your imagination is the limit.

I won’t discuss the basics of BASIC, but would like to touch on the hardware specific enhancements, like graphics and controller support.

GRAPHICS

There are five graphics statements and one function.  The five statements are:

  • SET x,y
  • RESET x,y
  • LINE startx,starty,endx,endy,on or off
  • BOX startx,starty,endx,endy,on or off
  • CIRCLE startx,starty,radius,on or off

The function is:

  • <var>=GET(x,y)

GET will return the setting of a pixel at x,y. If the pixel is lit, it returns a TRUE (1) otherwise a FALSE (zero).

For LINE, BOX and CIRCLE, ‘on or off’ means a one for on and a zero for off.  If you BOX a section of the screen with text or other graphics, you can set ‘on or off’ as a 2 and it will invert that section of the screen. This is a good way to highlight text.

HARDWARE ACCESS

There are two statements that can set pins on the 328:

  • AWRITE <pin>,on or off or value (sets the ANALOG pin)
  • DWRITE <pin>,on or off or value (sets the DIGITAL pin)

There are three functions to read values from the hardware:

  • <var>=AREAD(<pin>)
  • <var>=DREAD(<pin>)
  • <var>=IN( 0 )

AWRITE and DWRITE will send a value to the specified pin. A zero sets the pin LOW, a one sets it HIGH, any other value is simply sent to the pin. AREAD and DREAD will return a value from the specified pin. NOTE: the ‘A’ in AREAD and AWRITE specify the ANALOG pins, while the ‘D’ means DIGITAL pin.

IN( 0 ) returns the current value from the RX pin (D0) on the 328p chip. This could be useful to monitor the serial interface for incoming data.

SAMPLE CODE

Since adding support for graphics and the Nunchuck, simple games like Space Invaders or simple shoot them ups are fairly easy.  Nunchuck support is complete, too…you can not only read the buttons and the thumbstick, but also the accelerometer. While the Classic Controller will work, no support for it is included. Maybe a later version.

The first sample I want to show is Kaliedoscope:

100 CLS
110 X=RND(40)
120 Y=RND(20)
130 P=RND(40)
140 Q=RND(20)
150 SET X,Y
160 SET 80-X,Y
170 SET 80-X,40-Y
180 SET X,40-Y
200 RESET P,Q
210 RESET 80-P,40-Q
220 RESET 80-P,Q
230 RESET P,40-Q
240 IF INKEY(0)=27 STOP
250 IF RND(100)<95 GOTO 290
260 BOX 0,0,79,39,0
270 FOR I=1 TO 500
280 NEXT I
290 GOTO 110

This little gem will display random pixels that are mirrored in four quadrants on the screen.  Randomly, the screen will invert. It can be quite mesmerizing.

Here’s a Nunchuck example:

100 X=1: Y=1 #INITIALIZE OUR START
110 SET(X,Y)
120 P=PAD(0) #GET THE X VALUE
130 Q=PAD(1) #GET THE Y VALUE
140 IF P>200 X=X+1 #IF VALUE IS MORE THAN 200, GO RIGHT
150 IF P<100 X=X-1 #IF VALUE IS LESS THAN 100, GO LEFT
160 IF Q>200 Y=Y+1
170 IF Q<100 Y=Y-1
180 SET(X,Y) #LIGHT UP THE PIXEL
190 IF PAD(3) STOP #IF Z BUTTON IS PRESSED, STOP
200 IF PAD(2) RUN #IF C BUTTON IS PRESSED, RESTART
210 GOTO 120 #DO IT AGAIN

This bit of code is akin to an etch-a-sketch. PAD is the function which reads the controller. The parameter passed tells Tiny Basic which part of the controller to return a value: the x and y axis for the stick, the C and Z buttons and the accelerometer.  the modes are:

PAD number

Return value

0

Thumbstick x

1

Thumbstick y

2

‘C’ button

3

‘Z’button

4

Accelerometer x

5

Accelerometer y

6

Accelerometer z

BLINKY

This example will blink the PIN 13 LED:

100 FOR K=1 TO 50
110 DWRITE 13,1 #TURN ON LED ON PIN 13
120 FOR I=1 TO 500 #DELAY
130 NEXT I
140 DWRITE 13,0 #TURN OFF THE LED
150 FOR I=1 TO 500
160 NEXT I
170 NEXT K

Looking at the code, you see that line 110 turns on the LED and 140 turns it off.  120 and 150 create a delay so you can actually see the LED turn on and off.  We could add a line between 120 and 140 to test for the status of pin 13:

115 IF DREAD(13)=1 PRINT “LED IS ON.”

165 IF DREAD(13)=0 PRINT”LED IS OFF.”

Now, these lines are rather pointless in the example, because we know they SHOULD be set accordingly, you can see the utility of them. 

As you can see, there is a nice foundation here for something that can be quite useful in not only teaching a child how to program (or, anyone) but it is also useful for scripting hardware functions as well.  This version of Tiny Basic should run, as is, on an Arduino Mega2560. On that board, you will have more RAM to work with and create some really nice, useful or fun code.  You could also modify the interpreter for a slightly high resolution.

I have prototyped using a second 328 strictly for video generation. This gave me an effective resolution of 128 x 96 graphics and 22 by 12 text.  However, communication between the two is serial and I did not fully implement graphics. Once the console is complete, I will return to this side project and fully develop it. Perhaps HB Console II will feature two 328 chips.

Developing this Tiny Basic has been fun and brought up many memories of when I was a wee lad, experimenting with this new thing called a home computer with my Dad.  I hope this can create similar memories for parents and children going forward and, along the way, spark an interest in these nifty little computers.

NOTE: I am currently stumped with the PIC16 version of TINY BASIC.  I have the interpreter working very nicely with low res color graphics, sound and hardware support. BUT…I’ve been stumped with a big bug in the SAVE-LOAD code.  We utilize the SD Card (FAT16) library and can read and write and get the directory listing. If you are familiar with the PIC and know C and would like to help, PLEASE drop me a note.  I can’t reward you with a financial reward, but you will have my eternal thanks and recognition both here and in the Tiny Basic code.

EDIT: since publishing this post, I have been able to squeeze 200 more bytes into RAM by moving the keyword scan tables into PROGRAM MEMORY. More optimization may be possible. Who knows, maybe I can get a whole 1k of RAM. That’s what the original ZX-81 had.