Skip to content

Week 08: Embedded Programming

Assignments:

  • Group assignment: Compare the performance and development workflows for different microcontroller families. Document your work (in a group or individually).

  • Individual assignment: Read the datasheet for the microcontroller you are programming. Program the board you have made to do something, with as many different programming languages and programming environments as possible.

What to learn:

  • Identify relevant information in a microcontroller datasheet.

  • Implement programming protocols.

Have you?

  • Linked to the group assignment page

  • Documented what you learned from reading a microcontroller datasheet.

  • Programmed your board

  • Described the programming process/es you used

  • Included your source code

  • Included a short ‘hero video’ of your board

DOUBT: Is it enough for the group assignment if we compare different microcontrollers in theory? Answer: No, You need to program at least two different family MCU’s.

DOUBT: Do I have to design and make a new board for this week? Answer: No, You can use the board you made in electronics design

DOUBT: If I adjust existing code, is that now my code? Answer: If you use someone’s else code as a starting point, remember that you must acknowledge whoever made it. See General Essentials. To succeed in this assignment, experiment with changing the code, understand how that worked, and write your own.

DOUBT: How do I prove I’ve read the Datasheet? Answer: Point out things in your code and board design that you learnt from the Datasheet. Also point to other weeks when you used information from the Datasheet.

DOUBT: How should I put my code on my website? Answer: As a file for download, same as all your other assignments. Keep your webpage tidy and easy to read.

GROUP ASSIGNMENT: Compare the performance and development workflows for different microcontroller families. Document your work (in a group or individually).

Embedded programming involves programming small computers(embedded system) that drive devices using a programming interface.

Hardware(visible) + software(invisible) working together, perform some action called embedded system. Embedded systems perform specific tasks which are controlled by a microcontroller.These systems are smart and more efficient, which is increasing their use day by day.

For the group assignment we will compare the workflows of working with different architectures.

Understanding architectures:

  • [Von Neumann architecture](https://www.wiley.com/legacy/wileychi/wang_archi/supp/appendix_a.pdf) is the computer architecture where data and programs were in the same space.

  • The [Harvard architecture](https://harvardmagazine.com/2014/04/mark-i-rebooted) came from the lineage from the computer shown in the link where where data and programs are in different spaces. We will be using the idea of Harvard architecture in embedded systems. There is memory for programs and there is memory for data.

  • RISC(Reduced Instruction Set Computers): CPU design strategy based on simple instructions that just do one thing but can be executed very quickly.

  • CISC(Complex Instruction Set Computer): CPU design strategy based on single instructions which can do many different things. It has a large number of complex instructions, which makes it longer to execute.

There is a very understandable link here on the difference between CISC and RISC.

  • We will be using microcontrollers instead of microprocessors:

microcontrollers

microprocessors

  • In the following table I explain the difference between the two which I understood here
Microcontrollers Microprocessors
Mini-computer capable of performing a task on its own. Central processing unit inside our computers
Less powerful processor but on the chip they have the processor, memory, communication and everything you need to make a system. Very powerful but it can’t do anything by itself it needs many other chips to function.
Does not need external components to work Its packaging does not contain RAM, ROM and other components required to perform a task, so it needs external components.
It is used in embedded systems It is used in computers as it is the brain of a computer.
Used in compact devices and with a low power consumption. Devices made from microprocessors are bigger are more power consuming
It has a fixed amount of memory that cannot be upgraded. The memory can be upgraded.
Faster Slower
Cost-effective, battery-operated electronics. High processing capacity for complex tasks such as games, website and software development, etc., functions are unlimited.
  • GPU run faster

  • TPU versions for machine learning, specialised for high performance computing. We will not be using them.

  • FPGA allow for custom logic.

  • Tiny FPGA The TinyFPGA boards are a new series of low-cost, open-source FPGA boards in a tiny form factor. Solder on pins for use in a breadboard or PCB socket; or solder connectors, wires, and components directly onto the board. They are a handy family to use before making a chip from scratch by making a virtual chip and running it on the Tiny FPGA.

  • This link is a research about spatial computing models where you represent programs as geometry.

We will be using microcontrollers with a Harvard architecture and a RISC instruction set.

Henk introduced us to different families of boards:

differentarchitecture

  • The Fab lab academy works with different ATtinys (there is the old and new version, we will stick to the new version 412)

  • Arduino is a complete ecosystem. The main Arduino board is Arduino UNO.

  • There is also other types like Arduino Mega, Arduino Yun, Arduino Mini, Oli Mex, …

  • The ESP88366: has a built in wifi and radio.

  • ESP32: has a built in wifi and camara.

  • The Makey Makey: is a kit introduction for electronics, it contains a USB and alligator clips which you connect to your computer and allow you to transform almost anything into a “key” that tells your computer what to do, whether that’s typing a letter or controlling a game character.

Understanding datasheets:

For example, when looking at the ATTiny 412 datasheet you can see it is 500 pages long. There are subsections on pinout (what pins do), types of memory, peripherals,.. It also has information about packaging and performance. We don’t need to read every word on the 500 pages but we do need to scroll through it to understand the different subsections.

Subsection of memory:

In a processor there can be different types of memory:

  • REGISTER: where instructions are held, executes quickly, processor instructions are only here.

  • SRAM: data that is fast but not dense)

  • DRAM: (data storage much larger but not as fast)

  • EEPROM: (stores data without power, non-volatile, stores data without power)

  • FLASH: (stores data without power, denser but harder to program, programs, strings)

  • FUSE: (store configuration)

Subsection of peripherals:

Depending on the processor there can be different peripherals:

  • Ports: send signals out to pins and read them in from pins.

  • A/D: converts analog voltages into digital values.

  • Comparator: quickly compare two different voltages.

  • D/A: converts numbers into analog voltages

  • Timer/ counter/ PWM: count times, count events or make pulses of varying width

  • USART: serial communication

  • USB: USB communication

Subsection of word size:

As the word size gets bigger the processor is more powerful (but even the smallest one has a lot of utilities), we will be using 16 bit and 32 bit processor:

  • 8 bit processor: which means each instruction processes 8 bits

  • 16 bit processor: which means each instruction processes 16 bits

  • 32 bit processor: which means each instruction processes 32 bits

  • 64 bit processor: which means each instruction processes 64 bits

Subsection of families:

In Digikey the family can be found here: familydigikey

This link is a test that shows the speed of ring oscillators for many types of processor families. Each of them is an example of the ring oscillator, for each of these processors it shows how to talk to the pins. Each of them is a way of understanding how to read and write the pins.

  • Logic is a 4 bit processor made from cardboard.

  • Megaprocessor processor less powerful than the one we will be using but weighs a few tonnes.

  • 8051 ancient but esentially obsolete

  • PIC came from microchip, elements of PIC are now in AVR

  • MSP another family type

  • We will be focusing on [AVR](https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors/8-bit-mcus/avr-mcus) for 8 bit: Quoting from their website: “Offering unsurpassed performance, power efficiency and flexibility, they are an excellent choice for a variety of embedded system designs. Their combination of easily customizable peripherals and the industry’s most code-efficient architecture enable you to bring multiple functions to a single chip with minimal programming.” We mostly use this family because it goes from 6-100 pin packages (you can go from tiny processors to giant ones all in the same family).

ATtiny45V and ATtiny44A: they are not obsolete, still in production but not recommended for new designs because the following 1 series have many more integrated features.

We will make a lot of use of these processors: ATtiny412, ATtiny1614, ATtiny3216. They are 1-series processors, 8 bit, run down to 1.8 and up to 5.5V, and run 20 MHz. They have single-cycle global instructions which means each time the clock picks everything moves forward, really good to use when you need tight timing. They have simple peripheral register access. They have low pin-count packages which means they come all the way till tiny packages and they have one-pin serial programming, (you only need one pin to program them). They are cheap, flexible and powerful processors to start with.

In this family there is also the ATtiny1624 which is a newer version of the above, it is 2 series and the main difference it is a programmable gain amplifier which means it can reduce big signals and amplify tiny signals. It also has a more powerful analog section.

The AVR128DB32 is also new. The most interesting difference is its amazing analog section, beyond amplifiers, the DB has a switchable feedback network and multiple amplifiers. It runs 24 MHz, has an analog signal conditioning, level shifting and hardware multiplier(to do maths faster).

The DD which is coming has all these features but in lower pin counts.

  • ARM is another family type which designs chips but sends them to another place to be licensed. They have in this family: D11C, D11D, D21E, D51. This family is a more powerful family to grow into after AVR, but the strongest reason to start using it is their native USB. They are 32 bit, 1.6-3.6V. They also have faster clocks, more complex clock distribution and synchronization than AVR. They have more powerful peripherals, but they are harder to use, you can’t write simple code to program them, they need more complex register access and libraries. It is a diverse family with larger packages. It has a standard in-circuit debugging, really powerful tools to do code development.

  • Xtensa we will especially use this family because of the radio they integrate in their ESP8266 and ESP32. Processors with integrated bluetooth and wifi, also very powerful processors

  • RISC-V is an open processor architecture, just coming now in chips.

  • PSoC, xCORE, Propeller, Lattice, NVIDIA: these are all parallel, they are versions of little processors with many cores in them, not just 1. They have more performance for example for real time image video processing.

Vendors of these families:

Vendors start making them, demand ramps up, then out of stock, they make too many, You can have a perfect processor but out of stock.

  • Octopart search engine for parts, it looks for your processor on different vendor pages.

  • Digi-Key vendor we buy parts from.

  • Mouser vendor we buy parts from.

  • Newark vendor we buy parts from.

  • Farnell vendor we buy parts from.

  • SparkFun maker oriented, you do not buy processors from them but you buy all sorts of peripherals.

  • Adafruit maker oriented, you do not buy processors from them but you buy all sorts of peripherals.

Packages:
  • DIP: we will not use them, they are through holes, for plugin bread broad or drilling holes in PCB

  • SOT: surface mount packaging we will be using

  • SOIC: surface mount packaging we will be using

  • TSSOP surface mount packaging we will be using

  • TQFP surface mount packaging we will be using

  • LQFP surface mount packaging we will be using

  • MLF, WLCSP, [BGA](http://fab.cba.mit.edu/classes/S62.12/people/moritz.kassner/bga_pcb.html) these are the tiniest packaging.

Group assignment: compare the performance and development workflows for other architectures

We first started playing around with the Arduino IDE environment. I was working with Phil, Lucia and Erwin. When you get to the Arduino software you first have to choose the port you will be taking to. It is either the UPDI (to program) or the FTDI(to see the serial output). It took us a while to understand where everything was.

choosingport

When we chose the right port and right Arduino board in the IDE environment we started our first test, make the LED blink.

connections connections connections connections

We first set the places (ints) where we are going to store the values that will alter our board (i.e blink light)

int led_pin = 9 // int is for whole numbers and float would be used for fractions int on_periode = 50; int off_periode = 50; // if you change this to longer like for example 150 the blinking will go slower

codeandled

Erwin explained to us that the microprocessor has a frequency of 1000 actions per second. We wanted to test out the right speed that would make the blinking be invisible to the human eye so we modified the frequency by 1000/25 (blinking every 0,04 second). We could still see it blinking. We tried 1000/50 and then the blinking was no longer appreciated.

We also learned about Dutycycle terminology which meant “on” and downcycle “off”

int frequency = 1000/50;
float dutycycle = 80; // we use float here because they are not whole nubers
float downcycle = 100-dutycycle;

We now wanted to check the button so we added a button and connected it to Pin 7 on the arduino Board and to GROUND. The way this works is that the LED turn HIGH when the button turn LOW because 5V is more stable than 0V (due to possible noise) so if it is not exactly at 0V it won’t work properly.

addingbutton

connections

Erwin did a code which said if the button is on turn the LED blinking all the time using the “if”. We changed the frequency to 1000/10 so we could see the blinking.

We then tried making the LED blink in an analogue way incorporating a potentiometer to the breadboard. The difference between analogue and digital is that:

  • Computers only think in 0 and 1 so digital only has two status: 0V or 5V // On or Off

  • Analog: All the values between -120V and 120V. You can control the intensity. It is normally used to measure things like moisture, gas concentration, humidity, etc

This allowed us that with a screwdriver we could adjust the resistance of the potentiometer (variable resistance) and adjust the LED blinking either high or low (on or off). The code also says that if you push the button the LED will turn on.

int analoginput = A0;
int erwinsbutton = 7; //button connected to breadboard
int ledpin = 9; //LED connected to breadboard
int frequency = 1000/10;
float dutycycle = 60;
float downcycle = 100-dutycycle;
int potentio = 0;

void setup() {
pinMode (ledpin, OUTPUT);  // put your setup code here, to run once:
pinMode (erwinsbutton, INPUT_PULLUP);
}

void loop() { // actual program, instructions you give to your microcontroller.
  if (digitalRead(erwinsbutton) ==LOW){
  digitalWrite(ledpin, HIGH); // digital write high means on
  delay(frequency*dutycycle/100); // modifies the miliseconds between the blinking
  digitalWrite(ledpin, LOW); // digital write low means off
  delay(frequency*downcycle/100);

potentio = analogRead (analoginput);
dutycycle = map (potentio,0,1023,0,100);
downcycle = 100-dutycycle;
}

Individual assignment: Read the datasheet for the microcontroller you are programming. Program the board you have made to do something, with as many different programming languages and programming environments as possible.

What we will be doing this week is called in-system development which means that after designing a board(covered how to do it in the electronics production and design weeks), where we put a processor on our board, as well as a LED and a button, we now have to make the board do something (for example blink the LED, …). You are programming the chip in the board, by getting code into it. Remember you have a communication port (Arduino IDE) when you push the switch you can send the message out when you get a message in you blink the LED, …

Programming protocols:

  • ISP: OLD VERSION FOR AVRs: (not recommended for new designs): If you are using an ATtiny45 or ATtiny44 it will use an ISP protocol. To program it, this is a programmer with a USB on one side and a 6 pin programmer on the other side. Then we use the program AVRDude to load the program in.

  • UPDI (AVR 0,1,2-series,DA,DB,DD): NEW VERSION FOR AVRs: There are two protocols we use to load in the programs in the new AVR versions: the pyupdi where you communicate in through one pin (simple stand alone program) and thepymcyprog(more complex program). What both do is read the instructions and send them into the processor. To do the loading there are a few examples here: For example the hello.serial-UPDI is just a converter, the 6 pin go to a serial interface, it uses a resistor between two pins (transmit and receive) and this will led a serial interface talk to UPDI helloserialUPDI

For example this UPDI version(FT230X) uses a chip to convert directly from USB to serial interface: helloserialUPDI

This is a board to that goes from serial to D11C, implementing UPDI and also UART nodes: SAMD11C

All of these convert a computer signal to the signal for your processor and they use the pyupdi to load it.

  • JTAG for ARM it is recommended to use:

For software: Edbg: to load the program into the ARM parts we are using.

program: edbg -b -t target_type -pv -f binary_file
read fuses: edbg -b -t target_type -F r,*,file_name
write fuses: edbg -b -t target_type -F w,high_bit:low_bit,bit_value

For hardware Atmel makes a commercial programmer, and this can program both AVRs and ARMs. PICO is a development board for a processor but it comes preprogrammed as a programmer. You can use a Raspberry Pi to do it.

  • Bootloaders: it is a program that loads programs, you do not need any special hardware anymore, the computer uses the bootloader to program.

Assembly language: Where is the programming coming from?

  • At the lowest level you are sending in files that look like this: hex files. These are the instructions the processor knows (what we ultimately have to produce).

  • To get to it the processor has an instruction set, each of the families have an instruction see for example in page 18 and then underneath it the code(op-code) you have to send to give that instruction. instruction

  • At the lowest level you can write the codes directly, (used to do this in the old days, we don’t have to do this anymore because the compilers have got very good.)

Programming language we will use: C

We will be using the C language. Old but widely used because it is very efficient, it is specially used in open source software and embedded systems. This a link to an introduction for programming. C++ is a more modern extension of C.

  • We will be using [GCC](https://gcc.gnu.org/) compiler which goes from microncontrollers all the way up to biggest computers. Quoted from Computer Notes: “We know that a computer can understand only Machine Language But the Program Written by a user is in the Form of English Language So it very necessary to convert the human Language into the Machine Language. So for this purpose we use Compiler which Converts human code into the machine code.

The compiler takes my code: mycode

and turns it into processor code: hexcode

  • This is a link which explains how to manipulate not just numbers and characters but also bits (as what we will be doing is reading data from port about a pin, modifying the bits and sending data out, so we have to know how to work with bits in this process).

We will also need to set up a tool chain; a tool chain is the thing that compiles the program from a higher level language into the hex code. For example in the Arduino IDE environment the program has a loop that makes the LED blink. The tool chain takes the instructions and turns them into the code the processor understands. There are many frameworks to install the tool chain directly:

  • AVR: has libraries that are supported. (Linux) These libraries are the libraries that are supported, let you install the AVR libraries in Linux

  • ARM: also has standard packages for that These are standard packages for that

  • Microchip: (Linux, Mac and Windows). They also have these device packs on how to specialise the tool chain for the processors you are using.

IDE (Integrated Development Environments): this is an environment you use to interface the compiling process: which allow you to write your code, reference the documentation, build programs that have multiple packages independences, load code and debug.

There are a couple of steps(toolchain) for the processor to understand the instructions (code) but the compiler is a key step.

Frameworks

Arduino is 6 things:

  • set of boards

  • an installation of a toolchain (a very easy way to install it)

  • it is a set of libraries(convenient but inefficient)

  • it is an IDE for development (newer version more modern is going to be released)

  • a type of bootloader(depending your project)

  • it is a header, a form factor for peripherals(you may or may not want your board to interfere with the header)

When you say Arduino, you casually mean all of this, but the true thing is you can use every one of these separately.

Arduino is C. When you are programming in the Arduino environment you are writing C code but you are doing it with libraries. You can write C code either in the Arduino IDE or out of it.

  • The original Arduino used a processor 328P but these are already obsolete.

  • Cores are how you specialise the Arduino environment for a target type of processor board. These are arduino cores for Attiny, tinyAVR. DxCore, SAMD, ESP8266, ESP32. When you install the core, it brings in all the tools you need to talk to the processor. Even if you do not use the Arduino environment for anything else, installing the Arduino core is the most convenient way of installing the toolchain. The one caution is the library, the arduino libraries are very inefficient, take many more instructions and space in the code space. You might choose the Arduino IDE but not the library.

There are also other frameworks apart from Arduino:

PlatformIO: rapidly growing in popularity, it is a generalised version of Arduino, environment where you can pick one of many processors, many types of boards and then it configures everything you have to do with it.

Mbed: environment for development for ARM devices.

Boards:

If you need a lot of board in the future you can buy them already made from Atmel, Adafruit, Olimex, Polulu, MattairTech.

There has also been students in the Fab Lab Academy which have created board: Adrianino, SAMDino, D11Cdevkit, D21E devkit.

Clocks: your processor needs to tell time.

  • They can have onboard oscillators: RC (10%, 1% calibrated), ceramic (0.5%), quartz (50 ppm)

  • PLL: if you need tighter timing control we use external clocks.

  • Instruction cycles: you need to be aware of the number of clock ticks it takes to do something, differs based on the processor architecture.

  • Underclocking: to run processors slower (saves power)

  • Overclocking: to run processors faster

Host communication: we will be sending messages to and from the processor

  • RS232: ancient standard that makes a signal go up and down to send data.

  • Terminal programs: on the computer side you use a terminal to connect (VT100/ANSI/ISO/ECMA terminal/ Screen/ Kermit/ Minicom/ Arduino)

  • pySerial is a python library on the computer to talk to a port.

python -m serial.tools.miniterm /dev/your_device_port your_baud_rate
  • USB: you can do software in a USB on slower processors, and then more powerful processors would have hardware USB: LUFA, ASF and Arduino

  • FTDI: is a company that makes a converter between USB and serial, you can get USB cables; which has USB on one side and digital serial on the other, and you can also make your own; the hello.USB-serial.FT230X board.

Example of what we would have to do for individual assignment:

ATtiny412: 8 pin processor:

In this board it takes in power ground, with a programming pin and an LED, simplest board you can make.

In the Arduino program, you have to tell the pin whether it wants to be an input listening or an output talking. arduinprogramblink

You do this through C language: cprogramblink

In this video it shows how in the Arduino IDE, first we install the core for the 1-series ATtiny412 from Xpense, then we compile the program and load the code. Then it shows how by changing the code the blinking slows down.

D11C: d11c

This one has an ARM processor and it can talk directly to USB. Note that the Arduino D11 libraries take up nearly all of the chip before you put in the code.

See more examples of how to program boards with low level code here

Trying to program my hello board

I should have done the debugging step on the electronics design week but I missed out this learning outcome so I did it this week

Debugging my hello board

This week I learned the origin of debugging from here. This comes from american engineers calling small machine flaws “bugs” because “when the first computers were built during the early 1940s, people working on them found bugs in both the hardware of the machines and in the programs that ran them. In 1947, engineers working on the Mark II computer at Harvard University found a moth stuck in one of the components. They taped the insect in their logbook and labeled it “first actual case of bug being found.” This log book was probably not Hopper’s, but she and the rest of the Mark II team helped popularize the use of the term computer bug and the related phrase “debug.”“

I also learnt how your programming problems can be all about DEBUGGING, like me this week. Here is a quick checklist Neil did for debugging, there are all kinds of things that can go wrong both in hardware:

  • inspect, reflow solder joints

  • check component orientation, values

  • verify data sheets to make sure it is right

  • confirm connector orientation

  • measure supply voltages

  • probe I/O signals oscilloscope, logic analyzer

and software:

  • in code once your LED is blinking you can use your LED blinks to debug your code by putting in messages.

  • once you have a terminal connected you can have it print out messages(print statements)

  • you can also use embedded debuggers (gdb, ddd, Atmel Studio) that allow you to reach in and change the code as it is running.

Try to program my Hello Echo Board.

  • I have a UPDI(same than FTDI but with a two pin connector) and a Hello Echo Board. I still have to make a FTDI board.

  • My UPDI is working.

  • My Hello Echo Board it not working (LED blinks but it is not going into the system). LEDworking

  • I assume the problem is within the UPDI connector and the chip. So the first thing I will do is check the traces with the multimeter, check that the traces that should connect to each other are connected but also check that the traces that should not be connected to each other are not connected. multimeter

  • For this I have to open my schematic because I can’t visually see all the traces (some are under each other). After opening Kicad, I check the paths and I discover that one of the UPDI pins has extra solder at the back of the pad. This extra solder connects to the paths behind the pin which makes that pin connect to the button when it shouldn’t, it should only connect to one of the legs of the chip. (Paths connected where they should NOT connect). error

  • To solve it I try sucking the solder out: sucking

  • This does not work so Henk helps me out and uses the hot gun till the component slowly moves out of place. After this he sucks out the solder iron, perfilates the path with a cutter to remove any excess solder and resolders the component again in the right place.

Soldering a FTDI:

I also had to create a new FTDI (hello.USB-serial.FT230X) as I did not have one. So I milled my board and soldered it.

Connecting FTDI, UPDI and echo board to my laptop:

00

  • I had previously downloaded the Arduino IDE for my group assignment here

  • Basically when programming a board you need to set up a board and a programmer but the Arduino default does not have AtTinys so I also followed these steps from Adrian which explain how to set up and download the library of the AtTinys and Atmegas for the Arduino environment (this sets up the right environment for the UPDI to read my helloechoboard, and this is also explained in the tutorial above). From the megatinycore page I follow the following steps: 1

  • I open Arduino and install the board package through the board manager. The boards manager URL is:

http://drazzy.com/package_drazzy.com_index.json
  • For this I go to File -> Preferences, enter the above URL in “Additional Boards Manager URLs”. 2 3

  • Then go to Tools -> Boards -> Boards Manager…, wait till the list loads and type “megaTinyCore”, “megaTinyCore by Spence Konde” and click “Install”. For best results, choose the most recent version. 4 5

  • I then configure the Arduino IDE for the ATtiny412 (the processor I have in my hello board). Make sure also the clock speed is set up to 20MHz. 6.

  • It is important to have the FTDI-USB connected and choose the “Serial Port and 4.7k (pyupdi style) programmer. This new version has the UPDYI uploader already integrated in the Arduino environment (before you would have to download this from terminal as the previous tutorial explains). 7

  • I check my UPDI is connected to the computer in About this mac > system report. 8

  • And I now connect it by selecting it under Tools > Port 9

  • We will use the Arduino IDE to compile the code. In order to find the compiled files to send to the updydi tool which uploads the code to the board we will need to edit a the configuration file in order to send this files to a specific folder. To do this we have to go to Arduino > Preferences and click on the preferences files. 10

  • We can only edit this when Arduino is closed so we close Arduino and open the preference file. Once it is opened: 11

  • We will add “build.path=home directory12

  • and set it up to where my home directory is which I will know by opening terminal and typing:

cd
pwd (print working directory)
  • This will show my home directory which is “/Users/paulalonso” 13

This is not just the home directory but where the Arduino files will be. I type my home directory in the preferences text file with a new directory called build. 14

  • Save this and closed it. Go back to terminal and type
cd Documents/Arduino/
ls
  • This will show up a new folder for a libraries. 15

  • We need to make a build directory: 16 17

  • We now have the folder that will hold our Arduino compile file (hex file).

  • In the programing examples here, there are two options: the Arduino IDE option or the echo option (which is if you want to directly try command programming). I will go for the Arduino option.

//
// hello.t412.blink.3.ino
//
// tiny412 blink hello-world, 3-pin UPDI+VCC header
//
// Neil Gershenfeld 1/10/21
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//

#define LED 4

void setup() {
   pinMode(LED,OUTPUT);
   }

void loop() {
   digitalWrite(LED,HIGH);
   delay(100);
   digitalWrite(LED,LOW);
   delay(100);
   }
  • You basically copy this to test out your programming workflow and you define the LED by comparing the datasheet of the microcontroller with my kicad pcb diagram and checking what pin is connected to the LED. I also saved the file. 19 18 20

  • Then in the define section you define the LED which in my case would have to be the “PA6” or “2” pin. I define it and upload the program but the LED does not blink. I try all the different pins but none of them work. 22 21

  • I will try to make my button work and see if this works. The button is an input for the ATtiny412. For this I go to Nadieh’s documentation and copy her code directly as I have seen we both have the same chip orientation and for her it works, which means that if it does not work for me then I have something wrong on my board. 27

  • This did not work either. Henk helps me out and we try to see if maybe the button is the wrong way around? We check with the multimeter and we realise the problem is that one of the corners of the button has solder and this connects it with the ground path(which it shouldn’t).It would not stop beeping when pressing the button. 37.2 37

  • Henk took the solder out with quick braid and the solder heat; 33 34

  • But when realigning the trace with the cutter the trace got destroyed so it now has a nice bypass but it works: 36

  • After fixing this we uploaded the program again but it still did not work. So we followed the pyserial procedure 23 terminal1 terminal2 terminal3

  • We checked again with the multimeter and realised that all the pins from the FTDI would connect to each other (they beeped), this meant the solder pads had got into the trace behind it. 33 38

  • When I took out the FTDI connector with the hot gun, traces came out, and we realised the pads from the FTDI connector were too close to the trace behind it. They have to be at least 0.4mm distance- How do we measure in Kicad to know they are so far apart? 39 24 25

  • Henk fixed this by taking out all the traces, connecting with solder the GND, RX and TX connections from the FTDI connector. For the VCC he made a bypass. He then connected all the FTDI pins with hot glue. 41

  • We tried programming again and the button worked, screen when opening the serial monitor: 0and1s 0and1s

  • We then checked the LED and realised the resistor had solder in between its two pads and it should not because it is a bridge to a path underneath it: 26

  • So we took it out, took the excess solder and solder it again.

  • The program was now working!

In later assignments Input Devices Week and Output Devices Week you can see further code for embedded programming.

What have I learned?
  • I have learned that I have to be more careful when soldering, especially taking into account the pads and traces and be sure to not solder the traces I should not.

  • Constantly check the KiCad schematic to be sure of this.

  • Check with multimeter carefully all the traces that should be connected but also the traces that should NOT be connected, as well as the components itself.


Last update: July 4, 2021