So, I wrote a simple program to test the link between my Arduino MEGA 2560 and my TI-84+. It's just using 4 pushbuttons to send remote commands for the 4 arrow directions. Here is my code:


Code:
#define tLeft 22
#define tUp 23
#define tDown 26
#define tRight 27
#define TIring 6
#define TItip 7
#define ERR_READ_TIMEOUT 1000
#define ERR_WRITE_TIMEOUT 2000
#define TIMEOUT 4000
#define GET_ENTER_TIMEOUT 30000

uint8_t kLeft [4]  = {0x23,0x87,0x02,0x00};
uint8_t kUp [4]    = {0x23,0x87,0x03,0x00};
uint8_t kDown [4]  = {0x23,0x87,0x04,0x00};
uint8_t kRight [4] = {0x23,0x87,0x01,0x00};

void setup()
{
   resetLines();
   
   pinMode(tLeft, INPUT);
   pinMode(tUp, INPUT);
   pinMode(tDown, INPUT);
   pinMode(tRight, INPUT);
}

void loop() {
   if (digitalRead(tLeft))
      par_put(kLeft, 4);
   else if (digitalRead(tUp))
      par_put(kUp, 4);
   else if (digitalRead(tDown))
      par_put(kDown, 4);
   else if (digitalRead(tRight))
      par_put(kRight, 4);
}

void resetLines() {
   pinMode(TIring, INPUT);           // set pin to input
   digitalWrite(TIring, HIGH);       // turn on pullup resistors
   pinMode(TItip, INPUT);            // set pin to input
   digitalWrite(TItip, HIGH);        // turn on pullup resistors
}

static int par_put(uint8_t *data, uint32_t len) {
   int bit;
   int i, j;
   long previousMillis = 0;
   uint8_t byte;

   for(j=0;j<len;j++) {
      byte = data[j];
      for (bit = 0; bit < 8; bit++) {
         previousMillis = 0;
         while ((digitalRead(TIring)<<1 | digitalRead(TItip)) != 0x03) {
            if (previousMillis++ > TIMEOUT)
            return ERR_WRITE_TIMEOUT+j+100*bit;
         };
         if (byte & 1) {
            pinMode(TIring,OUTPUT);
            digitalWrite(TIring,LOW);
            previousMillis = 0;
            while (digitalRead(TItip) == HIGH) {
               if (previousMillis++ > TIMEOUT)
               return ERR_WRITE_TIMEOUT+10+j+100*bit;
            };

            resetLines();
            previousMillis = 0;
            while (digitalRead(TItip) == LOW) {
               if (previousMillis++ > TIMEOUT)
               return ERR_WRITE_TIMEOUT+20+j+100*bit;
            };
            } else {
            pinMode(TItip,OUTPUT);
            digitalWrite(TItip,LOW);      //should already be set because of the pullup resistor register
            previousMillis = 0;
            while (digitalRead(TIring) == HIGH) {
               if (previousMillis++ > TIMEOUT)
               return ERR_WRITE_TIMEOUT+30+j+100*bit;
            };

            resetLines();
            previousMillis = 0;
            while (digitalRead(TIring) == LOW) {
               if (previousMillis++ > TIMEOUT)
               return ERR_WRITE_TIMEOUT+40+j+100*bit;
            };
         }
         byte >>= 1;
      }
      //delayMicroseconds(6);
   }
   return 0;
}

static int par_get(uint8_t *data, uint32_t len) {
   int bit;
   int i, j;
   long previousMillis = 0;

   for(j = 0; j < len; j++) {
      uint8_t v, byteout = 0;
      for (bit = 0; bit < 8; bit++) {
         previousMillis = 0;
         while ((v = (digitalRead(TIring)<<1 | digitalRead(TItip))) == 0x03) {
            if (previousMillis++ > GET_ENTER_TIMEOUT)
            return ERR_READ_TIMEOUT+j+100*bit;
         }
         if (v == 0x01) {
            byteout = (byteout >> 1) | 0x80;
            pinMode(TItip,OUTPUT);
            digitalWrite(TItip,LOW);      //should already be set because of the pullup resistor register
            previousMillis = 0;
            while (digitalRead(TIring) == LOW) {            //wait for the other one to go low
               if (previousMillis++ > TIMEOUT)
               return ERR_READ_TIMEOUT+10+j+100*bit;
            }
            //pinMode(TIring,OUTPUT);
            digitalWrite(TIring,HIGH);
            } else {
            byteout = (byteout >> 1) & 0x7F;
            pinMode(TIring,OUTPUT);
            digitalWrite(TIring,LOW);      //should already be set because of the pullup resistor register
            previousMillis = 0;
            while (digitalRead(TItip) == LOW) {
               if (previousMillis++ > TIMEOUT)
               return ERR_READ_TIMEOUT+20+j+100*bit;
            }
            //pinMode(TItip,OUTPUT);
            digitalWrite(TItip,HIGH);
         }
         pinMode(TIring, INPUT);           // set pin to input
         digitalWrite(TIring, HIGH);       // turn on pullup resistors
         pinMode(TItip, INPUT);            // set pin to input
         digitalWrite(TItip, HIGH);        // turn on pullup resistors
      }
      data[j] = byteout;
      //delayMicroseconds(6);
   }
   return 0;
}


When I push the buttons, nothing on the calculator happens. I am just using the cursor in DoorsCS7 to test it.

TIring is going to the left channel and TItip is going to the right channel of the cable I'm using, but as far as I can tell that shouldn't matter. Everything is connected together correctly, and some simple serial debugging shows the pushbuttons work as expected. I'm not entirely sure that the packets are correct, but I think they should be.

When I plug in the cable to my calculator the cursor on the main blank screen (where you do calculations) stops blinking, and resumes blinking when I unplug it, so the cable is making some kind of contact. I haven't changed KermMartian's linking code at all, except defining the pins.

When plugging the cable into the calculator it doesn't feel like it's going in all the way, so I think that may be the problem. The 3.5mm female to 2.5mm male adapter I am using is pretty wide and might be getting in the way. Unless someone can find something in the code that might be causing problems, I'll try finding a different way to link them.

Thanks to anyone that offers help and/or advice!
The first thing that I spot is that you're using the cursor in Doors CS 7 to test it. Doors CS doesn't use the TI key routines, so it won't accept silent link keypress instructions. Try quitting Doors CS, going to the graphscreen, and using your program there. You should see the cursor moving around the graphscreen if your program is correct.
Thank you, I did not know that. I tried it on the graph screen, but still nothing. However, whenever I push a button on the Arduino side the cursor stops blinking (the single pixel in the middle of the crosshair) and when I let go of the button it blinks again. So something must be getting sent to my calculator, but not correctly.

Something may be wrong with my code, or it's very likely the cable is just not sitting in the jack all the way. I ordered a 2.5mm TI calc-to-calc (probably just a generic, but only $3.50 with no shipping) cable and a 2.5mm female to 3.5mm male adapter that should eliminate any possible connection problems.
I figured out the problem. On the second page of KermMartian's linking routines thread he said you need to acknowledge the calculator's return command, or else it won't do anything. I added that in and it works great. Smile

The only problem is you sometimes have to hold the push button down for a full second before the cursor on the calc will start moving. It doesn't seem there's a way around this, since in the video in the first post of that thread, there seems to be quite a bit of delay in the controls too.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement