using the ATtiny85 Chip
in this iteration, was to make and assemble a PCB board with the main controller board "ATtiny85" microcontroller
that chip can control a PC through USB using HID Keyboard or Mouse as an input devices
our project will sizing down or Shrinking the last iteration we already did before,
controlling a simple game like SuperMario as an example it will have 2 modes :
buttons as arrows keys (up, down, left, right & fire or space )
2 Tilt Switches sensors controlling (left & right ) movements
a button dedicated to switching modes
.... so lets see what we will get to :)
our used Components is :
ATTiny85 as the Brain
6x tactile switch
2x Mercury Tilt Switch Module KY017.
PCB .
some resistors and capacitors
USB type B
Soldering iron and flux and soldering wire
3mm Acrylic sheet of 15x15 cm roughly
3d printer for the housing
m3 screws 4x(5mm) 4x(15mm) for tightening the case together.
some basic knowledge of the followings :
Arduino C/C++ coding and ide.
Eagle software for designing the PCB
Fusion360 for designing the enclosure box.
3dprintng basic knowledge our prototype.
milling with the "Rollandmill mdx20"
laser machine for cutting acrylic.
soldering iron.
this iteration's main idea was
how to shrink down your project, and make it tidy inside and out :D
cleaning and de-cluttering miss wires and using smaller buttons
also, learning more about electronic circuit and how to prototype or manufacture a small scale PCB Circuit.
here in this iteration
i started the design * inside out, (started with PCB )
which gave me the chance to think more about the size relations of all the components and the casing
this iteration we learned new software which is
Autodesk EAGLE , this software makes PCB "Printed circuit board",
here eagle software makes the tracks you see on a pcb that connect components to each other instead of using the jumper wire like we used to do and thus eliminating connectivity issues, and it shrink down the overall size too ................................ so let's dig in.
Schematic diagram
what makes the circuit is to the components and how they are connected to each other it is represented by a schematic diagram that is easily to read and copy with other electronic engineers or hobbyists.
we started with Google of course :D
we searched for the "minimum setup attiny85 circuit schematic"
this gave us what is the component used to connect our ATtiny85 Chip
Step 1
replicating the schema in Eagle software, we start by setup eagle and importing some library "Adafruit " which will help us search and insert the used components to get the exact footprint.
Step 2
inserting components from the Adafruit library and connecting GND and 5v to their places as the schematic
Step 3
give a check on the design rules or the DRC that is the distances and measurements of the pads and track width and the spacing between each of them to the other ,
we starts with the line tool to outline a rough dimension of the board, then laying components close to each other to minimize unused distances, we used a common ground GND, lastly generating routes/traces and make sure we don't have any airwires "unconnected item " it was fun like a puzzle game :D
it took me, longer time more than what you may think.
after finishing we exported the files for manufacturing on the "Rollandmill mdx20 machine" using (CAM Processor ) generating button
Step 1
Rolland milling machine _ MDX20
the milling process here
simply using the machine to etch out un wanted copper from the surface of the PCB thus making the routes only
and after that we will make holes or drills for components and screws
lastly cut the outline of the baord.
the designed we generated by Eagle (CAM Processor )was exported as GRBl files, eagle exports the file as layers we will need "Routs/Pads - Drills - outline " there is some other useful layers like the shapes and names of the components and symbols called silkscreen but we wont use in milling
We used a secondary app "Grbl Viewr" To convert grbl files to Pdf files that can be edited on gimp or photoshop to convert it to indexed Black & White and save png format
inverted:- black is what we want to remove white is the copper tracks
we start the process attaching the pcb to the machine surface using double layered tape and masking tape
and then send the layers one by one to the machine in this order you can start with tracks or drills but make sure to cut the outline last setting in the attached figure
Tracks
Drills
Outline
in the machine settings we choose machine type Rolland mill and choose mdx20 we choose the process type (outline or traces )
after that we clean the surface from unwanted pointy copper smoothed it out with lite Sandpaper
drills .png file
routes .png file
outline frame .png file
drills
routes
outline frame
i started with drills
finished PCB _ for the main chip and usb
i did the same steps again :
to create the PCB for the buttons
*so now i have two PCBs.
buttons PCB
drills .png file
routes .png file
outline frame .png file
2. Soldering Electronics
soldering part i soldered all buttons ground to each other and did the same with the tilt switches grounds and +ve terminals too then i got a signal for every button and switch to connect to the Arduino's pins
main board
main board
button's board
button's board
the main chip ATtiny85
capacitor 22mf for stapling the current
Zener diods and usb
next step is fusion i started by importing the PCB the cool thing is that eagle and fusion are both integrated with each other they are both made by Autodesk, there is a send button in eagle that sends the file to Fusion360 and you can SYNC between each other so any modification made in Eagle will be updated in Fusion360
after that i projected the PCB on an empty sketch and started building a compact design
i added the buttons to a separate board and made a screw fit for mounting with the top cover
i added an acrylic sheet as a spacer to keep the two board spaced away from each other,
the bottom cover has some screw fit too to combine all parts as one body
there is a clear acrylic window add in the bottom part
files
here after i finished the exporting each mesh component as an STL file
i imported them in ultimaker Cura Slicer software
and reoriented the bodies on their flat surface ,
i selected PLA and used 0.3 as a preset for the resolution of the print
i added supports for the slopes and hangings in the outer shape
and made sure of the heat to be (215)
i generated a gcode and saved it to a card and uploaded in the machine
it took about 3 hours to print and it looked surprisingly great from the first print :D
( 3mm Plywood Fabrication )
in LaserWork app > the laser machine software used at fablab
i rearranged the two acrylic parts.
made sure there is no overlapped duplicated lines.
assigned power and speed for Cut (10 speed , 60 power)
and for Scan (50 speed, 15 power)
uploaded the file to the machine .......
after uploading
placed a scrape piece of acrylic roughly 15x15 cm 3mm thickness
did a test run on the frame of the file uploaded
made check of focus distance of the laser
making sure of the air flow and
then hold your breath and click RUN . . . . . . . . .
i gathered all components
it was the first time i cut acrylic so some of the parts got black burns on them,
i add the m3 screws for the buttons first to the top 3dprinted part
then i put the board in its place and sandwiched the acrylic between the 3dparts and closed it all and add the long m3 screws
i assembled the 3dprinted case and made sure it all fits.
before we start coding we need to setup the driver for the chip ATtiny, so PC can know it when connected
we do that with the help of Arduino UNO
we use the Arduino UNO as a programmer here is a link we followed and it worked great
https://makesomestuff.org/tiny-cairoduino-kit/#How_To_Program_Your_Board
after connecting the ATtiny to the breadboard and the Arduino UNO
we connect it to pc and
step 1
add this path to the IDE's preferences
http://digistump.com/package_digistump_index.json
as following >>>>
step 1
step 2
this will add the name of the Attiny85 board in the board manger of Arduino IDE
step 2
step 3
step 4
after setup driver
download and extract those files to this Path:
"C:\Program Files (x86)\Arduino"
you have to edit with notepad and write the Arduino's COM "number" connected to your pc
step 4
now you should see your ATtiny85 chip when connected to pc as a new hardware and it will be shown in the device manager
step 4
to use the usb input device on a pc
we have to include a library called DigiKeyboard.h
this library make sure connection is established through the USB HID of the ATtiny85 and PC as input devices
i then assigned the buttons pin mode we are using Analogue read from the buttons value pin 2 that when called as an Analogue read we type pin 0
then adding sensor digital readings pin 1 & 0
we set sensores as low
in this part of coding its a loop that run only ones at the beginning of the code :
setting pinMode inputs for buttons and sensors
in this part of coding its a loop that run continuously and loops back over and over non stop
this part of the code i will put the mode selector part that will switch modes after pressing a button a count of times.
and it will call either of the next two functions or Modes
this function or Mode will assign a keyboard arrow key to every button
you can add a hex number of one of the keys on a pc keyboard or you can write down its reference modifiers from the library itself . with a DigiKeyboard.sendKeyPress();
i found some of the (hex no and modifiers ) here is a link : https://github.com/digistump/DigistumpArduino/blob/master/digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h
#define KEY_ARROW_UP 82
#define KEY_ARROW_DOWN 81
#define KEY_ARROW_LEFT 80
#define KEY_ARROW_RIGHT 79
#define KEY_SPACE 44
for testing ATtiny85 don't communicate with serial port so i added "DigiKeyboard.println("key pressed")" after every key press just for testing
ATtiny85 don't have many pins so to get a different value for each key stroke from one pin, we used the analogue pin read and add resistors to get different values with each one,
so i assigned a variable and stored the value from the Analogue read in it
here is the different values from the resistor
val == 144
val == 168
val == 201
val == 252
val == 337
val == 507
i then mapped them to each button placed on the game controller
and to release keys i did this probability when val is 0
if (val == 0 ) {
DigiKeyboard.sendKeyPress(0, 0); //Release keys or press nothing
this function or Mode will assign the tilt switches to press a key to click arrow left or right instead of the buttons.
sensors is very normal digital reade if one sensor pin is HIGH keypress a button and vice versa for the other sensor
What I learned this week is...
i learned a lot in this Project
more fittings techniques < fusion360
i learned a whole new software Eagle which is awesome i never used before "i need to pratice more with it"
new chip ATtiny85 < coding
how to read different Analogue values and make a small read multiplexer if you can say