<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pinMode Archives - CyberBlogSpot</title>
	<atom:link href="https://cyberblogspot.com/tag/pinmode/feed/" rel="self" type="application/rss+xml" />
	<link>https://cyberblogspot.com/tag/pinmode/</link>
	<description>Not just another blogspot site</description>
	<lastBuildDate>Tue, 24 Jan 2023 07:26:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://cyberblogspot.com/wp-content/uploads/2018/08/cropped-iphone-iphone3gs-32x32.jpg</url>
	<title>pinMode Archives - CyberBlogSpot</title>
	<link>https://cyberblogspot.com/tag/pinmode/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Program Digispark ATtiny85 Board with Arduino IDE</title>
		<link>https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/</link>
					<comments>https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 07 Jan 2023 12:18:43 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ADC]]></category>
		<category><![CDATA[Analog to Digital Converter]]></category>
		<category><![CDATA[analogRead]]></category>
		<category><![CDATA[AnalogWrite]]></category>
		<category><![CDATA[Arduino IDE]]></category>
		<category><![CDATA[ATtiny85]]></category>
		<category><![CDATA[ATTinyCore]]></category>
		<category><![CDATA[Digispark]]></category>
		<category><![CDATA[Digispark ATtiny85]]></category>
		<category><![CDATA[Digispark ATtiny85 Development Board]]></category>
		<category><![CDATA[Digispark ATtiny85 Pinout]]></category>
		<category><![CDATA[Digistump]]></category>
		<category><![CDATA[digitalRead]]></category>
		<category><![CDATA[digitalWrite]]></category>
		<category><![CDATA[ICSP Programmer]]></category>
		<category><![CDATA[ISP Programmer]]></category>
		<category><![CDATA[Micronucleus]]></category>
		<category><![CDATA[Micronucleus bootloader]]></category>
		<category><![CDATA[pinMode]]></category>
		<category><![CDATA[Sketch]]></category>
		<guid isPermaLink="false">https://cyberblogspot.com/?p=5316</guid>

					<description><![CDATA[<p>A bare chip ATtiny85 needs to be connected to an ICSP (aka ISP) programmer in order to upload Arduino sketches. To facilitate programming, Digistump created the Digispark ATtiny85 USB Development Board. The Digispark ATtiny85 board does not need an ICSP programmer. Instead, it is directly connected to the USB port of the computer hosting the&#8230;&#160;<a href="https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/" rel="bookmark">Read More &#187;<span class="screen-reader-text">How to Program Digispark ATtiny85 Board with Arduino IDE</span></a></p>
<p>The post <a href="https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/">How to Program Digispark ATtiny85 Board with Arduino IDE</a> appeared first on <a href="https://cyberblogspot.com">CyberBlogSpot</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-types-jpg.webp"><img fetchpriority="high" decoding="async" width="802" height="486" src="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-types-jpg.webp" alt="A picture showing two types of Digispark ATtiny85 development boards  for which this tutorial How to Program Digispark ATTiny85 Board with Arduino IDE is all about" class="wp-image-5550" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-types-jpg.webp 802w, https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-types-300x182.webp 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-types-768x465.webp 768w" sizes="(max-width: 802px) 100vw, 802px" /></a><figcaption class="wp-element-caption">Figure 1.  Two Version of Digispark ATtiny85 Development Board</figcaption></figure>



<p>A bare chip ATtiny85 needs to be connected to an ICSP (aka ISP) programmer in order to upload Arduino sketches.  To facilitate programming, Digistump created the Digispark ATtiny85 USB Development Board.  The Digispark ATtiny85 board does not need an ICSP programmer.  Instead, it is directly connected to the USB port of the computer hosting the Arduino IDE.  This is the normal way of how to program a Digispark ATtiny85 board.</p>



<h2 class="wp-block-heading">Difference in Uploading the Sketch</h2>



<p>Although a Digispark ATtiny85 board plugs directly into a USB port like any other Arduino development board, there is a slight difference in uploading a program or a sketch.  While an Arduino board is connected first to the USB port prior to uploading a sketch, the Digispark board is connected to the USB port after initiating the upload sketch procedure.  That is, to upload a sketch to the Digispark board, you have to first press the &#8220;Upload&#8221; button on the Arduino IDE.   Afterwards, a message saying &#8220;Please plug in the device (will time out in 60 secs)&#8221; will appear on the Arduino IDE.  Then, you plug in the Digispark board and the sketch starts uploading.  Finally, when the sketch is successfully uploaded, Digispark will run the sketch automatically after five (5) seconds (not instantly as in other Arduino boards).  </p>



<h2 class="wp-block-heading">Configuring Arduino IDE for Digispark ATtiny85 Programming</h2>



<p>To program the Digispark ATtiny85 board, first, install the latest version of <a href="https://www.arduino.cc/en/software" target="_blank" rel="noreferrer noopener">Arduino IDE</a> if you do not have the Arduino IDE yet on your computer.  If you need help on installing the Arduino IDE, please see <a href="https://cyberblogspot.com/how-to-install-arduino-ide-on-windows-10/" target="_blank" rel="noreferrer noopener">How to Install Arduino IDE on Windows 10</a> if you are using Microsoft Windows.</p>



<p>Next, you need to install the <a href="https://github.com/SpenceKonde/ATTinyCore" target="_blank" rel="noreferrer noopener">ATtinyCore </a>on the Arduino IDE in order for Arduino IDE to recognize the Digispark ATtiny85 boards.  You may want to read the article <a href="https://cyberblogspot.com/how-to-install-attinycore-on-arduino-ide/" target="_blank" rel="noreferrer noopener">How to Install ATtinyCore on Arduino IDE</a>.</p>



<h2 class="wp-block-heading">Uploading the Blink Program on Arduino IDE</h2>



<p><strong>STEP 1 &#8211; Open the Arduino IDE and select the proper board.</strong></p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-attinycore-digispark-board-1000-cropped-finally.png"><img decoding="async" width="1000" height="594" src="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-attinycore-digispark-board-1000-cropped-finally.png" alt="Screenshot of Arduino IDE showing a step in How to Program a Digispark ATtiny85 Development Board" class="wp-image-5577" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-attinycore-digispark-board-1000-cropped-finally.png 1000w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-attinycore-digispark-board-1000-cropped-finally-300x178.png 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-attinycore-digispark-board-1000-cropped-finally-768x456.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></a><figcaption class="wp-element-caption">Figure 2.  Arduino IDE Illustration on How to Select the Digispark ATtiny85 Board</figcaption></figure></div>


<p><strong>STEP 2 &#8211; Create a new sketch.  Then copy and paste the sketch below.</strong></p>



<pre class="EnlighterJSRAW">/*
www.cyberblogspot.com
07Jan2022  
*/

#define LED_BUILTIN 1  //PB1 for Model A
                       //PB0 for Model B

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}</pre>



<p><strong>STEP 3 &#8211; Click on the Upload button.</strong></p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-upload-button-cropped-final.png"><img decoding="async" width="1001" height="526" src="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-upload-button-cropped-final.png" alt="Screenshot of Arduino IDE showing the location of the Upload button to upload a sketch" class="wp-image-5578" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-upload-button-cropped-final.png 1001w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-upload-button-cropped-final-300x158.png 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-upload-button-cropped-final-768x404.png 768w" sizes="(max-width: 1001px) 100vw, 1001px" /></a><figcaption class="wp-element-caption">Figure 3.  Arduino IDE with the Upload Button </figcaption></figure></div>


<p><strong>STEP 4 &#8211; Insert the Digispark ATtiny85 board into the USB port when the message to do so appears.</strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="has-text-align-center">If the message &#8220;USB device not recognized&#8221; appears when you insert the Digispark ATtiny85 board, the board may not have the Micronucleus bootloader installed.  See the article <a href="https://cyberblogspot.com/digispark-usb-device-not-recognized/" target="_blank" rel="noreferrer noopener">Digispark USB Device Not Recognized</a> to resolve the issue.</p>
</blockquote>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-plug-device-message-final.png"><img loading="lazy" decoding="async" width="1003" height="729" src="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-plug-device-message-final.png" alt="Screenshot of Arduino IDE showing the fourth step in programming a Digispark ATtiny85 board" class="wp-image-5580" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-plug-device-message-final.png 1003w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-plug-device-message-final-300x218.png 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-plug-device-message-final-768x558.png 768w" sizes="auto, (max-width: 1003px) 100vw, 1003px" /></a><figcaption class="wp-element-caption">Figure 4.  Arduino IDE Showing the Message to Plug in the Digispark ATtiny85 Board</figcaption></figure></div>


<p>After the last step, you should see the messages as shown below and the LED on the Digispark ATtiny85 board should start blinking.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-micronucleus-done.png"><img loading="lazy" decoding="async" width="1002" height="729" src="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-micronucleus-done.png" alt="Screenshot of Arduino IDE after a successfule programming of Digispark ATtiny85 board" class="wp-image-5571" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-micronucleus-done.png 1002w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-micronucleus-done-300x218.png 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/arduino-ide-micronucleus-done-768x559.png 768w" sizes="auto, (max-width: 1002px) 100vw, 1002px" /></a><figcaption class="wp-element-caption">Figure 5.  Arduino IDE with the Messages of a Successful Sketch Upload</figcaption></figure></div>


<h2 class="wp-block-heading">Important Notes on Digispark ATtiny85 I/O Ports </h2>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-pinout-original_final.png"><img loading="lazy" decoding="async" width="802" height="602" src="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-pinout-original_final.png" alt="Pin configuration of Digispark ATtiny85 development board used in How to Program Digispark ATtiny85 Board with Arduino IDE" class="wp-image-5546" srcset="https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-pinout-original_final.png 802w, https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-pinout-original_final-300x225.png 300w, https://cyberblogspot.com/wp-content/uploads/2023/01/digispark-attiny85-pinout-original_final-768x576.png 768w" sizes="auto, (max-width: 802px) 100vw, 802px" /></a><figcaption class="wp-element-caption">Figure 6.  Digispark ATtiny85 Pinout</figcaption></figure></div>


<p>According to specifications, Digispark ATtiny85 boards support a total of six (6) digital I/O ports.  However, there are several points to consider.  Please refer to the Digispark ATtiny85 pinout in Figure 6. </p>



<ul class="wp-block-list">
<li>PB5 is by default being used as a Reset pin, hence, unavailable as a digital IO.  ATtiny85 fuses have to be set to enable PB5 as an IO port.  Moreover, PB5, when used as an output port, have some peculiarities.  When it is at output HIGH, its output is 3V instead of 5V.  Aside from that, it has limited current sourcing capability unlike the other ports that can source up to 20 milliamperes (20mA).</li>



<li>Either PB0 or PB1 is used by the built-in LED depending on the Digispark model.  Model A uses PB1 while Model B uses PB0.  The explanation can be found here: <a href="http://digistump.com/board/index.php?topic=134.0" target="_blank" rel="noreferrer noopener">Digispark Model A vs Model B.</a>  </li>



<li>PB3 is used as USB+ for USB communication and has a 1.5K pull-up resistor.</li>



<li>PB4 is used as USB- also for USB communication. </li>
</ul>



<h2 class="wp-block-heading">How to Address or Reference Digispark ATtiny85 Ports in Program </h2>



<p>When programming the Digispark ATtiny85 in Arduino IDE, references to the IO ports differ between digital IO and analog input.  When using the ports as digital input or digital output, PB0 to PB5 are referred to by their port numbers.  That is, PB0 is 0, PB1 is 1, PB2 is 2, PB3 is 3, PB4 is 4, and PB5 is 5.  For example:</p>



<pre class="EnlighterJSRAW">pinMode(0, INPUT);  //PB0 is input
pinMode(1, INPUT);  //PB1 is input
pinMode(2, INPUT);  //PB2 is input
pinMode(3, OUTPUT);  //PB3 is output
pinMode(4, OUTPUT);  //PB4 is output
pinMode(5, OUTPUT);  //PB5 is output
bool x,y,z;
x = digitalRead(0);  //read PB0
y = digitalRead(1);  //read PB1
z = digitalRead(2);  //read PB2 
digitalWrite(3, HIGH);  //make PB3 HIGH  
digitalWrite(4, HIGH);  //make PB4 HIGH 
digitalWrite(5, LOW);  //make PB5 LOW</pre>



<p>However, when the ports are used as analog input, the port references are different.  Please refer to Digispark ATtiny85 pinout in Figure 6.  There are only four (4) ports usable as ADC input.  These are PB2, PB3, PB4, and PB5.  Their corresponding ADC port numbers are  ADC1, ADC3, ADC2, and ADC0.  In other words, </p>



<ul class="wp-block-list">
<li>PB2 is ADC1 </li>



<li>PB3 is ADC3</li>



<li>PB4 is ADC2 </li>



<li>PB5 is ADC0    </li>
</ul>



<p>As an example,</p>



<pre class="EnlighterJSRAW">//pinMode() always refer to the Port B numbers
//applicable to both digital and analog I/O
pinMode(5, INPUT);  //Make PB5 as input (ADC0)
pinMode(2, INPUT);  //Make PB2 as input  (ADC1)
pinMode(4, INPUT);  //Make PB4 as input (ADC2)
pinMode(3, INPUT);  //Make PB3 as input (ADC3)
int a, b, c, d; 
//Uses analog port numbers instead of Port B numbers
a = analogRead(0);  //Read PB5
b = analogRead(1);  //Read PB2
c = analogRead(2);  //Read PB4
d = analogRead(3);  //Read PB3</pre>



<p>Now, how about analogWrite()?  Does it use the analog port numbers too?  The answer is NO.</p>



<p>Again, referring to the Digispark ATtiny85 pinout above, there are three (3) ports capable of PWM outputs.  These are PB0, PB1, and PB4.  Let us look at an example of how to use them.</p>



<pre class="EnlighterJSRAW">//all port references are Port B numbers like digitalRead() and digitalWrite()
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(4, OUTPUT); 
analogWrite(0, 255);  //100% duty cycle (fully on) PWM on PB0
analogWrite(1, 128);  //50% duty cycle PWM on PB1
analogWrite(4, 0);  //0% duty cycle (off) PWM on PB4</pre>



<h3 class="wp-block-heading">Summary on How to Address or Reference Digispark ATtiny85 Ports in Program</h3>



<p>To summarize, the commands pinMode(), digitalRead(), digitalWrite(), and analogWrite() all use the Port B number references.  Specifically, 0 for PB0, 1 for PB1, 2 for PB2, 3 for PB3, 4 for PB4, and 5 for PB5.  However, as an exception, analogRead() uses its own ADC port numbers.  Namely, 0 for PB5, 1 for PB2, 2 for PB4, and 3 for PB3.</p>



<h2 class="wp-block-heading">References on How to Program Digispark ATtiny85 Board with Arduino IDE</h2>



<p><br><a href="https://cyberblogspot.com/how-to-program-attiny85-with-arduino-ide/" target="_blank" rel="noreferrer noopener">How to Program ATtiny85 with Arduino IDE</a><br><a href="https://cyberblogspot.com/digispark-usb-device-not-recognized/" target="_blank" rel="noreferrer noopener">Digispark USB Device Not Recognized</a><br><a href="https://cyberblogspot.com/how-to-enable-serial-monitor-on-digispark-attiny85/" target="_blank" rel="noreferrer noopener">How to Enable Serial Monitor on Digispark ATtiny85</a><br><a href="https://cyberblogspot.com/digispark-attiny85-pinout-and-configuration/" target="_blank" rel="noreferrer noopener">Digispark ATtiny85 Pinout and Configuration</a><br><a href="https://cyberblogspot.com/how-to-use-at-09-ble-with-arduino-and-smartphone/" target="_blank" rel="noreferrer noopener">How to Use AT-09 BLE with Arduino and Smartphone</a><br><a href="https://www.arduino.cc/en/software" target="_blank" rel="noreferrer noopener">Arduino IDE Download Page</a><br><a href="https://github.com/SpenceKonde/ATTinyCore" target="_blank" rel="noreferrer noopener">ATtinyCore by SpenceKonde on Github</a><br><a href="http://digistump.com/board/index.php?topic=134.0" target="_blank" rel="noreferrer noopener">Digispark Model A Versus Model B</a><br></p>



<p> </p>
<p>The post <a href="https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/">How to Program Digispark ATtiny85 Board with Arduino IDE</a> appeared first on <a href="https://cyberblogspot.com">CyberBlogSpot</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cyberblogspot.com/how-to-program-digispark-attiny85-board-with-arduino-ide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
