3D-printed camera mount with a single-board computer and camera module on the strut of a 3D printer on a light wooden workbench

AI print watchdog with the Arduino UNO Q (part 5): tuning and finishing touches

The watchdog is running, and in its first hours of duty it caught five genuine failed prints (part 4). That proves the concept — but only the concept. One detail from part 4 kept bothering me: the camera hung on a clamp that shifted at the slightest knock. And because an anomaly model does not learn what “spaghetti” looks like but rather “this is how it normally looks here”, every camera that moves is a small write-off. So in this episode the watchdog gets a proper mount — designed from scratch, parametrically in FreeCAD, with all files available for printing.

The hardware for this series – an Arduino UNO Q*, its Media Carrier* and an IMX219 camera* – is covered in part 1.

Links marked with * are affiliate links, which makes them advertising. If you buy through one, I earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Learn more

The price for that became obvious immediately: after the rebuild the training data set had to be built from scratch. Whatever was collected before is worthless the moment the scene changes. That is exactly why the hardware rebuild comes first in this episode and the re-training after it. Collect first and then start screwing, and you collect twice.

Why the first mount was not enough

The clamp from part 1 was deliberately quick and dirty: clipped onto the printer housing, nothing drilled, nothing glued — exactly right for a first attempt. In daily use three weaknesses showed up. First, it sat in a spot where you constantly bump into it during a filament change. Second, on taller prints it eventually stopped pointing at the part, and a taller clamp would have been even more awkward and less stable.

Elegoo Neptune 4 Plus printing with the AI camera watchdog mounted
The first clamp solution that got scrapped, front left at the print bed

That gave three requirements for round two: a stiff arm in a place nobody touches in daily use; the board carried properly instead of dangling from its cable; and a joint that lets the camera be aimed horizontally and vertically. On top of that a practical requirement that often gets overlooked in 3D printing: the whole thing should break down into separate, easily printable parts — the bigger and more convoluted a part is, the more support material it needs and the more painful a dimension change becomes.

Three parts instead of one lump

What came out is a kit of three printed parts:

  • The arm clamps onto the printer’s Z column and carries everything.
  • The tray holds the UNO Q, with cable slots on both sides.
  • The camera adapter lets the camera pan and tilt.

Everything is held together with ordinary screws and nuts; there are no printed threads. The reason for splitting it up is purely practical and paid off on the very first test print: if one dimension is off, you reprint one part — not the whole lump.

Renderings of the three printed parts of the camera mount: arm, tray and camera adapter
The three parts as they sit on the build plate — arm, tray and camera adapter

This time I designed in FreeCAD instead of Tinkercad, and parametrically: every dimension lives in a spreadsheet, and one change propagates through the whole model. That is the steeper learning curve, but it saves exactly the fiddling that three iterations would otherwise cost. If the design side interests you, the STL files, the complete FreeCAD model with its parameter sheet and the scripts are in the repository — here the topic is edge AI.

Two more things for reprinting: only the tray needs support material, and only for the two upward-facing pins — nothing else. And my tray turned out a touch too tight. The board fits, but without any play; if you reprint it, give the inner contour half a millimetre more.

The printed tray for the Arduino UNO Q board with remains of support material on the holding pins
The tray straight off the printer — at the top you can see the supports on the two pins, the only place that needs any

Printing and assembling

I print all three parts in PLA* at 0.2 mm layer height with four to five wall lines — the arm carries weight, and there the extra perimeters are worth more than a high infill. The assembly order:

  1. Slide the arm’s jaw onto the Z strut and secure it with the two screws in the jaws.
  2. Push the tray sideways onto the two pins until the tongue sits under the beam.
  3. Place the camera adapter on top of the beam, nut from below into the recess, screw from above — finger tight for now.
  4. Hang the camera housing into the fork with an M5 screw and nut.
  5. Put the board into the tray and route the camera cable and USB-C through the slots.
Side view of the assembled mount made of arm, tray and camera adapter
How the parts interlock: clamping jaw on the right, tray pushed on from the side, camera adapter at the bottom left

Only then do you aim it — and for that the live view from part 2 is worth its weight in gold: open the camera image in the browser, nudge pan and tilt into place, tighten both screws, done. The shopping list is short: two wood screws (or two M3 threaded inserts), one M6 or 1/4 inch screw with a nut, and one M5 screw with a nut.

The Arduino UNO Q sitting in the printed tray, the camera cable leading to the camera housing
The board in the tray, camera cable and USB-C routed through the side slots

All files live in the GitHub repository under cad: the three STL files for printing straight away, the complete FreeCAD model with the parameter spreadsheet, and the scripts I use to build the model, export the STLs and render the views. The folder of the first version stays untouched next to it — if you are rebuilding the old setup, it is still there.

The finished mount with Arduino UNO Q and camera on the Z strut of the 3D printer
Mounted on the Z strut — board at the top in the tray, camera below it on the joint

A new mount means training the model again

Now for the unpleasant side of the rebuild. A FOMO-AD model does not learn faults, it learns normality — and specifically normality as seen from the camera perspective it was trained on. Once the new mount was in place, the camera image looked different: new setup, new perspective. On top of that the filament changed from white to black at the same time and the sun went down outside, so colour and brightness no longer matched either. To us humans both are “the printer”. To the model they are two different worlds.

Two camera images compared: on the left the bright view of the old mount onto white printed parts, on the right the darker view after the change to the new mount
Same camera, two worlds: on the left before the rebuild in daylight with white filament, on the right afterwards with black filament under artificial light

The consequence: the data set has to be rebuilt. Images from before no longer belong in it — otherwise the model learns two normal states as one and gets blurrier at both. A handy side effect for the clean-up: because every image carries its capture time in the file name, the line between “before the rebuild” and “after” is easy to draw later.

So for your own build this matters a lot: lock down the hardware first, then collect data. Every change to camera position, lens or lighting invalidates everything recorded before. That sounds trivial, but it costs real days — images only accumulate as fast as the printer prints.

The watchdog itself keeps running during this collection phase, just as a silent observer: we set the alarm threshold to 100 so it never triggers, and ticked the box for creating training images, so the watchdog diligently writes images into its training buffer. Remember to upload or fetch those images after a few hours, otherwise they get overwritten automatically.

One thing belongs in the collection phase on purpose: variety. We deliberately printed in different filament colours — most recently another round in matte grey — and collected across several times of day, from daylight to artificial light in the evening. That sounds like a contradiction to what stands a few paragraphs above, but it is the other side of the same coin: what must not change is the camera perspective. What should change is everything that varies in normal operation anyway.

The reason is the same mechanism that made the rebuild so expensive, just turned around: in the end the model knows exactly the normality it has seen. If the training set contains only black filament, then a grey print is something unfamiliar to the model — and with anomaly detection, unfamiliar is by definition what raises an alarm. The broader the normality in training, the less often the watchdog later reports something that is not a fault at all.

💡 Can’t you just generate the fault images?

The question is obvious, and Edge Impulse even has a tab for it: under Synthetic data you can generate images via DALL·E or FLUX Pro. It still does not help in our case — for two reasons.

First, anomaly detection needs no fault images at all for training. It learns only the normal state — that is precisely why we chose it in part 3. We need fault images only to set the alarm threshold.

Second, the score the model assigns depends on your concrete scene: your viewing angle, your print bed, your lighting, right down to the noise of your camera. A generated tangle of spaghetti is just as foreign to the model as a shot from the old mount. You would calculate a threshold perfectly cleanly — just the wrong one.

What helps is a real failed print in front of the real camera. And if none comes along: put an existing tangle of filament on the bed, take a few images, done.

Training again with the new perspective

Before training, the fresh project needs its own impulse — the chain of image preprocessing and learning block. The structure is the same as in part 3, with one deliberate change: this time the image block gets 160 × 160 pixels instead of 96 × 96.

The camera records at 632 × 480, and the images land in the data set at exactly that resolution. The 96 × 96 from part 3 were never a property of the images, only the size the impulse scaled them down to. The hope behind raising the resolution: a starting pile of spaghetti is a fine structure, and at 96 × 96 too little of it may survive — so we want to improve detection. The downside is more computing time per image for the anomaly check; with a check cycle of 15 seconds we have plenty of that.

Whether that jump really paid off, I honestly cannot quantify. Measuring it properly would need a test set with plenty of fine strings — and that is exactly what we still lack. The higher resolution therefore remains a justified decision, but not a proven one.

A second field in the same block deserves more attention than its unremarkable name suggests: the resize mode. It decides how the rectangular camera image becomes a square. “Fit shortest axis” scales the short edge to 160 and cuts away roughly twelve percent of the image width on each side — together almost a quarter of the field of view that the watchdog will never see again. Our frame does not cover the whole print area as it is, so we do not want to give away another quarter. That is why the mode is set to squash, just as in part 3: the image is squeezed into 160 × 160, so it is distorted, but nothing is lost. For FOMO-AD the distortion is harmless, because training and later monitoring distort in exactly the same way — the model learns the squashed scene and sees precisely the same one in operation. If you change the mode afterwards, you have to run Generate features again; the previously computed features no longer fit.

And once more the trap from part 3, because it catches people out so easily: the learning block you need is called “Visual Anomaly Detection (FOMO-AD)” and only appears in the selection dialog once you click “Show all blocks”. The block called “Anomaly Detection”, which is visible without that click, is something else entirely — it expects sensor data and answers our images with a reshape error.

Edge Impulse Create Impulse with the image block set to 160 by 160 pixels, resize mode squash and the learning block Visual Anomaly Detection FOMO-AD
The impulse for round two: 160 × 160 pixels instead of the 96 × 96 from part 3, resize mode “squash” — and once again the “Visual Anomaly Detection (FOMO-AD)” block

In the end the data set held around 2,300 images, collected over three days from several prints, in different filament colours and from daylight to artificial light in the evening. The watchdog recorded them itself while running alongside.

Before training comes the split into training and test data — in the studio under Dashboard → Perform train/test split. For us that became 1,838 images to learn from and 473 to check against. Why that is not an incidental detail was already covered in part 3: the test half needs unseen normal images, because only they show how often the model raises an alarm for no reason in everyday use. Without them you end up knowing the hit rate but not the false alarm rate — and only both together give you a usable alarm threshold.

Training itself took about 35 minutes across 7,352 passes. That is considerably longer than in part 3, and the reason is the 160 × 160 pixels: the model breaks every image into a finer grid, and that costs computing time. You pay it once, in the cloud, not on the board.

Turning the model into a file

After that it is the same procedure as in part 4: under Deployment pick the target Arduino UNO Q and have the .eim file built. But this page holds one number I had not expected.

Edge Impulse deployment page with the Arduino UNO Q target and the comparison of computing time between int8 and float32
The deployment page estimates the computing time on the board — and here the quantised version is the slower one

The usual rule is that quantising — boiling the model down from 32-bit floating point to 8-bit integers — makes it smaller and faster. On the UNO Q it is exactly the other way round: 119 milliseconds for the quantised version against 67 milliseconds for the unquantised one. The reason: the speed advantage of int8 only materialises if there is dedicated hardware for it. Without that, all that remains of the calculation is the extra effort of converting. So we take the unquantised version. With a check cycle of 15 seconds the difference is irrelevant anyway — for comparison, in part 3 at 96 × 96 it was 41 milliseconds.

Back onto the board

The rest is manual work on the UNO Q and follows part 4. One piece of advice from experience: leave the old model in place. The new .eim goes into the same folder under its own name, gets its own model.yaml, and in the app’s app.yaml you only switch the model name. If the new model disappoints, the way back is a single changed line rather than a rescue operation.

The first check came immediately and was reassuring: on a running print the old model produced values between 48 and 61 in the new scene — it found its own surroundings permanently suspicious. The new model answered on the same print with 29 to 38. Exactly the numbers the test run had predicted. That made it clear the model works not only in the cloud but also through the camera pipeline on the board — the point where the white balance got in the way back in part 4.

Re-calibrating the threshold

And then the studio shows this result:

Edge Impulse model testing with 40 percent accuracy and a confusion matrix that finds every anomaly but wrongly flags many normal images
40 percent accuracy, F1 score 0.10 — stop here and you throw away a working model

40.16 percent accuracy. F1 score 0.10. That looks like a write-off. A glance at the confusion matrix next to it tells a completely different story: 100 percent of the fault images were detected — not a single one missed. What the model is being punished for is the other column: it also flagged 62 percent of the normal images as faults.

This is the same trap as in part 3. The number the studio displays applies to a preset alarm threshold, and that one is set far too low. It is not a verdict on the model but on a setting we are about to make ourselves. The actual work is to look at which values normal and faulty images really get.

Putting the distributions side by side

The fault images were 17 shots: mostly staged scenes — a tangle of filament placed on the bed, in white, beige and dark, sometimes large, sometimes small, sometimes at the edge of the frame — plus two genuine shots of a print that had come loose from the bed. Against those stand the 471 normal images from the test half.

Value
Normal images — median28.9
Normal images — 95 percent are below39.1
Normal images — 99 percent are below47.1
Normal images — highest value63.5
Fault images40.4 to 60.2

In part 3 this looked different. Back then the normal images were practically all below 33 and the weakest genuine fault sat at 43.8 — with a gap in between where the threshold could comfortably be placed. This time the two ranges overlap. There is no value left that catches every fault and hits no normal image at the same time:

ThresholdFalse alarmsMissed faults
4019 of 471 (4.0 %)0 of 17
458 of 471 (1.7 %)5 of 17
503 of 471 (0.6 %)8 of 17
65017 of 17

Where the overlap comes from

Before settling on a number I wanted to know which normal images were being scored so highly. In part 3 a supposed false alarm had turned out to be a genuine strand — the model had found our own labelling mistake. So I downloaded the ten highest-scoring normal images and looked at them.

This time it was not a labelling mistake. What those images show are bright finished printed parts at the edge of the frame, reflections on the bed and unusually bright room light. All perfectly normal states — just ones that barely appear in the training data set, because it is dominated by a dark bed and dark filament. The model finds “bright” unfamiliar, and with anomaly detection unfamiliar means suspicious.

So the advice from further up comes back to bite. Different colours and lighting moods do belong in the data set, yes — but every additional variant also widens what counts as normal, and a broader normal range makes the model less sensitive to weak faults. Variety is not free.

The decision: 40

I settled on 40, the option that catches all 17 faults and accepts four percent false alarms for it. A missed fault costs a night full of spaghetti and a roll of filament. A false alarm costs a glance at your phone.

On top of that, those four percent are individual images. The watchdog only raises an alarm when three out of four consecutive checks are suspicious — the time filter from part 4. A single outlier, because a bright part happens to stick into the frame, therefore triggers nothing at all. How much that damps things in practice cannot be calculated from the test data, because the split tears apart the chronological order. Operation has to show that, and that is exactly why the automatic print pause stays off for now.

The most effective lever is not the threshold anyway: it is more normal images with bright parts in the frame. Those lower the upper edge of the normal distribution exactly where it breaks the separation — without needing a single new fault image.

Arming the auto-pause

Up to this point the watchdog ran as a silent observer. Now it was supposed to get serious: threshold at 40, and if that holds for a few prints it may stop the printer by itself. That was the plan.

The first alarm came after a good four minutes. On a completely normal print.

The watchdog status page showing an alarm at score 41.5 with red marked regions on the empty bright area of the print bed
The first armed alarm — and a false one. The red tiles do not sit on a tangle but on the empty, bright area of the bed

The annotated image makes the cause immediately visible: the red tiles sit not on the printed part but across the empty, bright area of the bed. Exactly what the analysis of the test data had already suggested. The watchdog is bothered by brightness it does not know.

The log explains the rest. On that same normal print the values swung like this:

  • 28.7 — 34.0 — 37.4 — 41.3 — 41.5 — 41.6 — 43.1 — 47.8

So the threshold of 40 is not just barely exceeded, it is crossed every couple of minutes. And with that my own assumption from the previous section falls apart: the time filter that demands three suspicious checks out of four does not catch this. It is built against isolated outliers — against one image in which a hand happens to appear. Here the bright area is a persistent property of the scene; it stays there across many images. Three hits in a row are then not a matter of chance but only a matter of time.

The flaw in our own curation

While thinking about how to fix this I ran into a more fundamental problem. The training buffer from part 4 deliberately stores only images below the alarm threshold. That was meant as curation: no broken prints into a training set that is supposed to contain nothing but normal states. A sensible rule.

Except: the bright scenes the model does not know, the ones that trigger the false alarms, sit above the threshold. So they never get collected in the first place. And what is never collected can never make it into training, and what never makes it into training stays unfamiliar to the model forever. The watchdog excludes exactly the images it would need in order to get better. As long as it is armed it can no longer improve — it cements its own blind spot.

This is not a quirk of our implementation, it is in the nature of the thing: every system that filters its own training data by its own judgement has this problem.

The decision: not yet

So back to the start. The threshold is at 100 again, the watchdog observes and collects — this time including the bright phases. After a few more prints the images go into the project, the model gets retrained, and only from the distributions measured then does a threshold emerge that holds up in operation. Only after that will the automatic print pause be switched on.

The alternative would have been to simply push the threshold to 50. That would practically eliminate the false alarms — but eight out of seventeen fault images would slip through as well. A watchdog that misses half the faults but never disturbs anyone is a decorative object.

Autostart: the watchdog comes up with the board

A detail that is more annoying in practice than it sounds: after a restart of the UNO Q — a power cut, an update, the power supply pulled by accident — the watchdog did not come back. An app you start with Run in App Lab only keeps running until the next reboot. For a device meant to sit unattended next to the printer for months, that is not enough.

That’s what the default app in arduino-app-cli is for: whichever app you set as default, the App Lab daemon starts on its own at boot. Open the board’s terminal, either via the >_ icon at the bottom left next to the board name in App Lab or over SSH as the user arduino, and register the watchdog:

