DIY I2C Devices with ATtiny85

Originalartikel

Backup

<html> <p>[Pawel] has a weather station, and its nerve-center is a Raspberry Pi. He <a href=„https://quadmeup.com/attiny85-light-sensor-i2c-slave-device/“ target=„_blank“>wanted to include a light sensor</a>&#160;but the problem is, the Pi doesn&#8217;t have a built-in ADC to read the voltage off the light-dependent resistor that he (presumably) had in his junk box. You can, of course, buy I2C ADC chips and modules, but when you&#8217;ve already got a microcontroller that has ADC peripherals on board, why bother?</p> <p>[Pawel] wired up a tremendously simple circuit, downloaded some I2C slave-mode code, and added an LED for good measure. It&#8217;s all <a href=„https://github.com/DzikuVx/attiny_photoresistor_i2c“ target=„_blank“>up on GitHub</a> if you&#8217;re interested.</p> <figure id=„attachment_228116“ style=„width: 410px“ class=„wp-caption alignright“><a href=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png“ target=„_blank“><img data-attachment-id=„228116“ data-permalink=„http://hackaday.com/2016/11/07/diy-i2c-devices-with-attiny85/cropped_shot_2016-10-21-112958/“ data-orig-file=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png“ data-orig-size=„865,340“ data-comments-opened=„1“ data-image-meta=„{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}“ data-image-title=„cropped_shot_2016-10-21-112958“ data-image-description=„“ data-medium-file=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=400&amp;h=157“ data-large-file=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=800“ class=„wp-image-228116 size-medium“ src=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=400&amp;h=157“ alt=„cropped_shot_2016-10-21-112958“ width=„400“ height=„157“ srcset=„https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=400&amp;h=157 400w, https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=800&amp;h=314 800w, https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=250&amp;h=98 250w, https://hackadaycom.files.wordpress.com/2016/10/cropped_shot_2016-10-21-112958.png?w=768&amp;h=302 768w“ sizes=„(max-width: 400px) 100vw, 400px“/></a><figcaption class=„wp-caption-text“>Bright by Day, Dark by Night!</figcaption></figure><p>We&#8217;re covering this because we rarely see people coding for I2C slave devices. Everyone and their mom <em>uses</em> I2C to connect to sensors, for which the Arduino &#8220;Wire&#8221; library or &#8220;i2c-tools&#8221; on the Pi do just fine. But what do you do when you want to <em>make</em> the I2C device? [Pawel]&#8217;s project makes use of <a href=„https://github.com/rambo/TinyWire/tree/master/TinyWireS“ target=„_blank“>TinyWireS</a>, a slave-mode SPI and I2C library for AVR ATtiny Arduino projects.</p> <p>Here, [Pawel] just wanted a light sensor. But if you&#8217;re building your own devices, the sky is the limit. What&#8217;s the most esoteric I2C sensor that you can imagine? (And is it really the case that we haven&#8217;t seen an I2C slave device hack <a href=„http://hackaday.com/2010/08/06/make-your-own-mindstorm-sensors/“>since 2010</a>?)</p> </html>