Lecture

Review of Electronics Design Week

Recitation: Debugging

Weekly assignments

Group Assignment

  1. Use the test equipment in your lab to observe the operation of a microcontroller circuit board (in minimum, check operating voltage on the board with multimeter or voltmeter and use oscilloscope to check noise of operating voltage and interpret a data signal)
  2. Document your work to the group work page and reflect on your individual page what you learned

Individual Assignments

  1. Redraw one of the echo hello-world boards or something equivalent, add (at least) a button and LED (with current-limiting resistor) or equivalent input and output, check the design rules, make it, test it. Optionally, simulate its operation.

Have you?

  • Linked to the group assignment page
  • Documented what you have learned in electronics design
  • Explained problems and how you fixed them, if you make a board and it doesn’t work; fix the board (with jumper wires etc) until it does work.
  • Included original design files (Eagle, KiCad, etc.)
  • Included a ‘hero shot’ of your board
  • Loaded a program and tested if your board works

Group assignment

Our group assignment page.

This week, Krisjanis demoed two things:

  • How to make a double-sided PCB board
  • How to use the test equipment at the lab

I was not able to join the sessions, but I watched the video recordings that were made.

Planning out my individual assignment

I’m quite confident that the world already has enough of boards that just blink one LED. I wanted to use this week to make something that I would actually want to use in the future. I decided to make two different boards.

Board #01: SAMD11C USB MIDI Controller Board

MIDI board ready

In one of my classes I have been introducing people to the basics of digital fabrication by having the students make a simple MIDI controller using the Teensy LC boards. I really like them, as they have a fast processor, a decent amount of memory, support native USB modes (keyboard, mouse, HID, MIDI), and have many other nice features. They are my go-to boards for developing all kinds of projects. Here is an example of one of the controllers my students have built during the class.

Midi for VJs by Juan Qin

In the context of Fab Academy, I want to create a custom board for these purposes that I can make at a lower cost and I can produce locally here at the university.

MIDIUSB Library

I tested earlier that the ATSAMD11 microcontrollers support the MIDIUSB library from Arduino. This library is not quite as nicely implemented as the one for Teensy, but still does the trick just fine. So I was confident that I can make this board work without any issues.

Here is a video using my programmer board to test the library. I am just sending one controller change value going back and forth between 0-127.

Board #02: D11 Board for Testing Various Sensors (Qwiic-Compatible)

Qwiic board ready

The other board that I wanted to make this week, was a general use board that would break out the available pins of the SAMD11C and that would have a separate connector compatible with the Sparkfun Qwiic and Adafruit Stemma QT connectors. Both use the JST SH 4-pin connectors for I2C communication between development boards and various breakout boards. We have quite many sensor breakout boards with these connectors at the university. They are really nice for quick prototyping and testing ideas. I want to make a board based on the SAMD11C that would allow working in this same ecosystem.

Designing the Boards

Before I jump into drawing schematics and PCBs, I need to understand my limitations and needs a little bit better. In order to know what pin I should connect to where, I need to do some research on the SAMD11C microcontroller features.

Pinout for SAMD11C14A

img/samd11c-pinout.jpg

img/samd11c-adc-pins.jpg

For the MIDI controller, I am mainly concerned about which of the pins have ADC (analog-to-digital converters) that allow me to read the voltage from potentiometers and sliders. It seems like the following pins have ADCs:

  • PA02
  • PA04
  • PA05
  • PA14
  • PA15

So I could have 5 analog potentiometers or sliders for my simple MIDI controller. At this point, I’m considering to switch to the ATSAMD11D, since it has more pins and 8 ADCs but decided not to bother for now. Five is still ok for this test board.

For the sensor testing board, I need to also connect a specific connector to the I2C pins. At first I was a little bit frustrated, because the datasheet of the microcontroller seems to make it unnecessarily hard to find out what pins are the I2C pins. Or more specifically, what should I use as SDA and what as the SCL pin?

img/samd11c-i2c-pins.jpg

After some research I understood that this is actually because in the SAMD family of microcontrollers they are not fixed pins, but you can rather use multiple SERCOM modules and configure each of them as either:

  • USART with full-duplex and single-wire half-duplex configuration
  • I2C Bus up to 3.4MHz
  • SMBUS/PMBUS
  • SPI
  • LIN slave

This Adafruit tutorial helped me understand this a little bit better. I still don’t understand all the details of the way the multiplexing works, but at least I’m grasping some of it.

Now this option also started to make more sense to me in Arduino IDE for these boards:

