#ESPHome Clock with Breakout Game

203 messages ยท Page 1 of 1 (latest)

verbal salmon
#

I've gotten into freeform circuits and built a small desk clock with an SSD1306 and a rotary encoder. I have also added a beeper and a vibration motor to it. It has a simple menu system to navigate the features it has.

After realising the power of display lambdas, I was able to create a bouncing box on the screen which got me inspired. From there it just escalated and I wrote a full breakout game for the "clock". It is played by rotating the encoder but also has an autoplay mode. I'm still adding features to it but it's already pretty fun.

Here are some sneak peeks of it as this project is only a week old and will surely continue to evolve from here on ๐Ÿ˜†
Edit: Code can be found here: https://github.com/richrd/esphome-clock-os

proud yacht
#

Nice job

brittle blade
#

This is from the YT comments?

verbal salmon
#

Will be releasing the code on GitHub hopefully soon

#

@brittle blade yeah ๐Ÿ˜Š

brittle blade
#

So awesome!

#

Please do release the code for it ๐Ÿ™‚

proud yacht
#

Kudos for the 13:37 time capture as well

#

When Doom?

verbal salmon
#

I think someone already ported it but without ESPHome :D

proud yacht
#

Doom in esphome lambda coming soon

#

2 weeksโ„ข

verbal salmon
balmy badger
#

@tiny field yooooooooooo here's how we get games on M-1s. lul

verbal salmon
#

I think after breakout I will need to make a snake game, and I have some other ideas as well. These side projects really tend to get out of hand fast ๐Ÿ˜…

balmy badger
#

1-hour project, amirite?

proud yacht
#

five passengers set sail that day,
for a three hour tour...๐ŸŽต

#

Feature creep is ESPHome's middle name.

balmy badger
#

Y'all saw today that my project with the epaper display influenced making things easier to pull from Home Assistant. At least some feature creep is useful. lul

verbal salmon
balmy badger
#

I love that thing, my son watches it for when he can bother me, it's so useful.

proud yacht
#

I think that deserves a cross post.

turbid fable
proud yacht
#

make some espnow motion controllers

turbid fable
#

More esphome games would be cool to have, this one is cool

verbal salmon
proud yacht
#

What did you have to do to keep esphome happy (prevent blocking) while the game is on going?

brittle blade
verbal salmon
#

Yeah honestly I didn't think this would work, and I might be abusing some features. But it indeed works surprisingly well

fading mauve
#

This is crazy!!! Incredible work

verbal salmon
#

I have lately implemented sounds, rumble feedback, power ups like shield and multiball and a nice progress bar for the pause screen ๐Ÿš€ EDIT: sounds are pretty quiet so might need to raise your volume to hear them

proud yacht
#

Nice job it worked!

proud yacht
#

Made ESPHomario with this technique ๐Ÿ•น๏ธ

turbid fable
#

"We're sorry but the princess is in another castle"

verbal salmon
#

Wow, so happy to see other people doing this too! ๐Ÿคฉ @proud yacht is that first screenshot my Snake game? If so, great that you got it running and The ESPHomario looks amazing already! I'd love to work on a platformer too, but with my current hardware only having a rotary encoder for control it's not very suitable for that.

Once I acquire some more parts and time, I'm going to build another similar device but with a rechargeable battery and a gamepad form factor, that should unlock a lot more potential. I'd like to clone the Space Impact game from the old Nokia phones ๐Ÿš€

verbal salmon
proud yacht
proud yacht
#

Then just make a macro to exit like 10 quick clicks is exit or something

brittle blade
balmy badger
#

YES

turbid fable
#

probably

proud yacht
#

I just got a full keyboard working via usb_host maybe mouse next, get some WASD going

turbid fable
#

nice

proud yacht
#

It wasn't happy though when I added a hub said the P4 doesn't have Transaction Translator support ๐Ÿ™

#

(low speed stuff fails)

#

So no classic 4 port multiplayer hub action [16:09:58.398][D][esp-idf:000]: E (487151) HUB: Connected device is LS, transaction translator (TT) is not supported ๐Ÿ˜„

#

Though maybe control pads are highspeed?

#

or I need a 3.0 hub then maybe it won't care if low speed stuff is then plugged into that...

#

Seems USB RF dongles are HS and standard wired keyboards are LS

