Digishark ATtiny85 is skipping lines

I am trying to automate keyboard strokes on my Android. The idea is to automate creating a new contact in the phone, saving it and then dialing the number. Here is the code:

#include "DigiKeyboard.h"

#define KEY_ARROW_DOWN 0x51
#define KEY_TAB 0xB3
#define KEY_RETURN 0xB0

void setup() {
//empty
}

int var = 0;

void loop() {
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_C, MOD_GUI_LEFT);
DigiKeyboard.delay(1000);
while (var < 300) {
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, 0);
var++;
}

DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, 0);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, 0);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_RETURN);
DigiKeyboard.delay(1000);
DigiKeyboard.delay(1000);
DigiKeyboard.print(F("Soandso"));
DigiKeyboard.delay(300);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_RETURN);
DigiKeyboard.delay(100);
DigiKeyboard.print("7078675309");
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_RETURN);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_TAB);
DigiKeyboard.delay(100);
DigiKeyboard.sendKeyStroke(KEY_RETURN);
for (;:wink: {
/empty/
}
}

It opens contacts by pressing windows key + C, it scrolls down using arrow down, and then it delays for a moment to wait for the +, or rather the "add contact" button to appear. This is where it gets strange. It skips over 15 lines of code and enters the phone number in the "name" field.

Could this be due to a faulty board? Did I solder it incorrectly? Is there something wrong with my code? Any help would be appreciated.

Soldered circuits..... I can't resist asking for schematics and close up photos. Unattended bridges is a rather common reason for trouble.

I can’t resist asking for < CODE TAGS >

1 Like

@ lastchancename
The indentation is minimal so I dropped that....

The 999 area code is wrong, 707.

a7

I just tested something out. I added a few lines of code at the top.. if its skipping due to hardware failure, it should be consistent... but I'm seeing the same behavior.

Isn’t that what consistent means?

This

while (var < 300) {
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, 0);
var++;
}

don’t look right. 300 key_arrow_downs?

a7

There are a ton of contacts in my phone... I'm pretty sure its the soldering. I just tried to make a rickroll for android and its skipping text. Thanks you guys.

This is not a hardware problem. It is a software problem.

It might well be the attempt to send an arbitrary number of down-arrow presses instantaneously as noted above.

Also verifying whether all of hte keystrokes are sent or the same ones are skipped after disabling the windows key that pops up whatever it is you're entering would also be a useful avenue.

If that shows the same misbehavior, I'd try to do the same program on a Micro/Leo using it's keyboard library (find+replace to convert the calls to the appropriate ones for the 32u4) - those have proper USB support.

The code is actually indented, but leading whitespace in standard text is stripped by the forum's markup parser (as is standard for Markdown). This is another reason why it's important to post code properly.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.