Building your own programmable clock

20180120_204454Wow, it’s been quite a while since the last posting.  I thought we would start the year off with a cool project, a reboot of my Half-Byte Clock, featuring Embedded Tiny Basic. This time, I use an Arduino Nano and a nice canvas/wooden ‘case’ to house it all.

Instead of using the somewhat large Half-Byte Console board, I use the Nano so it fit inside the wooden frame. The frame is roughly one inch thick, just big enough for the Nano and all of the components to fit. On this particular iteration, the light sensor and speaker are on the back of the frame and, because of poor planning, the temperature sensor sticks out of the side. I intend to remedy that, but that will be later.  I am too busy to worry about that right now.

The Components

For the project, you will need:Samsung 6980

    • Arduino Nano or similar 328 based microcontroller board
    • HC-06 Bluetooth module
    • DHT-11 Temperature sensor
    • Light Sensor (I used the OSEP LIGHT 01 module)
    • Two or Three 8×8 LED Matrix displays, assembled with controller
    • DS3231 RTC for Arduino (Real Time Clock)
    • Small speaker (I stole this out of a toy cell phone I purchased at Dollar Tree)
    • Case/Frame/Canvas

My total cost is about twenty five dollars. The most costly part was the canvas frame-$8.95 at Target. All other parts were sourced from Hobby Town or Amazon.


The clock features programmability via Half-Byte Embedded BasiSamsung 6945c, though you can use whatever code you like. This project, though, is aimed at a reprogrammable device that can display the time/date, temperature/humidity, output sound, use the ambient light to brighten or darken the display and be programmable over Bluetooth.  You have about 1k of RAM to store your Basic code and, once saved, will remain in memory, even if you unplug it. Upon power up, if there is something in memory, it will auto start after five seconds.

Wiring it Up

I was going to get all fancy and draw a diagram, but I think the pin connections will make more sense to more people, so that’s what I am going to do.  There are also photos you can look at.  As my hands aren’t as steady as they once were, my soldering leaves a lot to be desired.

DHT 11:

  • Data line to pin 2 of Nano
  • (+) to +5v on NanoSamsung 7010
  • (-) to GND on Nano



  • SCL to A5
  • SDA to A4
  • GND to GND
  • VCC to +5v


Light Sensor:

  • Pin S to A0 on NanoSamsung 7008
  • (+) to 3.3v on Nano
  • (-) To GND on Nano


LED Array:

  • data to pin D12    DIN pin of MAX7219 module
  • load to pin D10    CS pin of MAX7219 module
  • clk to pin D11       CLK pin of MAX7219 module



  • GND to GND
  • + to Pin D8 on NanoSamsung 7014


HC-06 Bluetooth:

  • VCC to +5v
  • GND to GND
  • RX to TX on Nano
  • TX to RX on Nano

Sample Embedded Basic Startup Apps:

Example 1:

100 PRINT "Welcome to Half-Byte LED Programmable Clock"
111 SCROLL " Clock."
112 IF HOUR(0)<12 SCROLL " Good Morning! "
114 IF HOUR(0)>11 IF HOUR(0)<18 SCROLL " Good Afternoon! "
116 IF HOUR(0)>17 IF HOUR(0)<=23 SCROLL "  Good Evening!  "
120 TIME
125 IF IN(0)<>-1 GOTO 600
130 SCROLL ".   Temp is "
140 TEMP
145 SCROLL "F  "
150 SCROLL "Humidity is "
170 SCROLL "  Hello!  "
180 IF IN(0)<>-1 GOTO 600
190 IF RND(99)>50 GOTO 110
200 SCROLL "       "
205 O=MINUTE(0)
210 W=15
220 H=7
230 X=RND(W)
240 Y=RND(H)
250 P=RND(W)
260 Q=RND(H)
265 IF IN(0)<>-1 GOTO 600
290 SET X,Y,0
300 SET 16+(X),Y,1
310 SET 16+(X),H-Y,1
320 SET 16+(W-X),Y,1
330 SET 16+(W-X),H-Y,1
340 IF IN(0)<>-1 GOTO 600
350 SET 16+(P),Q,0
360 SET 16+(P),H-Q,0
370 SET 16+(W-P),Q,0
380 SET 16+(W-P),H-Q,0
390 IF IN(0)<>-1 GOTO 600
400 K=MINUTE(0)
410 IF K-O>1 GOTO 110
590 GOTO 230

