Saturday, August 27, 2011

By request: Frankenkindle demo code

Mike at Hackaday suggested that I submit the code used to generate the keystroke sequences that control the Kindle.  He correctly noticed in the prototype video that the pages don't turn very quickly.  I believe that this issue is caused by the custom script running on the Kindle itself.  You can see that the Up and Down buttons used on the menu selection screen operate very quickly, but the page turn operation takes more time.  At this point it's something I think I can live with but I'm always looking for ways to optimize my design.  This project will be completely open source anyway, so there's no harm in publishing it a bit early.

The basic operation is as follows:  The microcontroller waits until a button is pressed, at which point it calls the appropriate subroutine.  These subroutines manipulate control signals going to two multiplexer chips, which effectively act as Single Pole, Quadruple Pole switches.  When activated, they short specific pairs of wires that are connected to the Kindle, mimicking actual button press events.  Note that turning individual pages is not possible from the main Kindle keypad, so the software had to be hacked to allow custom control through specific key press sequences.  Turning a page to the right is accomplished by pressing the Shift key followed by the 5-way Right key.  There is specific timing required to make this work.

TL;DR: Microcontroller waits for you to press a button, then presses a button on the Kindle for you.

Note that the controller itself is a Teensy++ v1.0 (PJRC has since updated the design and currently sells v2.0 boards).  It runs in a mode Paul at PJRC calls Teensyduino, which allows it to use Arduino code.  A full design package (code, schematics, BOM, etc) will be published once I feel the design is complete.  For now, here is the code you saw running in the demo video:


Arduino code

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
///////////////////////////////////////////////////////////////////////
//
// Frankenkindle v0.1 code
//
// Glenn Johnson
// 8/2011
//
// Monitor simple pushbuttons from V.Reader device and translate
// into Kindle-compatible keypad control signals.  
//
// Note: Chip select signals not used - both multiplexers
//       are always powered.
//
////////////////////////////////////////////////////////////////////// 



void setup() {              

  //Set up serial for debug messages
  Serial.begin(9600);
  
  //set up the digital inputs from the V.Reader
  pinMode(PIN_B0, INPUT_PULLUP);  //Down, marked "Replay"
  pinMode(PIN_B1, INPUT_PULLUP);  //Home, marked as "Exit"
  pinMode(PIN_B2, INPUT_PULLUP);  //Up, marked as "Play"
  pinMode(PIN_B3, INPUT_PULLUP);  //(Not connected)
  pinMode(PIN_B4, INPUT_PULLUP);  //Right
  pinMode(PIN_B5, INPUT_PULLUP);  //Select (Enter), marked as "Bookmark"
  pinMode(PIN_B6, INPUT_PULLUP);  //Left
  
  //set up digital outputs to control the mux
  pinMode(PIN_C0, OUTPUT);    //IN1_1
  pinMode(PIN_C1, OUTPUT);    //IN2_1
  pinMode(PIN_C2, OUTPUT);    //IN1_2
  pinMode(PIN_C3, OUTPUT);    //IN2_2
  //pinMode(PIN_C4, OUTPUT);    //chip select 1
  //pinMode(PIN_C5, OUTPUT);    //chip select 2
  
  pinMode(PIN_D6, OUTPUT);    //LED, for testing
  
  //Set control signals to unused states
  digitalWrite(PIN_C0, HIGH);
  digitalWrite(PIN_C1, HIGH);
  digitalWrite(PIN_C2, HIGH);
  digitalWrite(PIN_C3, HIGH);  
  //digitalWrite(PIN_C4, LOW); 
  //digitalWrite(PIN_C5, LOW);
  
}

void shift()
{
  
  //press SHIFT
  digitalWrite(PIN_C0, LOW);   //IN1_1
  digitalWrite(PIN_C1, HIGH);  //IN2_1
  
  delay(100);

  //release SHIFT
  digitalWrite(PIN_C0, HIGH);
  digitalWrite(PIN_C1, HIGH);
  
}

void left()
{
  
  //press DPAD_LEFT
  digitalWrite(PIN_C0, HIGH);   //IN1_1
  digitalWrite(PIN_C1, LOW);    //IN2_1
  
  delay(100);
  
  //release DPAD_LEFT
  digitalWrite(PIN_C0, HIGH);   //IN1_1
  digitalWrite(PIN_C1, HIGH);   //IN2_1
  
}

