Tag Archives: arduino

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 ..

Micropython and TFT display test environment

This exercise is to get a micropython dev environment with a graphical display.

pip3 install esptool adafruit-ampy

Erase board (use correct tty device!)

esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash

Flash using

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20190125-v1.10.bin

Download from https://micropython.org/resources/firmware/esp32-20220618-v1.19.1.bin

Test with

screen /dev/ttyUSB0 115200

Enter
import machine
or
help()

Great up and running

Now we have to install a boot loader
Use ampy to list files

#list boot
ampy -p /dev/ttyUSB0 ls 
/boot.py

#get boot.py
ampy -p /dev/ttyUSB0 get boot.py

vi boot.py (create new)

#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()

def connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('WIFISSID', 'WIFIPASS')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())

Push the file

ampy -p /dev/ttyUSB0 put boot.py
Usage: ampy [OPTIONS] COMMAND [ARGS]...

  ampy - Adafruit MicroPython Tool

  Ampy is a tool to control MicroPython boards over a serial connection.
  Using ampy you can manipulate files on the board's internal filesystem and
  even run scripts.

Options:
  -p, --port PORT    Name of serial port for connected board.  Can optionally
                     specify with AMPY_PORT environment variable.  [required]
  -b, --baud BAUD    Baud rate for the serial connection (default 115200).
                     Can optionally specify with AMPY_BAUD environment
                     variable.
  -d, --delay DELAY  Delay in seconds before entering RAW MODE (default 0).
                     Can optionally specify with AMPY_DELAY environment
                     variable.
  --version          Show the version and exit.
  --help             Show this message and exit.

Commands:
  get    Retrieve a file from the board.
  ls     List contents of a directory on the board.
  mkdir  Create a directory on the board.
  put    Put a file or folder and its contents on the board.
  reset  Perform soft reset/reboot of the board.
  rm     Remove a file from the board.
  rmdir  Forcefully remove a folder and all its children from the board.
  run    Run a script and print its output.

Connect to serial console using screen

sudo screen /dev/ttyUSB0 115200
(use CTRL-A \ to exit)

Connect to wifi

import boot
connect()

Led blinky test, with below file named ledtest.py

import time
from machine import Pin
led=Pin(2,Pin.OUT)        #Internal led pin

while True:
  led.value(1)            #Set led turn on
  time.sleep(0.5)
  led.value(0)            #Set led turn off
  time.sleep(0.5)

Upload and run script

ampy -p /dev/ttyUSB0 put ledtest.py
import ledtest (without .py!)

Next todo: boot.py @boot ?!?
Run custom python after booting.
Connect display and play with drawing.

Tip: Install rshell !

sudo pip3 install rshell
fash@zspot:~$ rshell 
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.

No MicroPython boards connected - use the connect command to add one

/home/fash> autoconnect: /dev/ttyUSB0 action: add

/home/fash> ?

Documented commands (type help <topic>):
========================================
args    cat  connect  date  edit  filesize  help  mkdir  rm     shell
boards  cd   cp       echo  exit  filetype  ls    repl   rsync

Use Control-D (or the exit command) to exit rshell.

Connecting the display

I’ve connected the display as above. Note the different connections on the display. Above fritzing part has connections for touch screen!
The 4 or 5 pins on the other side are for sdcard functionallity.

display       esp
-----------------
SDO/MISO      D19
LED           VIN (5v)
SCK           D18
SDI/MOSI      D23
DC/RS         D15
RESET         D14
CS            D5
GND           GND
VCC           3.3V

Not my different ESP, gpio has high numbers and only 30 pins.
Most ESP have 2 SPI controllers. Check yours!

Software part

git clone https://github.com/rdagger/micropython-ili9341

Next create a setupmydisplay.py file, and edit your pin connections

from ili9341 import Display
from machine import Pin, SPI

TFT_CLK_PIN = const(18)
TFT_MOSI_PIN = const(23)
TFT_MISO_PIN = const(19)

TFT_CS_PIN = const(5)
TFT_RST_PIN = const(14)
TFT_DC_PIN = const(15)

def createMyDisplay():
    #spi = SPI(0, baudrate=40000000, sck=Pin(TFT_CLK_PIN), mosi=Pin(TFT_MOSI_PIN))
    spiTFT = SPI(2, baudrate=51200000,
                 sck=Pin(TFT_CLK_PIN), mosi=Pin(TFT_MOSI_PIN))
    display = Display(spiTFT,
                      dc=Pin(TFT_DC_PIN), cs=Pin(TFT_CS_PIN), rst=Pin(TFT_RST_PIN))
    return display

