Tag Archives: arduino

Blender plugin for 8 potmeter input

This weekend I saw a corridor crew video about controlling CGI objects using input devices.

This made me think of a half finished project I did a while ago.
So lets finish it.

(I know, dirty screen .. too much outside hacking)

8Angle M5 thingy using I2C (Pin D1 and D2)

CODE for wemos

Very simple code to read pots using I2C and printing values on the serial output using the wemos.
Only needs 5V,GND,SDA,SCL (D1 D2)

279,206,520,1023,1023,60,300,985,0
Output example 8 potmeters 0-1023 value and last value 0 or 1 for the switch

Serial plotter example below

#include "m5angle8.h"

M5ANGLE8 MM;

void setup()
{
  Serial.begin(115200);

  Serial.println();
  delay(100);

  Wire.begin();
  MM.begin();
}


void loop()
{
  for (int ch = 0; ch < 8; ch++)
  {
    Serial.print(MM.analogRead(ch, 10));
    Serial.print(",");
    delay(1);
  }
  Serial.print(MM.inputSwitch());
  Serial.print("\n");
  delay(100);
}

Plugin for Blender

filename unit8angle_blender/__init__.py

made into a zip you can install using

zip -r myplugin.zip unit8angle_blender

Blender edit > preferences > add-ons > Install from disk

import bpy
import serial
import serial.tools.list_ports

ser = None


def open_serial():
    global ser

    if ser:
        return

    # Change this to your COM port
    ser = serial.Serial("/dev/ttyUSB0",115200,timeout=0)


class SERIAL_OT_start(bpy.types.Operator):
    bl_idname = "wm.unit8_start"
    bl_label = "Start Unit8"

    _timer = None

    def modal(self, context, event):

        if event.type == 'TIMER':

            global ser

            if ser and ser.in_waiting:

                line = ser.readline().decode(errors="ignore").strip()

                try:

                    values = list(map(int,line.split(",")))

                    if len(values) >= 8:

                        obj = context.active_object

                        if obj:

                            obj.location.x = values[0] / 100.0
                            obj.location.y = values[1] / 100.0
                            obj.location.z = values[2] / 100.0

#                            obj.location.x = values[0] / 1023.0
#                            obj.location.y = values[1] / 1023.0
#                            obj.location.z = values[2] / 1023.0

                            obj.rotation_euler.x = values[3] / 1023.0 * 6.28318
                            obj.rotation_euler.y = values[4] / 1023.0 * 6.28318
                            obj.rotation_euler.z = values[5] / 1023.0 * 6.28318

                            s = 0.1 + values[6] / 1023.0 * 3.0
                            obj.scale = (s,s,s)

                except Exception:
                    pass

        return {'PASS_THROUGH'}

    def execute(self, context):

        open_serial()

        wm = context.window_manager

        self._timer = wm.event_timer_add(0.01, window=context.window)

        wm.modal_handler_add(self)

        return {'RUNNING_MODAL'}


class SERIAL_PT_panel(bpy.types.Panel):
    bl_label = "Unit8Angle"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Unit8'

    def draw(self, context):
        self.layout.operator("wm.unit8_start")


classes = (
    SERIAL_OT_start,
    SERIAL_PT_panel,
)


def register():
    for c in classes:
        bpy.utils.register_class(c)


def unregister():
    for c in reversed(classes):
        bpy.utils.unregister_class(c)

Giving people ability to control my Xmas lights

At the WHY2025 hackers event, we used bigred’s antenna pole to make a huge sign using leds.

It gave me the idea to make a pole which displays digital “fireworks” using leds.
Fireworks are becoming illegal the next year in the Netherlands, I think.

So why not going digital?
12 Meter pole, 300 Leds.

There is a QR code and a website link mentioned on a page at the gate.
10 presets to select via a website.

Notification on my TV

While waiting for the first visitor I made a magnetic game.
Using a bunch of magnets, and 3D printed hexagon rings.
Two players try to place magnets in a small area without moving the others. If magnets slam together, you have more pieces to place.
(Below, last player has to take those 6 pieces)

CODE for website index.html

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WLED Mast</title>

<style>
body {
    background: #111;
    color: #fff;
    font-family: Arial;
    margin: 0;
    padding: 20px;
    text-align: center;
}
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}
button {
    padding: 25px;
    font-size: 22px;
    border-radius: 20px;
    border: none;
    background: #333;
    color: #fff;
    font-weight: bold;
}
button:active {
    background: #555;
}
</style>
</head>

<body>

<h1>WLED Mast</h1>

<div class="grid">
    <button onclick="run('b1')">off</button>
    <button onclick="run('b2')">fireworks</button>
    <button onclick="run('b3')">sound<BR>reactive</button>
    <button onclick="run('b4')">bounch-balls</button>
    <button onclick="run('b5')">fire</button>
    <button onclick="run('b6')">juggle</button>
    <button onclick="run('b7')">swing</button>
    <button onclick="run('b8')">sparkle</button>
    <button onclick="run('b9')">popcorn</button>
    <button onclick="run('b10')">comet</button>
</div>

<script>
const API_KEY = "misuse-prevent";

function run(action) {
    fetch(`/action.php?action=${action}&key=${API_KEY}`)
        .then(r => r.json())
        .then(j => console.log(j))
        .catch(err => alert("Error"));
}
</script>

</body>
</html>

CODE for Wled API

<?php

$public_api_key = "misuse-prevent";
if (!isset($_GET['key']) || $_GET['key'] !== $public_api_key) {
    http_response_code(401);
    die("Unauthorized");
}

$action = $_GET['action'] ?? null;

// Map 10 buttons → WLED preset numbers
$allowed_actions = [
    "b1"  => 19,
    "b2"  => 22,
    "b3"  => 23,
    "b4"  => 20,
    "b5"  => 21,
    "b6"  => 3,
    "b7"  => 8,
    "b8"  => 2,
    "b9"  => 4,
    "b10" => 14
];

if (!$action || !isset($allowed_actions[$action])) {
    http_response_code(400);
    die("Invalid action");
}

$preset = $allowed_actions[$action];

// ---- WLED IP address ----
$wled_ip = "http://WLEDDEVICEIP";   // <-- CHANGE THIS

// API endpoint
$url = $wled_ip . "/win&PL=" . $preset;

// Call WLED directly
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);

$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);

header("Content-Type: application/json");

if ($error) {
    echo json_encode(["ok" => false, "error" => $error]);
} else {
    echo json_encode(["ok" => true, "preset" => $preset]);
}

An idea I had to detect and count pages

One of my old ideas, never made or tested.
I saw a post on Reddit with this question, I decided to post a little drawing using my idea.

Center of below picture shows pages (the lines), with coppertape going front to back and connect to following page

Inductive copper tape

Taking resistors of the same value, you’ll get a logarithmic voltage divider.
If you want the values evenly spaced, to make sure you are not misreading the value you have to make the resistors more like:
10k,6k,3k3,2k5,2k,1k68,1k5

New afvalwijzer using Home Assistant

New version of :

New schematic using ESPHOME and has reset button (pressing the lid).
(Resets the LED when you’ve put the trash at the street curb.)

Above, a simplified version. I’m using 4 ws2812 leds now.

ESPHOME code:

esphome:
  name: afvalwemos
  friendly_name: AfvalWemos
  on_boot:
    priority: 800
    then:
    - delay: 1s
    - light.turn_off: main_leds

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "bT76oR8vOxxxxxxxxxxxxxxxxxxxxxxxxQbyjY6M="

ota:
  - platform: esphome
    password: "c1dbxxxxxxxxxxxxxxxxxxxxxxxxxx36e75"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Afvalwemos Fallback Hotspot"
    password: "vVxxxxxxxxxxxxxxaw"

captive_portal:

# LED strip definition
light:
  - platform: neopixelbus
    type: RGB
    variant: WS2812
    pin: D5
    num_leds: 4
    name: "All LEDs"
    id: main_leds
    restore_mode: ALWAYS_OFF   # ensures all LEDs start off


  # Individual LED partitions
  - platform: partition
    name: "LED 1"
    segments:
      - id: main_leds
        from: 0
        to: 0

  - platform: partition
    name: "LED 2"
    segments:
      - id: main_leds
        from: 1
        to: 1

  - platform: partition
    name: "LED 3"
    segments:
      - id: main_leds
        from: 2
        to: 2

  - platform: partition
    name: "LED 4"
    segments:
      - id: main_leds
        from: 3
        to: 3


# Physical button on D6 to turn off all LEDs
binary_sensor:
  - platform: gpio
    pin:
      number: D6
      mode: INPUT_PULLUP
      inverted: True
    name: "All Off Button"
    on_press:
      - logger.log: "Button pressed — turning all LEDs OFF"
      - light.turn_off: main_leds

Home Assistant automation:

alias: Afvalwijzer Plastic
description: Afvalwijzer leds
triggers:
  - at: "18:00:00"
    trigger: time
conditions:
  - condition: template
    value_template: >
      {% set raw = states('sensor.gad_pmd') %} {% if raw not in ['unknown',
      'unavailable', 'none', ''] %}
        {% set clean = raw.replace('Tomorrow, ', '').replace('Today, ', '').strip() %}
        {% set parts = clean.split(', ') %}
        {% set date_part = parts[-1] if parts|length > 1 else clean %}
        {% set pmd_date = strptime(date_part, '%d-%m-%Y').date() %}
        {% set tomorrow = (now().date() + timedelta(days=1)) %}
        {{ pmd_date == tomorrow }}
      {% else %}
        false
      {% endif %}
actions:
  - action: light.turn_on
    target:
      entity_id: light.afvalwemos_led_3
    data:
      rgb_color:
        - 236
        - 199
        - 14
mode: single

Easy cheap touch light

Remember those expensive touch lights you can buy?

This is a less than 5 euro version.

Warning : Some tricks I used

  • Using D5 as GND (I didn’t want to splice GND Wire.)
  • Using PWM for dimming
  • Using 5V led, use resistor if using a generic LED (220ohm)

TTP223 sensors are only a few cents!
And react even without touching (< 5mm)
So, you can build this in a case or behind fabric!

NOTE: If you are using an ESP32 you can configure a pin as touch!!!
So no TTP223 needed.
But ESP32 are more expensive as Wemos mini.

Code:

#define TOUCH_PIN D2 // My video has D7
#define LED_PIN   D6
#define FAKE_GND D5

// Brightness steps (0 = off, 255 = full bright)
int brightnessLevels[] = {0, 25, 125, 255};
int currentLevel = 0;
bool lastTouchState = LOW;

void setup() {
  
  pinMode(TOUCH_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(FAKE_GND, OUTPUT);

  digitalWrite(FAKE_GND, LOW);  
  analogWrite(LED_PIN, brightnessLevels[currentLevel]);  // start OFF
}

void loop() {
  bool touchState = digitalRead(TOUCH_PIN);

    if (touchState == HIGH && lastTouchState == LOW) {
      // Advance brightness step
      currentLevel = (currentLevel + 1) % 4;  // 0-3 steps
      int pwmValue = brightnessLevels[currentLevel];
      analogWrite(LED_PIN, pwmValue);
    }

  lastTouchState = touchState;
}

Dim levels less obvious on recording, but you can change the levels in the code!

Three display C64 audio monitor

While I made this for my Commodore C64, it is applicable for many things.

It started with some cheap displays from Ali, and some leftover Wemos D1 from my Pressure Lab project.

I Started measuring the audio output from sound devices and from my C64.
I soon discovered that I needed some way to get the offset and amplification correct for the analogue input of a Wemos. (0-3v3)

So a little op-amp circuit was born, but not without some struggles.
I forgot many things about amplifiers. It was one of the first school books I got rid of. (Sorry mister Rafaela)

After searching the internet and posting a question on Reddit I ended up with the following.

R1 and R2 are 100M. The potentiometer P1 allows me to set the offset.
R3 is 1M
C1 is 100nF to decouple the audio signal from the RCA.

R4 is 47K and C2 is 330nF (thanks tycho205)
Cimportant=1/(2πfR2)
where f is the lowest frequency of interest. In this case Cimportant should be about 330nF

LM324 is a quad amplifier, leftover from another project.
Note, the SINGLE RAIL power.

P2 potentiometer is 2M (leftover) and gives me a variable amplifying opportunity.


A = Audio input

B = Setting the offset with P1

C = Setting the amplification

Below input signal (note negative values) above amplified signal with offset!

The displays are 3 Wemos controllers with a cheap I2C display.
These are just fast enough to do FFT.

Analogue in is the output from the OP-amp offsetter ..

CODE

Needs cleaning up, and a better stabilizing routine.

ESPHome HA notification helper

A while ago I made a little notify thingy using an LCD display, LED, button and a buzzer.

Some friends of mine made one also, and today I was talking to a new guy.
I could not find this project on my site .. again .. so I’ll post it now.

Some things it does right now

  • Front door opens
  • Door bell rings (because my lab is in the garden)
  • Girlfriend is 10Km away, so let’s start cooking
  • Garage door opens (friend of mine uses this to know when kids arrive)
  • More .. because it’s very easy to customize in Home Assistant

Doorbell pressed: Led starts blinking, backlight LCD enabled, text displayed on LCD, Buzzer sounds (or plays a RTTTL ringtone)
LCD backlight on and buzzer beep until acknowledge button pressed.

Heating for brewing: temperature on display, led on when temperature reached. Press acknowledge to start timer.

….. etc

CODE:

esphome:
  name: lcdalarm
  friendly_name: LCDAlarm
  on_boot:
    priority: -100.0
    then:
      - lambda: 'id(lcddisplay).no_backlight();'

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "OOpDzMu0VvfWAnJXXXXXXXXXXXXXXXXXXXXXXXXKNDa74OJ1Cc="

ota:
   - platform: esphome
     password: "627992017XXXXXXXXXXXXXXX738c2a3"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lcdalarm Fallback Hotspot"
    password: "z9dZXXXXXXXX7a"

captive_portal:
web_server:
  port: 80

i2c:
  sda: D2
  scl: D1
  scan: true
  frequency: 400kHz

light:
  - platform: binary
    name: "Status LED"
    output: light_output
    icon: "mdi:led-on"
    id: led


binary_sensor:
  - platform: gpio
    pin:
      inverted: true
      number: D5
      mode:
        input: true
        pullup: true
    name: "LCD Button"

text_sensor:
  # Create text input helper in homeassistant and enter id below
  - platform: homeassistant
    entity_id: input_text.lcd_display_text
    id: lcd_display_text

  - platform: wifi_info
    ip_address:
      id: ip_address
      name: IP address
    mac_address:
      id: mac_address
      name: Mac address
    ssid:
      id: connected_ssid
      name: Network SSID
    bssid:
      id: connected_
      name: Network Mac

sensor:
  - platform: wifi_signal
    id: wifisignal
    name: wifi-signal
    update_interval: 300s

globals:
  - id: backlight_on
    type: bool
    initial_value: 'false'
  - id: flash_beep_on
    type: bool
    initial_value: 'false'

switch:
  - platform: template
    name: "LCD Backlight"
    id: backlight
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - globals.set:
          id: backlight_on
          value: 'true'
      - globals.set:
          id: flash_beep_on
          value: 'false'
      - lambda: |-
          id(lcddisplay).backlight();
      - delay: 5s
    turn_off_action:
      - globals.set:
          id: backlight_on
          value: 'false'
      - lambda: |-
            id(lcddisplay).no_backlight();
    lambda: |-
      return id(backlight_on);

  - platform: template
    name: "Flash and Beep"
    id: flash_beep
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - globals.set:
          id: flash_beep_on
          value: 'true'
      - globals.set:
          id: backlight_on
          value: 'false'
      - lambda: |-
          id(lcddisplay).backlight();
      - lambda: |-
          id(buzzer).turn_on();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).no_backlight();
      - lambda: |-
          id(buzzer).turn_off();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).backlight();
      - lambda: |-
          id(buzzer).turn_on();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).no_backlight();
      - lambda: |-
          id(buzzer).turn_off();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).backlight();
      - lambda: |-
          id(buzzer).turn_on();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).no_backlight();
      - lambda: |-
          id(buzzer).turn_off();
      - delay: 0.75s
      - lambda: |-
          id(lcddisplay).backlight();
    turn_off_action:
      - globals.set:
          id: flash_beep_on
          value: 'false'
      - lambda: |-
            id(lcddisplay).no_backlight();
      - lambda: |-
          id(buzzer).turn_off();
    lambda: |-
      return id(flash_beep_on);


  - platform: restart
    name: "Restart ESPhome"

output:
  - platform: gpio
    pin: D3
    id: buzzer
  - platform: gpio
    pin: D6
    id: light_output

display:
  - platform: lcd_pcf8574
    id: lcddisplay
    dimensions: 16x2
    address: 0x27
    lambda: |-
      if(id(wifisignal).has_state()) {
        if (id(lcd_display_text).state != "") {
          it.print(0, 0, id(lcd_display_text).state.c_str());
        }
      } else {
        it.print("    ESPhome        booting...   ");
      }

CODE: RTTTL (Use passive buzzer!!!!)

esphome:
  name: lablcd
  friendly_name: LabLCD

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "ga17mNCtxdiXXXXXXXXXXXXXXXXXXXXX70a5W0VPZR51Q="
  actions:
    - action: rtttl_play
      variables:
        song_str: string
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'

ota:
  - platform: esphome
    password: "84013b9XXXXXXXXXXXXXXX5401039f7c"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lablcd Fallback Hotspot"
    password: "nnzXXXXXXXXXXXXXXXXXXXCb"

rtttl:
  output: rtttl_out
  on_finished_playback:
    - logger.log: 'Song ended!'


captive_portal:

i2c:
  sda: D2
  scl: D1
  scan: true
  frequency: 400kHz

light:
  - platform: status_led
    name: "Status LED"
    icon: "mdi:led-on"
    pin:
      number: D5
      inverted: true

binary_sensor:
  - platform: gpio
    name: "Push Button"
    pin: 
      number: D4
      inverted: true
      mode: 
        input: true
        pullup: true
    on_press:
      - homeassistant.service:
          service: homeassistant.toggle
          data:
            entity_id: input_boolean.esphome_notification_lcdlab_push_button

text_sensor:
  # Create text input helper in homeassistant and enter id below
  - platform: homeassistant
    entity_id: input_text.esphome_notification_lcdlcd_display_text
    id: lcd_display_text

  - platform: wifi_info
    ip_address:
      id: ip_address
      name: IP address
    mac_address:
      id: mac_address
      name: Mac address
    ssid:
      id: connected_ssid
      name: Network SSID
    bssid:
      id: connected_
      name: Network Mac

sensor:
  - platform: wifi_signal
    id: wifisignal
    name: wifi-signal
    update_interval: 300s

globals:
  - id: backlight_on
    type: bool
    initial_value: 'false'
  - id: flash_beep_on
    type: bool
    initial_value: 'false'

switch:
  - platform: template
    name: "LCD Backlight Lab"
    id: backlight
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - globals.set:
          id: backlight_on
          value: 'true'
      - globals.set:
          id: flash_beep_on
          value: 'false'
      - lambda: |-
          id(lcddisplay).backlight();
    turn_off_action:
      - globals.set:
          id: backlight_on
          value: 'false'
      - lambda: |-
            id(lcddisplay).no_backlight();
    lambda: |-
      return id(backlight_on);

 
  - platform: restart
    name: "Restart ESPhome"

output:
  - platform: esp8266_pwm
    pin: D8
    id: rtttl_out

display:
  - platform: lcd_pcf8574
    id: lcddisplay
    dimensions: 16x2
    address: 0x27
    lambda: |-
      if(id(wifisignal).has_state()) {
        if (id(lcd_display_text).state != "") {
          it.print(0, 0, id(lcd_display_text).state.c_str());
        }
      } else {
        it.print("    ESPhome        booting...   ");
      }


Weather display using LilyGO T5-4.7 inch S3 E-paper E-ink ESP32-S3

I was planning to make a RSS reader using this display, but I came across a weather display project I wanted to check out.
(So I probably end up buying another one)

There are many questions and issues around this project using the S3.

So here is my solution.

Install vscode

Goto plugins and install platformio

git clone https://github.com/Xinyuan-LilyGO/LilyGo-EPD-4-7-OWM-Weather-Display.git

Warning this is NOT the branch you want to use

git checkout web

(git pull)

open directory in code

open platformio.ini and change line 13
default_envs = T5_4_7Inc_Plus_V2
(If needed add upload_port = /dev/tty**** at the end)

Change INO file lines 144-146.
Comment serial out, else update won’t work using regular power or battery.



When saving this platformio.ini file, some downloading and installing should be popping up.
When issues occur about libraries see below.

Fill out
data>config.json
and owm_credentials.h to be sure.
(use owm_credentials information to fill config.json)

Next press the platformio icon

Fix for uploading:

Press and hold STR_IO0 button
Press REST button
Release STR_IO0 button

Libraries:

Press platformio icon, libaries and install ArduinoJson, Button2 and LilyGo-EPD47 (select your project while doing so!)

Note: Per default once per hour update, change if you want to.
Line 70 in the INO file

Build/Upload errors? .. Press clean to recompile using a clean state !