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 Webboggles.com.  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)

    Falling like a rock: Pebble is no more

    wp_20150708_22_15_12_proA few short years ago, a product came on the market that I got excited about. The product utilized ePaper, could go a week between charges and was programmable. Better yet, it was ‘crowd funded.’  The product took off, initially, and raised a lot of money from Kickstarter.  That product, the Pebble Smartwatch, was a successful kickstarter project, probably the most successful of any from that site.

    Last year, I finally got one.  I like it a lot.  The problem, though, was my smartphone. I use a Windows Mobile 10 device and there is no official app from Pebble. Eventually, someone developed a nice Pebble watch app for my favorite smartphone operating system.  For the last few months, I’ve been very happy with this setup: I see my notifications, calls, email, etc. on my watch, I don’t need to pull the phone out.  Great.

    The app even works with some of the back end plumbing from Pebble.  Nice. I get weather and some other things. Very cool.

    Last week (December of 2016) I see a rumor that Fitbit was purchasing Pebble.  I think, GREAT! My favorite smartwatch will get a much needed boost from an established company, that is also Windows Mobile friendly. Awesome. I may even get the new Pebble 2!  How sweet is that?

    Turns out, it is bitter.

    Fitbit did, in fact, buy Pebble. BUT…they only bought the services and software, NOT the hardware. So, Pebble is now history.  There is no word on when the services will cease. The watch will still work with phones, but the stuff that made it special, the heart of Pebble, will be pebble-geek-watchfaces_2-300x300going away.

    No more new watches.  Fitbit did not want the hardware. Nor did they want about sixty percent of the employees either.

    I now have one more piece of hardware that is orphaned.  Man, my ability to choose platforms is horrible.

    Zune, Windows Phone/Mobile, Palm OS, webOS for Palm, Vista, Windows 8, CED Video Disc, LaserDisk, HD-DVD, Pontiac…and, now…Pebble.  Wow.  What a record, huh?

    So, RIP, Pebble. It was nice while it lasted.

    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.

    Assignment:

    01

    Let

    Var (00-0F)

    Value (00-FF)

    Conditionals:

    02

    IF

    Var (00-0F)

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

    03

    Jump if true

    Addr (00-FF)

     

    Program Flow:

    04

    Goto

    Addr (00-FF)

    Transfer control to address

    05

    Call

    Addr (00-FF)

    Call a subroutine

    06

    Return

       

    07

    End

     

    Ends program

    Input/Output

    10

    Inkey

    Var (00-0F)

    Gets input from the keyboard

    11

    Out

    Var (00-0F)

    Outputs a value

    12

    Temp

    Var (00-0F)

    Gets a reading from the temperature sensor

    13

    Pinset

    00-FF

    Send a value to pin

    14

    Pinread

    00-FF

    Get a value from pin

    15

    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.

    Download Half-Byte Tiny Basic 3

    When I published the Tiny Basic 3 announcement, I included a link to download the installation package.  Well, that link was to the programming in Tiny Basic book.  Here is the correct link to download the source to upload to your Arduino or compatible:

    https://1drv.ms/u/s!AnSbTyHNR1Q_vvlyQ9Om0fdanKbUHg

    The link has been updated in the article as well.

    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

    HB Tiny Basic Type in Game: Hurkle

    For those of you who are old enough to know and remember the TRS-80, Cromemco or Altair will remember the game of Hurkle.

    WP_20160908_23_16_10_Pro (2)A Hurkle is a legendary beast that, even today, remains highly elusive creature.  So elusive, in fact, that few have seen a Hurkle and lived to tell about it.  Of course, you, our intrepid adventurer, are different.  For, you, you have HALF-BYTE’S Tiny Basic and an Arduino or compatible microcontroller at your disposal.  An arsenal worthy of such of hunt.

    Our Hurkle adventure takes place on a 10 by 10 grid.  You have to find the creature by deducing its where abouts on the 10 by 10 grid. Unfortunately for you, you will have from five to twenty moves in which to find the creature. Each time your adventure begins, your time is recalculated. This makes the level of difficulty even higher. You will, of course, through the use of the microcontroller, be told which direction you must travel.  Your grid follows a North-South, East-West pattern.  The X axis is West to East and Y axis is North to South. 

    This simple game is rather difficult to play.  Sure, there is a way to cheat, but I’ll let you figure that out. And, once you do, you should just type NEW and move on to something else.

    This game was originally published by the People’s Computer Company in Menlo Park California. I have adapted it from the Big Book of Computer Games, published in the early 1970’s.

    NOTE: I had originally posted a version of the game, as part of a sample code page. The listing was broken and the game did not work correctly, as published.  This one does.  Apologies for that.

    Below is the HB Tiny Basic listing.

    10  CLS: ?”HURKLE”
    20  ?”FOR HB TINY BASIC”
    99  # Converted to TINY BASIC by George Gray
    100 # HURKLE – PEOPLE’S COMPUTER COMPANY, MENLO PARK CA
    110 N=RND(10)+5
    120 G=10
    210 ?
    220 ? “A hurkle is hiding on a “,G,” by “,G,” grid.”
    230 A = RND(G)
    240 B = RND(G)
    310 FOR K=1 TO N
    320 ? “Guess #”,K
    330 ?”X=”;: INPUT X
    335 ?”Y=”;: INPUT Y
    340 IF ABS(X-A)+ABS(Y-B)=0 GOTO 500
    350 # ? INFO
    360 GOSUB 610
    380 NEXT K
    420 ? “Sorry, that’s “,N,” guesses.”
    430 ? “The hurkle is at “,A,”,”,B
    450 ? “Let’s play again. Hurkle is hiding.”
    470 GOTO 285
    500 ? “You found him in “,K,” guesses!”
    530 FOR I=1 TO 10
    532 TONE 1000,75
    534 NEXT I
    540 GOTO 440
    610 ? “Go “;
    620 IF Y=B GOTO 670
    630 IF Y<B GOTO 660
    640 ? “South “
    650 GOTO 670
    660 ? “North “
    670 IF X=A GOTO 720
    680 IF X<A GOTO 710
    690 ? “West “
    700 GOTO 720
    710 ? “East “
    720 ?””
    730 RETURN