- Arduino/TI-84+ link test program
- 19 Mar 2014 04:40:55 am
- Last edited by yowann on 26 Mar 2014 03:25:40 am; edited 1 time in total
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:
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!
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!