ATTINY85 – SIMULTANEOUSLY USING I2C AND SPI PROTOCOLS
Introduction: ATTINY85 – SIMULTANEOUSLY USING I2C AND SPI PROTOCOLS
The Attiny85 does not support specific hardware for SPI and I2C comunications as on ATmega series, instead there is a hardware module called UNIVERSAL SERIAL INTERFACE (USI) that can be only configured to perform SPI or I2C. In this small project, I'd like to share how to perform both SPI and I2C protocols simultaneously on the ATTiny85 by:
* Using USI for I2C with TinyWireM library to read MPU-6050.
* Using remaining pins for Software SPI to control one LED MATRIX 13x15.
Let’s getting started by video below.
Step 1: Bill of Materials and Tools
Main components:
* 200pcs x LED 3mm, optional color, blue in my case.
* 2pcs x Double Sided DIY Protoboard Circuit 7x9cm.
* 1pcs x DigiSpark ATTiny85.
* 1pcs x MPU-6050 Accelerometer + Gyro.
* 2pcs x Shift Register 74HC595N.
* 2pcs x Power Logic 8-Bit Shift Register TPIC6B595N.
* 16pcs x Transistor A1013.
* 300pcs x R100.
* 16pcs x R1K.
* 4pcs x Capacitor 0.1uF.
* 4pcs x Copper Standoff Spacers 15mm.
* 2pcs x Female 40pin 2.54mm Header.
* 2pcs x Male 40pin 2.54mm Header.
* 1pcs x XH2.54mm – 3P 10cm Wire Cable Double Connector.
* 1pcs x XH2.54mm – 4P 10cm Wire Cable Double Connector.
* 1pcs x XH2.54mm – 6P 10cm Wire Cable Double Connector.
* 1pcs x Power Bank 5V, minimum 2A.
* 1meter x 8P Rainbow Ribbon Cable.
* Some small bolts and nuts.
Tools:
* Intelligent Digital Oscilloscope Multimeter. This is an useful multimeter tool with reasonable price and it is integrated waveform signal display within 20KHz.
* Hot glue gun.
* Soldering machine.
Step 2: Idea and Schematic
My idea is to use only one ATTiny85 to make an auto-rotating message led matrix - size 13x15. It uses an MPU-6050 Accelerometer + Gyro to calculate the angle and detect whenever led matrix is in upside-down position, then it will carry out the correction by rotating the message on led matrix and its direction as well.
You can download schematic with high resolution PDF file HERE.
Step 3: Protoboards Soldering
I soldered the led matrix shield and control circuit on 2 prototype boards 7x9cm as diagram shown on STEP 2.
1. Soldering led matrix shield 13x15
I cut led pins short enough and ensure all led anodes/ cathodes to be soldered together without any extension wires. Led matrix shield have all 15 rows and each row has 13 leds. At the bottom, male headers for led anodes (rows) and cathodes (columns) were soldered to plug on the control board.
* Top view
* Bottom view
2. 611
Soldering control circuit
I soldered the control circuit to another DIY protoboard 7x9cm. All the wires were arranged on PCB top and they will be hidden when led matrix shield is plugged.
* Top view
* Bottom view
* Plugging ATTiny85 and MPU6050 into their female headers.
* Connecting the wires from ATTiny85 male header to SPI and MPU-6050 male headers. Control board is DONE. The ATTiny85 USB port is protruded from the protoboard so that it can be plugged into a computer or power bank.
3. Connecting protoboards together
* Plugging matrix shield to control board.
* DigiSpark ATTiny85 was glued into the control protoboard to avoid wobbling.
Step 4: Eagle Design
Because the protoboard 7x9cm has limited space so I took my times to design this project in Eagle software. With the same hardware configuration, Eagle PCB can control led matrix 16x16 with auto-rotating function.
I have just finished designing and did not send to fabrication company. I think it should work as same as my protoboards.
And here is my design. 611