Example 1 will randomly display random dot pattern for about a minute. It also analyses the time and inserts ‘Morning’, ‘afternoon’ or ‘evening’ in the greeting.  If you are connected via USB or Bluetooth, you can interrupt the app by sending a character followed by the ENTER key.


200 SCROLL "        "
210 W=15
220 H=7
230 X=RND(W)
240 Y=RND(H)
250 P=RND(W)
260 Q=RND(H)
300 SET 16+(X),Y,1
310 SET 16+(X),H-Y,1
320 SET 16+(W-X),Y,1
330 SET 16+(W-X),H-Y,1
340 IF IN(0)<>-1 GOTO 600
350 SET 16+(P),Q,0
360 SET 16+(P),H-Q,0
370 SET 16+(W-P),Q,0
380 SET 16+(W-P),H-Q,0
390 IF IN(0)<>-1 GOTO 600
590 GOTO 230

Example 2 is the kaleidoscope from Example 1


100 SCROLL " Half-Byte Clock "
110 H=HOUR(0)
120 IF H<12 SCROLL " Good Morning! "
130 IF H>11 IF H<18 SCROLL " Good Afternoon! "
140 IF H>17 IF H<=23 SCROLL "  Good Evening!  "
150 TIME
160 IF IN(0)<>-1 GOTO 600
170 SCROLL " Temp is "
180 TEMP
190 SCROLL "F  "
200 SCROLL "Humidity is "
215 SCROLL "%         "
220 SET 20,2,1
230 SET 23,2,1
240 SET 20,4,1
250 SET 23,4,1
260 SET 21,5,1
270 SET 22,5,1
280 FOR X=1 to 5
300 SCROLL"  "
320 SCROLL"  "
530 IF IN(0)<>-1 GOTO 600
540 NEXT X
580 SCROLL "       "
590 GOTO 110

Example 3 displays the date and time as well as the humidity and temp. It also shows an animated smiley face.


100 SCROLL ” Half-Byte Clock ”
110 H=HOUR(0)
120 IF H>=0 IF H<12 SCROLL ” Good Morning! ”
130 IF H>11 IF H<18 SCROLL ” Good Afternoon! ”
140 IF H>17 IF H<=23 SCROLL” Good Evening! ”
150 TIME
155 IF H=17 IF MINUTE(0)>=0 IF MINUTE<=10 SCROLL ”  TIME FOR name TO COME HOME!”: TONE 8,3000,3000
160 IF IN(0)<>-1 GOTO 600
163 SCROLL ” ”
170 SCROLL “Temp is ”
175 TEMP
177 SCROLL “F  Humidity is ”
190 SCROLL “%”
200 SCROLL ”   ”
220 SET 20,2,1: SET 23,2,1
240 SET 20,4,1: SET 23,4,1
260 SET 21,5,1: SET 22,5,1
280 FOR X=1 TO 5
281 DELAY 40
300 SCROLL ”  ”
320 SCROLL ”  ”
530 IF IN(0)<>-1 GOTO 600
560 NEXT X
580 SCROLL ”       ”
590 GOTO 110
600 SCROLL “Interrupted!”

Example 4 is an example of an ‘alarm’. It evaluates the hour and minute and displays a custom message and then generates a tone. It also features the animated smiley.

Samsung 7025With some clever coding, you could write a game, create an interesting art display, message board and more.  There are unused pins on the Nano that you can also use to wire up something to control (like a pet watering device, lights, etc.)  All of the sensors are available in Basic or, if you choose to write your own custom code, use the pin outs above to read or write to them. You are only limited by your imagination. And, well, that tiny bit of RAM that these things have. C’mon, we went to moon on less.


Using Half-Byte Embedded Tiny Basic to Teach