void right()
{
  
  //press DPAD_RIGHT
  digitalWrite(PIN_C0, LOW);    //IN1_1
  digitalWrite(PIN_C1, LOW);    //IN2_1
  
  delay(100);
  
  //release DPAD_RIGHT
  digitalWrite(PIN_C0, HIGH);   //IN1_1
  digitalWrite(PIN_C1, HIGH);   //IN2_1
  
}

void up()
{
  
  //press DPAD_UP
  digitalWrite(PIN_C2, LOW);    //IN1_2
  digitalWrite(PIN_C3, LOW);    //IN2_2
  
  delay(100);
  
  //release DPAD_UP
  digitalWrite(PIN_C2, HIGH);   //IN1_2
  digitalWrite(PIN_C3, HIGH);   //IN2_2
  
}

void down()
{
  
  //press DPAD_DOWN
  digitalWrite(PIN_C2, HIGH);    //IN1_2
  digitalWrite(PIN_C3, LOW);    //IN2_2
  
  delay(100);
  
  //release DPAD_DOWN
  digitalWrite(PIN_C2, HIGH);   //IN1_2
  digitalWrite(PIN_C3, HIGH);   //IN2_2
  
}

void enter()
{
  
  //press DPAD_CENTER
  digitalWrite(PIN_C2, LOW);     //IN1_2
  digitalWrite(PIN_C3, HIGH);    //IN2_2
  
  delay(100);
  
  //release DPAD_CENTER
  digitalWrite(PIN_C2, HIGH);   //IN1_2
  digitalWrite(PIN_C3, HIGH);   //IN2_2
  
}


void shiftLeft()
{

  //send SHIFT keystroke
  shift();
    
  delay(200);
   
  //send DPAD_LEFT keystroke
  left();
  
  
  //Two second delay, ensure that the script has time to execute.
  delay(2000);
  
}



void shiftRight()
{
  
  //send SHIFT keystroke
  shift();
  
  delay(200);
  
  //send DPAD_RIGHT keystroke
  right();
  
  //Two second delay, ensure that the script has time to execute.
  delay(2000);
    
}

void shiftUp()
{
  
  //send SHIFT keystroke
  shift();
  
  delay(200);
  
  //send DPAD_UP keystroke
  up();
  
  //Two second delay, ensure that the script has time to execute.
  delay(2000);
    
}



void loop() {
  
  //if a button is pressed, it goes low
 
  if (!digitalRead(PIN_B0))  
  {
    
    //Down
    
    //Kindle command
    down();
    
    delay(1000);
    
  }
  
  if (!digitalRead(PIN_B1))
  {
    
    //Home

    //Kindle command
    shiftUp();
    
    delay(1000);
    
  }
  
  if (!digitalRead(PIN_B2))
  {
    
    //Up

    //Kindle command (Home = Shift + Up)
    up();
    
    delay(1000);
  }
  
  if (!digitalRead(PIN_B3))
  {

    //Not connected
    
  }
  
  if (!digitalRead(PIN_B4))
  {
    //Turn page right

    //Kindle command 
    shiftRight();
    
    delay(1000);
    
  }
  
  if (!digitalRead(PIN_B5))
  {

    //Select

    //Kindle command 
    enter();
    
    delay(1000);
    
  }
  
  if (!digitalRead(PIN_B6))
  {

    //Turn page left

    //Kindle command (page turn left = Shift + left)
    shiftLeft();
       
    delay(1000);
    
  }  
   
}

Thursday, August 25, 2011

Exciting times for the Frankenkindle!


Yesterday was a huge day for the Frankenkindle!


Site traffic jumped, to say the least, as word of the functional prototype demo spread.  Special thanks to Drew from Build Lounge, who saw the post on Reddit and forwarded the link to a few other websites. 

Throughout the day it spread all over the world.  Here are some other sites promoting the project.  I urge you to take a moment to check them out, as many of these sites are dedicated to making devices for disabled individuals just as I am, and could benefit from some additional exposure.  




Tinta-e (from Spain! Translated to English)



The Digital Reader

The Nerd Insurance

MobileRead Forums (these guys are great.  I got the Launchpad script I used to hack the Kindle on a different thread on this site.)

Richard's Notes (personal blog)

I also sat for a couple interviews, so be on the lookout for those stories to be published soon.  I’ll post links when they’re up. 

Stay tuned for an update on the project itself, where I will attempt to answer some of the questions posed by comments to the above linked stories.  There are some fantastic discussions going on in this niche market, and it’s exciting to be a part of it. 

