TI to PICAXE - now it should be easy to make extra hardware!

A General Discussion forum for TI calculators

Moderator: MaxCoderz Staff

Post Reply
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

TI to PICAXE - now it should be easy to make extra hardware!

Post by benryves »

After all this talk of robots, I decided that it was time to try and interface my calculator to a PIC of some sorts. Hunting around in the boxes under my bed I found what I was looking for - a PICAXE-08 chip, firmly seated in a miniature breadboard. It wasn't great, but would have to do. Further probing unearthed a "programming board" - a PCB with a couple of sockets at one end (one a 3.5mm stereo minijack and the other a power supply connector). At the other end was a bunch of wires - a 5V, 0V, serial in and serial out. The board didn't actually do much - it had a big red button on it connected to another (unused) wire that could be use to reset the PICAXE it was connected to. It also had a capacitor, a few resistors and a diode on it for voltage supply smoothing and for doing mildly unimportant to the serial connections. It also had 3 small holes. Oh. It looks like I'd removed the 5V voltage regulator and put it somewhere else. No worries - a quick inspection of the bottom of the board and a piece of wire later and I'd connected the output of the diode straight to the 5V. If I powered the board carefully (6V was an option on my PSU) I could get 5.3V to my circuit. Not too dangerous at all!

Image
Some of my tools

I downloaded and installed the latest version of the free programming software, connected everything up, checked that I could send programs to the PICAXE-08 (with the amazing capacity for 128 bytes of code) and found an old broken TI cable. Cut it open, bared the wires, verified the plug worked with a multimeter and hooked it up directly to the IO pins 1 and 2 on my PICAXE-08. I created a blank program, sent it to the PICAXE-08. I connected the TI to the board and powered up. I was running CalcSys on my calculator, so could check the link port status. To my relief, when a pin on the PIC is acting as an input it doesn't drag the data line low (which is pretty damned important). I knocked out a series of routines that would set the individual data lines low or high, wait for the other line to acknowledge by switching to that state then resetting to the old state (which always ends up with both lines being inputs - the "INPUT" instruction sets a particular pin to be an input again.

With that done, I encapsulated all these instructions into a for...next loop that could (hopefully) send a whole byte. I then stepped through the 0-255 range in another for...next loop outputting each byte in turn. Plugged in my TI, ran Telnet83 on the calculator, sent the program to my PICAXE and ran it. Huzzah! There was the entire ASCII set, in order. To check that it was sending the right values, I looked up H,e,l and o in QBASIC and sent those values (the l twice) to see "HelloHelloHelloHelloHel..." and so on on the TI's screen. It worked!


Image
The PICAXE-08 chip and surrounding circuitry

Next it needed a getByte routine. Not a tricky task, with the stuff already in place to show that it was possible. Once written, I wrote a program that got a byte, sent it back then looped. In Telnet83, this should have meant that when typing on the keypad I should have seen my keys echoed back. How odd, I thought, when they weren't, and was getting garbled messages. I found a few keys did echo letters back, not just odd characters and noted them down. I then worked out what they should have been, in binary, then what they really were in binary. No relation whatsoever! They weren't shifted, they weren't inverted, they weren't in a flipped bit order - nothing.

I added the "debug" instruction to my code. This outputs the values of all the variables via the serial port to a window in the programming editor. Typing keys next to eachother showed that in fact I was getting the bits in the wrong order. I swapped the order around by replacing the addition of a 1 to an addition of 128, and divided the received byte each loop by 2 rather than multiplying by 2 (no shift operators in PICAXE basic). It worked! The reason that I hadn't seen any relation between what was happening before was that I was getting uppercase chars back from the PICAXE, and assumed that I was also sending uppercase chars. In fact, I was sending them in lowercase.

Image
The serial connection and power board

I optimised the code as best I could, wrote the documentation, then wrote a quick sample program that would send a variable (real A) to the calculator with a set value (pinched from the link docs I had). Sadly, I ran out of room on the EEPROM at this point. I need the PICAXE-08M, as that doubles the amount of memory available for programs. Maybe I can write a useful program on that..? The sample program that comes with the link routines is basic remote control stuff that sends the keycode for kCatalog, so the calculator will open the catalogue every 10 seconds or so when running my program.

Ideas
With the link routines as they are there is VERY little space for a useful program. However, there are some really simple programs that could be written. I'm sure that you could, with a little extra bother, write a program that allows the PIC to act as a RS232 serial device that translates serial commands into TI link protocol commands and vice versa. The problem here is that my link routines will lock up if they lose the connection and never time out, so working out how and when to transfer between the two could be interesting to say the least. It might need a few extra loops and timers to allow for graceful error handling, which are probably beyond the capabilities of 128 bytes of BASIC. However, rather than just acting as a serial bridge, why not try and build real extra bits of hardware? The PICAXE has internal functions for (in example) the Sony IR protocol. So, with a bit of extra work, I could turn my TI into a Sony-compatible TV remote control. Or, even easier, the PICAXE has simple monophonic sound routines. It would be no problem (even on this simple PICAXE-08 ) to send a "ready" byte, get two bytes (pitch, duration) then issue the instruction to play a tone then loop... and with this arrangement, all your TI would have to do is wait to see until something is trying to send it a byte inside the game loop. If it is, it grabs two bytes from the "tune" lookup table in your ASM game, outputs them via the link port, then carries on. This way you could have in-game music! Naturally, having a PIC dangling off the end of your calculator isn't great, but you've seen how much supporting circuitry a PICAXE requires - none. All you'd need is a smallish box with a 3.5mm stereo jack in it (maybe also a potentiometer for volume control). The fact that your headphones would be powered would also mean that you could also smooth the sound a little. Add a small transistor amp in there and a mini-loudspeaker (the connection to which is broken by the switch on the 3.5mm stereo jack) and you have sound hardware fit for a king.

