From bd6c7237c5c950e30c1532aba649973d706834ab Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Mon, 6 Sep 2021 20:43:06 +0200 Subject: [PATCH] Putting this on Gitea so I don't lose it --- README.md | 11 ++++++ TI-84_DFPlayer.ino | 91 +++++++++++++++++++++++++++++++++++++++++++++ TI/DFPlayer.8xp | Bin 0 -> 626 bytes TI/DFPlayer.txt | 60 ++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 README.md create mode 100644 TI-84_DFPlayer.ino create mode 100644 TI/DFPlayer.8xp create mode 100644 TI/DFPlayer.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..177faa2 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# TI-84_DFPlayer +TI-84 Plus with inbuilt MP3 player using an ATtiny85 as a communication bridge. + +## Usage +- Put the `.ino` file on your MCU of choice, I used an ATtiny 85. +- Connect the DFPlayer to the MCU using the Serial port, use pins 0 (RX) and 1 (TX) on the ATtiny 85 +- Connect the calculator to the MCU using its serial connection, use pins 4 (TIP) and 3 (RING) on the ATtiny 85 +- Power the MCU using an external battery or steal power from the calculators batteries, you will need an external power switch and make a voltage devider +- Put music on the DFPlayers SD card +- Put DFPlayer.8xp on your calculator to control the DFPlayer +- Enjoy! \ No newline at end of file diff --git a/TI-84_DFPlayer.ino b/TI-84_DFPlayer.ino new file mode 100644 index 0000000..0687a60 --- /dev/null +++ b/TI-84_DFPlayer.ino @@ -0,0 +1,91 @@ +#include +#include +#include "CBL2.h" +#include "TIVar.h" + +CBL2 cbl; +SoftwareSerial SoftSerial(0, 1); // RX, TX +DFRobotDFPlayerMini DFPlayer; + +#define MAXDATALEN 32 +uint8_t header[16]; +uint8_t data[MAXDATALEN]; + +int onSendAsCBL2(uint8_t type, enum Endpoint model, int *headerlen, int *datalen, data_callback *data_callback); +int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen); + +void setup() +{ + SoftSerial.begin(9600); + DFPlayer.begin(SoftSerial); + DFPlayer.play(2); + + cbl.setLines(4, 3); + cbl.resetLines(); + cbl.setupCallbacks(header, data, MAXDATALEN, onGetAsCBL2, onSendAsCBL2); +} + +void loop() +{ + int rval; + rval = cbl.eventLoopTick(); + if (rval && rval != ERR_READ_TIMEOUT) + { + SoftSerial.print("eventLoopTick: error code "); + SoftSerial.println(rval); + } +} + +void sendtoDFP(short command, short parameter) +{ + switch (command) + { + case 1: + DFPlayer.next(); break; + + case 2: + DFPlayer.previous(); break; + + case 3: + DFPlayer.play(parameter); break; + + case 4: + DFPlayer.volumeUp(); break; + + case 5: + DFPlayer.volumeDown(); break; + + case 6: + DFPlayer.volume(parameter); break; + + case 8: + DFPlayer.randomAll(); break; + + case 13: + DFPlayer.start(); break; + + case 14: + DFPlayer.pause(); break; + + case 17: + DFPlayer.stop(); break; + } +} + +int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen) +{ + uint16_t list_len = TIVar::sizeWordToInt(&(data[0])); // Convert 2-byte size word to int + int size_of_real = TIVar::sizeOfReal(model); + + short cmd = TIVar::realToLong8x(&data[size_of_real * 0 + 2], model); // First list element starts after 2-byte size word + short parameter = TIVar::realToLong8x(&data[size_of_real * 1 + 2], model); + + sendtoDFP(cmd, parameter); + + return 0; +} + +int onSendAsCBL2(uint8_t type, enum Endpoint model, int *headerlen, int *datalen, data_callback *data_callback) +{ + return 0; +} diff --git a/TI/DFPlayer.8xp b/TI/DFPlayer.8xp new file mode 100644 index 0000000000000000000000000000000000000000..652d0b397013ef0c9d6ae58de76c6be60e740a9e GIT binary patch literal 626 zcmZXR%}&BV6os+DL`hu00!demA;!)mgbFBbm{2Hzq-_cZQ@yK{%H3ahv7iCS!BUVqff=V4060&1WD(O0{?Z z5)TL^f4hV_CIX~;BPfE5SY6fN5Ymw0Z@8&b;`0d~_eT6(borFD@jrkpq3tB9IVStr z(+c}Z_JP94Rl&tI>!F*-%j#xggUqMm8ru*)QXuypdB7*a4+?iESrF=al(_sA6`%1N z3kPl!x9}_iWW;$F&+Cz4%Mzw+LzoaA99?+oAfB$!^+ff2%}wO;8V&Zjsh~oUPcXcf zii!*UVt0YsQ9qme;e=Z;ZHA_H;Ru84ZY8PKandJ{uuu=@5tI1tze)Tqs)cF#IEY_I jDhcI~+@(>-su