Tag Archives: arduino

Connect the wires puzzle

As part of my internet based escape room.

I took the idea from the Keep-talking-and-nobody-explodes game.

When starting up, is gets the configuration from a Mqtt Topic.
So i can create a different setup over the internet.

The result is also send back via MQTT.

(example play, all players are on different locations)

  • Player 1 figures out the wires.
  • Player 2 connects the wires.
  • Player 3 sees the result (correct or not) and next puzzle opens up for Player 3

I used a wire with a line. Multiple colors for jacks and sockets.
It’s also possible to connect a jack to a jack.
Loads of possibilities.

Todo:

Wifi and Mqtt part
Debounce software or hardware

Arduino Concertina

Lets try to make a Electronic Concertina

UPDATE:
https://www.henriaanstoot.nl/2023/01/10/arduino-concertina-poc/
https://www.henriaanstoot.nl/2023/01/17/arduino-concertina-poc-2/

First design

So we need some pushbuttons … at least 14 .. for the most simple tunes.
A sensor for push and pull.
A buzzer or better yet .. a jack for earphones.
Arduino with enough pins to connect a keyboard matrix.
When using a keyboard matrix only single keypresses are detected.
So we cant do chords!

Radar module RCWL-0516 with MQTT

RCWL-0516 module (radar)

Last year i was playing with this radar module also, but today i made a version with MQTT and a linux client.
(There is a project on the internet which uses a HC-SR04, and a arduino connected to the Laptop. This setup is more sensitive and no need for a usb thinghy.)

HC-SR04 module (ultrasound)

Last years version, using a micro transformer and a ESP-12

When using MQTT i can integrate this in HomeAssistant, Domoticz, NodeRed and more.
But i’ve written a python script which runs on my Laptop.
For example i can: Kill vlc, change to my work desktop, stop sound output and lock the screen. (everything you can script)

I wanted to have a “mobile” version of the sensor so i can place it anywhere. (Frontdoor, gardengate, candydrawer 🙂 )

These modules are very cheap, but do their job well!

I’ve used a Wroom ESP32 and a BattBorg together with the module, that’s it.

Simplified schematic (without the battborg)

I’m using PIN34 as an analog input.

Radar module pins:

  • CDS not used
  • VIN 5V power
  • OUT 0-3.3V signal (analog)
  • GND
  • 3v3 not used

Arduino sketch

#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>

const char* ssid = "MYSSID";
const char* password = "MYPASS";
const char* mqtt_server = "IP-MQTT-SERVER";
const char* mqtt_username = "";
const char* mqtt_password = "";
const char* clientID = "radar";

const int tiltPin = 34;
int tiltState = 0;    
int previousState = 0;   

WiFiClient espClient;

PubSubClient client(espClient);

String translateEncryptionType(wifi_auth_mode_t encryptionType) {
 
  switch (encryptionType) {
    case (WIFI_AUTH_OPEN):
      return "Open";
    case (WIFI_AUTH_WEP):
      return "WEP";
    case (WIFI_AUTH_WPA_PSK):
      return "WPA_PSK";
    case (WIFI_AUTH_WPA2_PSK):
      return "WPA2_PSK";
    case (WIFI_AUTH_WPA_WPA2_PSK):
      return "WPA_WPA2_PSK";
    case (WIFI_AUTH_WPA2_ENTERPRISE):
      return "WPA2_ENTERPRISE";
  }
}
 
void scanNetworks() {
   int numberOfNetworks = WiFi.scanNetworks();
   Serial.print("Number of networks found: ");
  Serial.println(numberOfNetworks);
   for (int i = 0; i < numberOfNetworks; i++) {
 
    Serial.print("Network name: ");
    Serial.println(WiFi.SSID(i));
 
    Serial.print("Signal strength: ");
    Serial.println(WiFi.RSSI(i));
 
    Serial.print("MAC address: ");
    Serial.println(WiFi.BSSIDstr(i));
 
    Serial.print("Encryption type: ");
    String encryptionTypeDescription = translateEncryptionType(WiFi.encryptionType(i));
    Serial.println(encryptionTypeDescription);
    Serial.println("-----------------------");
 
  }
}
 
void connectToNetwork() {
  WiFi.begin(ssid, password);
   while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Establishing connection to WiFi..");
  }
   Serial.println("Connected to network");
 }

void reconnect() {
  while (!client.connected()) {
    if (client.connect(clientID, mqtt_username, mqtt_password)) {
    } else {
      delay(2000);
    }
  }
}
void setup()
{
  {
    Serial.begin(115200);
    scanNetworks();
    connectToNetwork();
    Serial.println(WiFi.macAddress());
    Serial.println(WiFi.localIP());
    client.setServer(mqtt_server, 1883);
    pinMode(tiltPin, INPUT);
  }
}
void loop() {
  tiltState = analogRead(tiltPin);
    if (tiltState < 3048) {
      client.publish("radar/state", "0"); //
    } else {
      client.publish("radar/state", "1"); //
    }
     delay(100);
   {
    if (!client.connected()) {
      reconnect();
    }
    client.loop();
  }
}

