Skip to content

Embedded programming View Page Source

Modular Things

RGBB Thing

To get into Modular Things, I first tried to get the rgbb board to work. I managed to put a bootloader onto the SAMD21E18A chip on the rgbb board. I downloaded edbg to C:\code\SAMD21, opened the Command Prompt there by typing cmd into the folder's address bar, and ran the following string of commands:

C:\code\SAMD21>edbg-windows-r54 -bpv -e -t samd21 -f sam_ba_Generic_x21E_SAMD21E18A.bin
Debugger: ATMEL Atmel-ICE CMSIS-DAP J42700061250 1.0 (SJ)
Clock frequency: 16.0 MHz
Target: SAM D21E18A (Rev D)
Erasing... done.
Programming.... done.
Verification.... done.

Wow! It worked! That was exciting.

Then I put the Fab SAM core on the SAMD21 in the Arduino IDE (first I put a different core on it and the COM port disappeared).

I connected it to the computer, opened up the web interface and after a bit of coding the red LED turns on when I press the button!

The RGB diode was very dim, so my instructor Þórarinn took to the electronics workbench, tested it, replaced it with a new LED and discovered that the current-limiting resistors were 10kOhm instead of the recommended 1kOhm. I got to try the soldering tweezers for the first time and boy, are they handy for removing components from a board!

Þórarinn debuggingÞórarinn lighting up the diodes with the bench power supply.

Soldering tweezersYou just grab the part with the hot tweezers and it comes off!

Þórarinn lecturing me on diodesÞórarinn explained diodes on the whiteboard and I discovered that I've had anodes and diodes backwards all these years! No wonder I was never particularly good at calculating electrical circuits. My wife also has this backwards. We think that the confusion comes from Chemistry class in school, because the anode on a chemical battery is not defined by which way the current is flowing, but by which type of reaction is going on there. The current goes in one direction when the battery is being charged and in the opposite direction when the battery is being discharged. But the anode and cathode don't switch places accordingly. I find this annoying.

Design file

Download RGBB Modular Thing code

Stepper Thing

I was happy to get the rgbb board working, but then the stepper Modular Thing that I made suddenly stopped working.

Stepper Thing error

I sent Quentin Bolsée the image above and asked him if he knew what the errors meant. But before he could reply, I remembered something that Árni Björnsson had showed me. Apparently, the pin assignments have changed in the latest Modular Things code for the RP2040 board. I reverted them back to the original ones, and the stepper worked!

Stepper Thing pin assignments

Design files

Download Stepper H-bridge RP2040 Modular Thing Arduino code

Download svavar-rgbb.js

My BLDC Thing

I tried to make a BLDC Modular Thing using the instructions in the Modular Things repository.

bldc thingI added bldc to the list of constructors in ModularThingClient.ts.

import bldcI also added this line to ModularThingClient.ts.

I got an error that I couldn't figure out:

Parse failure: Unexpected token (3:33)
Contents of line 3: export default function bldc(name: string) {
Failed to load url ../osapjs/osap (resolved id: ../osapjs/osap). Does the file exist?
 error   Parse failure: Unexpected token (3:33)
  Contents of line 3: export default function bldc(name: string) {
  File:
    C:\code\modular-things-main\C:\code\modular-things-main\node_modules\vite\dist\node\chunks\dep-5e7f419b.js:51642:15
  Stacktrace:
Error: Parse failure: Unexpected token (3:33)
Contents of line 3: export default function bldc(name: string) {
    at ssrTransformScript (file:///C:/code/modular-things-main/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:51642:15)
    at ssrTransform (file:///C:/code/modular-things-main/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:51617:12)
    at Object.ssrTransform (file:///C:/code/modular-things-main/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:60941:20)
    at loadAndTransform (file:///C:/code/modular-things-main/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39336:24)

Failed to load url ../osapjs/osap (resolved id: ../osapjs/osap). Does the file exist? (x2)

I don't have more time to try to understand this system, so I'm going to leave it at that for now.

Design files

Download failed BLDC Modular Thing code

Here's the most promising step towards integration of SimpleFOC with OSAP (the networking layer that communicates with the Modular Things web interface). I managed to hard code a motor command in the Arduino code. It worked. This means that I don't need to run the SimpleFOC Commander communication protocol in order to make the motor work, I should be able to swap it out for OSAP and send motor commands as strings over serial:

Download hardcoded SimpleFOC command code

SimpleFOC

The SimpleFOC motor control library works when I use Xiao SAMD21 modules, but when I design my boards, I'd like to use the bare SAMD21E18A chip. I ran into an issue compiling the motor control code to the bare chip and asked for help on the SimpleFOC community forum:

Error compiling to SAMD21 (bare chip) - SimpleFOC Community

I got a very helpful answer from @AdinAck. Adin made a brushless DC motor control board with a SAMD21 chip running the SimpleFOC library. When programming the chip, he told the Arduino IDE that he was programming an Adafruit Feather board. All he had to do was to design the board so that it conformed to the Feather, and everything worked!

So I tried to upload the motor control code to the rgbb Modular Things board by telling the Arduino IDE that I was uploading to a MattAirTech Xeno Mini. No luck. Then an Arduino MKRZERO. That didn't work either. Then an Arduino MKR1000. Nope. I was just randomly trying different boards and finally tried the Arduino Nano 33 IoT. It worked! I even got serial output from it:

All zeroes.All I get is errors and zeroes, because there is no motor and no angle sensor connected to the MCU. But I'm happy, because the code compiled!

Then I checked if I could upload the Modular Thing code to the SAMD21 chip under the pretense that it was an Arduino Nano 33 IoT. That worked too!

rgbb code working with Arduino Nano 33 IoT coreI even got a 'false' response from the button (in the bottom right corner). Aw yeah!

Next, I soldered the necessary parts onto the breadboard Thing and connected it up to the LED test board that I made in Electronics Production week. I wrote a loop that blinks every pin on the IC and sends the corresponding pin number to the serial port. With this I was able to identify which pin in the Arduino Nano 33 IoT board definition applied to which pin on the IC itself.

Design file

Download Blink_all_pins.ino