Saturday, May 28, 2016

TI-Innovator Light Meter

My previous post was about a "first" program on TI-Innovator. But, most of the idea was from something else I had already done, so it was more of an adaptation of an already done task than a new idea. But it gave me the idea for my second program. The Innovator has an on-board light sensor, which gives readout of light intensity as a decimal number from 0 to 100. I thought to tie my LED array in to the sensor readout to create a digital light intensity gauge.

The LED array is same is in my Knight Rider program -- 10 LED on a breadboard with inline resistors, jumpered to the breadboard pinout and ground from Innovator. Challenge was to modify my program to light a number of LED in the array based on the sensor readout.

Basic ideas weren't hard. I have 10 LED, so divide the readout by 10, and then use a floor function to convert it to integer (used Int(... which is a standard TI-84 function). Then modify my lighting loop, instead of going 1 to 10, go from 1 to whatever the readout specified.

But I also wanted it to go down when light intensity decreased. This threw me for a little while in one of those good ways that is obvious after you thought about it, but is also why coding is a good activity for the brain. (thanks Jo Boaler. my brain grew.) The key was, unlight pin numbers to one greater than the sensor output.

The way I wrote the program, I also echo the sensor reading to the TI-84 screen. I'm sure I could code this much cleaner if I spent some time on it. Here's a short video showing it in operation. It's a cloudy day, so I couldn't get a very high light reading. This morning I was pinning the sensor at 10.



One of the things that bothers me about my program is, I don't know how to quit cleanly. I can force a quit by pressing [on] on the calculator, but that sends an error message to the screen. I also don't know why but sometimes when I run a program, the Innovator Hub beeps. The program still runs, but I assume the beeping is indicating some error state.

Anyhow, that's my exploration. It was fun borrowing the Innovator for a few days. Now I've got to return it. Thank you Texas Instruments Education Products.

*** edit 2016 May 28 16:23 ***
I'm a little embarrassed of the quality of my code, but some have asked, so here's the program that ran my meter. I'm sure it could be made much cleaner and elegant.:
For(N,1,10)
Send("CONNECT LED eval(N) TO BB eval(N)
End
0→B
0→L
While 1
Send("READ BRIGHTNESS ")
Get(B)
int(B/10)→B
Disp B
If B>L
Then
For(N,1,B)
Send("SET LED eval(N) ON")
End
Else
If B<L
Then
For(N,10,B+1,­1)
Send("SET LED eval(N) OFF")
End
Else
Disp B
End
End
Wait .2
B→L
End

Friday, May 27, 2016

TI-Innovator Hub and Knight Rider

One of the things that happens because I am a TI Instructor is I get early access to products. Back in February, during the TI T^3International Conference we were shown a product being developed called TI-Innovator. For the past week, I've been fortunate enough to work with a pre-production version of this product.


To describe Innovator the first comparison that comes to mind is Arduino. The Innovator is a programmable box, with some built in LED, inputs, outputs, light sensor, speaker, and breadboard pins.
One thing that distinguishes it is, it can be programmed directly from a handheld calculator, either TI-84 Plus CE or TI-Nspire. Note that this is the newest version of the 84 Plus. I was told that there are some USB version issues that prevent it from working with the older monochrome 84 Plus or the fairly recent 84 Plus Color. Regardless, the handhelds it works with represent a good portion of the installed base already in schools.

The loaner equipment I received consisted of a TI-Innovator box and a TI-84 Plus CE. I could have used my own handheld, but it requires a newer, pre-release version of the OS, and I chose not to install that on my own equipment.

The calculator had a few sample programs on it. These, mostly, make use of the built in LED, light sensor, and speaker. One of the built in LED is a 3-color LED, and they've got a sample program where you adjust the RGB levels to create your own output color. Fun, but I wanted to see what else I could make it do.

Some years back, when I was first introduced to Arduino, the workshop facilitators had us program what they called Knight Rider. That is, have a series of LED turn on and turn of in a sequence reminiscent of KITT in the old TV show. I set about trying to do that with the Innovator.

I found a breadboard, wire, resistors, and LEDs. My skills with Arduino made it short work to set up the electrical components. The Innovator has output pins numbered 1 through 10, which I jumpered to my breadboard. Each output pin has a ground pin, but I realized the ground is all shared, so I routed just a single ground from my breadboard back to the Innovator.

So, I set out to write the program. TI Basic on the 84 family is a very bare-bones language, without access to comments, and without some of the visual spacing cues that I gotten used to in more modern languages. For a simple program this is no big deal. But if you get a few nested For loops with some If Then Else statements, you've got to really keep track of the beginnings and endings. But, I've done it before, and I did it again.

So, I got it working. 
(I've never uploaded video before, and not sure if this will display properly)

Next, I want to take input from the Innovator's light sensor and feed it to my LED array as a sort of digital output light meter.

*** edit 2016-06-02 ***
change description of TI-Basic from "rudimentary" to "bare-bones"
*** edit 2016-05-31 ***
There's been a request for the TI-Basic code. Appended below:

For(N,1,10)
Send("CONNECT LED eval(N) TO BB eval(N)
End
For(R,1,10)
For(N,1,10)
Send("SET LED eval(N) ON")
Wait .1
End
Wait .2
For(N,10,1,­1)
Send("SET LED eval(N) OFF")
Wait .1
End
Wait .5
End