HBPortableLabIt is 2017 and we have a slew of low cost or free tools available that teach anyone how to program a computer.  Just for Windows, we have something called Small Basic, from Microsoft. It is free and has a bunch of material you can use to teach anyone, especially children, how to code. There is also Python, Minecraft and a host of other, modern tools.

So, why use something as crude as Tiny Basic? One that requires a terminal? Well, there are a few reasons you may want to do this.

Cost, for one. 

It is free. It runs on Arduino and Arduino clones.  You can use it to also teach basic electronics.

And, that is what I am doing…using it to teach not only programming, but also how computers work.  It is really more for the latter as Small Basic cannot manipulate sensors and other hardware like Tiny Basic can.  Since Tiny Basic includes instructions for reading temperature sensors and a real time clock, it is perfect for teaching things like turning on something on if the temperature gets above a given number or it if is 5 o’clock, turn off something.

I recently started doing this with my step son.  We used Embedded Tiny Basic on my ‘portable’ lab, which contains an Arduino UNO clone, a 2 x 16 LCD, breadboard and voltmeter.  We first made one green LED blink, then added a second, red LED blink.  I used Tiny Basic to explain how to talk to the LED’s and used the DELAY instruction to make the LED’s blink at a constant interval.  I also took the opportunity to teach him binary.  We had discussed it previously, but I don’t think he really got it. Until now.  Using the DWRITE statement, which takes two parameters…pin number and a zero for off or 1 for on.  Having him use that code got him to understand the concept.  Small steps.

His mind is wandering now…’I can build a robot…a game…something to tell me when Xander is coming down the hall…’ Xander is his four year old brother. 

There are those of you out there who are thinking that this is a terrible idea, using Tiny Basic, that is.  Well, no, not really.  He is getting real instruction with a more object oriented and modern language while using Tiny Basic to learn the nitty gritty of the hardware.  You do not need a modern, object oriented language to blink an LED. 

I will post future updates on our progress as well as sample code.  Below is the code we used to blink the LED’s.

110 FOR X=1 TO 50
120 DWRITE 3, 1
140 DWRITE 3,0
160 NEXT X

(For single LED-it was on digital pin 3)

Build your own ATtiny85 programmer using an UNO

attiny85programmerAs part of my ATTiny 85 learning adventure, I had to create some way to actually load code on to the 85 itself. My first go ’round was a breadboard monster. The thing I hate about bread boarding are the bloody wires.  What a mess. Once I got my game working, I set out for a better way to program the chip.  I could have bought one, but what’s the fun in that? As it turns out, it is simple to build, provided you have an Arduino UNO handy.

I decided to make a shield for the UNO. I wasn’t concerned with passing through all of the pins, so only the ones I needed are exposed.  This is something I won’t do often, so I made no attempt to pretty it up either.  The whole thing consists of an 8 pin socket, one six pin header and one ten pin header and a 10 uf capacitor. Oh, a small perf board to mount it all.

Wiring is tedious and made the same mistake as I did with the game (see my last post) as I got the four pins (5 to 8) reversed. I know, I know.

Mistake aside, it took about a half hour for me to wire it up.

One thing that was a bit problematic for me, as I have a vision impairment, was getting the pins lined up to the proper UNO pins for the headers.  That took a few tries, but I got it.

The connections are below for using an UNO:

UNO Pins

ATTiny 85 Pins (actual pin)

+5v Vcc (8)
Gnd Gnd (4)
Pin 13 pb2 (7)
Pin 12 pb1 (6)
Pin 11 pb0 (5)
Pin 10 reset pb5 (1)

In the table above, the left is the Uno, the right is the ATTiny 85 socket. You need a 10uf cap between the Uno gnd and reset.

Before you can do anything with the Arduino IDE and the 85, you must first install the support…

By default Arduino IDE doesn’t support ATtiny85 so we should add ATtiny boards to Arduino IDE. Open File -> Preferences and in the Additional Boards Manager URLs give this url Arduino IDE Attiny support. Then, open Tools -> Board -> Board Manager, scroll down the list where it says “attiny by Davis A. Mellis”. Click toinstall it. Once installed, you can select ATtiny as the board type. You will also have to select chip type (45,85,etc.) Along with the processor, you will also need to specify the speed.  1 Mhz is the default, I used 8 Mhz for the code I downloaded for the game. Adjust to suit your needs.

