![]() ![]() it has a count argument to tell you how many. it has to be able to handle multiple bytes. it only cares about the one byte at a time and will be called multiple times to get more data. You need a request event, and all that does is send the data in the current register (just an array and an index variable), and increments its index (thus subsequent events can read out the entire array, in typical i2c fashion). just register them right after TinyWireS.begin() using TinyWireS.onReceive() and TinyWireS.onRequest(), both take a function for their respective events. then, some years later, i used the callbacks and now it works like a charm. The first time i gave it a go, and i also couldn’t get it to work and gave up. ![]() Posted in ATtiny Hacks Tagged arduino, attiny85, i2c, light sensor, sensor, slave, tiny Post navigation What’s the most esoteric I2C sensor that you can imagine? (And is it really the case that we haven’t seen an I2C slave device hack since 2010?) But if you’re building your own devices, the sky is the limit. But what do you do when you want to make the I2C device? ’s project makes use of TinyWireS, a slave-mode SPI and I2C library for AVR ATtiny Arduino projects. Everyone and their mom uses I2C to connect to sensors, for which the Arduino “Wire” library or “i2c-tools” on the Pi do just fine. We’re covering this because we rarely see people coding for I2C slave devices. ![]() It’s all up on GitHub if you’re interested. wired up a tremendously simple circuit, downloaded some I2C slave-mode code, and added an LED for good measure. You can, of course, buy I2C ADC chips and modules, but when you’ve already got a microcontroller that has ADC peripherals on board, why bother? He wanted to include a light sensor but the problem is, the Pi doesn’t have a built-in ADC to read the voltage off the light-dependent resistor that he (presumably) had in his junk box. Has a weather station, and its nerve-center is a Raspberry Pi.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |