Skip to content

14. Interface and Application Programming

This week’s assignment is to write an application that interfaces a user with an input and/or output device that you made.

Individual Assignment

Goal

For this assignment, I’m going to interface the FAB23 XIAO RP2040 Dual-H Bridge board with the Modular Things interface and learn how to control a motor with the web interface. The advantage of the Modular Things using the USB-C is that the USB-C interface is capable of providing communications and power for the stepper motor in a single port. Additionally, multiple motors can be controlled via the web interface and a USB-C PD hub.

Board Production

JLCPCB Board-Commercial Board House

As I’ve documented in my final project notes here, I was having trouble producing the two Fab 23 Dual H-bridge boards necessary for my final project, so I ordered some boards from JLCPCB to get started while I figured out how to mill and stuff the board successfully. The process of order was pretty straightforward.

  • Open the design files in KiCad
  • Export all the layers as Gerber files into a folder
  • Go to JLCPCB.com
  • Upload the folder with the all Gerber files
  • Review the design that is loaded from your folder for accuracy
  • Decide on options
  • Place the order

Here is a picture of my order: JLCPCB_Order-1

Once I received the boards I went ahead and stuffed one. It took a lot of work to get the board working. Here are some photos of the process:

  • JLCPCP Board BP-1
  • Adding the SEEED XIAO RP2040 using SainSmart Miniware MHP30 and solder paste. You can see in the above picture that I preheated the solder paste and then added the XIAO. BP-2
  • After adding the rest of the components minus the headers using traditional SMD soldering. I was diligent and checked for continuity with my multimeter on all the traces as I went to make sure I had the appropriate amount of solder for the joints. I also checked for shorts too. I did have a couple issues with shorts that I resolved by adding heat with the soldering iron and coaxing the solder away from the joint to alleviate the short BP-3
  • After adding the headers. BP-4
  • At this point I was ready to test it out with the Modular Things interface and see if I can get it to turn the motor.

Update-Milled Board Success…Eventually

After I had the JLCPCB board running successfully, I went back and milled/stuffed a board to make sure it would also work. Eventually I got it to work. It was significantly more challenging to stuff than the JLCPCB board. It turns out that the soldermask on the first board made shorts less common and easier to solve. - Here are some pictures from the process: - Milling setup on the Bantam (Part 1). BP-5a - Milling setup on the Bantam (Part 2). As I learned previously the key is to select “Use Detail Tool Everywhere” to get the Bantam to mill the board correctly BP-5b
- Result before removal from the mill. BP-5 - After cleanup. BP-6 - After two and a half days of soldering and troubleshooting for continuity and random shorts, I finally had a milled board that worked. BP-7 - The issue turned out to be that, with the copper ground pour on the design and without the solder mask of the commercially produced board, shorts to ground were quite common if I used just a bit too much solder paste, especially with the SEEED BP-6.
- The ground shorts were unable to be seen because they were under the microcontroller. Circled in blue are the location of the all the shorts I ended up diagnosing. While I tired to use heat to coax the solder away from the shorts like I did with the commercial board above, it didn’t work, so I ended up using the hot air gun and removing the XIAO instead. At that point I used Lesnow Desolder Wick to remove the excess solder with good result. Once that was complete, I was able to successfully solder the XIAO to the board without further issues.

Modular Things

The Modular Things interface makes use of a few different programming languages at once (JavaScript, HTML, and C++), so I will get to learn a few things at one time. Also, my final project uses Modular Things and this will allow me to gain some experience with it.

Setup

Firmware

As part of this process it is necessary to load the appropriate code on the RP2040 so the Modular Things site can recognize the board when it is connected via USB-C to the computer accessing the Modular Things website. Once this happens, the RP2040 can be control by the code on the website. The general process is described in this paper and the notes in Github

  • After successfully stuffing the board, I tried loading the firmware from GitLab. Here is a link to the ‘bin’ stepper-hbridge-rp2040.ino.uf2 file I loaded with Arduino IDE.

  • I then opened the Modular-Things site with the board connected to the computer to see if it would recognize the firmware. I was able to get the Device to be recognized, but that was all. Initial Attemp0Device I tried running the single axis code from GitHub one-axis.js by copying and pasting in the website editor and no luck. When I went to view the UI, it was blank (below). Initial Attempt

  • I had accomplished my first goal which was to get the device firmware recognized, so that was a win. I needed to do more research to get the stepper to turn, so I did more research.

Code

  • After some additional research I found the Instrctor’s Bootcamp 2024-Modular-Things CoreXY

  • It was an updated starting point, so I followed the process laid out on the site and made additional progress.

    • Installed OSAP library in Arduino
    • Verified that I had the “Earle F. Philhower, the Third’s PICO build” in my Board Manager.
    • Downloaded the Arduino code from Quentin’s WS which turned out to be the same one I was using previously. I realized that later.
    • Double-checked the pin assignments as recommended.
    • I uploaded the code to the board.
    • Opened Modular-Things site again and copied the JavaScript Code in the editor.
    • Connected the board and successfully paired it to the site again.
    • Ran the code (Shift+enter)
    • Switched to the View tab, nothing again. Same as above.
    • Tried it a few more times from the beginning with the same results.
    • Back to more research
  • More research found FabLab Kannai machine week page, which had the answers I needed.

    • I noted that the Kannai lab was using a different version of the stepper driver than I had been using. They were using the “Simple-Stepper” that was an updated version of the one used in the Leon Boot camp that I had unsuccessfully tried, so I downloaded the Simple-Stepper and tried it out.
    • Initially it wouldn’t compile and gave the error below. ArduinoError
    • I read the error, and it said there was a previous definition of ‘chunk_float32’ with the “^” under the “c” for emphasis I intuited
    • My intuition said to try changing the lower case “c” to and uppercase “C” to see if that might help and it did. The code compiled.
    • After that I successfully uploaded the firmware to the XIAO RP2040 board.
    • Opened Modular-Things again and used the yuichi4 code from Fablab Kannai’s machine building tips page above.
    • Successfully paired the boards to the site.
    • Renamed them “motorA” and “motorB” to line up with the motor names in the code.
    • Ran the code and the stepper connected to motorA started to spin. Finally, success.
  • Once I had the stepper motor working, I learned some JavaScript to get the UI to better fit my needs. To get a basic understanding of JavaScript I reviewed the link in Neil’s notes for the week, so I could better understand the Modular Things coding.

  • I adjusted the UI to make it work on the 7” Touchscreen with the Raspberry Pi 4 I’m using for the final project. Essentially I tweaked and moved the buttons to make them more accessible on the smaller screen.

  • Here is the user interface at the end of the process.

    • UI
  • Once I had one board (motorA) successfully communicating the with the interface, I added a second board (motorB). At that point I noted the tab on Chrome had a graphic on it so I moused over it and saw “This tab is connected to a serial port” and then checked the device manager to see exactly how they were communicating with my pc. Here were the results. CommPorts, so that confirmed the connections that were shown in the Arduino IDE software.

Files

-Original Code

Learning

  • One of the challenging parts of coding in the Modular-Things website is it’s not very fault-tolerant. When you make a mistake in the JavaScript, the View window just goes blank without explanation. Using the Dev Tools that come up with “ctrl + shift+ j” can be helpful, but takes time to learn how to interpret the results and I couldn’t find not much information to with the reason it went blank. My best method was to use the ever reliable “ctrl+Z” to undo the last change. I also kept a series of “last good code” pages in VS Studio Code to revert to when necessary as there is not a “Save” option on the Modular-Things website yet.

Group Assignment

Here is a link to our group assignment