My first concern is whether or not the ATTINY84 can execute the necessary tasks. No doubt, it can turn LEDs on and off. But will the I2C bus communicate to the accelerometer? Can it be put into Sleep mode? And can it be wakened with a pin change interrupt? A few experiments will confirm or deny the capabilities.
The experimental breadboard is shown (*****). A Teensy2 is used as the programmer, and as an independent test platform when needed. An IMU with a couple of accelerometers is there to test the I2C bus, then to test possible uses. And, obviously, an ATTINY84, complete with a status LED.
A few details are worth noting. First, the accelerometer operates at 3.3V. In the planned application, I'll use a 3V Lithium cell, but for testing, the Teensy2 needs to use 3.3V. Fortunately, the Teensy is designed to do this by just putting an MCP-1825S-3302EDB regulator on it and fixing the appropriate jumpers - all detailed on the PJRC web site. In the Arduino environment, be sure to set the correct clock rate: 8 MHZ for 3.3V operation. [explain set up of T2 to be a programmer, and how to use it from Arduino.] Use the Arduino environment to configure the Teensy2 to program the ATTINY84. From the File / Examples menu, select ArduinoISP and load it to the Teensy2. Connect to the ATTINY84: MOSI to MOSI, etc. Teensy2 Pin 10 is connected to ATTiNY84 Reset. Get power and ground from the Teensy2 also. Select Tools / Programmer / Arduino as ISP to load a program to the ATTINY84.
With 3.3V operation in place, let's configure the ATTINY84 for 8 MHz operation and try Blink. If you're playing along at home, be sure to set up the ATTINY84 in Arduino following the excellent instructions at http://highlowtech.org/?p=1695. As explained, run Tools / Burn Bootloader to set the ATTINY84 8 MHz bit. Time to load Blink and watch happily as it does its thing.
Easy! Time to try I2C. For the first test, I used the Teensy2. Pull-up resistors are on the I2C lines on the IMU - I use 4.7K and it works fine. The Scan example from https://playground.arduino.cc/Main/I2cScanner was used to verify basic operation and to show that my IMU parts were at the expected addresses. I then modified a couple of example programs from the Wire library to test a simple write and read back. Easy to do using the Serial Monitor. But thinking ahead, I wanted an easy way to verify I2C with the ATTINY84. No Serial Monitor! Hmmmm. Lots of options, but the simplest one I could think of was my Rigol DS1074Z. The I2C capture and decode modes were perfect and will work with the ATTINY84. With some suitable planning, I can use it with the circuit board I'm designing for the POV. Output from the Rigol is shown (******).
On to the ATTINY84! I am using the TinyWire library available here: https://playground.arduino.cc/Code/USIi2c. I have made a couple of minor mods to the library. First, I added support for the ATTINY84 and removed the F_CPU definition so that the clock rate will be set correctly by the Arduino environment. I also changed receive and send to read and write for compatibility with other Arduino libraries. My version of the library is one of the project files. In passing, I humbly claim authorship of the original USI_TWI_MASTER code (adapted from Atmel Apps Note). That code was released in this Instructable: https://www.instructables.com/id/I2C_Bus_for_ATtiny_and_ATmega/ Thanks to BroHogan for the excellent C++ wrappers he provided and for adding support for processors beyond the ATTINY2313. The Teensy code was easily modified to use TinyWireM and the Rigol quickly verified correct operation.
Next up is Sleep Mode and Wake on Interrupt. Sleep Mode is one area that I had no experience with. Needless to say, Google was my friend! The talented Nick Gammon, plus a few others, provided me the direction I needed. In fact, they even included examples of how to use the pin change interrupts. Turns out that Atmel has supplied some useful libraries, and the examples showed the rest. When the ATTINY84 was put to sleep, power dropped into the uA range, and when the appropriate pin was toggled, it woke up and lit the status led. Perfect!
Putting the accelerometer into the correct mode to provide the wake up signal is still not solved, but I know that the key elements work. I2C communication works, Sleep Mode works, and Wake on Pin Change works. Next step is the circuit board design.
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.