Now you can use the library by editing a example like demo_bouncing_boxes.py

Add and change

# At the beginning of the file
import setupmydisplay.py

Futher down comment two lines and add your own setup

        # Baud rate of 40000000 seems about the max
        #spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
        #display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
        display = setup.createMyDisplay()

Upload to ESP32 and testing!

ampy -p /dev/ttyUSB0 put demo_bouncing_boxes.py
ampy -p /dev/ttyUSB0 put setupmydisplay.py
# connect and start
sudo screen /dev/ttyUSB0 115200
import demo_bouncing_boxes.py

Race track Controller

I got a vintage racetrack from a colleage a while back.

In the past i had some ideas controlling train or race tracks.
For train tracks i wanted to write intelligent maneuver software.
For a racetrack a web controllable race. Maybe with a webcam mounted on the car??

L298N – DC motor controller

So i bought a little DC motor controller (2 channels) and took a esp32.

ESP: 
GPIO04 Player1 IN1 
GPIO05 Player1 IN2
GPIO19 Player2 IN1 
GPIO18 Player2 IN2
GPIO13 PWM Player1
GPIO14 PWM Player2

The webinterface is behind a reverse proxy (apache)

TO BE POSTED .. arduino code

<VirtualHost *:443>
   SSLEngine on
   SSLProxyEngine On

   SSLProtocol all -SSLv2 -SSLv3 +TLSv1
   SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:!RC4+RSA:+HIGH:+MEDIUM

   SSLCertificateFile /etc/ssl/.......cer
   SSLCertificateKeyFile /etc/ssl/private/........key
   SSLCertificateChainFile /etc/ssl/private/GlobalSignRootCA.cer
   SSLCertificateChainFile /etc/ssl/private/AlphaSSLCA-SHA256-G2.cer

   CustomLog /var/log/httpd/media_ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"


    ServerAdmin webmaster@henriaanstoot.nl
    ServerName race.henriaanstoot.nl

ProxyRequests Off
ProxyPreserveHost On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off

<Location />
ProxyPass  http://10.1.0.25/
ProxyPassReverse  http://10.1.0.25/
</Location>

    ErrorLog /var/log/httpd/race.henriaanstoot.nl-error.log
    CustomLog /var/log/httpd/race.henriaanstoot.nl-access.log combined
</VirtualHost>

Arduino IDE

Adding boards:

File > Preferences > Additional Boards
Add url (comma separated)
Press OK

ESP32 :

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

ATTINY85:

https://arduino.esp8266.com/stable/package_esp8266com_index.json,https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

After that go to the Board manager.
Tools > Board: ..... > Board Manager
Search board, click and install.
NOTE: Some sketches require a specific version!

Select your board, and write/open you sketch.

First thing to do is test compiling your sketch

Press the little button on the left

Libraries:

When you get a compile error like below, you are missing those libraries

Goto tools > Manage libraries

