A Tiny Compass With ATtiny85
by raul7321 in Circuits > Arduino
12417 Views, 156 Favorites, 0 Comments
A Tiny Compass With ATtiny85
This is our first project with ATtiny85; a simple pocket digital compass (in collaboration with J. Arturo Espejel Báez).
ATtiny85 is a high performance and low power microcontroller. It has 8 Kbytes of programmable flash memory. Due to this, the challenge in this project was to reduce the size of the program, since the circuit is very simple, thanks to the I2C protocol.
Supplies
For the Compass:
- ATtiny85
- HMC5883L Magnetometer
- SSD1306 I2c 0.96" 128x64 OLED Display
- Self-locking square button switch
- 3.7V 300mAh Lipo Li-polymer Battery
- 3D printed case (2 parts, please find the STL links)
For the Charger:
- Two pieces of PCB; 17x10mm and 13x18mm
- 3D printed case (2 parts, please find the STL links)
- Micro USB 5V 1A TP4056 Lithium battery charger module
The Program
It is necessary to load the program AB.ino into the ATtiny85 before wiring it in the circuit. For this, you can follow any of the tutorials on the internet, such as https://www.instructables.com/id/DIY-Attiny-Progr...
To compile the program, you need to install the library ssd1306 by Alexey Dynda, available in https://platformio.org/lib/show/1904/ssd1306
The Circuit
Wiring the ATtiny85
It is convenient to cut the unused pins of the ATtiny before soldering.
Prepare two 10-cm pairs of wire by stripping two 2-mm sections halfway and separated by about 5 mm from each other, as shown in the 1st and 2nd photos. Solder one section of the first pair of cables (A) to SDA (pin 5) and the other section to SCL (pin 7) as shown in the 3rd picture. With the other pair of wires (B), solder one cable to GND (pin 4) and the other one to +V (pin 8), like in the 4th photo.
Wiring the OLED Display
Solder the four wires of one side of the ATtiny (SDA, SCL, +V, and GND) to the corresponding contacts of the OLED display and glue it to the case. Protect the display board with insulating tape.
Place the Charger Contacts
Take two wires from a male header pin connector. Fold each one forming a hook as in the first photo. Insert one in the lateral side of the display case, and the other in the bottom lid as shown.
Wiring the HMC5883L
Glue the HMC5883L magnetometer to the bottom lid as shown. Solder the SCL and SDA wires from the ATtiny to the corresponding contacts of the magnetometer, fold the charger contact wire and solder to the GND contact. Solder the +V and GND wires from the ATtiny to the corresponding contacts. Protect the magnetometer board with insulating tape.
Wiring the Battery
Solder the negative pole of the battery to pin 4 of the ATtiny, and the positive to the charger contact in the side of the case. Add a wire from this contact to the switch (see next step).
Wiring the Switch
Solder the wire from the lateral charger contact to one contact of the switch, and then another one to the +V contact of the magnetometer. Now you can test the Compass and glue the bottom lid.
Calibrating
The program AB.ino has an automatic calibrating algorithm. You only have to turn on and rotate the compass 360º as shown in the video.
ATTENTION!
Never connect both external contacts as this would short-circuit the battery.
Charger I
Cut two pieces of PCB of 17 mm x 10 mm and 13 mm x18 mm. Drill a hole in the small piece that matches with the hole in the round 3D printed part, pass a wire through and solder it. Glue the PCB as shown in the photo.
Charger II
Solder a wire in the 17x10mm PCB piece and pass it throw the slot in the 3D printed part. Glue it as shown.
Charger III
Fit and glue the 3D printed parts as shown and solder the wires to the battery charger module. The wire soldered in the bottom part is the negative. Now you can charge the compass' battery with a mini USB cable.