arduino-app-cli app list
arduino-app-cli properties set default user:spaghetti-waechter
arduino-app-cli properties get default

The first line lists your apps; the ID column shows the name the second command needs. If your app is called something else, use its ID there instead. properties get default confirms the setting with Default app: …. To turn autostart off again, set the value to none: arduino-app-cli properties set default none.

One more pitfall: the live view service and the image collector from part 2 have to stay switched off (sudo systemctl disable --now liveview capture). Only one process can use the camera at a time — if the collector starts first at boot, the app comes up, finds no image and says exactly that.

I checked this with a real reboot on the current board image (arduino-app-cli 0.14.1): just under three minutes after power-on, arduino-app-cli app ps lists the default app as running. So give the board a few minutes after switching it on before you check.

Rebuilding it yourself: the app as a zip

The complete app is available as a zip in the repository: app. In App Lab click the plus next to Apps, drag the file into Import an App, hit Run — that is it.

Arduino App Lab with the Import an App dialog open, ready for the zip file of the watchdog app
The plus next to Apps opens Import an App — drop the zip in, done

It starts right away even though you do not have your own model yet. The reason is in the app.yaml: the model entry there is the placeholder concrete-crack-anomaly-detection, which App Lab ships with. Without a registered model the app would not even come up but abort with Model … Not Found — and then you would not reach the interface to collect images either. Chicken and egg.

The anomaly values are meaningless with that placeholder — it knows cracks in concrete, not your print bed. It only makes sure the app runs. That is why the threshold sits at 100: no alarm is ever raised, but you see the live view, the values and the log, and the training buffer collects the images for your own model from the very first print.

My model is deliberately not included. It learned my camera position, my bed and my lighting and would report everything as a fault on your printer. As soon as your own .eim is registered, you swap the model name in the app.yaml and determine the threshold from your own distributions — the way it is described further up.

Conclusion

Five parts later there is a system that works: a camera on a self-designed mount, an anomaly model computing locally on the UNO Q, a status page in the browser, notifications in Home Assistant — and a board that comes back up on its own after a power cut. In operation none of it runs in a cloud and the camera frames stay in the house; only the training images went to Edge Impulse.

System overview of the spaghetti watchdog: printer with camera, Arduino UNO Q running the anomaly model and the training buffer, Home Assistant, status web page and the learning loop for re-training
What was actually built by part 5. Everything in green was added since the plan in part 1 — mount v2, the new model, the training buffer, the status page, the alarm image in Home Assistant and the autostart

And it worked where it counted: in part 4 the watchdog caught five genuine failed prints in a row before they turned into tangles. That was not a lab experiment, that was damp filament on an ordinary afternoon.

What the UNO Q can really do

The honest answer: more than I expected, and less than the data sheets suggest. Pushing one image through the anomaly model takes 67 milliseconds — with a check cycle of 15 seconds that is computing power in abundance. The limits were elsewhere: in the camera connection, which cannot go beyond 632 × 480 pixels because the memory for it is tight. In the NoIR sensor without an infrared filter, which delivers a flat, low-contrast image. And in an image pipeline that needed manual help.

The processor was never the bottleneck. The bottleneck was always the image.

What I would do differently next time

  • Lock down the hardware first, then collect. The most expensive mistake of the whole series was a camera that moved. A data set is only valid for as long as the scene stays unchanged.
  • Collect fault images from the start, not at the end. Without them no alarm threshold can be determined — and whoever waits for a genuine failed print to come along may be waiting for weeks.
  • Deliberately record the full range of the normal state, especially the rare bright moments. What is missing from training turns into a false alarm later.
  • Treat the lighting as part of the build, not as an afterthought. Contrast is cheapest to buy with light, not with more pixels.
  • A camera with an infrared filter instead of the NoIR version — that was the wrong choice for this project, even though it works flawlessly otherwise.

Where it goes from here

The next step is unspectacular: keep collecting, retrain, determine the threshold, arm the auto-pause. After that comes rebuilding the mount in PETG — PLA gives way slowly under sustained load, and an arm that sags a couple of millimetres over weeks is more expensive for an anomaly model than an arm that breaks. A broken one is noticed immediately.

And at some point the question: how much better would all of this be with a plain webcam with an infrared filter? Not because of the resolution — we do not need that — but because of the contrast. That would be worth an experiment of its own.

The hard part of an edge AI project is not the model. It is the question of what “normal” actually means — and that is answered not by the computer but by whoever collects the images.

Similar Posts