Thomas Buck před 1 rokem
rodič
revize
0ced464a8d

+ 107
- 0
input/projects/cat-toy.md Zobrazit soubor

@@ -0,0 +1,107 @@
1
+title: Cat Toy
2
+description: Laser pointer on two servos with Raspberry Pi Pico W
3
+parent: projects
4
+git: https://git.xythobuz.de/thomas/CatToy
5
+date: 2023-04-22
6
+comments: true
7
+---
8
+
9
+I never wanted to own pets.
10
+Having to look after an aquarium when I was a child was more then enough to put me off of this thought.
11
+Nonetheless, for complicated reasons beyond the scope of this article, I now find myself living with two cats.
12
+This requires some adjustments to my flat. 👷
13
+
14
+<!--%
15
+lightgallery([
16
+    [ "img/cats_1.jpg", "Ares sitting on my 3D printer" ],
17
+    [ "img/cats_2.jpg", "Aphrodite sitting on my 3D printer" ],
18
+    [ "img/cats_3.jpg", "Aphrodite sitting on my laser engraver" ],
19
+    [ "img/cats_4.jpg", "Ares and Aphrodite sharing my printer tower" ],
20
+])
21
+%-->
22
+
23
+Obviously I had to come up with some kind of gadget to help me keep them occupied.
24
+
25
+<!--%
26
+lightgallery([
27
+    [ "img/cat_toy.mp4", "video/mp4", "", "", "Demonstration video" ],
28
+    [ "img/cat_toy_2.jpg", "Servos and laser diode" ],
29
+    [ "img/cat_toy_1.jpg", "View inside box" ],
30
+])
31
+%-->
32
+
33
+So on the afternoon of easter monday I took a plunge into my parts bins and built this device.
34
+Getting to an initial workable prototype, both hardware and software wise, only took about 4 to 6 hours.
35
+It consists of two RC micro servos and a laser pointer diode mounted to each other.
36
+They are controlled by an RP2040 on a Raspberry Pi Pico board.
37
+The servos were spare parts for a model aircraft build.
38
+The laser diodes I bought a whole bunch of from china a long time ago.
39
+The batteries came out of a cheap chinese headlamp.
40
+
41
+If you were to buy all the parts, the shopping list could look something like this:
42
+
43
+<!--%
44
+tableHelper([ "align-right", "align-right", "align-right", "align-left", "align-right monospaced" ],
45
+    [ "Description", "Type", "Count", "Link", "Price" ], [
46
+        [ "MCU", "Raspberry Pi Pico W", "1x", "<a href=\"https://www.berrybase.de/raspberry-pi-pico-w-rp2040-wlan-mikrocontroller-board\">BerryBase</a>", "6.90€" ],
47
+        [ "Servo", "MG90S", "2x", "<a href=\"https://www.roboter-bausatz.de/p/mg90s-micro-servo-motor\">Roboter-Bausatz</a>", "7.90€" ],
48
+        [ "Laser Diode", "650nm 5V 5mW", "1x", "<a href=\"https://www.radiomag.com.de/product/mini-650nm-6mm-5v-5mw-laser-dot-diode-module-head-wl-red-laser-led_58363.html\">Radiomag</a>", "1.40€" ],
49
+        [ "Battery", "18650 Li-Ion 3.7V 2900mAh", "2x", "<a href=\"https://www.akkuteile.de/en/bak-n18650cnp-2500mah-3-6-3-7v-li-ion-battery-20a-discharge-current_100846_3093\">AkkuTeile</a>", "9.38€" ],
50
+        [ "Holder", "18650 holder", "2x", "<a href=\"https://www.akkuteile.de/en/battery-holder-for-1x-18650-cell-with-connector_400422_1454\">AkkuTeile</a>", "2.58€" ],
51
+        [ "DC-DC", "LM2596 step-down module", "1x", "<a href=\"https://www.makershop.de/module/step-downup/lm2596-step-down/\">MakerShop</a>", "1.70€" ],
52
+        [ "Sum", "", "", "", "~30.00€" ]
53
+    ]
54
+)
55
+%-->
56
+
57
+I also added a power switch, a push button and an LED (with resistor) as a physical user interface.
58
+To measure the battery voltage I used a simple voltage divider made out of an 18kΩ and a 10kΩ resistor.
59
+There's also a micro USB connector and some male and femal dupont connectors as well as some copper wire in there.
60
+It's not really economical to buy these in single quantities, so I didn't list them above.
61
+
62
+The case of the device is made out of a recycled cardboard box, with some holes poked into it and some hot glue.
63
+I really like this method of prototyping electronics.
64
+It's easily available, quick, cheap and relatively sturdy.
65
+
66
+<!--%
67
+lightgallery([
68
+    [ "img/cat_toy_3.jpg", "Buttons" ],
69
+    [ "img/cat_toy_4.jpg", "PCB" ],
70
+])
71
+%-->
72
+
73
+This time I used [MicroPython](https://docs.micropython.org/en/latest/rp2/quickref.html) again to build the software.
74
+Is it my second time using it, after [the MCH2022 cocktail machine badge app](http://localhost:8080/2022_07_29_MCH2022.html#app).
75
+It was a little bit more complicated to first get my head around it, compared to the usual C/C++ firmwares, and I was not able to figure out an easy way for OTA firmware updates yet.
76
+But in the end it was much quicker to build a working prototype with it.
77
+I recommend using [rshell](https://github.com/dhylands/rshell), there's also a small script for it [in my repo](https://git.xythobuz.de/thomas/CatToy/src/branch/master/copy.sh) to use it to copy the firmware to the device.
78
+
79
+The RP2040 continues to be a delight to work with!
80
+I really like the available tools and documentation.
81
+Getting started with a working firmware prototype was unbelievably quick, even including "advanced" features like WiFi and an HTTP interface.
82
+All without any strange Cloud IDEs or similar stuff (*cough* Arduino).
83
+
84
+<!--%
85
+lightgallery([
86
+    [ "img/cat_toy_web.png", "Webinterface of the Cat Toy" ],
87
+])
88
+%-->
89
+
90
+The laser diode is PWM controlled and I only run it at 10%, and on top of that with 3.3V instead of 5V.
91
+It is still more than bright enough.
92
+The webinterface also shows the console output of the script, which is very useful for debugging issues that happen while no USB cable to a PC is connected.
93
+Everything can be controlled using the webinterface.
94
+For ease of use, the LED in the box blinks the index number of the currently selected set of servo angle limits.
95
+With a short button press, the selected index is cycled through.
96
+With a long button press, the currently selected index is used to start movements and turn on the diode.
97
+By configuring different limits, the movements of the laser dot can be constrained, depending on where the device is placed, so the cats don't run into furniture or similar stuff.
98
+
99
+Of course this concept could be extended much further.
100
+On the technical side, a nice 3D-printed enclosure would go a long way.
101
+There are [a couple of examples](https://www.printables.com/search/models?q=laser+cat+toy) out there for inspiration.
102
+Currently the servos are simply commanded some random angles in a specified range.
103
+This could be "linearized" so the laser dot is moving similar distances everywhere on the ground, by including the height of the device above ground in the calculation.
104
+If this were to be paired with some kind of webcam, maybe with vision detection, the capabilities of the system could be greatly enhanced, for example to avoid shining the dot onto the cats body, where it doesn't notice it usually.
105
+Also, remotely controlling the device via eg. a Telegram Bot interface could be useful to play with the cats while not at home.
106
+And of course the webinterface could be made to look much prettier.
107
+But I don't think I will implement any of this to be honest, it already does the job well enough for me 😅

binární
static/img/cat_toy.mp4 Zobrazit soubor


binární
static/img/cat_toy_1.jpg Zobrazit soubor


binární
static/img/cat_toy_1_small.jpg Zobrazit soubor


binární
static/img/cat_toy_2.jpg Zobrazit soubor


binární
static/img/cat_toy_2_small.jpg Zobrazit soubor


binární
static/img/cat_toy_3.jpg Zobrazit soubor


binární
static/img/cat_toy_3_small.jpg Zobrazit soubor


binární
static/img/cat_toy_4.jpg Zobrazit soubor


binární
static/img/cat_toy_4_small.jpg Zobrazit soubor


binární
static/img/cat_toy_poster.png Zobrazit soubor


binární
static/img/cat_toy_thumb.png Zobrazit soubor


binární
static/img/cat_toy_web.png Zobrazit soubor


binární
static/img/cat_toy_web_small.png Zobrazit soubor


binární
static/img/cats_1.jpg Zobrazit soubor


binární
static/img/cats_1_small.jpg Zobrazit soubor


binární
static/img/cats_2.jpg Zobrazit soubor


binární
static/img/cats_2_small.jpg Zobrazit soubor


binární
static/img/cats_3.jpg Zobrazit soubor


binární
static/img/cats_3_small.jpg Zobrazit soubor


binární
static/img/cats_4.jpg Zobrazit soubor


binární
static/img/cats_4_small.jpg Zobrazit soubor


Loading…
Zrušit
Uložit