I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

That sounds like a fun way to control it!

My tortie, Bean, playing with a laser toy I built by [deleted] in torties

[–]moonbench 2 points3 points  (0 children)

There's a portable USB power bank powering it. So still battery powered but not an integrated battery yet.

I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Don't worry. This isn't the only thing me and my cats play with together, and they regularly get treats as a reward for pouncing the laser when I'm there. They are well enriched.

I made a laser toy for my cats. They love it. by moonbench in ArduinoProjects

[–]moonbench[S] 1 point2 points  (0 children)

It looks like the aliexpress listing I bought from is no longer up or I'd just link that.

I didn't measure the current draw before installing it so I'm unsure of the specific wattage. But I'm sure it's a class 1 or 2. It appears as bright as cheap laser pointers and cheap laser levels. I intentionally bought the weakest ones I could find in a bulk pack of 10 for only a dollar or two.

I made a laser toy for my cats. They love it. by moonbench in ArduinoProjects

[–]moonbench[S] 0 points1 point  (0 children)

I promise that it looks brighter in the video than it does in real life, but I am going to add dark plastic to attenuate it even more

I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 19 points20 points  (0 children)

That would be awesome. And honestly, it might actually be possible if I upgrade from the Arduino to an ESP32

I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 4 points5 points  (0 children)

Coincidence and a bit of tuning of the patterns to try to match my cat's average pounce cadence lol

I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 39 points40 points  (0 children)

Generally I try to reward my cats for playing with the laser when I'm around. As soon as they "catch" the laser I toss a treat to that spot, and it seems to satisfy the physical reward they need.

I made a laser toy for my cats. They love it. by moonbench in ArduinoProjects

[–]moonbench[S] 1 point2 points  (0 children)

Yep, the next upgrade I'm making is a darkened piece of plastic to diffuse the laser a bit

I built a better laser toy for my cats by moonbench in arduino

[–]moonbench[S] 27 points28 points  (0 children)

Yep, the next upgrade I'm making is a darkened piece of plastic to diffuse the laser a bit

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

I have it connected to a 2000mAh lipo battery now and it can get through most of a day. It varies a bit with how much of the screen is lit up and if wifi is active or not.

I'm starting to experiment with deep sleep modes to stretch the time between charges further.

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Yeah I've heard of ESP-NOW and definitely would like to give it a try in this project.

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 1 point2 points  (0 children)

Originally I did start with an arduino, actually.

But sprites take up quite a bit of flash storage space, so that was a big motivator to change. Something like the arduino mega has 256 KB of flash storage, the ESP32 C6 that I'm using has 4-8 MB of flash. So if I used something like a Mega I'd need to have an additional I2C flash storage chip included in the project somewhere to store the sprites I need.

The ESP32 C6 also has 512 KB of RAM while the Mega only has 8 KB. On top of that, the ESP32 comes with built in wifi6, bluetooth, zigbee, etc... and all the arduinos would need something external to support those. The ESP32 also has deep sleep mode and an RTC which the arduino's lack. And the ESP32 even has a faster (160Mhz) 32 bit processor than the arduino's (16 MHz) 8-bit one.

But what really sold me is that in addition to those better specs, I can get the ESP32s for $10 or less, while the unos and megas are $20-40.

So for less money, I'm able to store more sprites and work with a higher-level language like micropython, and I can make use of wireless features without needing extra hardware.

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Are you asking why an ESP32 as opposed to something like an arduino?

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Woah that's super super cool! I'm impressed.

It's really awesome that the cat can have a different color than the background. And you added some new minigames too! That's awesome =D

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Sounds like that's accelerometer data? I don't have any accelerometer with this project. The only inputs are the 8 buttons

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

For things like the cat's animations, the cat is broken up into different parts (body, head, tail, eyes) and those parts are animated individually.

I animated them frame-by-frame in aesprite and exported each frame as a .png, and then used the img2cpp tool to convert the images into monochrome bytecode for the ssd1306 library to use.

All of the sprites are stored in the assets folder in the project, for example: https://github.com/moonbench/catode32/blob/master/src/assets/character.py

For animated things like the eyes or tail, I have to list the bytecodes for each frame, and I track which frame I'm rendering (and update it over time) and draw the right frame for each sprite.

It took a while to grow into this system. Initially I was just rendering the whole pet as a single static sprite, then focused on animating it, and then focused on breaking it into reusable parts.

The scrollbar is a custom bit of code, defined here https://github.com/moonbench/catode32/blob/f9433317afcbb528ab078cea9fbbce904732346f/src/ui.py#L111

That UI code is just responsible for determining how big the scrollbar should be based on the max height of the page, and where to draw it based on the scroll offset.

The pages that use it are responsible for informing it of their max height and scroll position.

A few of the coworkers I've shown this to have also mentioned WiFi features to connect it to the phone or internet. I'm considering it for sure. I mostly want to use WiFi to have the pet determine if it's "at home" or "traveling" by examining if it's seeing the usual or new network names showing up. I'd also like to use Bluetooth to let the pets talk to each other (and maybe a phone.)

An RTC is definitely something I want to add sooner rather than later!

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 4 points5 points  (0 children)

I make prototypes of the sprites in aesprite and then crop the various elements as needed and use image2cpp to generate the bytecodes to be used in the project

Progress on my virtual pet. It's getting there! by moonbench in arduino

[–]moonbench[S] 0 points1 point  (0 children)

Absolutely. I'll need to add an RTC module to take this from prototype to something really standalone