Finally, we also received our first donation!  I’m not sure if it was intended to be anonymous so I’ll err on the side of caution.  You know who you are, and we thank you.  Just to recap, we accept donations through PayPal or Bitcoin (information on the sidebar).  If you want to help but don't have / don't want to send the cash, just have a look at the ads on the side of the page.  Every little bit helps!

Thanks again for taking the time to follow my little project. 

Sunday, August 21, 2011

Frankenkindle prototype demo


That's right, it's alive!

The Frankenkindle is alive, and fully functional.  The 5-way keypad (up, down, left, right and center) and 'Home' have all been implemented with a substitute keyboard.  (Also,if you turn up your speakers you may hear Queen playing Bohemian Rhapsody in the background - don't say I never give you anything.)

Functionally it's complete, but there's still a fair bit to be done to make it more robust.  The Kindle itself needs to be semi-permanently mounted to the front panel rather than just resting on two wood screws.  The circular interface board along with the flat cable connecting it to the Kindle are both quite fragile and will need to be covered.  Finally, the cables will need to be routed in a more organized fashion.

Here are some pictures to better illustrate what you saw in the video.  Keep in mind that this is a prototype if ever there was one.  It's not pretty, but it doesn't have to be.  It's functional.  Once my sister has a chance to play with it I'll be able to take some good notes on what works and what doesn't, and fold them into the next revision.  Right now I'm designing for what I think she'll need.  The only way to find out if it's useful to her is to actually turn her loose on it and watch what happens.

 The disassembled Frankenkindle.  Front panel, Kindle, and control board are all visible.



Side view, showing the circular board used to interface the main control board
to the Kindle's keyboard input.



 Rear view, showing the control board.  


Power is supplied from a 5V "wall wart" style power supply and the 9-pin serial cable is used to provide an  easy quick-disconnect for the new front panel buttons.

Closeup of the main control board.  

5V DC power is fed through the black cable and used to power the Teensy controller directly (the long green board with USB connector).  It is then fed through a series of diodes to provide a sexy red power LED and stable 3.3V for the multiplexers (actually closer to 3.5V, but who's counting?).  The multiplexers are the surface-mount chips on the red breakout boards.  The bank of resistors in the upper right form a series of voltage dividers, useful for dropping the 5V control signals from the Teensy into 3.3V signals suitable for use with the multiplexers.

And there you have it!  More pictures will be posted to document progress on the enclosure itself.  Also, be on the lookout for a full bill of materials (BOM) and more formal documentation.

Thanks for reading! 

Saturday, August 20, 2011

Rookie mistake

We all do it, and we all hate to admit it.  But every now and then a facepalm-worthy event occurs that just can't stay hidden.

A few weeks ago I finished rewiring the main control board on the Frankenkindle, adding quick-disconnect cables and fitting it into the crude wooden stand I made.  Everything looked good, but it stubbornly refused to actually control the kindle. 

I tested everything.  I checked the code, made special modified subroutines for testing, played with the timing, checked continuity on every connection on the board.  Then I did it again.  Then (you guessed it), I did it again.  This worked on the breadboard, so what's different about my new wiring?

Then it hit me.

I came back to this blog post wherein I explained the keyboard connector on the back of the Kindle itself.  Sure enough, there it was in black and white:  "As seen in this picture, pin 1 is at the bottom, and pin 20 on top."  It seems in my infinite wisdom I had failed to document this fact anywhere else in my notes, and wired the Kindle connector board in reverse.  As is usually the case, it's always the simplest things that trip us up. 

I haven't facepalmed that hard in a while.  It was so bad I had to share. 


Thursday, August 4, 2011

It's a girl!

I just wanted to stop by and explain the painful lack of updates recently. 

Short version: it's my wife's fault.  :)

We're expecting a baby, and have been seeing doctors and attending all sorts of classes to prepare for having our lives turned upside down in a little over a month.  Zoey Kristina is set to arrive September 17th, so you can imagine that the past few months have messed with my normal schedule a bit.  As those of you with kids know, this disruption is likely to only get more pronounced in the coming months when she gets here. 

I am still working on the Frankenkindle, albeit sporadically.  I wire-wrapped the whole circuit onto a perfboard, tore it apart and rewired it all over again, then mounted everything onto a hastily constructed stand.  At this point all the pieces are in place, I just need to squash a few small bugs in my code and triple-check the board's wiring.  It shouldn't be long now until I have a working demo to show you.

So, thank you for continuing to follow this project.  I assure you it's not dead, just don't expect updates as often as before.

See you soon!