I hope I've given you guys food for thought!

Download the code here: http://benryves.com/bin/piclink/tiLink.bas
Last edited by benryves on Wed 30 Mar, 2005 2:24 pm, edited 1 time in total.
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Wow Ben this is great stuff, i read the topic and immediately thought "Ben was excited by the robot talk" :).
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I've just checked the pricing of chips - the PICAXE-08 is £1.15, and the PICAXE-08M (with loads of extra routines and twice the memory) is £1.50. Postage and packaging is a bit silly, really (I might just go the whole hog and buy a load of bits and bobs from them).
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

I was just about edit my post and say that it is cool but i dont have any of these components then i thought, why not see how much this PIC actually costs?

Then i read this and you have already done that for me :).

I have some non-volatile memory laying around somewhere ... perhaps i could make good use of that >8).
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

The main problem is that the bigger chips with loads of pins and memory do not have IO pins that can be switched between input and output modes, so you'd have to do some funky things to get it to work (extra circuitry). The PICAXE-08M is pretty ideal. I'll grab a few parts from their site. The main problem is that the link routines take up ~88 bytes on their own, and out of the 128 bytes available for programming that's pretty sucky.
In the interim I'll probably see if I can music-up one of my old games (Fire Track 2 would be ideal, were it not already so huge).
merthsoft
Extreme Poster
Posts: 496
Joined: Tue 21 Dec, 2004 6:49 am
Location: WI

Post by merthsoft »

Which PIC compiler did you use?
Shaun
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

It's not just a PIC. It's a PICAXE, which is a PIC with a special piece of software loaded onto it which hosts a large range of features. It runs BASIC code, and doesn't need a PIC flasher (the software on the PIC understands the serial protocol, so you just download the BASIC code to the PIC). So I used the free "Programming Editor" for it.
merthsoft
Extreme Poster
Posts: 496
Joined: Tue 21 Dec, 2004 6:49 am
Location: WI

Post by merthsoft »

Oh, alright... I havn't messed with PICs (or even PICAXEs) for so long my brain died....
Shaun
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I don't have any of my good PIC stuff (I took it to school and left it in the Electronics lab one night - it all went walkies) any more. Anyway, the problem with supercool ASM PIC stuff is that no one would be able to build any hardware I designed as the PIC flashers are quite pricy. With a PICAXE *anyone* can build the hardware, providing they have a serial port and a handful of basic electronic parts. The software is free, the PICAXE chips are cheap. That was the major incentive.

Had I done it "properly" anyway, I wouldn't have used a compiler anyway. ASM is a better bet.

I've also noticed that you can set the clock speed on the PICAXE-08M (all the PICAXE chips run at 4MHz as standard but you can clock them up with an instruction). It's a bit like the 83+ (PICAXE-08 ) versus the 83+SE (PICAXE-08M).
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

Ben, I totally hate you :D That's so cool! You always do such cool things in such short time... it keeps amazing me! It took me weeks to get a PIC, make a programmer, make hardware to connect it to the calculator, and come to the conclusion that my programmer didn't work or something :( At which point there was no time left and we kinda gave it up...
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Timendus wrote:Ben, I totally hate you :D That's so cool!
Thanks! :)

Ah. I can understand your frustration if you were using a blank PIC and PIC flasher. As I keep saying, programming the PICAXE is embarassingly simple. Not as bad as the STAMPII (that's just 4 wires straight from a serial cable - the PICAXE requires two resistors!) but it still feels like cheating. However, it's kinda important that, should I develop any TI hardware it should be easy for other to copy my work.

I've been looking at the PICAXE site and some of the stuff they sell is very cool. 256K Flash EEPROM, with i2c so you can connect it to one of their i2c chips? No problem! (Shame the PICAXE-08 doesn't have i2c, but it could be made to swap TI-protocol bytes between the calc and a better chip using the serial data transfer routines). Other stuff is listed on their site - a speech synthesizer, Micromega uM-FPU floating point coprocessor... and of course, simpler stuff like IR kits.

The site is http://www.rev-ed.co.uk/picaxe/.

My main problem is that I threw out most of my electronics stuff a while back (all components scavenged from old hardware - old VCRs, old record and tape decks) so even basic stuff is tricky to find. Even wire is tricky to lay my hands on!
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

I too threw out my electronics stuff a while ago, and recently i had to go and buy a whole load of resistors and stuff because i had none :(.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Post Reply