Embedded Programming

Week 6

This week our group assignment is to compare the performance and development workflows for other architectures(Link: The Group Assignment is Here! ). Individually we have to read a microcontroller data sheet program your board to do something, with as many different programming languages and programming environments as possible

Tools PCB Mill (Clank), Soldering Iron, KiCad
Date: 10.22.2020

Here is my schematic for reference. I have a SERVO motor, Peltier Chips and a a capacitive sensor.



Arduino setup
1-Download the Arduino IDE from their website.
2-Load the ATtiny cores by going to File-->Preferences, then pasting the following in the Additional Boards Manager URLS field: http://drazzy.com/package_drazzy.com_index.json
3-Go to Tools-->Boards-->Board Manager, and scroll all the way down and install the latest version of megaTinyCore by Spence Kode. Now the cores are installed. 4-Under Tools-->Chip:, be sure to select the microprocessor you are using. In my case, I am using the attiny1614. 5-Write your program in the Arduino IDE. You can open any example, I used File-->Open Recent-->motor_2. It really does not matter what you choose, we are only setting up now. 6-Go to File-->Preferences, and click on the preferences.txt to add the following line: build.path=C:\Users\jkrit\Documents\Arduino\Hexes. The idea is that you create a folder inside the Arduino folder (where all your coded sketches get saved) where the Arduino will store the .hex files every time a code is compiled. I created a folder called Hexes in my Arduino folder, which will make it easy for me to go in there, copy the .hex file, and paste it in its respective sketch folder.

Not Arduino setup
7-Install the latest version of python. You can do this by opening CMD on windows and typing: python, which will immediately launch the Microsoft Store and click on "Get" to download. First run 8-An optional step is to update pip3 to the latest version. > Any time you use pip3 in CMD, it will direct you to the link to update. 9-Go to this repository and clone to your location of preference and extract the zip file. You can alternatively type : pip install https://github.com/mraardvark/pyupdi/archive/master.zip in CMD to install, though this did not work for me. Maybe because I used pip, but should have used pip3 since I installed python 3.8? In any case, you need to install pyupdi which is a python script that flashes your code onto your board. Note: you need to know the exact path to pyupdi.py, and maybe copy the entire path down somewhere to make your life easier later. 10-In CMD, type: pip3 install intelhex pylint pyserial 11-Finally, in CMD, cd into the directory of the coded sketch that you wish to flash on to your board, then type: python3 A -d B -c C -b 115200 -f D where A is the full path to pyupdi.py, mine is C:\Users\jkrit\Downloads\pyupdi-master\pyupdi-master\updi\pyupdi.py B is your chip name, mine is tiny1614 C is the port where you plugged in the FT232. You can find this in Arduino's IDE under Tools-->Port: and plug in the FT232 and unplug and see what appears. In my case, it is COM9 D is the name of your hex file All together, you should have a command that looks like this: python3 C:\Users\jkrit\Downloads\pyupdi-master\pyupdi-master\updi\pyupdi.py -d tiny1614 -c /COM9 -b 115200 -f motor_2.ino.hex Hitting enter will load your program into your chip.

Motor Clockwise, Anticlockwise Program The first thing I did was write a program that can control the motor to run clockwise and anticlockwise. The important thing to note is calling pin names in Arduino is not exactly calling the pin number. We have to refer to this schematic again:
datasheet schematic>



My motor one leg is connected to Pin 12 on the chip, which can be called using its port name PA2 (which can be a bit complicated to call) or by the brown/blue numbers, in this case 9. Similarly, the other leg is connected to Pin 11 on the chip, which can be called using its port name PA1, so I call it using 8 in Arduino. Here is my code:



After writing this, I compile the code by clicking the verify (checkmark) button in the Arduino IDE. I then copy the .hex file from my Hexes folder into the folder containing the sketch. Then I go into CMD and cd into the Arduino folder containing the sketch and input: python3 C:\Users\jkrit\Downloads\pyupdi-master\pyupdi-master\updi\pyupdi.py -d tiny1614 -c /COM9 -b 115200 -f motor_2.ino.hex -v I found out that having the -v on the end makes it take longer to flash the code onto my board because it prints everything. So I removed that from future use for faster uploads. Here is the result:



This week taught me the neat ways of bringing all of these tiny parts togehter, getting familiar with clank and that I need more familiarity with coding to be able to continue making things.