Lockscreen!

Below shows the speed of detection, and sending though the network

Python script which does a lock-screen using XDOTOOL

from paho.mqtt import client as mqtt_client
import subprocess
import time

broker = 'MQTT-SERVER'
port = 1883
topic = "radar/state"
client_id = "radarclient"

def connect_mqtt() -> mqtt_client:
    def on_connect(client, userdata, flags, rc):
        if rc == 0:
            print("Connected to MQTT Broker!")
        else:
            print("Failed to connect, return code %d\n", rc)

    client = mqtt_client.Client(client_id)
    client.on_connect = on_connect
    client.connect(broker, port)
    return client

def subscribe(client: mqtt_client):
    def on_message(client, userdata, msg):
        state = msg.payload.decode()
        print (state)
        if state == "1":
            subprocess.Popen(["xdotool","key","Super_L+l"])
            time.sleep(30)


    client.subscribe(topic)
    client.on_message = on_message

def run():
    client = connect_mqtt()
    subscribe(client)
    client.loop_forever()

if __name__ == '__main__':
    run()

change
subprocess.Popen([“xdotool”,”key”,”Super_L+l”])
into
subprocess.Popen([“switchdesktop”])
to run a script named switchdesktop

#!/bin/bash
# This is the switchdesktop script, it goes to the next screen using winows-page-down combo
xdotool key "Super_L+Page_Down"

Todo:

3D print a case
Make a version which becomes a Access Point.
Then make another arduino setup which controls my Nikon.
So it can act like a wildcam (offline)

Something like below, using a optocoupler ( i still got some leftovers from my doorbell to gpio-pin project.)

Composite video with Atmega328p

I started to get some composite video generated with a arduino for my 6502 project.

UPDATE: 20221021

It is based on Grant Searle’s design, and yesterday I had some signals on my scope which looked like a screen with a character. But my monitor would not recognize a usable signal.

Today I tried a second version and another set of chips and crystals.

It looks like a signal, but I can’t see a clock pulse from the crystal?! So .. how?

Maybe I used a bad power supply. And killed something?

UPDATE: 20221021

After switching to another power supply, and checking the atmega328p fuses again (also wrong) .. at least SOME success!

Still a little sync problem, but i’ve got a blinking cursor!
Some minipro info
#Erase
minipro -p ATMEGA328P@DIP28 -E

#Flash hex code
minipro -p ATMEGA328P@DIP28 -w SBCVideo.hex

#Flash fuses
minipro -p ATMEGA328P@DIP28 -e -c config -w fuses

#Used fuses file
fuses_lo = 0xf7
fuses_hi = 0xd9
fuses_ext = 0xff
lock_byte = 0xff

#Dump all from atmega328p
minipro -p ATMEGA328P@DIP28 -r dump -f ihex


Some info about the fuses:
https://www.allaboutcircuits.com/projects/atmega328p-fuse-bits-and-an-external-crystal-oscillator

6502 update

  • New amplifier part using a LM386
  • Buzzer and led on VIA 2, blinky and sound timed by the internal timers of the 6522
  • ACIA testing still going on, writing software
  • Mini matrix keyboard removed, and used the temporary cursor buttons for the test with a rom which allows for a 8bits upload method using a arduino and the 6522. (I’m working on the big keyboard)

Work in progress code

PORT2B = $5000 		; VIA PORTB
PORT2A = $5001 		; VIA PORTA
DDR2B = $5002  		; Data direction register
DDR2A = $5003  		; Data direction register

PORTB = $6000 		; display
PORTA = $6001 		; control display + matrix keyboard
DDRB = $6002  		; data direction register
DDRA = $6003  		; data direction register
SID = $7000   		; sid base address

E  = %10000000		; enable bit
RW = %01000000		; RW bit 
RS = %00100000		; Register Select bit 
HOME = %00000010 	; VIA PORTB HOME command
DADDR = %00010000 	; VIA DADDRESS

LINENO = $0200		; temp address linenumber (move to other location)
NEXTLINE = 40		; 2x16 Chars but internally 40


  .org $8000

reset:
  ldx #$ff
  txs		; reset stack

; ###################################################
; #                 DISPLAY CONTROL                 #
; ###################################################
; VIA Setup

  lda #%11111111 	; Set all pins on port B to output
  sta DDRB
  lda #%11100000 	; Set top 3 pins on port A to output
  sta DDRA

; DISPLAY Setup
  lda #%00111000 	; Set 8-bit mode; 2-line display; 5x8 font
  jsr lcd_instruction
  lda #%00001110 	; Display on; cursor on; blink off
  jsr lcd_instruction
  lda #%00000110 	; Increment and shift cursor; don't shift display
  jsr lcd_instruction
  lda #$00000001 	; Clear display
  jsr lcd_instruction

; ###################################################
; #             PRINT MESSAGE LINE NO 0             #
; ###################################################
  lda #0  		; set line number
  sta LINENO      	; store for subroutine
  jsr gotoline		; move cursor

  ldx #0		; message index pointer
print:
  lda message0,x 	; start of message
  beq nextprint      	; stop when null in message (asciiz <- Zero padded)
  jsr print_char	; print char
  inx			; incr index
  jmp print		; resume print
; ###################################################
; #             PRINT MESSAGE LINE NO 1             #
; ###################################################
nextprint:
  lda #1  		; set line number
  sta LINENO      	; store
  jsr gotoline
  ldx #0  		; index pointer                 
print2:
  lda message1,x  	; absolute address message + x in A
  beq sidsound        	; if x is 0, end of message     
  jsr print_char  	; jump subroutine
  inx             	; increment x
  jmp print2      	; loop print2



; ###################################################
; #             SID SOUND                           #
; ###################################################
sidsound:
  lda #0		
  sta SID+$5		; attack/decay duration
  	
  lda #250
  sta SID+$6		; sustain level/release duration
  	
  lda #$95		; frequency voice 1 low byte
  sta SID+$0
  	
  lda #$44		; frequency voice 1 high byte
  sta SID+$1
  
  lda #%00100001	; sawtooth + gate
  sta SID+$4		; control register voice 1
  
  lda #$0f		; filter mode and volume (bits 3-0 main volume)
  sta SID+$18		; filter mode and volume



; ###################################################
; #             2ND VIA                             #
; ###################################################
  lda #%11111111 	; set port A output
  sta DDR2A

  lda #%11111111	; all ones!
  sta PORT2A
; ###################################################
  lda #%11111111 	; set port A output
  sta DDR2A

  lda #%11111111	; all ones!
  sta PORT2A



; ###################################################
; #             MAIN PROGRAM LOOP                   #
; ###################################################
loop:
  jmp loop
;                   1234567812345678
message0: .asciiz  "VIA 1,2 SID TEST"
message1: .asciiz  "   FASH  2022   "

; ###################################################
; #             ONLY SUBROUTINES                    #
; ###################################################

; ###################################################
; #             Subroutine gotoline                 #
; # Moves character placement position on display   #
; # Needs : $LINENO ADDRESS                         #
; # Exit values : -                                 #
; # Destroys registers: -                           #
; ###################################################

gotoline:
  pha                             ; store a
  txa
  pha                             ; store x
  ldx LINENO
  lda #HOME                       ; cursor down
  jsr lcd_instruction
  lda #$80
nextline:
  ldx LINENO
  cpx #00
  beq endnextlines
loopline:
  adc #40
  jsr lcd_instruction
  dex
  stx LINENO
  jmp nextline
endnextlines:
  pla                             ; pop a
  tax                             ; a to x
  pla                             ; pop a
  rts




; ###################################################
; #             LCD SUBROUTINES                     #
; ###################################################
lcd_wait:
  pha
  lda #%00000000  ; Port B is input
  sta DDRB
lcdbusy:
  lda #RW
  sta PORTA
  lda #(RW | E)
  sta PORTA
  lda PORTB
  and #%10000000
  bne lcdbusy
  lda #RW
  sta PORTA
  lda #%11111111  ; Port B is output
  sta DDRB
  pla
  rts
lcd_instruction:
  jsr lcd_wait
  sta PORTB
  lda #0         ; Clear RS/RW/E bits
  sta PORTA
  lda #E         ; Set E bit to send instruction
  sta PORTA
  lda #0         ; Clear RS/RW/E bits
  sta PORTA
  rts
print_char:
  jsr lcd_wait
  sta PORTB
  lda #RS         ; Set RS; Clear RW/E bits
  sta PORTA
  lda #(RS | E)   ; Set E bit to send instruction
  sta PORTA
  lda #RS         ; Clear E bits
  sta PORTA
  rts

nmi:
  rti

irq:
  rti

  .org $fffa
  .word nmi
  .word reset
  .word irq
;  .word $0000

Generic matrix keyboard

In this case designed for my 6502, but it is a generic setup.

I it just a dual 16key matrix decoder merged together. You can probably use this with raspberries, arduinos etc.

I wanted to use 74C923 but these are nowhere to be found. And even then, the number of keys wil be 20.
So i am tying together two 74C922 using some logic in a PLD.

First draft

It wil be something like above. Using the data availabe signal i can combine both 16key matrixes. (In theory .. it is all untested)

PLD Code

GAL22V10
Address Decoder