proud yacht
#

I'll try to find an old usb gamepad

verbal salmon
proud yacht
#

I was just trying to make every button work on it first so far I think I got everything... media keys, LEDs, locking buttons, num lock buttons, etc

verbal salmon
#

Are you talking via some low level usb protocol like on a byte level or via some library that can talk to keyboards?

proud yacht
#

Are you using the S3? it only works on the S3/P4

#

(I'm using the P4 as it has the USB-A soldered on the board)

proud yacht
#

Ok I got USB Keyboard/MediaKeys/Touchpad, Mouse, Wired Switch Pro Controller Gamepads working /w rumble

turbid fable
#

i want to add controller support to my pong game

proud yacht
turbid fable
#

basically

#

i had been thinking of extending the effects framework i made to just run game logic (since it already runs things at a chosen framerate and has ways to pass data in to them, but instead i'm beating my head against the wall on gdma code

proud yacht
#

do you have a picture of your pong?

turbid fable
#

i threw the code together a while ago, haven't touched it in a while but it just plays itself

proud yacht
#

I should see if I can attach these two devices over espnow for one delayed controlling exp

turbid fable
#

hah yes

proud yacht
verbal salmon
proud yacht
#

What kind of USB remote would you use?

verbal salmon
#

I realized I don't have an ESP with USB support so not sure at the moment. I have an 8BitDo controller which I think should work over USB but not sure. I think I will need to explore the Bluetooth options for now until I get an S3/P4. The controller also has a 2.4Ghz USB receiver, not sure if that would work with an ESP32.

That said I got side tracked with building other features for the clock (like an alarm feature, finally ๐Ÿ˜… ) and my friend is doing some pixel art for the project so perhaps the controller stuff will have to wait after all.

rough hare
#

Feels like we might need external components for various games. Snake, breakout, tetris, could all be done quite easily, depending on the display. Given the resolution of the display, could influence the quality of the graphics - a 64x32 pixel hub75 display would have different abilities to a 7" 800x480 display.
Games would be idle until triggered by a lambda, typically, and could expose actions for things like user input (id(breakout).move_left(n), id(breakout).update_display(), etc).

#

Would allow configuration of various input devices from binary_sensor to usb HID, and activation/deactivation as necessary.

if (page == 1) {
  id(breakout).update_display();
  return;
} else {
  id(breakout).pause();
}

etc

proud yacht
#

I thought you said that was an S3?

verbal salmon
#

The Clock is C3 actually, I thought I might have had an S3 or something lying around but nope :/

proud yacht
#

So essentially you are in the same spot as me I only had this esp32-wrover with a display then needed to use the S3 for the remote ๐Ÿ˜„

#

USB Remote -> S3 -> ESP-Now -> C3 -> Display

tender dirge
#

omg my son will love this, I need to build this now ๐Ÿ˜„

verbal salmon
proud yacht
verbal salmon
proud yacht
#

Cute

#

are you manually drawing the graphics or is there a algorithm to it, micro floor plan designer?

#

Did you use lead free solder on your frame?

verbal salmon
verbal salmon
smoky rover
gleaming scroll
smoky rover
gleaming scroll
#

or just chop it and use any connector you like ๐Ÿ˜›

brittle blade
verbal salmon
gleaming scroll
verbal salmon
prisma talon
#

I will try your code. I found a board with some buttons, display and rotary dial combined to make the project a bit easier

#

Can you add some more information about the vibration motor u used?

verbal salmon
# prisma talon Can you add some more information about the vibration motor u used?

It's a random one I found in my smartphone repair box which I cut off the flex PCB. I have ordered 2 types of vibration motors off AliExpress and can report back how they work when I get them. I'll admit I'm running the current one directly off one of the GPIOs with a resistor in between. I think the smaller the better to keep the power draw as low as possible but I don't have any proper specs.

verbal salmon
prisma talon
#

i did got it running but i think you miss some substitutions like some wifi settings in the main yaml. Also i did not find where to set the clock.

#

The esp32-C6 also have a extra usb so i used that one to build the esphome clock

prisma talon
verbal salmon
balmy badger
verbal salmon
verbal salmon
balmy badger
#

It's all pretty basic from what we can tell. We think they used copilot to throw this together, but it's not done in a bad way.

#

I need to get a better video of the thing. My voice wasn't picked up in the one I did at Universe.

prisma talon
#

Maybe it is an idea to make an official esphome clock combined with a speaker and mic, like a small google nest

balmy badger
verbal salmon
prisma talon
turbid fable
#

you can "watch" repos in github

verbal salmon
prisma talon
turbid fable
#

Have you considered moving over to lvgl?

brittle blade
kind spear
#

I only know it from the Chrome offline screen. Did that come from somewhere else?

turbid fable
#

Think they just made it as an Easter egg

verbal salmon
verbal salmon
brittle blade
#

Random thought: ship these as external components.
Would be a little bit of wrapper work to have the python init file, but it can have an simple schema with id and sinple to_code

Then people can include the external component and do something like:

display:
  platform: ...
  pages:
    - id: breakout
      lambda: id(breakout_id).play(it);

And have actions or simply lambdas to send the controls

#

End random thought. Time to ๐Ÿ’ค

verbal salmon
verbal salmon
turbid fable
turbid fable
verbal salmon
turbid fable
#

its fun, I should finish my flying toasters and aquarium screen savers one of these days

#

lmk if you need help or have questions, it doesn't look like it would be too bad to do

rough hare
#

Iโ€™m sure a simple example could be made that just needs filling in of the actual game logic in loop(), the display update routine in display(it), and overriding predefined D-Pad or joystick movements.
I suspect the python part would be the most intimidating as you say. Having something 95% done should help a lot, with an example of how to do the last 5% yourself.

turbid fable
#

If I get a few mins tomorrow I can set up something similar to my fx library for games

#

Should be pretty easy

verbal salmon
rough hare
#

It's actually not too bad. The real meat is in figuring out the schema for validation, which can be as simple as:

breakout_ns = cg.esphome_ns.namespace("breakout")
Breakout = breakout_ns.class_(
    "Breakout", cg.Component
)
CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(Breakout)
        }
    )
)