You also need to upload the ‘ArduinoISP’ sketch to the UNO before programming the ATTiny 85. Once you upload this sketch, the UNO will pass along to the 85 what ever you send.

For my little handheld, I had to burn the bootloader first, then upload the game sketch. Don’t forget to  set the Arduino IDE to ‘Programmer ‘Arduino as ISP’. Once the bootloader is burned to ATtiny, you are ready to upload your code.

You should be good to go.  Here is a site (from Arduino) that goes into far greater detail.

An ATTiny85 based handheld game

WP_20161228_21_29_19_Pro (2)Yes, I love gaming.  And there is nothing more satisfying, to me, than building, sometimes coding and playing something I made.  Now, I don’t always WRITE the code, after all, time is a premium these days, but I don’t mind taking something someone else did and making it work with what I built.  For this project, I was very lazy: the design is also someone else’s.  I really wanted to do something with the ATTiny85, but have not really done anything outside of playing with the Adafruit Trinket or Digispark.

So, for this little project, I wanted to also use one of my cool little ssd1306 OLED screens.  While perusing the net, I came across  Here, they are selling a nifty little kit called the ATTiny Arcade Keychain. It looks to be of high quality and the author (Ilya Titov) goes through much detail in the design and build.  There are several posts about it and the games.  The game code and schematic have been made readily available. The first of the games was breakout and that is where I started. 

