you'll have to have an AVR programmer set up. If you don't have that, click here to find out about different versions. You'll have to have some sort of an I2C connection already on the Raspberry Pi, click here to learn about this.
Some extra reading and resources:
On the theory of operation, calibration and precision check this application note from Atmel. On increasing resolution and oversampling look at this note. On a basic integer averaging technique and code optimization look at my post here.
Let's get started.
1. Download the usitwislave library.
2. Download the analogue digital converter C code from my github. Put them in the same directory.
3. I achieved reliable communication when the ATtiny worked at 8 MHz or above and brownout is set to 2.7V (see more on stability of I2C here). The fuses have to be set for this. Here are the avrdude options:
To get a voltage on channel 1 you'll have to send the command 1 over I2C to the ADC and read the value by sending a write request.
NOTE: you'll have to send the write request twice since the output buffer is 0 after a write. See the end of this post. When you first power up the ATtiny it will blink its device ID. I.E. for 3 it will blink three times. So use lower IDs or delete this from the ATtiny code. Sometimes it comes handy in our application. Also after the last bit has been sent the LED blinks shortly.
5. Make the board. The parts you'll need:
- A small PCB board (2 cm x 5cm is enough)
- 8 way IC socket
- one 500 and a 22k resistor
- one LED for feedback to the user
- 8 header pins
- 0.1uF capacitor
The schematics are below:
An ADC conversion takes time, when you want to take a measurement at an exact point in time (eg 0.01 ms precision), you'll have to consider the inner workings of an ADC conversion a bit more. This is just an example code to understand how things work and the code will work, too, for a generic application. To dig deeper in this field, check out the datasheet of the ATtiny25 to get an idea about ADC trigger modes, times for conversions, ADC cycles and interrupts.