{"id":250,"date":"2020-03-31T15:07:13","date_gmt":"2020-03-31T04:07:13","guid":{"rendered":"http:\/\/www.vk1zdj.net\/?p=250"},"modified":"2023-01-27T10:21:00","modified_gmt":"2023-01-26T23:21:00","slug":"using-the-usb-attiny-85-boards","status":"publish","type":"post","link":"https:\/\/www.vk1zdj.net\/?p=250","title":{"rendered":"Using the USB ATTiny 85 boards"},"content":{"rendered":"\n<p>I have always loved the Arduino universe.  I started originally with Microchip PIC devices, but once I discovered Arduino, my world changed :-).<\/p>\n\n\n\n<p>For the last year or so, I have been playing with a tiny board that has an AT Tiny85 installed on it.  These are available from eBay for about $4 each &#8211; and are handy for devices that emulate UBS mice and the like, especially to help with pesky corporate screen locks.  I believe that the original iteration of these boards was designed and sold by DigiSpark.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"391\" height=\"327\" src=\"http:\/\/www.vk1zdj.net\/wp-content\/uploads\/2020\/03\/ATTiny85.png\" alt=\"\" class=\"wp-image-251\" srcset=\"https:\/\/www.vk1zdj.net\/wp-content\/uploads\/2020\/03\/ATTiny85.png 391w, https:\/\/www.vk1zdj.net\/wp-content\/uploads\/2020\/03\/ATTiny85-300x251.png 300w, https:\/\/www.vk1zdj.net\/wp-content\/uploads\/2020\/03\/ATTiny85-80x67.png 80w\" sizes=\"(max-width: 391px) 100vw, 391px\" \/><figcaption>ATTiny85 Board<\/figcaption><\/figure>\n\n\n\n<h2>Adding the appropriate board to the Arduino IDE.<\/h2>\n\n\n\n<p>To allow Digispark boards to be seen by the Arduino IDE you need to add  an Additional Boards manager URL through Menu > File > preferences:<\/p>\n\n\n\n<p><a href=\"http:\/\/digistump.com\/package_digistump_index.json\">http:\/\/digistump.com\/package_digistump_index.json<\/a><\/p>\n\n\n\n<p>Once you have the board added select the Digispark board in Menu > Tools > Boards.  That will setup the IDE to use the Digispark boards.<\/p>\n\n\n\n<p>Once the board is set, you will see examples for Digistump in the Menu > File > Examples section.<br><\/p>\n\n\n\n<h2>Compile and Upload a program<br><\/h2>\n\n\n\n<p>You program a board in two steps;<\/p>\n\n\n\n<ol><li>Start the compile and upload process as you usually do for the Arduino.<\/li><li>Plug in the Digispark ATtiny85 to initialise USB detection.<\/li><\/ol>\n\n\n\n<h3>1. Normal Arduino Compilation<\/h3>\n\n\n\n<p>To start programming simply hit the compile and upload button on the IDE.  Once uploading starts you will see information about compilation in the status window. <\/p>\n\n\n\n<h3>2. Micronucleus USB Detection and Upload<\/h3>\n\n\n\n<p>Once compilation is finished, simply plug in the Digispark Attiny85. Once it has been detected, you will see the device being programmed.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2>Sample program:<\/h2>\n\n\n\n<p>My favourite and most useful example is from Jeff White &#8211; It wriggles a mouse&#8230;  (Note that I had to insert a DigiMouse.begin();  in the Setup() function &#8211; without that it didn&#8217;t operate.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ DigiMouse Mouse Wiggler\n\/\/ Jeff White (jwhite@white.nu)\n\/\/ MIT License\n\n#include &lt;DigiMouse.h>\n\n#define MOUSE_LEFT 1\n#define MOUSE_RIGHT 2\n#define MOUSE_DOWN 3\n#define MOUSE_UP 4\n\n\/\/ Milliseconds range to move the mouse\n#define MIN_DELAY_TIME 10000\n#define MAX_DELAY_TIME 15000\n\n\/\/ Pixel range to move the mouse\n#define MOUSE_MIN 2\n#define MOUSE_MAX 5\n\nunsigned int moveamount = 4;\nunsigned int mousemove = MOUSE_LEFT;\nunsigned long endtime;\nunsigned long currtime;\nint rollovers;\n\nvoid setup() {\n  \/\/Do nothing? It seems as if the USB hardware is ready to go on reset\n  randomSeed(analogRead(0));\n  endtime = millis() + random(MIN_DELAY_TIME, MAX_DELAY_TIME);\n  pinMode(0, OUTPUT); \/\/LED on Model B\n  pinMode(1, OUTPUT); \/\/LED on Model A \n  DigiMouse.begin(); \/\/start or reenumerate USB - BREAKING CHANGE from old versions that didn't require this\n  \n}\n\nint millisRollover() {\n  \/\/ get the current millis() value for how long the microcontroller has been running\n  \/\/\n  \/\/ To avoid any possiblity of missing the rollover, we use a boolean toggle that gets flipped\n  \/\/   off any time during the first half of the total millis period and\n  \/\/   then on during the second half of the total millis period.\n  \/\/ This would work even if the function were only run once every 4.5 hours, though typically,\n  \/\/   the function should be called as frequently as possible to capture the actual moment of rollover.\n  \/\/ The rollover counter is good for over 35 years of runtime. --Rob Faludi http:\/\/rob.faludi.com\n  \/\/\n  static int numRollovers=0; \/\/ variable that permanently holds the number of rollovers since startup\n  static boolean readyToRoll = false; \/\/ tracks whether we've made it halfway to rollover\n  unsigned long now = millis(); \/\/ the time right now\n  unsigned long halfwayMillis = 2147483647; \/\/ this is halfway to the max millis value (17179868 for earlier versions of Arduino)\n\n  if (now > halfwayMillis) { \/\/ as long as the value is greater than halfway to the max\n    readyToRoll = true; \/\/ you are ready to roll over\n  }\n\n  if (readyToRoll == true &amp;&amp; now &lt; halfwayMillis) {\n    \/\/ if we've previously made it to halfway\n    \/\/ and the current millis() value is now _less_ than the halfway mark\n    \/\/ then we have rolled over\n    numRollovers++; \/\/ add one to the count the number of rollovers\n    readyToRoll = false; \/\/ we're no longer past halfway\n    endtime = 0; \/\/ prevent rollover\n  } \n  return numRollovers;\n}\n\nvoid LEDon() {\n  digitalWrite(0, HIGH);   \/\/ turn the LED on (HIGH is the voltage level)\n  digitalWrite(1, HIGH);\n}\n\nvoid LEDoff() {\n  digitalWrite(0, LOW);   \/\/ turn the LED on (HIGH is the voltage level)\n  digitalWrite(1, LOW);\n}\n\nvoid loop() {\n  \n  DigiMouse.update();\/\/call this at least every 50ms\n  \/\/calling more often than that is fine\n  \/\/this will actually only send the data every once in a while unless the data is different\n  \n  if (millis() > endtime) {\n    switch (mousemove) {\n        case MOUSE_LEFT :\n          DigiMouse.moveX(-moveamount);\n          LEDon();\n          break;\n        case MOUSE_RIGHT :\n          DigiMouse.moveX(moveamount);\n          LEDoff();\n          break;\n        case MOUSE_DOWN :\n          DigiMouse.moveY(moveamount);\n          LEDon();\n          break;\n        case MOUSE_UP :\n          DigiMouse.moveY(-moveamount);\n          LEDoff();\n          break;\n        default :\n          moveamount = random(MOUSE_MIN, MOUSE_MAX);\n          mousemove = 0;\n    }\n    mousemove++;\n    currtime = millis();\n    endtime = currtime + random(MIN_DELAY_TIME, MAX_DELAY_TIME);\n  }\n  delay(10);\n  rollovers = millisRollover();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have always loved the Arduino universe. I started originally with Microchip PIC devices, but once I discovered Arduino, my world changed :-). For the last year or so, I have been playing with a tiny board that&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[34],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/posts\/250"}],"collection":[{"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":1,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vk1zdj.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}