and then the to_code(): method, which basically instantiates your c++ class:

async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
#

it gets a little more complicated if you want the python code to do validation before the compiler has a chance

#

and if you want to define invocable actions, vs just using id(breakout).update_display(it); lambdas. (I think the update display will always have to be a lambda, actually, since it starts off in a lambda by design). You could use invocable actions for the controls, though, but lambdas would be less effort ๐Ÿ™‚

turbid fable
#

ok, I just put this external component together https://discord.com/channels/429907082951524364/1434617002496098354 and ported the snake & breakout games & added the pong game I had built. Is setup to allow people to easily drop new games in to the runner. No doubt needs more work, but should be easy to flush out further & fix bugs. Does use LVGL.

balmy badger
#

Pavlov: I need to finish all the projects I have fast!
Also Pavlov: OOH NEW SHINY

#

๐Ÿ˜‚

turbid fable
#

yeah well

#

i have an extra hour with this dst change

balmy badger
#

Don't worry, I've found a new shiny to chase after since we spoke in person, too. ๐Ÿ˜‚

verbal salmon
#

New device in the works, it has an analog joystick for game control

prisma talon
#

Can you update your github with new code and reader information?

verbal salmon
verbal salmon
#

I wonder if there's a good way to support either a rotary encoder or a joystick in the ClockOS configuration, and then let the user choose which one to use (or maybe even both) and the code would then know which input method to use based on the users configuration. ๐Ÿค”

rough hare
#

I was thinking about how to deal with user input for the clock settings, as well as for the game. My inclination was to have the gamerunner: maintain an "Active" flag that could be set and checked. i.e. if you choose the game page in lvgl, you would set the active flag, and if you select a different page, you would clear it. This feeds into display updates (only update the display if active), as well as controls:

on_...:
  then:
    if:
      condition:
        id(gamerunner).isActive()
    then:
      - lambda: !id(gamerunner).action(whatever)
    else:
      - clock.set(whatever)
#

all pseudo-yaml, but hopefully the idea seems clear.

#

as to how to select which is in use, I would use a package:.

turbid fable
proud yacht
#

Have a mapping screen like emulators that lists the controls then lets you set buttons to whatever you press

rough hare
#

How do you select it if you don't have controls set up?

#

๐Ÿ” ๐Ÿฅš

proud yacht
#

