Embedded Tiny Basic: build apps for your projects

Embedded Tiny Basic: build apps for your projects

I, recently, embarked on building a useful if not glitzy digital clock. My first idea involved something retro: using four, seven segment, LED’s to look like something from the late 1970’s.  At the same time, I was also playing around with 8×8 LED Arrays, using the MAX7219 chip.  While playing with that, I connected one of my 1307 RTC’s to the array and loaded up a sketch to show the date and time on the arrays.  Then, it hit me…this is a much cooler clock and I can do more with it.

So, I built a prototype using one of my Half-Byte Console boards, minus the video, audio and Nunchucky connector.  Hardware wise, it was really simple…connect the arrays to pins 10, 11 and 12, the RTC to A4 and A5 and, for extra coolness, a BMP180 temp and humidity sensor to the sca and scl on the RTC.  Viola! modify the code to handle the BMP180 and Presto! A cool clock.

wp_20170121_01_55_22_pro

Prototype clock for developing Embedded Tiny Basic

I decided to build a second one to take to work.  I thought it might be useful to be able to throw up a custom message to scroll for when, say, I was in a meeting. The more I thought, the more I was convinced this thing needed some kind of control program that would be easily modified from, say, a smartphone and Bluetooth.

Well, I already had the genesis of that control program: Half Byte Tiny Basic.

So, I looked at the source and made a copy.  I then went in and removed stuff I would not need, like all of the graphics statements and functions. I removed the TVOut library, and  all of the video handling code. And TONE.  I miss TONE.

I did not need the Nunchuck code, so it was gone as well.  What was left was a nice, small shell of my control program.  I added the libraries for the 8×8 LED Array (MAXMATRIX) and added statements to manipulate the arrays: SCROLL to display text, SET to turn on or off individual LEDs, and DIRECTION to tell the arrays  which way to scroll the text.  I already had code to handle the DHT-11 temperature sensor, so I left that in (and decided to use it instead of the BMP180) and added T

wp_20170122_21_13_11_pro

Random dots on the clock

EMP and HUMID to scroll those values across the arrays, and added code for the RTC.I was going to add a mechanism that would interrupt the running program if a signal from the serial device was detected, but, there was already one there…the IN(0) function. So I left it. I now had a decent little programming language for the clock.  With HB Tiny Basic’s ability to autorun whatever is in the EEPROM, if it lost power, th

wp_20170119_15_23_11_pro

Clock, in action

e clock would just start running on its own. Sweet!

 

The HC-06 Bluetooth module works very nicely. It connects to the serial pins and communicates as if the device were connected directly to the controlling device-a PC or smartphone.  Everything fits nicely into these cheap pencil boxes I picked up from Wal-Mart for a buck each. They are just big enough for the HB Console board and are wide enough for the LED Arrays.  They don’t look all that impressive, until you power up the clock…the bright LED’s shine through the translucent plastic nicely.

Embedded Tiny Basic is useful for giving some level of intelligence to other wise dumb devices.  While you only have about 1K of RAM to use for Embedded Tiny Basic, I think that will be adequate for most things.  There is, currently, no motor control, but it could be quickly and easily added.  The functionality that is there is probably going to be good for quite a few projects.  If not, it can be modified quickly.  I am already seeing where it can be modified, even for just this particular project.  I have a few others in mind, so stayed tuned for those.

In the mean time, below is a list of the additions and a release date for the language is forthcoming.  I need to clean up the code-a bunch-before releasing it and, as well, making sure I have all you will need in order to compile and use Embedded Tiny Basic.

 New statements and function:
  • SETTIME hours,minutes,seconds,day,month,year
    • sets the time and date for the RTC
  • SET col,row,on or off
    • Turn on or off the LED at column, row
  • X=HOUR(0)
    • Get the current hour
  • X=MINUTE(0)
    • Get the current minute
  • X=MONTH(0)
    • Get the current month
  • X=DAY(0)
    • Get the current day
  • SCROLL var or “text”
    • Scrolls whatever is in the quotes
    • If there are no quoted strings, a variable value or number is displayed
  • DIRECTION 1-4 (1 is left, 2 is right, 3 is up and 4 is down)
    • Specifies the direction of the scrolling text, 1 is the default.
  • TIME (sends the date and time to the LED array)
    • Scrolls the current date and time
  • HUMID (sends humidity to LED array)
    • Scrolls the current humidity
  • Temp (sends the temp to LED array)
    • Scrolls the current temperature
  • X=TEMP(0 or 1)
    • Get the current temperature and put it in variable 'x'
    • A zero means use Celsius, a one means Farenheit
  • X=HUMID(0)
    • Returns the humidity to the variable 'x'

Below is the listing for the current “HELLO” app:

100 PRINT “Welcome to Half-Byte LED Programmable Clock”
110 SCROLL ” HALF-”
111 SCROLL “BYTE 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 ”
155 SCROLL “%”
160 HUMID
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
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
600 SCROLL “DONE  “

A note about how the arrays are referenced, using SET.  Embedded Tiny Basic is setup to handle up to four arrays. My clock only uses two, but Basic does not know this, so individual LED addressing has to be offset by 16.  Normally, with four arrays, the upper left LED would be 0,0. In my clock, it would be 16,0 since I am only using the RIGHT MOST TWO arrays, each are 8 across and 8 down.

