- BlueLink (An arduino-based Bluetooth GrayLink clone)
- 19 Apr 2015 12:01:27 pm
- Last edited by biohax17 on 20 Apr 2015 04:10:20 am; edited 7 times in total
BlueLink is my arduino-based serial to TI linkprotocol module. BlueLink allows you to use the onboard USB serial on the Arduino or an external powered serial bluetooth module (I used the HC-06).
My code is based on the linking routines by KermMartian.
Code:
When you use an arduino Mini Pro or a Micro it isn't hard to insert the module in the calculator. I soldered the power supply of the batteries of the calc to the arduino and bluetooth module separetely with a bipolar swich in between. Pictures can be found here: http://imgur.com/a/iLO7L
My module is seen as a GrayLink and works with both TiLP and TI Connect.
The main goal was to connect my TI84+ with any smartphone. This means that our smartphone could be used as a wifi and sms shield for our beloved TI84+. I've already made a server-side app (beta quality) for android which allows to send & receive text messages on the calc. If anybody is intressed i'll share my sources of the android app.
My code is based on the linking routines by KermMartian.
Code:
/*
* Copyright Karel Dhondt aka biohax.
* Thanks to KermMartian for the TI linking routines.
*/
#define TIring 8
#define TItip 9
#define ERR_READ_TIMEOUT 1000
#define ERR_WRITE_TIMEOUT 1000
#define TIMEOUT 2000
#define GET_ENTER_TIMEOUT 500
char temp;
boolean linkAvailable;
void setup()
{
Serial.begin(9600);
resetLines();
}
void loop()
{
while (Serial.available()){
writeByte(Serial.read());
}
temp = readByte();
while (linkAvailable){
Serial.write(temp);
temp = readByte();
}
//delay(50);
}
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
}
byte writeByte(uint8_t byte) {
long previousMillis = 0;
// Send all of the bits in this byte
for(int bit = 0; bit < 8; bit++) {
// Wait for both lines to be high before sending the bit
previousMillis = 0;
while (digitalRead(TIring) == LOW || digitalRead(TItip) == LOW) {
if (previousMillis++ > TIMEOUT) {
resetLines();
return ERR_WRITE_TIMEOUT;
}
}
// Pull one line low to indicate a new bit is going out
bool bitval = (byte & 1);
int line = (bitval)?TIring:TItip;
pinMode(line, OUTPUT);
digitalWrite(line, LOW);
// Wait for peer to acknowledge by pulling opposite line low
line = (bitval)?TItip:TIring;
previousMillis = 0;
while (digitalRead(line) == HIGH) {
if (previousMillis++ > TIMEOUT) {
resetLines();
return ERR_WRITE_TIMEOUT;
}
}
// Wait for peer to indicate readiness by releasing that line
resetLines();
previousMillis = 0;
while (digitalRead(line) == LOW) {
if (previousMillis++ > TIMEOUT) {
resetLines();
return ERR_WRITE_TIMEOUT;
}
}
// Rotate the next bit to send into the low bit of the byte
byte >>= 1;
}
return 0;
}
byte readByte() {
long previousMillis = 0;
uint8_t b = 0;
// Pull down each bit and store it
for (int bit = 0; bit < 8; bit++) {
int linevals;
previousMillis = 0;
while ((linevals = ((digitalRead(TIring) << 1) | digitalRead(TItip))) == 0x03) {
if (previousMillis++ > GET_ENTER_TIMEOUT) {
resetLines();
linkAvailable = false;
return ERR_READ_TIMEOUT;
}
}
// Store the bit, then acknowledge it
b = (b >> 1) | ((linevals == 0x01)?0x80:0x00);
int line = (linevals == 0x01)?TItip:TIring;
pinMode(line, OUTPUT);
digitalWrite(line, LOW);
// Wait for the peer to indicate readiness
line = (linevals == 0x01)?TIring:TItip;
previousMillis = 0;
while (digitalRead(line) == LOW) { //wait for the other one to go low
if (previousMillis++ > TIMEOUT) {
resetLines();
linkAvailable = false;
return ERR_READ_TIMEOUT;
}
}
// Now set them both high and to input
resetLines();
}
linkAvailable = true;
return b;
}
When you use an arduino Mini Pro or a Micro it isn't hard to insert the module in the calculator. I soldered the power supply of the batteries of the calc to the arduino and bluetooth module separetely with a bipolar swich in between. Pictures can be found here: http://imgur.com/a/iLO7L
My module is seen as a GrayLink and works with both TiLP and TI Connect.
The main goal was to connect my TI84+ with any smartphone. This means that our smartphone could be used as a wifi and sms shield for our beloved TI84+. I've already made a server-side app (beta quality) for android which allows to send & receive text messages on the calc. If anybody is intressed i'll share my sources of the android app.