Everything AI – TOC

This blog has plenty of posts about AI, some are about AI tools, others are about installing AI locally, so this post is where I am putting all the AI stuff I have ever blogged about in one place !

The section Local AI is about creating your own AI server using freely available sources, the API section lists all the services that provide an API that can be used remotely (Most can not be installed locally anyway), and the Online Services is where you can get things done via AI online (That can be used using your browser, whether they provide an API or not, and whether they can be installed locally or not is a different story)

Continue reading “Everything AI – TOC”

Detecting Light and movement with Arduino

When it comes to detecting light and movement with microcontrollers, one has quite a bit of options, after explaining each one, I will compare them for you at the bottom of this pots

LDR Light Dependent Resistor

This is the simplest one, and it only costs a few cents

Phototransistor

A photo transistor is in my oppinion a great tool to use with microcontrollers, very fast response time (Slightly slower than a photodiode), and can be used with the digital pins, the reason is that it works exactly like a transistor, but instead of enabling the current by providing voltage to the base, the current is provided from light !

So, if you were to connect the Emitter to ground, and the Collector to the digital pin, they would get connected when light is detected, that is it

Photo interrupter

A photo interrupter detects the presence, absence, or movement of an object by sensing when a light beam between an emitter and a receiver is blocked.

This is basically something you would find in your inkjet printer ! or in a factory (Conveyor belt), or most commonly, on en elevator (Door opens when an object is in the way)

The transmitter and receiver work together either side by side or opposing each other, when they are side to side, a mirror reflects the light onto the receiver

If you are trying to detect a red light or a light of the wavelength close to that of the interrupter, odds are that you can use the receiver on its own without the LED (Transmitter), simply do not power it up !

photodiode

PIR (Movement) sensors

PIR Sensors such as the HC-SR501 can detect movement, but they requier more than 1 component, the sensor itself, the plastic cover for the sensor (Pir Lens Cover creates a FRESNEL LENS), and an IC that amplifies the signal and analyzes it !

Project cloud electric meter

The cloud electric meter is a project consisting of a 3 parts

1- A microcontroller and a current transformer (As of now, I am using the SCT-013)
2- A server to collect the data from the microcontrollers
3- A mobile phone app to display the data

The second and third (Server and application) are beyond the scope of what we are doing here, here, I will be examining all the options for a microcontroller and current transformer, With and without the cloud part.

1- The no cloud setup

The first example we will be using is the current transformer (SCT-013) with a nodeMCU ESP8266 that shows data about the current on a screen, this is the simplest setup, and is for people who are here to figure out how to connect their transformer, To do this, you will need a 16 x 2 screen, and an LCD I2C Interface Adapter.

1- Connecting the LCD to an ESP8266 (Tutorials for arduino and ESP32 are all over the internet)
2- Connecting the Current Transformer
3- The software

Connecting the LCD through I2C board

Similar tutorials are all over the internet, this one is here so that I can have a compatible setup between all the devices in the IoT project, the way those 2 boards (The LCD and I2C board) are very popular, and are connected in more or less the same way in all tutorials, but since you are here, might as well make it as simple and complete as possible.

LCD displays require a lot of connected digital pins to work, but this is easily solved with a very cheap LCD-I2C board that connects to my 1602 (16×2) LCD display (Or 2004 20 x 4 LCD modules) with its 16 pins on one end, and connects to your microcontroller (ESP8266, ESP32, Or Arduino, etc…) via 2 I2C pins (SDA/SCL)

The LCD I2C Interface Adapter board is based of a popular 8-bit, remote I/O expander for the I2C bus namely the pcf8574T / ABX919… A remote expander can function as an LCD driver, but it also works for many other purposes, but that is beyond the scope of the simple instructions presented here, here we are interested in driving an LCD screen

The I2C address of can be set by setting the available solder points for addresses in the range of 0x20 – 0x27.

One thing you may want to know is that the jumper at one side of the nameless I2C board is for the LED backlight ! it can be fed through a separate power supply (Remember to combine the ground pins).

In this example, I am using an ESP8266 on a NodeMCU board.

Power

The ESP8266 and the ESP32 are 5V tolerant on the data pins (Proof here), So, because the linear voltage regulator on the ESP8266 NodeMCU board does not have a heatsink, we will be connecting the screen directly to the 5V power source, why burdain the small regulator with the screen !

So, on my I2C board, I connect the GND and VCC to the external power supply (Don’t power the board via USB and connect to the VIN, this is not how it works, VIN is for voltage input, not for output)

So, on my board, the geekcreit doit esp12f devkit v3 (In arduino studio, it is compatible with NodeMCU 1.0 – ESP-12E Module)

The data pins are connected as follows
SDA – D2 – GPIO-04
SCL – D1 – SPIO-05

You are done with this, now, how to print to the screen !

the first step is to find the I2C address, my board provides addresses in the range of 0x20 – 0x27. without soldering anything, the address is probably 0x20, but if not, we can figure it out.

To figure out the address of your LCD display, use the following code

#include <Wire.h>
void setup() {
Wire.begin(4, 5); // SDA, SCL
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices = 0;
Serial.println("Scanning...");
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
}
if (nDevices == 0) Serial.println("No I2C devices found\n");
else Serial.println("done\n");
delay(5000);
}

Roof screed job

The following all applies to a flat root cement slab that has slight ponding

You will need to apply the cement in 2 phases, 1- the slurry 2- the concrete mix

When i say by volume, what is meant is that 1 cup of cement gets x cups of aggregate, no weight involved

1- The bonding slurry

  • As thin as you can provided it is “Continuous” and “Worked into the surface”
  • thicker is bad not good
  • The concrete layer needs to be added IMMEDIATELY after applying the slurry, within lets say 10 minutes in warm weather
  • consistency should be thicker than emulsion paint

2- The concrete mix

The bare minimum height, for something that is not a foot path, and is not expected to hold any weight is 2.5CM ! cement cant be less than that, it will break and create problems later on !

Consistency = Thick enough to hold its shape

3- The proportions

1- Cement + SBR slurry

Equal amounts of all 3 by volume

1 SBR
1 Watter
1 Cement

The cement mix by volume…

1 cement
3 sand
1 stone dust
2–3 teaspoons per cup of cement, (5–8% of cement volume)

Things to watch out for

Substrate condition

  • Slab is sound (no loose flakes)
  • No dust when rubbed by hand
  • No oil, paint, curing compound, or algae
  • Cracks addressed (at least cleaned / chased)

Moisture state (SSD)

  • Surface is damp but not shiny
  • No standing water in depressions
  • Water does not bead up

Bonding slurry

  • Freshly mixed
  • Thin, paint-like
  • Fully covers area
  • Worked into pores
  • No puddles or ridges

Slurry Finger test

  • Sticky
  • Leaves residue on finger
  • Still dark

Screed mix consistency

  • Semi-dry
  • Holds shape when squeezed
  • No water sheen
  • Does not crumble

M271 thermostat

The lowdown: Before you go and get a thermostat, there is a part that is very often broken along with your broken thermostat, it is the casing (the plastic thing that holds the thermostat in place).

Again, this is my W211, and the process itself is very simple as you will see below, loosen the cold air duct in front of the engine to make room for the screws to be removed, remove a couple of screws, install, then put them back, that is all there is to it.

When i came to change my thermostat, i unscrewed the 2 screws that hold the plastic casing in place at the front of the engine, and before you know it, it dropped, i thought there would be pulling, but no, the spacer that holds the thermostat in place, and is part of the casing/pipe was broken from the word go

Before you try to pull the spacer (Plastic cylinder) from inside, you need to remove the o ring which is likely trapped between the spacer and the engine (Near the surface), once the o ring is out, the plastic cylinder will come right out.

Once you do, your thermostat might be busted, but in my case, the rubber seal was not sitting right, probably due to the broken spacer, and created a space between the thermostat and the spacer, hence the problem

Best compression algorithim for my sql file backups

SQL files are highly repetitive, I have been using bzip2 (pbzip2) for over 20 years, but is it really a sane choice in 2025 ?

We already know about gzip (even older than bzip2), it is super fast, but the compression is not great, so the options in question are “zstd” and “xz (LZMA2)” and “brotli”

zstd -19 -T12 myfile.bin (-19 for maximum compression (5 for low) T12 for 12 CPUs), original file is kept by default
unzstd myfile.bin.zst

xz -k -T0 -9 myfile.bin (Auto threads, high compression, -k for keeping original file)

Compressing a 200GB SQL file on an intel i7-4930K using 8/12 threads

zstd at compression level 19 (MAX) = 20.63% ( 40 GB)
xz at compression level 9 (Max) = 38GB

So, xz at max compression took much longer to finish, but resulted in a 2GBs smaller file….

zstd at compression level 15 seems to be the sweet spot, I will redo the experiments soon and bring in more precise results on what compression and how much time.

Fix Debian hum/buzz in speaker after a few seconds

On my system, whenever no sound comes out of the speakers for a bit, the speaker starts humming, the same sound that comes out of it when my PC is switched off

In my case, I am using Debian 13 with gnome

What is that sound

That sound is basically the speaker picking up the power line frequencies, and because it is an amplified speaker, it amplifies it, and makes it audible !

Why does it come out from my PC after some time

There are two audio drivers for linux, PulseAudio/ALSA and PipeWire, both supporting power saving mode, when no audio comes out of the speaker for some time, power saving mode kicks in, the sound chip (FKA the sound card) is disabled, so you get that sound exactly as if your computer was switched off !

How do i fix it ?

Disable power saving mode is the simplest method !

To disable it for this session, which works instantly, run the command

echo "0" | sudo tee /sys/module/snd_hda_intel/parameters/power_save

To make that change permanent (Later reboots)

sudo tee /etc/modprobe.d/snd-hda-intel.conf <<< "options snd_hda_intel power_save=0"

Google anti gravity

The Agentic AI IDE !

Here are a couple official videos

Now, to install google antigravity to debian 12/13

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://us-central1-apt.pkg.dev/doc/repo-signing-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/antigravity-repo-key.gpg
echo "deb [signed-by=/etc/apt/keyrings/antigravity-repo-key.gpg] https://us-central1-apt.pkg.dev/projects/antigravity-auto-updater-dev/ antigravity-debian main" | sudo tee /etc/apt/sources.list.d/antigravity.list > /dev/null
sudo apt update
sudo apt install antigravity

Creating ISO with large files

xorriso -as mkisofs \
-o /hds/1tb/tmp/mystuff.iso \
-iso-level 3 \
-full-iso9660-filenames \
-volid MyStuff \
/hds/12tb/mystuff

As simple as that, now you can just mount the ISO image and files larger than 4GB will just work, but it seems that filenames are correct in Linux, but in ALL CAPS in windows

Should start experimenting with

xorriso -as mkisofs \
-o /hds/1tb/tmp/mystuff.iso \
-iso-level 3 \
-full-iso9660-filenames \
-J \
-R \
-volid MyStuff \
/hds/12tb/mystuff

I am pasting this here because all the other methods (Mounting and writing to, or using the traditional tools seem to fail for some reason)

Laravel Socialite with socialite-ui

In a previous post, I explained how to install the third party (socialite-ui) on your website, which itself was written to help people with the “Gradually migrating to Laravel” post, but it seems it is not enough, so here is how to fully get socialite working, much of the work is outside your website though, and i won’t be covering that, all you need to do is ask google, for example, how do i enable social logins with google or facebook etc…

The redirect problem

After registering or logging in, your user will be redirected to an absolutely empty “/dashboard“, which is already handled by myrouter.php

Email verification

Before doing anything, let us check that email is working using your SMTP credentials

Create the following route for testing

use Illuminate\Support\Facades\Mail;

Route::get('/test-email', function () {
Mail::raw('This is a test email.', function ($message) {
$message->to('test@example.com')
->subject('Test Email');
});
return 'Email sent!';
});

socialite-ui does not come with email verification (during registration) by default, you will need to enable it, this is simply by following the instructions here

now edit the file (/config/socialite-ui.php) to enable the social logins you want enabled, and alter the other settings as per the page her (https://github.com/Laravel-Uis/socialite-ui)

php artisan config:clear
php artisan cache:clear