Some other things to note from the listing above…the line IF IN(0)<>-1 GOTO 600 that is sprinkled through out the program will poll the serial port to see if there is a key press. If there is a keypress, we want to stop execution and goto line 600.  In this case, it just says ‘Done’ and stops. Lines 205, 400 and 410 make up a timer. Lines 200 through 590 just displays a random dot pattern, as a distraction.  We don’t want this all day, so we only let it run for about a minute.  Line 205 records the minute it started and line 400 gets the minute after each pattern is displayed.  Line 410 evaluates the elapsed time by subtracting the start time from the end time. If the result is greater than a one, it goes back to the clock routine.  Otherwise, it displays a new pattern. Lines 112 through 116 determines if it is morning, afternoon or evening.

The Scroll statement is lacking and somewhat buggy. I am working on fixing it, and adding more functionality to it, to make it more versatile, like PRINT currently is. I also want to add a mechanism to the language to allow it to receive messages, via Bluetooth, from, say, a smartphone.  Limited gameplay may also show up in a future release.

Embedded Tiny Basic will be released soon.

Alcatel’s Idol 4s With Windows 10 Mobile

WP_20170103_21_30_52_Pro (2)Ever since I saw the announcement for the Alcatel Idol 4s With Windows 10 Mobile, I’ve wanted that phone.  Well, it is out and I finally bought it.  Why? Well, many reasons, biggest being its ability to support Continuum and its price: $469 from T-Mobile, in the United States.

The current package also includes Alcatel’s VR headset and the phone comes with a smattering of impressive imagery and a couple of VR games, both of which seem more like tech demos than actual games.

The phone is gorgeous, one of the prettiest phones I’ve ever seen, on par with the Apple iPhone 4, which I previously regarded as the best LOOKING piece of hardware.  The Idol 4s looks better.  It’s glass back, metallic rim and a screen that, for now, never WP_20170103_21_31_23_Pro (2)seems to get finger prints. It is just the right weight and the screen is amazing.

The phone sports a Snapdragon 820 CPU, which is a quad core processor running at 2.15ghz.  It has 4gb of RAM and 64gb of storage, expandable with an SD card.  It also features a 21megapixel back camera and an 8 megapixel forward camera.  The camera can be started via a hardware button on the side of the device, a convenient if annoying feature.

The phone ships with a release of Windows 10 Mobile that was a bit behind. It immediately wanted to update to, I think, the ‘anniversary update’ rollup.  Fortunately, it went off without a problem.

The camera, which I had read was a weak point, is actually pretty decent.  In lower light, the colors are a bit washed out, just like the Alcatel Fierce XL I have, but the resolution is excellent and the images still look really nice.  I have not yet tried outdoors at night, but will do so soon.

Perhaps the best thing about the phone…and Windows 10…is the ability to use the device as a deWP_20170103_20_06_00_Prosktop or laptop computer.  That is where this device really shines.  While I had to purchase a USB C to HDMI converter, the converter works great and also sports a spare USB 3.0 connector (for a keyboard or mouse) and a USB C female connector for charging the device while connected.  The HDMI port is 4k capable and is full size, so you don’t need any funky sized connector or adaptor. The particular hub I purchased was from Mokin and sold via Amazon. I paid $23 for the device.

Connecting the phone to the Mokin switched it to Continuum and presented the desktop, as you would expect from a desktop PC.  The phone screen turns into a mouse, though using this instead of an actual mouse can be frustrating as there is no obvious way to ‘click and hold’ to drag things. At least, I have not figured that out yet. A bluetooth keyboard was paired to the deviwp_ss_20170103_0001ce and, bam! There I was, using my phone as a desktop.

Continuum, admittedly, is not perfect. For example, nothing I had on the SD card would work. For whatever the reason, Microsoft is not allowing applications on the SD card to run in Continuum. Also, not every application is Continuum compatible either.  And, protected content will not work in this mode.

Overall, however, Continuum seems, to me, to be the killer feature (until MS introduces x86 emulation to the Snapdragon) for Windows Mobile 10.  I can see carrying just the phone and adapter.  Most places one would need a computer will, very likely, have an HDMI monitor along with keyboard and mouse. Or, you can take the travel size keyboard/mouse.  I can forsee this more than taking my old laptop or even a tablet, though, admittedly, tablets can be just as productive.

61tocr  emL._SL1500_While running Continuum, I was able to run Word, Excel, OneNote, Facebook and take a call…at the same time.  The phone showed no perceptible slowdown at all.

The VR gimmick is just that, a gimmick and really not a reason to buy this phone.  That said, and taking into account the limitation of the screen, it is still rather impressive, at first.  The screen is HD, 1080p.  That’s a problem only because the screen gets split in two to present the left and right images.  This makes things a bit fuzzy and pixelated. However, it is not so bad as to make the experience a poor one.  Quite the contrary, it works well.  Too well, I got a headache and was a bit nauseated by it because my brain knew I was not really experiencing anything, though my eyes said otherwise.

Overall, the Alcatel Idol 4s with Windows 10 Mobile is an excellent, premium phone at a great price…half what most others would cost.  It looks great, works well and is fast.  Windows 10 Mobile needs a little work, but it is, overall, a great operating system and works very well. Don’t let the notion of a poor ‘store’ steer you away. The app system on all of the mobile devices is bad, I don’t care if there aren’t five hundred fart apps.  I don’t even care that there is no Youtube app, the web site works and there are a few third party apps that fill in for what is missing.

I think you’d be satisfied with this phone. I sure am.

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.