PHI2 DA0 DA1 D01 D02 D03 D04 D11 D12 D13 D14 GND
NC D0 D1 D2 D3 D4 DA NC NC NC NC VCC

DA = DA0 + DA1
D0 = D01 & DA0 + D11 & DA1
D1 = D02 & DA0 + D12 & DA1
D2 = D03 & DA0 + D13 & DA1
D3 = D04 & DA0 + D14 & DA1
D4 = DA1 

DESCRIPTION
Key matrix merger

I’ve got my new keys of the keyboard in today!

  • 0-F – hex keys
  • G = Go
  • R = Reset
  • S = Step
  • M = Memory
  • Cursor keys (up/down for memory locations)
  • ??? I’ve got room for 8 more keys

My inkscape template (keys are 10/10mm)

Printed on white and red paper

https://media.henriaanstoot.nl/keyboardmatrix.svg

6502 progress

UPDATE: 20220815, 20220814, 20220815, 20230202

Flashing ROMs .. (eeproms). It used to be a pain in the *$$.
Burning took a looong time. But clearing one with UV took .. 20 minutes or so. Using one of these:

Altered clock module

  • Changed button press
  • Dipswitches for more speed control (red .. upper left)

Changed Rom/Ram

  • Changed addressing
  • Added RAM
  • ZIF Socket for ROM

VIC 6522

  • Fixed clock
  • Added buttons for interrupt

Display

  • Display works now
  • To test: Create Address logic to access display without VIA
    Can work, but not at high speed clock. Stays behind VIA
  • To buy: st7920 lcd 128×64

Generic improvements

  • Rewired most parts, using color codes
    (Blue data, Yellow Address and so on)
  • Added leds on data and address bus using ULN2803 darlington arrays
  • 100nF Decoupling capacitors on the power rails

To do’s or ‘have to look into’s’

  • For sound i planned to use a General Instrument AY-3-8910, it is somewhere in my Lab, i know it is.
    I saved this chip and a SID for my Amiga addon soundcard.
    Where are my plans for the simple v1 setup? (FOUND IT)

  • I have to start writing rom functions for display usage. Like
    JSR $ff00 – Clear screen subroutine .. etc
  • I’m scraping information from websites, to get started on my clock controller.
    ATmega328 with ssd1306 display and rotary encoder/dip switches

Notes about the movie:
Left side is Arduino IDE monitor reading Addressbus and Databus.
(I’m going to try to rewrite this to realtime disassemble)
Resetting system.
Stepping CPU with manual clock pulses.
Start vector being read at $FFFC/$FFFD.
Program being run from $8000.
Set clock on automatic ( ~ about 150 Hz )
Last opcodes you see a JMP loop 4C 2F 80, that is JMP $802F
Display enlarged on video, was not visible on movie i took on mobile.
(Wrong angle?)

Breadboard overview

Clock moduleReset module + Crystal
CPU + nmi/int buttonsRAM and ROM
Address decode + Bus divideAddres/Data bus leds
6522 VIA + Display2nd via + Buttons
?(sound board)

TIL: 6502 can run without ram only rom,expect when using JSR … which uses a program stack in RAM

TODO:

  • Make Clock module and 1Mhz Crystal switchable
  • NMI and INT debounce maken
  • Software buttons
  • Buy new darlingtons, for controlbus!
    • r/w, int, chip enables, etc
  • Labels on chips/breadboards

Altair 8800

After a whole day soldering yesterday, ending up with a wire mess.
Which didn’t work at the end…

Starting measuring some things, and create some test sketches (led blinky tests)
I found out that the main problem was not having the red switches connected to GND.
Blue switches where upside down, this was a easy fix. Because these are ON-ON switches, and where already connected to a common line.
Then a mixup between D0 and D6 (wires crossed)
And it is working! Made some lines and lettering on the frontplate after some playing around.

Weird to input stuff in octal (group of 3 bits)

Altair 8800

The Altair 8800 is a microcomputer designed in 1974 by MITS and based on the Intel 8080CPU. Interest grew quickly after it was featured on the cover of the January 1975 issue of Popular Electronics and was sold by mail order through advertisements there, in Radio-Electronics, and in other hobbyist magazines.

(picture from wikipedia)

UPDATE: 20220804 – Added Octal sheet

I alway loved the simple setup of this computer.
There was no screen and no keyboard.
Only later additions to the machine provided these.

One explanation of the Altair name, is that the name was inspired by Star Trek episode “Amok Time“, where the Enterprise crew went to Altair (Six).

There are only a few differences between the used 8080 CPU and the 8085 CPU of a machine i learned machinecode on.

See : https://www.henriaanstoot.nl/1989/01/01/8085-machinecode-at-school/

So for a really long time i wanted to have a Altair alike machine. There are do it yourself kits for sale. Which look like perfect relica’s and there are virtual machines and emulators. But i wanted to have the feeling of throwing the switches.
You can find a emulator here (https://s2js.com/altair/)

So i bought the components, a poker case which can hold the machine. And started building today.

The backend is a arduino based emulator, but with real leds and switches!
(https://create.arduino.cc/projecthub/david-hansel/arduino-altair-8800-simulator-3594a6)

Next to do:

  • Fix plate into case
  • Solder a LOT of wires and components!
    • Shall i get rid off the transitors and use darlington arrays?
  • Put lettering on the aluminium plate : Functions and Bus information.
  • Build a power connector in the case

And then … programming 🙂

UPDATE: 20220804 – Added Octal sheet

The Altair is a octal based machine, but i couldn’t find a opcode list in Octal. So i generated one.
When entering a MOV D,M instruction for example, you have to enter
x 0 1 0 1 0 1 1 0 using the switches
Thats 126 in octal but most tables are in hex ( MOV D,M is 56, which is 0101 0110 but not that clear on the switches)

Opcode (oct)InstructionfunctionsizeflagsOpcode
000NOP10x00
001LXI B,D16B <- byte 3, C <- byte 230x01
002STAX B(BC) <- A10x02
003INX BBC <- BC+110x03
004INR BB <- B+11Z, S, P, AC0x04
005DCR BB <- B-11Z, S, P, AC0x05
006MVI B, D8B <- byte 220x06
007RLCA = A << 1; bit 0 = prev bit 7; CY = prev bit 71CY0x07
0100x08
011DAD BHL = HL + BC1CY0x09
012LDAX BA <- (BC)10x0a
013DCX BBC = BC-110x0b
014INR CC <- C+11Z, S, P, AC0x0c
015DCR CC <-C-11Z, S, P, AC0x0d
016MVI C,D8C <- byte 220x0e
017RRCA = A >> 1; bit 7 = prev bit 0; CY = prev bit 01CY0x0f
0200x10
021LXI D,D16D <- byte 3, E <- byte 230x11
022STAX D(DE) <- A10x12
023INX DDE <- DE + 110x13
024INR DD <- D+11Z, S, P, AC0x14
025DCR DD <- D-11Z, S, P, AC0x15
026MVI D, D8D <- byte 220x16
027RALA = A << 1; bit 0 = prev CY; CY = prev bit 71CY0x17
0300x18
031DAD DHL = HL + DE1CY0x19
032LDAX DA <- (DE)10x1a
033DCX DDE = DE-110x1b
034INR EE <-E+11Z, S, P, AC0x1c
035DCR EE <- E-11Z, S, P, AC0x1d
036MVI E,D8E <- byte 220x1e
037RARA = A >> 1; bit 7 = prev bit 7; CY = prev bit 01CY0x1f
0400x20
041LXI H,D16H <- byte 3, L <- byte 230x21
042SHLD adr(adr) <-L; (adr+1)<-H30x22
043INX HHL <- HL + 110x23
044INR HH <- H+11Z, S, P, AC0x24
045DCR HH <- H-11Z, S, P, AC0x25
046MVI H,D8H <- byte 220x26
047DAAspecial10x27
0500x28
051DAD HHL = HL + HI1CY0x29
052LHLD adrL <- (adr); H<-(adr+1)30x2a
053DCX HHL = HL-110x2b
054INR LL <- L+11Z, S, P, AC0x2c
055DCR LL <- L-11Z, S, P, AC0x2d
056MVI L, D8L <- byte 220x2e
057CMAA <- !A10x2f
0600x30
061LXI SP, D16SP.hi <- byte 3, SP.lo <- byte 230x31
062STA adr(adr) <- A30x32
063INX SPSP = SP + 110x33
064INR M(HL) <- (HL)+11Z, S, P, AC0x34
065DCR M(HL) <- (HL)-11Z, S, P, AC0x35
066MVI M,D8(HL) <- byte 220x36
067STCCY = 11CY0x37
0700x38
071DAD SPHL = HL + SP1CY0x39
072LDA adrA <- (adr)30x3a
073DCX SPSP = SP-110x3b
074INR AA <- A+11Z, S, P, AC0x3c
075DCR AA <- A-11Z, S, P, AC0x3d
076MVI A,D8A <- byte 220x3e
077CMCCY=!CY1CY0x3f
100MOV B,BB <- B10x40
101MOV B,CB <- C10x41
102MOV B,DB <- D10x42
103MOV B,EB <- E10x43
104MOV B,HB <- H10x44
105MOV B,LB <- L10x45
106MOV B,MB <- (HL)10x46
107MOV B,AB <- A10x47
110MOV C,BC <- B10x48
111MOV C,CC <- C10x49
112MOV C,DC <- D10x4a
113MOV C,EC <- E10x4b
114MOV C,HC <- H10x4c
115MOV C,LC <- L10x4d
116MOV C,MC <- (HL)10x4e
117MOV C,AC <- A10x4f
120MOV D,BD <- B10x50
121MOV D,CD <- C10x51
122MOV D,DD <- D10x52
123MOV D,ED <- E10x53
124MOV D,HD <- H10x54
125MOV D,LD <- L10x55
126MOV D,MD <- (HL)10x56
127MOV D,AD <- A10x57
130MOV E,BE <- B10x58
131MOV E,CE <- C10x59
132MOV E,DE <- D10x5a
133MOV E,EE <- E10x5b
134MOV E,HE <- H10x5c
135MOV E,LE <- L10x5d
136MOV E,ME <- (HL)10x5e
137MOV E,AE <- A10x5f
140MOV H,BH <- B10x60
141MOV H,CH <- C10x61
142MOV H,DH <- D10x62
143MOV H,EH <- E10x63
144MOV H,HH <- H10x64
145MOV H,LH <- L10x65
146MOV H,MH <- (HL)10x66
147MOV H,AH <- A10x67
150MOV L,BL <- B10x68
151MOV L,CL <- C10x69
152MOV L,DL <- D10x6a
153MOV L,EL <- E10x6b
154MOV L,HL <- H10x6c
155MOV L,LL <- L10x6d
156MOV L,ML <- (HL)10x6e
157MOV L,AL <- A10x6f
160MOV M,B(HL) <- B10x70
161MOV M,C(HL) <- C10x71
162MOV M,D(HL) <- D10x72
163MOV M,E(HL) <- E10x73
164MOV M,H(HL) <- H10x74
165MOV M,L(HL) <- L10x75
166HLTspecial10x76
167MOV M,A(HL) <- A10x77
170MOV A,BA <- B10x78
171MOV A,CA <- C10x79
172MOV A,DA <- D10x7a
173MOV A,EA <- E10x7b
174MOV A,HA <- H10x7c
175MOV A,LA <- L10x7d
176MOV A,MA <- (HL)10x7e
177MOV A,AA <- A10x7f
200ADD BA <- A + B1Z, S, P, CY, AC0x80
201ADD CA <- A + C1Z, S, P, CY, AC0x81
202ADD DA <- A + D1Z, S, P, CY, AC0x82
203ADD EA <- A + E1Z, S, P, CY, AC0x83
204ADD HA <- A + H1Z, S, P, CY, AC0x84
205ADD LA <- A + L1Z, S, P, CY, AC0x85
206ADD MA <- A + (HL)1Z, S, P, CY, AC0x86
207ADD AA <- A + A1Z, S, P, CY, AC0x87
210ADC BA <- A + B + CY1Z, S, P, CY, AC0x88
211ADC CA <- A + C + CY1Z, S, P, CY, AC0x89
212ADC DA <- A + D + CY1Z, S, P, CY, AC0x8a
213ADC EA <- A + E + CY1Z, S, P, CY, AC0x8b
214ADC HA <- A + H + CY1Z, S, P, CY, AC0x8c
215ADC LA <- A + L + CY1Z, S, P, CY, AC0x8d
216ADC MA <- A + (HL) + CY1Z, S, P, CY, AC0x8e
217ADC AA <- A + A + CY1Z, S, P, CY, AC0x8f
220SUB BA <- A – B1Z, S, P, CY, AC0x90
221SUB CA <- A – C1Z, S, P, CY, AC0x91
222SUB DA <- A + D1Z, S, P, CY, AC0x92
223SUB EA <- A – E1Z, S, P, CY, AC0x93
224SUB HA <- A + H1Z, S, P, CY, AC0x94
225SUB LA <- A – L1Z, S, P, CY, AC0x95
226SUB MA <- A + (HL)1Z, S, P, CY, AC0x96
227SUB AA <- A – A1Z, S, P, CY, AC0x97
230SBB BA <- A – B – CY1Z, S, P, CY, AC0x98
231SBB CA <- A – C – CY1Z, S, P, CY, AC0x99
232SBB DA <- A – D – CY1Z, S, P, CY, AC0x9a
233SBB EA <- A – E – CY1Z, S, P, CY, AC0x9b
234SBB HA <- A – H – CY1Z, S, P, CY, AC0x9c
235SBB LA <- A – L – CY1Z, S, P, CY, AC0x9d
236SBB MA <- A – (HL) – CY1Z, S, P, CY, AC0x9e
237SBB AA <- A – A – CY1Z, S, P, CY, AC0x9f
240ANA BA <- A & B1Z, S, P, CY, AC0xa0
241ANA CA <- A & C1Z, S, P, CY, AC0xa1
242ANA DA <- A & D1Z, S, P, CY, AC0xa2
243ANA EA <- A & E1Z, S, P, CY, AC0xa3
244ANA HA <- A & H1Z, S, P, CY, AC0xa4
245ANA LA <- A & L1Z, S, P, CY, AC0xa5
246ANA MA <- A & (HL)1Z, S, P, CY, AC0xa6
247ANA AA <- A & A1Z, S, P, CY, AC0xa7
250XRA BA <- A ^ B1Z, S, P, CY, AC0xa8
251XRA CA <- A ^ C1Z, S, P, CY, AC0xa9
252XRA DA <- A ^ D1Z, S, P, CY, AC0xaa
253XRA EA <- A ^ E1Z, S, P, CY, AC0xab
254XRA HA <- A ^ H1Z, S, P, CY, AC0xac
255XRA LA <- A ^ L1Z, S, P, CY, AC0xad
256XRA MA <- A ^ (HL)1Z, S, P, CY, AC0xae
257XRA AA <- A ^ A1Z, S, P, CY, AC0xaf
260ORA BA <- A | B1Z, S, P, CY, AC0xb0
261ORA CA <- A | C1Z, S, P, CY, AC0xb1
262ORA DA <- A | D1Z, S, P, CY, AC0xb2
263ORA EA <- A | E1Z, S, P, CY, AC0xb3
264ORA HA <- A | H1Z, S, P, CY, AC0xb4
265ORA LA <- A | L1Z, S, P, CY, AC0xb5
266ORA MA <- A | (HL)1Z, S, P, CY, AC0xb6
267ORA AA <- A | A1Z, S, P, CY, AC0xb7
270CMP BA – B1Z, S, P, CY, AC0xb8
271CMP CA – C1Z, S, P, CY, AC0xb9
272CMP DA – D1Z, S, P, CY, AC0xba
273CMP EA – E1Z, S, P, CY, AC0xbb
274CMP HA – H1Z, S, P, CY, AC0xbc
275CMP LA – L1Z, S, P, CY, AC0xbd
276CMP MA – (HL)1Z, S, P, CY, AC0xbe
277CMP AA – A1Z, S, P, CY, AC0xbf
300RNZif NZ, RET10xc0
301POP BC <- (sp); B <- (sp+1); sp <- sp+210xc1
302JNZ adrif NZ, PC <- adr30xc2
303JMP adrPC <= adr30xc3
304CNZ adrif NZ, CALL adr30xc4
305PUSH B(sp-2)<-C; (sp-1)<-B; sp <- sp – 210xc5
306ADI D8A <- A + byte2Z, S, P, CY, AC0xc6
307RST 0CALL $010xc7
310RZif Z, RET10xc8
311RETPC.lo <- (sp); PC.hi<-(sp+1); SP <- SP+210xc9
312JZ adrif Z, PC <- adr30xca
3130xcb
314CZ adrif Z, CALL adr30xcc
315CALL adr(SP-1)<-PC.hi;(SP-2)<-PC.lo;SP<-SP-2;PC=adr30xcd
316ACI D8A <- A + data + CY2Z, S, P, CY, AC0xce
317RST 1CALL $810xcf
320RNCif NCY, RET10xd0
321POP DE <- (sp); D <- (sp+1); sp <- sp+210xd1
322JNC adrif NCY, PC<-adr30xd2
323OUT D8special20xd3
324CNC adrif NCY, CALL adr30xd4
325PUSH D(sp-2)<-E; (sp-1)<-D; sp <- sp – 210xd5
326SUI D8A <- A – data2Z, S, P, CY, AC0xd6
327RST 2CALL $1010xd7
330RCif CY, RET10xd8
3310xd9
332JC adrif CY, PC<-adr30xda
333IN D8special20xdb
334CC adrif CY, CALL adr30xdc
3350xdd
336SBI D8A <- A – data – CY2Z, S, P, CY, AC0xde
337RST 3CALL $1810xdf
340RPOif PO, RET10xe0
341POP HL <- (sp); H <- (sp+1); sp <- sp+210xe1
342JPO adrif PO, PC <- adr30xe2
343XTHLL <-> (SP); H <-> (SP+1)10xe3
344CPO adrif PO, CALL adr30xe4
345PUSH H(sp-2)<-L; (sp-1)<-H; sp <- sp – 210xe5
346ANI D8A <- A & data2Z, S, P, CY, AC0xe6
347RST 4CALL $2010xe7
350RPEif PE, RET10xe8
351PCHLPC.hi <- H; PC.lo <- L10xe9
352JPE adrif PE, PC <- adr30xea
353XCHGH <-> D; L <-> E10xeb
354CPE adrif PE, CALL adr30xec
3550xed
356XRI D8A <- A ^ data2Z, S, P, CY, AC0xee
357RST 5CALL $2810xef
360RPif P, RET10xf0
361POP PSWflags <- (sp); A <- (sp+1); sp <- sp+210xf1
362JP adrif P=1 PC <- adr30xf2
363DIspecial10xf3
364CP adrif P, PC <- adr30xf4
365PUSH PSW(sp-2)<-flags; (sp-1)<-A; sp <- sp – 210xf5
366ORI D8A <- A | data2Z, S, P, CY, AC0xf6
367RST 6CALL $3010xf7
370RMif M, RET10xf8
371SPHLSP=HL10xf9
372JM adrif M, PC <- adr30xfa
373EIspecial10xfb
374CM adrif M, CALL adr30xfc
3750xfd
376CPI D8A – data2Z, S, P, CY, AC0xfe
377RST 7CALL $3810xff

i2c and cap1188 Musical instrument (from vga to esp32?)

Way back in 2018 i was playing around with i2c and touch.

CAP1188 Multi touch sensor



I remembered that VGA was using i2c to get information from monitors like brand/type and connection information.

I managed to access the cap1188 up to my Laptop via VGA.

2018 Schematic i used to abuse vga …

The final python code i used to play with the variables and playing sound i can’t find.
But below is the test code

#!/usr/bin/python

# NOTE: i did a address scan, now i have 3v3 connected to AD, so probably the address is 0x28 !!

import smbus

bus = smbus.SMBus(1)    # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)

DEVICE_ADDRESS = 0x29      
DEVICEx = 0x10      
DEVICE_REG_MODE1 = 0x00
DEVICE_REG_LEDOUT0 = 0x1d

#Write a single register
bus.write_byte_data(DEVICE_ADDRESS, 0x1f, 0x3F)

#Write an array of registers
#ledout_values = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
#bus.write_i2c_block_data(DEVICE_ADDRESS, DEVICE_REG_LEDOUT0, ledout_values)
while True:

        print bus.read_byte_data(DEVICE_ADDRESS,0x10), bus.read_byte_data(DEVICE_ADDRESS,0x11) , bus.read_byte_data(DEVICE_ADDRESS,0x12), bus.read_byte_data(DEVICE_ADDRESS,0x13), bus.read_byte_data(DEVICE_ADDRESS,0x14), bus.read_byte_dat
a(DEVICE_ADDRESS,0x15), bus.read_byte_data(DEVICE_ADDRESS,0x16), bus.read_byte_data(DEVICE_ADDRESS,0x17)

Today i connected the cap1188 to a ESP32 and a piezo buzzer.

/*** Based on below library ***/
/*** Changed pins and added sound ***/

/*************************************************** 
  This is a library for the CAP1188 I2C/SPI 8-chan Capacitive Sensor

  Designed specifically to work with the CAP1188 sensor from Adafruit
  ----> https://www.adafruit.com/products/1602

  These sensors use I2C/SPI to communicate, 2+ pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/
 
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>

const int TONE_OUTPUT_PIN = 26;
const int TONE_PWM_CHANNEL = 0; 
int freq = 0;


// Reset Pin is used for I2C or SPI
#define CAP1188_RESET  9

// CS pin is used for software or hardware SPI
#define CAP1188_CS  10

// These are defined for software SPI, for hardware SPI, check your 
// board's SPI pins in the Arduino documentation
#define CAP1188_MOSI  11
#define CAP1188_MISO  12
#define CAP1188_CLK  13

// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
// On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
// On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21

// Use I2C, no reset pin!
Adafruit_CAP1188 cap = Adafruit_CAP1188();

// Or...Use I2C, with reset pin
//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_RESET);

// Or... Hardware SPI, CS pin & reset pin 
// Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CS, CAP1188_RESET);

// Or.. Software SPI: clock, miso, mosi, cs, reset
//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CLK, CAP1188_MISO, CAP1188_MOSI, CAP1188_CS, CAP1188_RESET);

void setup() {
  Serial.begin(9600);
  Serial.println("CAP1188 test!");
  ledcAttachPin(TONE_OUTPUT_PIN, TONE_PWM_CHANNEL);
 

  // Initialize the sensor, if using i2c you can pass in the i2c address
  if (!cap.begin(0x28)){
  //if (!cap.begin()) {
    Serial.println("CAP1188 not found");
    while (1);
  }
  Serial.println("CAP1188 found!");
}

void loop() {
  uint8_t touched = cap.touched();

  if (touched == 0) {
    // No touch detected
    return;
  }
  
  for (uint8_t i=0; i<8; i++) {
    if (touched & (1 << i)) {
      Serial.print(touched); Serial.print("\t");
      freq = (i * 100);
      ledcWriteTone(TONE_PWM_CHANNEL, freq);
      delay(100);
    }
  }

  Serial.println();
  delay(50);
}

Finding the right pins or above pinout was the hardest part.
The sketch reads the pins binary so value 129 is first and last bit.

Now i have to get the sound sounding a little better and add frequencies and fingersettings to the sketch to get a minimal electronic bagpipe. (V3 it is .. )

To be continued ..