9. Embedded programming¶
Due Wednesday March 25 2020
Assignment¶
Individual assignment:
1. read a microcontroller data sheet
2. program your board to do something,
3. with as many different programming languages and programming environments as possible
Group assignment:
1. compare the performance and development workflows for other architectures
Have you? Check Table¶
Have you? | Schedule | Done |
---|---|---|
Documented what you learned from reading a microcontroller datasheet. | March 22 | Yes |
What questions do you have? | ongoing | |
What would you like to learn more about? | ongoing | |
Programmed your board | June 14 | |
Described the programming process/es you used | June 14 | |
Included your code | June 14 |
Embedded Programming 2020 Assessment¶
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.
Learning outcomes
- 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
FAQ
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.
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
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.
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.
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.
My plan to complete the assignment¶
- Read ATtiny44A Datasheet
- Design my board in KiCad
- Mill my board with Easel CAM
- Stuff board
- Program board with my FabTinyISP, describing the process
- Post Board code download
1. Read ATtiny44A Datasheet¶
Features from reading data sheet¶
8 MHz clock speed using internal oscillator, no external crystal needed (p25)
Operating Voltage:– 1.8 – 5.5V (can I use battery pack?)
Twelve Programmable I/O Lines
Universal Serial Interface
PWM function of some sort. inverted or non-inverted PWM, PWM fast mode, compare PWM mode?
Analog Comparator
Analog to Digital Converter
Questions from reading datasheet¶
Reading the datasheet was overwhelming but also informative, and led to practical questions about what the ATtiny44A was capable of.
I found this ATtiny microcontroller comparison chart on wikipedia quite useful for a list of ATTiny44A features. For reference here is the ATtiny44A row from that chart:
Device (family) | Max clock (MHz) | Flash (KiB) | SRAM (bytes) | EEPROM (bytes) | UART | I²C (TWI) | SPI | Timer | PWM | ADC chans | GPIO pins | IC Packages | GCC arch ID | Pgm Dbg |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ATtiny44A | 20, 10 | 2, 4, 8 | 128, 256, 512 | 128, 256, 512 | USI* | master, slave* | master, slave* | 1 / 0 / 1 | 2 x 2 | 8 | 12 | DIP-14N, SO150-14, QFN-20, VQFN-20, UFBGA-15 | avr2.5 | ISP, dW, HVSP |
Note: * UART/I²C/SPI columns - * means a multi-feature peripheral that is chosen by setting configuration bits. Most USART peripherals support a minimum choice between UART or SPI, where as some might support additional choices, such as LIN, IrDA, RS-485.
See if ATtiny44A can¶
I had two questions about the ATtiny44A
Can drive two servos? Yes
Can make music? Yes
I wanted to see if servos could be driven by an ATtiny44A, so I searched the internet. It sure looks like the ATtiny44A can drive two servos:
Simplest-and-Cheapest-Arduino
4585-servo-library
Actually it looks like an ATtiny44A can drive up to 5 servos.
Website with discussion of fast PWM for driving servos with a microcontroller:
MicrocontrollerControlAHobbyServo
My next thought was can the ATtiny44A make music?
It looks like it can be programmed to play midi the-attiny-midi-plug-synth
This gave me the thought could I connect photocells and potentiometers to inputs to control pwm output to a speaker. However I am not as familiar with sound generation on microcontrollers. I think I will skip music for now and drive two servos instead.
Understand I/O pins¶
I found the high-low tech website useful not only for understanding the capabilities of the i/o pins, but also options for programming options for the ATtiny44A the references section of this site also includes a link to the Servo8Bit: Servo library for the ATtiny45/85. Which will be helpful for my goal of driving two servos.
2. Design my Servo Duo 44A board in KiCad¶
Design a board that drives 2 servos:¶
For many years I have designed and built radio control aircraft and robots using servos for control and locomotion. I want to design a board that controls two servos. I’ll program those servos to make a walking or rolling robot. Later in Fab Academy I will add sensors to that robot.
I will call my new board the Servo Duo 44A
Now to design my board, in KiCad. During the Electronics Design week of Fab Academy I learned board design using the official KiCad tutorials, but I wanted to learn more. The official KiCad tutorials seemed to focus more on theory rather than practical use. I searched and came across these very good, and practical videos by Shawn Hymel who works at DigiKey:
KiCad Playlist | DigiKey
I also found the BCN Fab Lab Kicad class quite useful.
Schematic¶
KiCad Schematic ATtinyServo design R1
KiCad PCB Layout ATtinyServo design R1
I realized that I had no way to plug in my battery pack. Back to add a 2 power input sources to my Schematic. I also noticed that I recalled that Reference designators seemed somewhat standardized on other boards I had worked on. Sure enough there is a list of reference designators on wikipeida. So I changed my designators in my schematic.
KiCad Schematic ATtinyServo design R2
KiCad PCB Air Wire Rats Nest ATtinyServo design R2
Trace layout¶
Now to layout my traces. I used this video to help learn more about trace layout:An Intro to KiCad – Part 6: Place Parts and Define Outline | DigiKey
Here is a short time lapse of my trace layout process:
Here is my board after executing a ground pour in KiCad:
KiCad ground pour
The solder mask layer is useful as a guide for stuffing the board and how to connect it up later. I wonder if I could use my vinyl cutter to pen plot the lettering on a piece of card stock and then cut opening for the components. Then I could place this onto the board to make it easier to understand during end use?
KiCad solder mask
KiCad ATtinyServo design R3
I realized I needed to add one zero ohm resistor, so I added one to the schematic.
3. Mill my board¶
Completed Tuesday March 24, 2020
I milled my board on a 500 x 500 mm X-Carve mill. I used the process I documented for Electronics production. I used Easel online CAM to generate g-code.
I used Inkscape to prep my SVG files for Easel.
Dirty KiCad SVG on left, cleaned up SVG on right
The SVG output from KiCad was quite messy. I decided to open the KiCad SVG in Gimp first and then export a high resolution PNG. I imported this PNG into Inkscape and then used the trace bitmap function to create the clean SVG seen above on the right.
Inverted Traces in Inkscape
Inverted Traces in Easel
Trace toolpaths in Easel
I milled at a feed rate of 40 in/min with a .010” diameter v-stub end mill. My board took about 6 minutes to be milled.
Board after milling
Board milled traces closer
Board milled traces closer 2
BOM output¶
Source,/home/meistertek/Documents/kicad/attiny44a/attiny44a.sch
Kicad Rev,Eeschema 5.1.5-52549c5~84~ubuntu18.04.1
Generated Date,Wed 25 Mar 2020 06:44:29 AM CDT
Title Block
Title,ATtiny 44a Servo Board
Company,Fab Academy 2020
Revision,02
Date Issue,2020-03-21
License: CC BY 4.0
Designer: Daniel N. Meyer
BOM¶
Reference | Value | Library | Library Ref |
---|---|---|---|
X1 | 20 MHz | fab | RESONATOR |
C1 | 1uF | fab | CAP-UNPOLARIZED |
H2 | ISP | fab | AVRISPSMD |
R1 | 499Ω | fab | RES-US1206 |
D1 | RED LED | fab | LED |
IC1 | ATTINY44A | fab | ATTINY44-SSU |
R2 | 10kΩ | fab | RES-US1206 |
H5 | SERVOS | fab | PINHD-2X3-SMD |
H4 | SENSORS | fab | PINHD-2X3-SMD |
H3 | FTDI | fab | FTDI-SMD-HEADER |
H1 | 5V BATTERY | fab | TERM-1X02-FABLAB |
R3 | 0Ω | fab | RES-US1206 |
4. Stuff board¶
Completed March 28, 2020
During the stuffing I realized that I had a current limiting resistor R1 and LED R1 swapped. I corrected the schematic and the traces to reflect this change and assigned it Revision 3:
Revision 3 Schematic, click to zoom
Revision 3 Traces
5. Program Servo Duo 44A with Atmel-ICE, describing the process¶
Atmel-ICE + Arduino IDE¶
June 15, 2020
To help get me started, I referenced
However I found the instructions from the MIT high-low tech group Programming an ATtiny w/ Arduino 1.6 (or 1.0) the most useful for step by step help with explanations.
I downloaded ARDUINO 1.8.12 for Linux 64 bits from Download the Arduino IDE
I installed the ARDUINO IDE using the guide Install the Arduino Software (IDE) on Linux
I then followed the “Installing ATtiny support in Arduino 1.6.4” on the MIT high-low tech group Programming an ATtiny w/ Arduino 1.6 (or 1.0) site.
In Arduino IDE I set up the following in the Tools menu:
Board: “ATtiny24/44.84”
Processor: “ATTINY44”
Clock: “External 20Mhz”
I then did a Tools, Burn Bootloader.
I got these errors:
Arduino: 1.8.12 (Linux), Board: “ATtiny24/44/84, ATtiny44, External 20 MHz”
Arduino: 1.8.12 (Linux), Board: “ATtiny24/44/84, ATtiny44, External 20 MHz”
avrdude: verification error, first mismatch at byte 0x0000 0x62 != 0xfe avrdude: verification error; content mismatch Error while burning bootloader.
I decided to try burning the bootloader in windows 10 and it worked. I am thinking my avrdude setup on my Linux machine may need reconfiguration due to mods I made to it to get it setup for Open TX Companion software I use to program my RC airplane transmitter.
Ok now on to doing some basic servo programming in the Arduino IDE for my Servo Duo 44 board.
I decided to test my ATTiny44A based board with Neil’s hello.ftdi.44.echo.c code.
I cut and pasted this code into the Arduino IDE and got the following message:
avrdude: usbdev_open(): cannot open device: Permission denied avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2141 An error occurred while uploading the sketch
Many sources mentioned that I need to be part of the dialout group as a user, which I had done a while back. I verified that I was in with the command groups
and got:
meistertek adm lp dialout cdrom sudo dip plugdev lpadmin sambashare
I am in the dialout group, so all good there.
I then used the dmesg
command to make sure my Atmel ICE could be seen:
[ 1.945833] usb 1-3: New USB device found, idVendor=03eb, idProduct=2141, bcdDevice= 1.01
[ 1.945834] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1.945835] usb 1-3: Product: Atmel-ICE CMSIS-DAP
[ 1.945836] usb 1-3: Manufacturer: Atmel Corp.
[ 1.945836] usb 1-3: SerialNumber: J42700007665
[ 1.973599] usbcore: registered new interface driver usbhid
[ 1.973600] usbhid: USB HID core driver
[ 1.974917] hid-generic 0003:03EB:2141.0001: hiddev0,hidraw0: USB HID v1.11 Device [Atmel Corp. Atmel-ICE CMSIS-DAP] on usb-0000:00:14.0-3/input0
It’s there, hmmm. I’ll try from windows 10 and see what happens.
References¶
If you have issues installing Arduino IDE in linux see this guide Install Arduino IDE 1.8.2 on Linux
David David Selles’ guide Programming with the FabTinyISP using Arduino IDE.
PROGRAMMING AVR MICROCONTROLLERS WITH LINUX (THE RELATIVELY EASY WAY)
6. Board code download¶
2x Servo Control Code Download