To build the little game, you will need the following:

  • Attiny85 + dip8 socket
  • SSD1306 OLED screen
  • 3x push buttons
  • 2x resistors (10kOhm optimal)
  • Piezo speaker
  • 3V 2032 coin cell battery
  • perf or vero board
  • I used a little speaker out of a toy cell phone instead of the piezo. I would also recommend socketing the screen instead of soldering it directly, you don’t have to, but I wish I had now.attiny85game_schem

    One other thing to keep in mind, you will need a way to program the ATtiny 85 chip, which I will describe in a follow up post. I actually built two programmers: one on breadboard and a quasi shield for the UNO.  I like that better.

    As you can see from the schematic, it is really simple. Even so, I made a few mistakes at first.  Not paying attention to the chip pinout, I got the pins reversed from pin 8 to pin 5. I, for whatever the reason, assumed the actual pin 8 was pin 5, instead of going from pin 4 to pin 5 at the bottom of the chip. Once I figured that out (I had yet to apply power) the rest was easy. I also got SCL and SDA backward (hey, I’m old).  Once I got my mistakes corrected, I was amazed that this simple circuit was now a little game machine.  Now, you aren’t going to play Call of Duty or even Doom, but you can play many classics on the devices.  I am going to build one or two more as this was a blast. I would also encourage ordering a kit from Webboggles as well.

    My next post will discuss creating an Attiny 85 programmer for the UNO.

    WP_20161231_15_20_15_Pro (2)

    A Programming Language for a Portable Development System

    Prototyping with Arduino and compatibles is fairly easy, especially when it comes to the hardware.  A breadboard simplifies things quite a bit.  A few months ago, I realized that I did not have any, so I purchased one, in a kit, on Amazon from a company called Elagoo. The kit, for about sixteen dollars (US) contained a lot of parts and the breadboard. Well, the board is fairly small, so I decided to create a portable workspace and mount the breadboard, an Arduino UNO R3 clone, a 2 x 16 LCD and some cord organizers.  It works great, and I can take my project around. Nice.  Problem, though, is that I still need to be tethered to the computer in order to write code.

    WP_20161001_18_38_08_Pro_LI (2)This got me thinking…could I come up with a small but easy to use interface language that could be coded with nothing more than a 12 key keypad?

    The answer is yes.  So, I have come up with an initial set of opcodes for programming with nothing more than what is on my workspace. 

    This language would more resemble CHIP-8 than, say, the Arduino language.  Commands, statements and functions all use a single byte but can have one or more subsequent values for parameters.

    The tables below outline the main features. The keypad I am using (because it was less than a buck) does not have enough keys for full hexadecimal, so I had to improvise. Still working on a scheme to allow alphanumeric entry without connecting a full ASCII keyboard.  For now, the language will be limited to reading sensors, accepting decimal (though integer only) numbers. No video, serial out to the 2×16 LCD or a Bluetooth module.

    For the tables, the first column is the opcode, second is what the opcode does, third is any parameter( s ) necessary and the last is a description.




    Var (00-0F)

    Value (00-FF)




    Var (00-0F)

    01 is equal, 02 is <, 03 is >, 04 is <>


    Jump if true

    Addr (00-FF)


    Program Flow:



    Addr (00-FF)

    Transfer control to address



    Addr (00-FF)

    Call a subroutine







    Ends program




    Var (00-0F)

    Gets input from the keyboard



    Var (00-0F)

    Outputs a value



    Var (00-0F)

    Gets a reading from the temperature sensor




    Send a value to pin




    Get a value from pin


    Xfer Pin

    Var (00-0F)

    Transfers value from read pin to variable

    I would envision the interpreter being fairly small, so it may be possible to integrate several libraries for the more popular sensors, like DHT-11 temp sensor and others.

    So, what do you think?  Is this something of interest? Please post your thoughts in the comments below.

    IT’s HERE! Half-Byte Tiny Basic 3!

    randomdotsOne of the things I have really enjoyed since embarking on my Arduino journey and this blog, is seeing others take things I’ve worked on or created and expand upon it. This is especially true with Half-Byte Tiny Basic, something that started out as the work of Mike Field, who, himself used the work of another person. HB Tiny Basic is an iterative work, built on the work of others as well as myself.  For HB Tiny Basic 3, I have incorporated the work of others to make it better.  I would love to take credit for these changes, but, I cannot.  This release is strictly due to Hill Satoshi of the Hirosaki University Faculty of Education and someone named ‘Koyama’.  A Big thanks to them.

    Please visit Hill Satoshi’s page. There are a lot of great ideas, basic electronics information and some code snippets…be careful, some features of the basic there were not incorporated in HB Tiny Basic, like the motor control and PLOT (which is the same as Set and Reset.)

    Among the additions and changes are an auto load and auto run feature (requested by many of you) and a better eSave and eLoad feature.  In fact, I like much of what was done to the language and may incorporate more at a later date.

    So, what’s new?

    Two new statements have been added: NUMLED and BMP.  A new function, TREAD.  The aforementioned auto load and auto save feature.  Three new operators: %, & and |. % returns the remainder of a division, & is logical AND and | is a logical OR.

    What’s changed?

    The code to do a eSave or eLoad has changed and should be more reliable.  The startup code has changed a little, dynamically calculating the amount of ram that is available.  Ability to read in characters from the serial input as if it were the keyboard. This means you can connect to a serial terminal and enter and run Tiny Basic code without a PS/2 Keyboard attached. And a few minor tweaks here and there.

    New Statements

    The first new statement is NUMLED.  If you connect a seven segment LED directly to the device you are running HB Tiny Basic on, you can output directly to the LED.  The syntax is:

    NUMLED x  where x is a digit from 0 to 9.


    20 for I=0 to 9

    30 numled I

    40 delay 1000

    50 next I

    60 goto 20


    BMP allows you to draw a bitmap on the screen.  It is very much like the DRAW statement in old Microsoft Basics. It feature its own mini design language for you to draw on the screen. A minimum of three parameters are required: x,y,string.  Where x and y are the start points and string is the definition.

    Table of Commands for Mini Language:


    (0 is black;
    1 is white)


    (0 is black;
    1 is white)







    10 cls 
    20 bmp0,0,"ffffc00000007fff","ffffc00000001fff", "fffe0000000003ff","fffc0000000000ff", "fff80000000000ff","fff000000000007f", "ffe000000000003f","ff0000000000003f" 
    30 bmp0,8,"ff0000000000001f","ff2f00000000000f", "ff1fc0000000000f","ff000c000000000f", "ff003f000000000f","ff0020400000000f", "fc0000fc1800000f","fc00000f7f3c000f" 
    40 bmp0,16,"f80000037f7e000f","f8000000007e0003", "f01c00c0001cf7c3","f03e03c00000efcf", "f03e07c00e00000f","c03f1ff01f000003", "c03ffff03f800003","cf3ffff87fc380c3" 
    50 bmp0,24,"ce3fffffffc3c0c3","c03fc03fffe7f1cf", "c03f003ffffff3c0","ff3fff3fff0fff88", "ff1ffffffc0fff1c","ff9ffffff043ff3c", "ff8fffc03ff3ff38","ff8fffc03ff3fe00" 
    60 bmp0,32,"ffcfffff3ffffc01","ffc7fffffffffcff", "ffc3fffffffff8ff","fff3ff007ffff1ff", "fff1ff0c7fffc3ff","fff0ff0c7fffc7ff", "fffc7f0c7fff8fff","fffe3f807ffe1fff"
    70 bmp0,40,"ffff3fc0fffe3fff","ffff07c3fff07fff", "fff023ffffe1ffff","ffe0203fff83ffff", "ff07e00000003fff","fc0fe3ffff8f0fff", "fc3fe3ffff8f0fff","f0ffe3ffff8fc1ff" 
    80 shift 1,3:delay 99:goto 80


    Aviary Photo_131159334768733501

    The example code above produces this bitmap.

    New Function:

    TREAD is an alternate method for reading a temperature sensor. It does not require any additional libraries and reads the sensor directly. Usage is: Var=TREAD(pin)  where pin is A0 to A7.


    100 a=TREAD(A3)

    The example reads in a value between –30 and 50 degrees Celsius.

    Auto Load and Auto Save

    HB Tiny Basic will now load the saved program in EEPROM.  You have three seconds to press a key or the loaded program will auto run.  If you press a key in those three seconds, you will get the normal prompt as in the past.  This feature is useful if you want to use HB Tiny Basic for embedded use or simply to restart if the device loses power.  There are a lot of uses for this feature.

    Other small changes have been made, but are not worth discussing as they are mostly cosmetic or code optimizations.

    In reviewing my code, I see just how sloppy it has become. I am going to clean it up, but, until I do, please feel free to offer up any suggestions you may have for features or changes.  As always, the code is free and open.  I ask that you leave the regular header intact, at the top of the code. I want all involved to be recognized.

    Thanks and let us know what you do with Half-Byte Tiny Basic.

    Download Link: Half-Byte Tiny Basic 3

    64 bit graphical hand held

    I read a post on Hackaday about a ‘64 bit graphics’ hand held game system powered by the atmel 328…an Arduino Uno like handheld.  Well, the headline was a bit deceptive, the 64 bit part was correct, as there is an 8×8 LED matrix being use for the ‘screen’. 

    WP_20160702_03_18_57_Pro (2)This is actually something I had toyed with building for quite a while now.  I had seen several (Super Pixel Brothers being the first) and, after seeing this particular build, I thought…why not?  I have a lot of those matrices lying about, so I took my last unbuilt matrix (it was a ‘kit’) and used it as the basis of my console.

    I used my previous handheld build as the basis for this one, which was also very similar to the Hackaday build.  I guess there aren’t many different to do this.

    My build has four buttons: Reset, left, right and action.  I deviated from the article’s build and used a battery pack that has three AA batteries.  The unit ran nearly 24 hours on those three batteries.

    While I have the hardware complete, I am working on software. The article’s build has six games: space invaders, pong, racing and three others.

    So, I now have a piece of nice hardware and nothing running on it.  I’m thinking about adapting the Super Pixel Brothers to the handheld or doing a Space Invaders type game.  Not sure yet. Heck, I WP_20160630_21_10_14_Promay just put several pre-programmed messages and use the buttons to select them. 

    What would you do?  Thoughts on software/games?  Leave them in the comments below.


    Link to the Hackaday article: