Tag Archives: machinelearning

Arduino Tiny Machine Learning Kit

A while ago I bought a little machine learning kit.

I’ve been reading at listening to ML podcasts and websites.

One on Spotify I liked was:

Also, the following Coursera was interesting
https://www.coursera.org/learn/machine-learning

I’ve been testing using Python on my Laptop.
(see other posts)

And a camera with esp32 using face detection.

See here multiple posts about these experiments.

https://www.henriaanstoot.nl/tag/machinelearning/

Today the first experiments using this kit.

  • Arduino Nano 33 BLE Sense board
  • OV7675 Camera
  • Arduino Tiny Machine Learning Shield
  • USB A to Micro USB Cable
  • 9 axis inertial sensor: what makes this board ideal for wearable devices
  • humidity, and temperature sensor: to get highly accurate measurements of the environmental conditions
  • barometric sensor: you could make a simple weather station
  • microphone: to capture and analyse sound in real time
  • gesture, proximity, light color and light intensity sensor : estimate the room’s luminosity, but also whether someone is moving close to the board
  • Microcontroller nRF52840
  • Operating Voltage 3.3V
  • Input Voltage (limit) 21V
  • DC Current per I/O Pin 15 mA
  • Clock Speed 64MHz
  • CPU Flash Memory 1MB (nRF52840)
  • SRAM 256KB (nRF52840)
  • EEPROM none
  • Digital Input / Output Pins 14
  • PWM Pins all digital pins
  • UART 1
  • SPI 1
  • I2C 1
  • Analog Input Pins 8 (ADC 12 bit 200 ksamples)
  • Analog Output Pins Only through PWM (no DAC)
  • External Interrupts all digital pins
  • LED_BUILTIN 13
  • USB Native in the nRF52840 Processor
  • IMU LSM9DS1 (datasheet)
Gesture test ( yes on a windows surface tablet, but Vincent and I installed linux on it!)

I just started and will update this page, with other experiments.

Note: displaying Arduino output without installing the IDE

stty -F /dev/ttyACM0 raw 9600
cat /dev/ttyACM0
................................
................................
................................
................................
................................
................................
................................
................................
................................
................####............
...............##..#............
..............##...##...........
..............#.....#...........
..............###...#...........
..............##.....#..........
..............##.....#..........
...............#....##..........
...............######...........
................................
................................
................................
................................

I asked ChatGPT to write code for a Crack the Code game.

The Game

elcome to Crack the Code!
The code has 4 digits. Each digit is between 0 and 9.
You have 10 tries to guess the code.
After each guess, you will be told how many digits you got correct and how many were misplaced.
Good luck!
Enter your guess: 1234
Guess 1: 1234 - 0 correct, 0 misplaced
Enter your guess: 5678
Guess 2: 5678 - 2 correct, 1 misplaced
Enter your guess: 5689
Guess 3: 5689 - 1 correct, 2 misplaced
Enter your guess: 9688 
Guess 4: 9688 - 1 correct, 2 misplaced
....
Sorry, you did not crack the code. The code was 5568.

Generated python code

import random

def generate_code():
    code = ""
    for i in range(4):
        code += str(random.randint(0, 9))
    return code

def check_guess(code, guess):
    correct_digits = 0
    misplaced_digits = 0
    for i in range(4):
        if guess[i] == code[i]:
            correct_digits += 1
        elif guess[i] in code:
            misplaced_digits += 1
    return (correct_digits, misplaced_digits)

def play_game():
    print("Welcome to Crack the Code!")
    print("The code has 4 digits. Each digit is between 0 and 9.")
    print("You have 10 tries to guess the code.")
    print("After each guess, you will be told how many digits you got correct and how many were misplaced.")
    print("Good luck!")
    code = generate_code()
    num_guesses = 0
    while num_guesses < 10:
        guess = input("Enter your guess: ")
        if len(guess) != 4 or not guess.isdigit():
            print("Invalid input. Please enter a 4-digit number.")
            continue
        num_guesses += 1
        correct, misplaced = check_guess(code, guess)
        print(f"Guess {num_guesses}: {guess} - {correct} correct, {misplaced} misplaced")
        if correct == 4:
            print("Congratulations! You cracked the code!")
            return
    print(f"Sorry, you did not crack the code. The code was {code}.")

play_game()

After this i let the AI made some changes, which kinda worked.
Scary nevertheless

ChatGPT IA generated chats/texts

ChatGPT is a large language model chatbot developed by OpenAI based on GPT-3.5. It has a remarkable ability to interact in conversational dialogue form and provide responses that can appear surprisingly human.

So i asked stuff like:

Thats a pretty good joke about a 6502 CPU. I tought it would be a hard question

The question : “what are women looking for in a man”
Gave a lot of lines :
No generic answer
Lines with Respect, Humor, Kindness, Confidence

Then it stopped with:

Typical .. even AI is baffled by women.

Below a chat session from a great friend of mine Tyrone

Tyrone: Ok could you write me a commodore c64 assembly routine to make the screen white?

