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.

100 PRINT “INTERVAL”;: INPUT I
110 FOR X=1 TO 50
120 DWRITE 3, 1
130 DELAY I
140 DWRITE 3,0
150 DELAY I
160 NEXT X

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

Advertisements

Using a 4 digit, 7 segment LED with Arduino

WP_20160316_22_25_00_Raw_LIDisplays.  I love them.  Pretty much anything that lights up is cool, but things that can display numbers, letters and other symbols are just awesome and making them work, even better.  One of the coolest things I remember from my childhood are seeing those red, seven segment displays. They became cool (and cheap) and showed up everywhere.  Newspapers and magazines would emulate the look in articles and stories and the ads. Science Fiction movies and tv shows ate them up.  They were everywhere.  Then…sometime in the late eighties…they sort of went away, in favor of LCD and other display tech.  Or, worse…they changed color!  But, for me, its’ those RED ones.

I just had to make something with those uber cool RED seven segments.  But, what? Well, why not a clock? Yeah, a clock.

So, I ordered one, four digit, seven segment display bar.  A Catalex.  Wow.

Well, the thing arrived and it looked cool. But, there was a problem…how the hell do I send it data?

It uses four pins: GND, VCC, DIO and CLK.

DIO and CLK can be any digital pins, that wasn’t the issue. My problem was how to do so in CODE.

A little bit of digging revealed a nice little library that worked great with the display. And, you can download it here.WP_20160316_22_24_45_Raw_LI

The trickiest part of the library is figuring out which digits go where.  Fortunately, it easy:

display.showNumberDec(number, show leading zero (true or false), number of digits, position)

Example:

display.showNumberDec(now.hour(),true,2,0);
display.showNumberDec(now.minute(),true,2,2);

The first line puts the hours in the left most digits and hours on the right most digits, starting at digit 2 (the numbering starts at zero) and with leading zeros, so 8:03 would display as 08 03.

The one thing I have not yet figured out is how to display the colon. It is there, but I have yet to turn the bloody thing on.

This is really nifty little display and was cheap…about two US dollars if you shop. I did not and paid nearly four bucks, but, it did not matter, I got it in a day, thanks to Amazon Prime.

Below is my early attempt at a clock.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
‪#‎include‬ <Wire.h>
#include “RTClib.h”
#include <Arduino.h>
#include <TM1637Display.h>

RTC_DS1307 rtc;

// Module connection pins (Digital Pins)
‪#‎define‬ CLK 2
#define DIO 3

// The amount of time (in milliseconds) between tests
#define TEST_DELAY 2000

TM1637Display display(CLK, DIO);

void setup () {

if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
}

if (! rtc.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setBrightness(0x0f);

// All segments on
display.setSegments(data);
}

void loop()
{
DateTime now = rtc.now();

display.showNumberDec(now.hour(),true,2,0);
display.showNumberDec(now.minute(),true,2,2);

delay(5000);

display.showNumberDec(now.month(),true,2,0);
display.showNumberDec(now.day(),true,2,2);

delay(5000);

}