img/samd11c-serial-config.jpg

We can choose how the modules are configured. If I wan’t to use I2C, I need to make sure that one of the ONE_WIRE options is selected for that setting.

Digging through the ArduinoCore-fab-sam repository, I found this:

====================================== ATsamD11C14A =====================================
Other  COM   PWM  Analog  INT  Arduino*           Arduino*  INT  Analog  PWM   COM  Other
=========================================================================================
                                  1-------------------
  SCK*/RX2  TCC01    *     *    5 | A5             A4 | 4    *    *  TCC00 MOSI*/TX2  REF
    MOSI*   TCC02          *    8 | A8 (XIN)       A2 | 2    *    *                   DAC
    SCK*    TCC03          *    9 | A9 (XOUT)     Vdd |
  SDA/MISO*  TC10    *    NMI  14 | A14           Gnd |
   SCL/SS*   TC11    *     *   15 | A15           A25 | 25                    USB/DP
BOOT                           28 | A28/RST       A24 | 24                    USB/DM
SWDCLK  TX1/MISO*              30 | A30           A31 | 31   *            RX1/SS*   SWDIO
                                   -------------------

* Most pins can be used for more than one function. When using PIN_MAP_STANDARD, the port
  pin number printed on the chip above is also used in Arduino (but without the 'A') for
  all of the supported functions (ie: digitalRead(), analogRead(), analogWrite(), etc.).
  When using PIN_MAP_COMPACT, the Arduino numbering is sequential starting from 0 at the
  top left pin (A5). PIN_MAP_COMPACT uses less FLASH.
* When USB CDC is enabled, Serial refers to SerialUSB, otherwise it refers to Serial1.
* When using ONE_UART_NO_WIRE_ONE_SPI, use SPI on pins 4, 5, 14, and 15.
  When using NO_UART_ONE_WIRE_ONE_SPI, use SPI on pins 8, 9, 30, and 31.
* Tone available on TC2. TC2 is not routed to pins in the D11C14A.
* Leave pin A30 floating (or use external pullup) during reset.
* DO NOT connect voltages higher than 3.3V!

Based on this information it appears that the pins are configured like this:

  • SDA: PA14
  • SCL: PA15

This is all the information I need for now to be able to get to the actual work. So it’s time to dive into the tools.

KiCad

KiCad 6

I have previously used Eagle for all my PCB design needs. I kind of hate it and love it at the same time. The hate part stems from the fact that the interface works so differently from all the other design tools that I use. I don’t make PCBs that often, so it always takes me at least half a day to get into the flow of things. After this, it’s usually quite therapeutic to try to work on the puzzle of getting all your traces to fit on just one layer. In some weird way I find it very enjoyable and addicting work.

However, I have wanted to learn KiCad for many years now. I have tried a couple of times but always went back to my old friend Eagle. KiCad 6.0 came out recently and it seemed to be a big improvement. A perfect opportunity to sit down and finally learn how to use it for my Fab Academy assignment.

Setup and installing libraries

Krisjanis has been working on a library for KiCad that covers all of the components found in the Fab inventory. I don’t know how long it took to make, but the work is really appreciated!

My only suggestion here is to actually do the steps in a slightly different order. I also use a little bit different paths:

  1. Clone or download the repository. You may rename the directory to fab.
  2. Store it in a safe place such as ~/Documents/KiCad/libraries/fab
  3. Run KiCad or open a KiCad .pro file.
  4. Go to “Preferences / Configure Paths” and add variable named FAB that points to the installation directory of the fab library: ~/Documents/KiCad/libraries/fab This will enable the custom 3D shapes to be found. The 3D shapes project has just started and most of them have to be populated still.
  5. Go to “Preferences / Manage Symbol Libraries” and add fab.kicad_sym as symbol library.
  6. Go to “Preferences / Manage Footprint Libraries” and add fab.pretty as footprint library.

Board #01: SAMD11C USB MIDI Controller Board

MIDI board ready

First up, the MIDI controller.

Schematic

The schematic is fairly straightforward. I had to use three 0Ω resistors to skip over some traces to make this work as a one-sided board. That sounds way too much, I feel like there should be a way to do it without them. Maybe on the next version.

MIDI board schematic

Designing the PCB

I didn’t really have a vison on what shape or size of a board I should make, so this is what came out in the end. I think I should do a new version with a little bit more thought put into the form.

MIDI board PCB