Certainly! Here is a simple assembly routine that will clear the screen and set all of the pixels to white on a Commodore 64:

Copy code

ldx #$00
ldy #$00 
clear_screen: 
sta $d800,x 
inx 
cpx #$40 
bne clear_screen 

This code will loop through all of the screen memory locations and set the value at each location to $00, which will turn all of the pixels white. The inx and iny instructions are used to increment the X and Y registers, which are used to keep track of the current screen position. The cpy instruction is used to compare the value in the Y register to $20, and the bne instruction is used to branch back to the clear_screen label if the values are not equal, causing the loop to continue until the entire screen has been cleared.

I hope this helps! Let me know if you have any questions.



Tyrone: Well a big code but i wanted to make the screen the color white not with a character space .. this is also white but it's more logical that the color is named then the white space this code should be three lines of could can you do this?

Certainly! Here is a simple assembly routine that will clear the screen and set all of the pixels to white on a Commodore 64:

Copy code

ldx #$00
ldy #$00 
clear_screen: 
sta $d800,x 
inx 
cpx #$40 
bne clear_screen 

This code will loop through all of the screen memory locations and set the value at each location to $ff, which will turn all of the pixels white. The inx instruction is used to increment the X register, which is used to keep track of the current screen position. The cpx instruction is used to compare the value in the X register to $40, and the bne instruction is used to branch back to the clear_screen label if the values are not equal, causing the loop to continue until the entire screen has been cleared.

I hope this helps! Let me know if you have any questions.



Tyrone: This is wrong here is a hint use registers d020 and d021 for screen and border color 

I apologize for the mistake in my previous response. Here is the corrected code that will set the screen and border colors to white on a Commodore 64:

Copy code

lda #$0f
sta $d020
sta $d021 

This code will store the value $0f in the memory locations at $d020 and $d021, which are the registers that control the screen and border colors on the Commodore 64. The value $0f corresponds to the color white.

I hope this helps! Let me know if you have any questions.



Thank you ai 

HuskyLens Test

I’ve bought a Husky lens recently. It was very cheap for what you get.
(50 Euro’s)
The first tests are promising.

Nice little, but powerful gadget.
https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336

Cables to connect Rpi or Arduino, mounts, Huskylens and Protectioncover (sold separately)
  • face recognition
  • object tracking
  • object recognition
  • line tracking
  • color recognition
  • tag recognition
  • object classification

Communication can be done via I2C and Uart.
Uses a sdcard to store learning data.
Has white leds for object lighting.

Build-in objects which are recognised out of the box. (Others can be learned by the device)

aeroplane, bicycle, bird, boat, bottle, bus, car, cat, chair, cow, dining-table, dog, horse, motorbike, person, potted plant, sheep, sofa, train, TV

Photo manager addition using ML!

A few years ago i wrote a photo manager .. again .. ( see post about my first previous photo manager )
It is a web gui to find photos in my huge photo archive.
I manually added 190k tags to 120k photos in 20+ years.

I thought wouldn’t it be nice if i can generate additional metadata using Machine Learning. A few years ago i did some testing and followed a podcast and free course about machine learning.

So today i started to implement a addition to my gui. Machine recognition tags!

It already kinda works.

Things to do :

  • Make it a background job, my fileserver doesn’t run Tensorflow on a GPU, so it is slooow
  • Embed in existing GUI and stats
  • Design a editor to remove wrong tags

Below a part of ML images

Command to get a thumbnail sheet with only directory names:

montage -verbose -units PixelsPerInch -density 300 -tile 7x6 -label "%d" -font Arial -pointsize 6 -background "#FFFFFF" -fill "black" -define jpeg:size=253x154 -geometry 253x154+2+2 -auto-orient */*.JPG -title "ML Thumbs" thumbsheet.jpg

Maybe, i can use debug output like below.

['lakeside, lakeshore (score = 0.47934)', 'seashore, coast, seacoast, sea-coast (score = 0.11385)', 'sandbar, sand bar (score = 0.08822)', 'breakwater, groin, groyne, mole, bulwark, seawall, jetty (score = 0.06281)', 'valley, vale (score = 0.01790)', '']

Machine Learning

Today i started with Coursera’s Machine Learning course.

My friend aloha is doing interesting stuff with ML, but recently i’ve been interested in a work related ML project.

Besides this course i’m following a spotify Podcast called “Machine Learning Guide”, i listen to this on my way to work and back.

I’ve been playing with a lot of code after that. Luckily there are many ebooks about this subject.

  • One of the first was a python program wich used the length of a person and shoesize to determine if it was a man or a woman
  • Another fun one was a program with could determine if a wine was red or white only based by a description
  • There are several graphic based programs i’ve tried. Deepfake, 8mm film enhancers, image classifiers, openface
  • For sound there was voice cloner to test. And audio to text (which i used to transcribe old cassette tapes and VHS tapes.

UPDATE: In 2022 i used what i have learned to enrich my photo metadata.
https://www.henriaanstoot.nl/2022/05/29/photo-manager-addition-using-ml/