Search for your needed library, sometimes there are multiple which look alike. This is a trial and error approach.
Sometimes it doesn’t exists and you need to upload a zip containing the library. (Sketch > Include Library > Add .zip library

Downloading a zip containing the library
Adding the library zip file

When looking at the first lines of you sketch, there are include statements like:

#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

But sometimes there are statements without the < > characters.
Then it will be a included file just for your sketch.

Note the second tab MPU6050x.h which contains specific code only for this sketch.

Redo a test recompile using the tic icon again.

Everything okay? .. Select the correct port in Tools > Port
And press the Arrowright icon to upload/flash.
Note: sometimes you have to hold a button or press a little flash button on your device to flash.

esptool.py v3.3
Serial port COM8
Connecting.....
Chip is ESP32-D0WDQ6-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c8:c9:a3:f9:02:d0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000c7fff...
Flash params set to 0x022f
Compressed 18880 bytes to 12992...
Writing at 0x00001000... (100 %)
Wrote 18880 bytes (12992 compressed) at 0x00001000 in 0.3 seconds (effective 482.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 627.7 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 1087.9 kbit/s)...
Hash of data verified.
Compressed 750976 bytes to 477779...
Writing at 0x00010000... (3 %)
...
...
...
Writing at 0x000bb633... (93 %)
Writing at 0x000c0acd... (96 %)
Writing at 0x000c6649... (100 %)
Wrote 750976 bytes (477779 compressed) at 0x00010000 in 6.3 seconds (effective 947.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Most of the boards you can connect via micro-usb.
Sometimes you need adaptors like:

TIPS ‘n tricks:

Open same file in another editor, so you can compare for example the top (declarations) and futher down the code.
Else you could be ending up scolling up/down all day long. And probably forgetting how a variablename was exacly spelled.

Use serial monitor!
When debugging this is a valuable tool.
Enter statements into you code, which prints debugging info to a serial monitoring window when your device is still hookedup to your PC.

Example printing connected IP and values registered
You even can use serial plotting!!

How to print?

void setup(){
  Serial.begin(115200);
  ... code 
  Serial.println("Connecting...");
  ... code
  Serial.println(WiFi.localIP());

  or 

  Serial.println(measuredvalue);

Other obvious tips:
Add comment lines (documentation)
Use variable names which make sense!
( Hard to find what aaaa() does, or what tmp-a is, but
LastTempValue says a lot more)

MCH 2022

Back from the hackers event “May Contain Hackers”

MCH2022 is a nonprofit outdoor hacker camp taking place in Zeewolde, the Netherlands, July 22 to 26 2022. The event is organized for and by volunteers from the worldwide hacker community.

Knowledge sharing, technological advancement, experimentation, connecting with your hacker peers and hacking are some of the core values of this event.

MCH2022 is the successor of a string of similar events happening every four years since 1989.
These are GHPHEUHIPHALWTHHAROHM and SHA.

I’ve bin to several of these big events. Besides these big events are many different smaller events (wannull, ne2000 etc).

First one i’ve been was HIP97. I went with Bigred at that time.
I had to get the tickets at that time, he didn’t had a handle at that time. It was Monique who came up with his new nick.

After HIP97 there was HAL2001 WTH2005 and OHM2013 which i was present.
HAL2001 the whole ICEcrew was present, WTH a part of them, OHM a few and i was with a few PRUTS friends.

Now i was with my girlfriend, AND with Bigred again!
Loads of fun and memories. Had not seen Bigred since a inbetween hacker party at my place.
So ’97 and now ’22 .. jeez 25 years!

So MCH, it was great again.
Loads of stuff to do and to see.
Weather was … okay. Two days where really hot, one day some light rain but a load of wind. Our neighbours tent collapsed, beer tents where reenforced.
First campsite with a supermarket!
Music stage was awesome, lasers and fire!

I went to a lot of talks, even my girlfriend found some she was interested in.

This was the last time i’ve brought my “Windows free zone tape”
This big roll of tape was used on many occasions.
I got this roll somewhere < 2000, I did a search but couldn’t find anything mentioning it on the web. Maybe some archive.org entry?

  • Starting a Home Computer Museum (which i almost did in the past)
  • streaming 360 video (going to try this with my Vuze XR Camera)
  • Non-Euclidean Doom: what happens to a game when pi is not 3.14159…
    (Really enjoyed this one)
  • Hacking the genome: how does it work, and should we?
  • And more

Besides the talks i’ve done some workshops:

  • Micropython on the badge (see my other post)
  • Kicad – PCB designing

Meanwhile we where looking at all the villages and hackerspaces. Loads of interesting people to meet. Like our neighbour two tents futher, he was also a home-brewer, and he brought a minifridge with beer taps connected to it.

When back at our tent or Bigreds Campervan, we talked about differences now and then. New technology, what we’ve been upto in the last years and tinkering, loads of tinkering.

I’ve brough a big plastic container with .. ehh “things to do ….”

  • My 6502, bigred helped me debugging the 16*2 display.
    (Luckily his campervan was packed with electronics!)
    We cannibalized one of his projects for a display, and re-flashed his eeprom programming arduino to test my display. ( The arduino i had to reflash later to program a rom he had given me for my 6502. )
    Other toys he gave me: Print for the programmer, and a C64 Cartridge print for Exrom and Game.
  • Mini C64 with a little screen and raspberry zero.
  • 5050 ledstrip (didn’t had time to reprogram this for our mood-light)
  • Handheld gamehat: Bigred found some old games he played when he was young
  • Mikrotik router, because i wanted to make a dmz for my girlfriends laptop. (MS)
  • Playing around with my Vuze XR camera
  • Huskycam, which i’m planning to use on a racetrack
  • DVB-T DAB FM Stick, got some hints and tips from Bigred.
    (Note to myself … fix the antenna!)
  • My Arduino touch bagpipe player with i2c
  • The wifi deauther, which has a display which i wanted to use to make a programmable clock for my 6502. Using a rotary encoder and the display to control the speed in Hz.
  • I spend many hours playing with the Badge and Kicad

Wrote some 6502 assembly, arduino sketches, php, bash and micropython.

While playing around with the badge i got some things working easily.
Spinning logo and blinky leds.
Next goal to achieve was, to get the gyroscope to control the angle of spinning.
Most of the code worked, but the gyro values stayed zero!
(After many hours …. you have to start/enable the chip/measurements on the bno055 first! .. duh! )

I didn’t had my dev directory from my main battlestation synced in my nextcloud, so changing things for the 6502 was a b*tch.
Used vasm and acme to generate a bin file to use to fill the rom.
Didn’t like the eeprom programmer program, because i could not easily check the rom contents.
Have to look into that later on.

While learning to use Kicad, which i only had been using to draw schematics (besides fritzing) , i learned to create a pcb.
Which gave me the idea to make a print for the power-on-reset for the 6502. Which is going to be the first PCB by ordering, instead of the old skool messing around with DIY print making. (see next post)

….. Oh, why my display was not working?
I even connected my 8bit logic analyzer to the pins of the display.

Everything was correct.
But i didn’t use a variable resistor for the contrast. Just a simple resistor i could find. Luckily … bigreds stash.
All those hours debugging, all for one resistor!
(I have to mention, we had a suspicion halfway. But it was too hot and we where too lazy to go to Bigred’s campervan, to get a potentiometer. )

Goodies from Bigred

DIY 6502 – VIC (Versatile Interface Adapter)

65c22 connected, new data, and address-bus ribboncables!

First led on Register B blinking!

Notes:
Temporary display wil be 2×16 Chars.
Ram in place, but not connected (is emulated by the Arduino Mega at the moment)
Rom is somewhere halfway the atlantic ocean .. still waiting on that one.
Ben Eatons clock module is disconnected, i’m using the Arduino as programmable clock right now.
(There wil be a little display and a rotary encoder to set clock speed.)

lda #$ff ; all bits
sta $6002 ; set direction (out) for B register
lda #$80 ; set 1 bit
sta $6000 ; set register B
lda #$00 ; reset bit
sta $6000 ; set register B
jmp $8005 ; jmp to bit set part

MCH2022 Badge

Almost … friday will be the day i’ll attend May Contain Hackers.
Besides the awesome villages and talks.

UPDATE: 20220727
UPDATE: 20220812

You get a hackable badge, this one is more amazing as previous versions.

I can’t wait to have a go at this cool gadget. I personally could do without the pcb fancy design.

  • Espressif ESP32 Wrover-E with 16MB of flash storage and paired with 8MB of PSRAM, for front-end badge computing and compatibility with the badge.team ecosystem back to the 2017 SHA badge.
  • Lattice ICE40UP5K FPGA for hardware-accelerated graphics and user FPGA hardware designs.
  • Raspberry Pi RP2040 for advanced USB communication and board management.
  • 2Ah LiPo battery to give you a full day of fun on a charge.
  • 16-bit DAC with stereo output to headphone socket, onboard mono speaker.
  • ILI9341 2.2 inch TFT display with a 240 by 320 pixel resolution.
  • Bosch BNO055 orientation sensor.
  • Bosch BME680 environmental sensor.
  • The usual array of addressable LEDs.
  • SAO and Qwiic expansion connectors, FPGA PMOD expansion, plus onboard prototyping area.

Downloadable apps, micro python, Arduino ide programming.
All kinds of GPIO pins, leds buttons, sound.
Check out https://hatchery.badge.team/

You can play with this virtually here!
https://wokwi.com/projects/335445228923126356

So much potential! Great start for a DIY project.

I won’t post about the workings, thats all well documented online.
I shall post about the hacks/findings i personally did.

UPDATE: 20220727
Made a micropython program to keep your NameTag level to the ground (Better version)

UPDATE: 20220812

Someone made a 8bit logic analyser using the pmod connector !

6502 and Arduino (due to missing components)

(Work in process, will certainly change)

Due to eeproms being scarce, i’m going to use a arduino as Rom emulator.
Below is a test setup i’m going to build.

Made the drawing in Kicad.

KiCad is a free software suite for electronic design automation. It facilitates the design and simulation of electronic hardware. It features an integrated environment for schematic capture, PCB layout, manufacturing file viewing, SPICE simulation, and engineering calculation.

Memory assignment:

$8000-FFFF - Rom
$4000-7FFF - Ram ?
$2000-3FFF - Multiple times the 6522 *
$0000-???? - Ram probably

* This is due to the fact i am only using Address lines: 0,1,2,3,13,14,15

Screens and DIY projects

Below some examples and connection diagrams to control displays.
More code and complete schematics will be added on this page or on a separate projects page.

UPDATE 20230119 Cost of 20×4 display in 1998

LCD

I’ve used a LCD display like this (HITACHI HD44780) on my PC in the 90s, and also written code to use this as a monitoring device on my amiga.

On Linux i used LcdProc – This module also was equiped with a serial connector
Now (2023) it is 8 euros!
;LCD Display Module             Parallel port
;        1 Vss                  20 GND
;        2 Vdd                  14 +5V
;        3 Vlc                  20 GND (contrast LCD display)
;        4 RS (register select) 11 BUSY
;        5 R/W                  12 POUT
;        6 E (enable)           13 SEL
;        7 DB0                   2 D0
;        8 DB1                   3 D1
;        9 DB2                   4 D2
;       10 DB3                   5 D3
;       11 DB4                   6 D4
;       12 DB5                   7 D5
;       13 DB6                   8 D6
;       14 DB7                   9 D7
Amiga code part
        bsr     initprt         ; CIA 8520 init
        bsr     initlcd         ; init lcd display module
        move.l  #0,d0
        rts

initprt:move.b  #$ff,$bfe301    ; parallel port is output
        move.b  $bfd200,d0
        ori.b   #$07,d0         ; select, p-out and busy
        move.b  d0,$bfd200      
        rts

initlcd:move.w  #$38,d0         ; multiple reset
        bsr     send
        bsr     delay2
        move.w  #$38,d0
        bsr     send
        bsr     delay2
        move.w  #$38,d0         ; 2*8 lines
        bsr     send
        bsr     delay2
        move.w  #$01,d0         ; clear display
        bsr     send
        bsr     delay2          ; wait
        move.w  #$0c,d0         ; display on
        bsr     send
        move.w  #$06,d0         ; Entry Mode Set
        bsr     send
        rts

send:   bsr     delay
        btst    #8,d0           ; test rs bit
        beq     reg0
        bsr     rs1             ; select register 1
        bra     skip
reg0:   bsr     rs0             ; select register 0
skip:
        bsr     delay
        bsr     rw0             ; read/write=0 
        bsr     delay
        bsr     e1              ; enable = 1
        bsr     delay
        move.b  d0,$bfe101      ; push data
        bsr     delay
        bsr     e0              
        bsr     delay
        rts

delay:  move.w  #$20,d1
dloop:  subi    #1,d1
        bne     dloop
        rts

delay2: move.w  #$800,d1
dloop2: subi    #1,d1
        bne     dloop2
        rts
Part of my MQTT display alarm thingy
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>  
LiquidCrystal_I2C lcd(0x27, 20, 4);
const char* ssid = "MYACCESSPOINT";
const char* password = "MYPASSWORD";
const char* mqtt_server = "mymqttserver";
const byte ledRed = 12;
const byte horn = 13;
int button = 2;
int press = 0;
boolean buttonToggle = true;


// Todo : DISPLAY 2ND LINE, DISPLAY SILENT, ...

WiFiClient espClient;
PubSubClient client(espClient);
bool toggle = false;
void setup_wifi() {
  delay(100);

  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length)
{
  if (length > 0) {
    toggle = true;
  }

  if (length == 0) {
    toggle = false;
  }

  Serial.print("Command from MQTT broker is : [");
  Serial.print(topic);

  Serial.println();
  Serial.print(" publish data is:");
  lcd.clear();
  lcd.backlight(); // turn off backlight

  {
  
    for (int i = 0; i < length; i++)
    {
      Serial.print((char)payload[i]);
      if (i < 16){
      lcd.setCursor(0, 0);
      lcd.setCursor(i, 0);
      } else {
      lcd.setCursor(0, 1);
      lcd.setCursor(i-16, 1);
      }
      lcd.write((char)payload[i]);
    }
  }


  Serial.println();
} 

void reconnect() {
  
  while (!client.connected())
  {
    Serial.print("Attempting MQTT connection...");
    
    String clientId = "mqttlcd";
    clientId += String(random(0xffff), HEX);

    if (client.connect(clientId.c_str()))
    {
      Serial.println("connected");

      client.subscribe("mqttlcd/message");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(6000);
    }
  }
} 

void setup() {
  Serial.begin(115200);
  pinMode(button, INPUT);
  digitalWrite(2, HIGH);
  pinMode(ledRed, OUTPUT);
  digitalWrite(ledRed, LOW);
  pinMode(horn, OUTPUT);
  digitalWrite(horn, LOW);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  lcd.init(); 
  lcd.backlight();
}

void loop() {

  
  if (!client.connected()) {
    reconnect();
  }
  if (toggle == true) {
    digitalWrite(ledRed, HIGH);
    digitalWrite(horn, HIGH);
    delay(200);
    digitalWrite(ledRed, LOW);
    digitalWrite(horn, LOW);
    delay(200);
  }
  if (toggle == false) {
    digitalWrite(ledRed, LOW);
    digitalWrite(horn, LOW);

  }

  client.setCallback(callback);
  client.loop();

  press = digitalRead(button);
  if (press == LOW)
  {
    if (buttonToggle)
    {
      digitalWrite(ledRed, HIGH);
      digitalWrite(horn, HIGH);
      buttonToggle = !buttonToggle;
    }
    else
    {
      digitalWrite(ledRed, LOW); 
      digitalWrite(horn, LOW);
      buttonToggle = !buttonToggle;
      toggle = false;
      client.publish("mqttlcd/button","pressed");
      lcd.clear();
      lcd.noBacklight(); // turn off backlight
    }
  }
  delay(500);  //delay for debounce
}

Oled

There are several oled displays, mostly controllable with i2c but some of them are SPI

SSD1306 – I2c connected

Using a wemos – Octoprint project for example
Octoprint (Note: this is NOT a multicolor display 1/4 of the display is yellow. )
My notification watch. Runs on a ESP12F connects to Wifi, has a piezo sound element
Using a raspberry (Part of my Lab Sensors Project)
pip3 install adafruit-circuitpython-ssd1306
git clone https://github.com/adafruit/Adafruit_Python_SSD1306 (old)
Edit file - comment SPI section

Some arduino’s have embedded displays like those i’ve used for a Lora project.

Other means of connecting : SPI

SPI connected display

Nextion

Nextion is a Human Machine Interface (HMI) solution combining an onboard processor and memory touch display with Nextion Editor software for HMI GUI project development.

Using the Nextion Editor software, you can quickly develop the HMI GUI by drag-and-drop components (graphics, text, button, slider, etc.) and ASCII text-based instructions for coding how components interact on the display side.

Nextion HMI display connects to peripheral MCU via TTL Serial (5V, TX, RX, GND) to provide event notifications that peripheral MCU can act on, the peripheral MCU can easily update progress, and status back to Nextion display utilizing simple ASCII text-based instructions.

My nextion domoticz box, tilt to wakeup
Domoticz controller

My biltong box using a Nextion

Raspberry displays

 3.5inch RPi Display – 480×320 Pixel – XPT2046 Touch Controller
edit cmdline.txt
add "fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo"
at the end
edit config.txt
add between custom comments at the bottom
dtoverlay=piscreen,speed=24000000,rotate=90
# Or check http://www.lcdwiki.com/3.5inch_RPi_Display

Above display’s i’ve used for Picore Players and the Lidar POC

To try: Getting above display running with a arduino
https://github.com/PaulStoffregen/XPT2046_Touchscreen

Raspberry HDMI display

Easiest of them all, just connect with HDMI, there is a adaptor for hdmi-hdmi (versions 1,2,3) and hdmi-mini-hdmi for RPi4 variants.

Epaper and 7-Segment displays

Other means of displaying information are for example

Epaper

ESP with epaper module, disconnected power for a while, artifacts appear.

7 Segment displays

I used a lot of 7-Segment display’s in the past. They look cool and are hardcore.

My homebrew computer uses this

Nixie tubes!

And there are https://en.wikipedia.org/wiki/Nixie_tube .. I’ve never had those

Above bigger 2D display i used with Wled and a digital microphone, so its sound reactive. The lower part i got in recently .

inmp441 digital microphone