I think I would also like to use a different type of USB connector. This board needs to go inside an enclosure and requires a longer cable from the computer. I was just too eager to get the first version done and did not spend too much time looking for alternative connectors at the lab.

Making the PCB

It seems that I did not take any pictures of the PCB milling process. It went quite smoothly, except that I forgot to drill the holes for the mounting points of the switch. I drilled them later by manually controlling the SRM-20 machine that I used to mill the boards. The first test of the board was successful.

JST Connectors and Patience

However, I managed to accidentally tear off the pads of one of the JST connectors as I was unplugging the cables from them. I knew that they are tight and I have ripped out the pads even from PCBs made at a PCB manufacturer. I was just impatient..

Broken pads

Gladly, this turned out to be a useful thing. As I was testing the switch that I had added on my board, I realized the pin PA09 cannot be used as input (or at least not with the internal pullup resistor). This pin seems to be the XOUT pin, which means that it’s the oscillator output pin. I did not get to the bottom of why it can’t be repurposed for something else, but since I had messed up one of the JST connectors, and it was conveniently just next to the switch, I decided to cut the trace of the switch and bridge it to the trace that was supposed to be used for one of my analog inputs. Problem solved!

Broken pads becomes a blessing

Testing with TouchDesigner

I created a simple program that:

  1. Reads the potentiometer connected to the JST connector
  2. Smooths the data using the EWMA library. I first just wrote the exponential weighted averaging myself, but since I used floats, my memory use exploded way beyond what is available on the microcontroller. This library has the same algorithm implemented using integers. Since I had it installed, it was just quicker to use the library rather than dig into it to see how to do it without floats.
  3. The smoothed value is then mapped to a scale suitable for MIDI (0-127) and sent out as a continuous controller value.
  4. Additionally, the code reads the state of the slide switch and changes the controller numberd to a different bank depending on what position it’s set to. (Essentially, the controller values are offset by +10 if the slide is activated).
  5. The other LED on the board tells the state of the switch.

I then connected the MIDI input from the controller board to a simple project in TouchDesigner. The video below shows me turning a potentiometer, which controls the intensity of the distortion effect in the live video input from my phone. The left side of the screen shows a graph of the raw values read from the analog input (in green) and the filtered values in yellow.

I have a bit of a problem though, this simple program uses 95% of the available storage space. As you can see, this issue with the high memory use is a recurring topic this week.

Sketch memory use

Board #2: SAMD11 Qwiic Board

Qwiic board ready

Schematic

Qwiic board schematic

Designing the PCB

By this time, I was getting more and more comfortable with KiCad and I have to say I enjoy this a lot more than Eagle. I was able to squeeze all of the components and traces on one-sided board without any 0Ω jumpers. It’s not a very complex board but I was still quite happy how it came out.

Qwiic board PCB

Copper pours, ground planes (sound like it should be a name of a band or book)

You might have noticed that I use copper ground planes on both the boards I made. This is something I used to always do in Eagle, so I wanted to also learn how to to do it in KiCad. It’s quite simple, use the “Add a filled Zone” tool to draw a shape that covers your entire board and select GND from the window that pops up.

Ground planes

I learned how to do this and a couple of other tricks from this video by YouTube user shabaz:

Milling the PCB

The clearance between the pads of the USB connector is something between 0.2-0.25 mm so I had to use the smaller milling bit we have at Aalto Fab Lab. All went smoothly and the board came out very clean straight from the machine. The only issue I had wes that CopperCAM was a little bit confused about the ground plane and did not allow me to create a proper hatching pass. Note to self: investigate this issue and also try Mods.

Remember to set the speed to something slower for the smaller milling bits. I used 5mm/s and it seemed to work out just fine.

Qwiic board after milling

Stuffing and soldering

The microUSB connector and the JST SH connector were tricky to solder, but I was able to eventually get all the components on the board. Generally, I solder all parts without any microscopes or magnifying lenses, but this time I had to resort to using the microscope.

Qwiic board under the microscope

Memory Problems

I tried one Qwiic connector enabled sensor that I had around, the VL531X Distance Sensor Breakout from Sparkfun. Unfortunately, the Bootloader and the VL531X library take up so much space that they do not fit on the FLASH of the D11C. So the board works, but I cannot really use it for the purpose I was planning to.

Future Work

I have started on the next revisions of both of these boards that are going to use the ATSAMD21 microcontrollers. They have more memory and more pins, I should not have the same issues that I was facing. I will do at least one of them during the Embedded Programming week.

Download

SAMD11C USB MIDI Controller

SAMD11C Qwiic Board