Already has a primary control I was talking about things you would plug in like remotes etc

rough hare
#

got it

#

Bluetooth HID vs USB HID vs individual binary_sensors, vs rotary controllers.

proud yacht
#

Some emulators let you set two buttons or more as well for the same control. So you could even have a duplication of the master control, you would just have to use it first to select those.

#

Some also auto select standardized objects to existing things as well if they know what the device is.

proud yacht
#

There's only so many hardware control functions. You could assume a lot with the primary control. Would basically just need pin definitions. You can have a standard set and make them optional for pin config. Rotary, D-Pad, Button, Analog Stick/Trigger.

esphome:
  name: esphomebrew

usb_host:
  # Configures the specific device your remote is.
  # You must find the VID and PID of your remote using a computer's Device Manager or 'lsusb'.
  devices:
    - id: switch_pro_controller # A friendly ID for this device
      vid: 0x1234               # Vendor ID (Example - Replace with actual)
      pid: 0x5678               # Product ID (Example - Replace with actual)

esphomebrew:
  # Control scheme USB_HID, ROTARY, BT, ESPNOW, etc
  ui_control: USB_HID
  
  # Optional: Reference the device ID configured in usb_host etc
  device_id: switch_pro_controller

  # Optional: Define what type of HID report this remote uses (e.g., GAMEPAD, KEYBOARD)
  hid_report_type: GAMEPAD
esphomebrew:
  # Control scheme USB_HID, ROTARY, BT, ESPNOW, etc
  ui_control: ROTARY
  rotary_pin_a: GPIO12
  rotary_pin_b: GPIO13
  # Optional: Primary pin selection
  action_select_pin: GPIO15 # Maps to ACTION_SELECT
  action_b_pin: GPIO2       # Maps to ACTION_B (Back/Cancel)
  action_start_pin: GPIO4   # Maps to ACTION_START
verbal salmon
#

Trying out my rusty pixel art skills, Cat Tamagotchi probably coming up one day ๐Ÿ˜ผ

rare pendant
#

nice job, why not adding touch senser for games? ๐Ÿค”

verbal salmon
rough hare
#

Given the skeletal design, touch surfaces could be an option. ๐Ÿค”

rare pendant
verbal salmon
proud yacht
#

Ideally with your frame skills there they may not even be needed as the esp supports touch without. You could just make a funky pad design in copper and hook it to the touch pins on the esp.

verbal salmon
proud yacht
#

You could make for your clock alarm, so if you touch the frame it snoozes etc

verbal salmon
#

That would be cool, the entire frames are connected to ground currently though so not sure if it would work in that case?

#

I have a working alarm, all my 3 devices woke me up separately this morning but I still need to add the snooze option

proud yacht
#

you could put some nylon screws in or fiberglass spacers in if your screws are grounding it then attach a lead to the gpio etc

#

Oh I see your directly using it as a ground for your buttons etc

#

You could do some hidden magic with thin magnetic wires

#

but that may over complicate your aesthetics

#

Think up some fancy isolation method

#

Magnetic wire is coated but still looks pure copper, so it wont ground out, if it was hiding along your rails etc. Then isolate the touch pattern from the frame maybe a piece of heat shrink on two sides to hold it in place.

#

Not sure how much wear n tear it would take but something like that.

#

jbweld?

#

LLM says "Yes, standard J-B Weld is electrically non-conductive"

#

so J-B Weld the design to the frame then run a thin magnet wire to it.

verbal salmon
balmy badger
stable orchid
#

Aww ai made it, that's less cool, still cool that it works though

balmy badger
#

Franck is one of the few people I trust to build something with AI. He does good reviews of the work, along with extensive testing.

It's definitely not what everyone should be doing, though. ๐Ÿ˜…

stable orchid
#

Yeah but it's no longer something cool that some person made, it's just some other AI thing

balmy badger
#

Eh, I still think it's cool. It probably would have taken months to do this as a single human.

stable orchid
#

I know he could've done it all himself too, and yeah it's still cool, just.... Eh

proud yacht
#

I think it shows that basically anyone could make an HA Add-on with AI. Which is more enabling to the general populous. Instead of the just searching for human clout.

balmy badger
#

There are some guidelines when it comes to submitting add-ons or integrations written by AI, too. We work hard to not accept slop.