Page 1 of 1
Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 1:44 pm
by t0nyt
I thought I'd create a thread on i2c & Minerva Mk2 to document my adventures on the topic in case anyone else wants to have a play now or in the future. Hope that's ok.
The intention is to document the devices I or anyone else tries, and more specifically "quick and dirty" basic programs to prove functionality and later the creation of extensions to super basic in assembler
It's targeted at i2c on a Minerva Mk2 board (either original or a remake
https://github.com/alvaroalea/QL_Minerva_MK2) so the basic test programs use i2c_io_bin (which is assumed to have already been lrespr'd)
A remake of the Minerva Mk2
(I'm using 15 pin D connectors for i2c to maintain hardware compatibility with my BBC Model B's i2c)
A 2 x device harness

- IMG_5014.jpeg (43.35 KiB) Viewed 144 times
A harness for attaching a device to the 2 x device harness or to the Minerva Mk2 (with an HTU21D attached)

- IMG_5016.jpeg (31.55 KiB) Viewed 144 times
Re: Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 2:09 pm
by t0nyt
There's a multitude of i2c LCD displays so I chose a simple 4 lines x 20 characters as my first i2c device to try
Having blatantly copied the code by MartinB on StarDot it proved to be straightforward, so I assume other displays will hopefully be just as simple (maybe not the matrix style that I've not tried yet)
A typical 4x20 LCD (with harness attached)
The reverse shows the PCF8574 GPIO extender board for the i2c (this is a TI version with ID &27, NXP's use &3F)

- IMG_5019.jpeg (58.94 KiB) Viewed 135 times
A simple basic test program
Code: Select all
30 PROC_INIT
40 DIM M$(80) : M$="SINCLAIR QL JS/Minerva v1.98 Mk2i2c LCD Interface "
50 FOR C=1 TO LEN(M$)
60 D$=M$(C TO C)
70 C%=CODE(D$)
80 H%=(C% && HEX('F0')) || HEX('09')
90 L%=((C%*16) && HEX('F0')) || HEX('09')
100 D%=H%
110 PROC_EN
120 D%=L%
130 PROC_EN
140 NEXT C
150 STOP
160 DEFine PROCedure PROC_INIT
170 DATA HEX('38'),HEX('38'),HEX('38'),HEX('28'),HEX('28'),HEX('88')
175 DATA HEX('08'),HEX('88'),HEX('08'),HEX('18'),HEX('08'),HEX('68')
180 DATA HEX('08'),HEX('E8'),HEX('88'),HEX('08')
190 RESTORE 170
200 FOR D=0 TO 15
210 READ D%
230 PROC_EN
240 NEXT D
250 END DEFine
260 DEFine PROCedure PROC_EN
270 D%=D% || HEX('04')
280 I2CTXB(D%) : REMark *I2CTXB 3F D%
290 D%=D% && HEX('FB')
300 I2CTXB(D%) : REMark *I2CTXB 3F D%
310 END DEFine
500 DEFine PROCedure I2CTXB(D%)
510 LOCal r$
520 r$=I2C_IO(CHR$(164) & CHR$(D%) & CHR$(255),0,HEX('27'),1)
530 END DEFine
Example output
Re: Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 2:21 pm
by t0nyt
Next up was an HTU-21D Temperature/Relative Humidity sensor
Device id &40

- IMG_5017.jpeg (35.78 KiB) Viewed 131 times
This was the first device I tried where information was being read back and it proved to be a difficult learning curve (see post
viewtopic.php?t=5402) and hair puller (not that I have that much now) so a big thanks to those who contributed
The main problem, having worked out the i2c_io syntax, was that Minerva Mk2 doesn't implement clock stretching so i2c_io didn't wait for the measurement to be made before trying to read the result. So it was necessary to split the measurement request and read request into separate i2c_io commands and pause in-between them
The test code
Code: Select all
100 c$=CHR$(164) & CHR$(HEX('FE')) & CHR$(255): REMark Soft Reset
110 r$=I2C_IO(c$,0,HEX('40'),1)
120 PAUSE 20 : REMark pause after reset?
130 r$=GetValue("T"): PRINT "Temperature: " & r$ & "c"
140 r$=GetValue("H"): PRINT "Relative Humidity: " & r$ & "%"
150 DEFine FuNction GetValue(V$)
160 LOCal e,v,c$,r$
170 SELect ON V$
180 ="H","h": e=HEX("E5") : REMark Relative Humidity
190 ="T","t": e=HEX("E3") : REMark Temperature
200 END SELect
210 c$=CHR$(164) & CHR$(e) & CHR$(255)
220 r$=I2C_IO(c$,0,HEX('40'),1)
230 PAUSE 200 : REMark WHAT PAUSE NEEDED???
240 c$=CHR$(2) & CHR$(188) & CHR$(255)
250 r$=I2C_IO(c$,3,HEX('40'),1)
300 v=CODE(r$(2 TO 2))
310 v=v&&253 : REMark strip status bits
320 v=v+(CODE(r$)*256)
330 SELect ON V$
340 ="H","h": v=-6+125*(v/65336)
350 ="T","t": v=-46.85+175.72*(v/65536)
360 END SELect
370 v=INT(v*10)/10
400 RETurn v
500 END DEFine
And the output
Because of the timing issues the super basic extension will have options to:
a) Measure/Wait/Read
b) Just Measure
c) Just Read
d) soft reset
Re: Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 5:24 pm
by dilwyn
Thank you t0nyt.
I have never dabbled with I2C, but it's still interesting to read about your experiences.
Re: Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 5:52 pm
by t0nyt
dilwyn wrote: Fri Sep 05, 2025 5:24 pm
Thank you t0nyt.
I have never dabbled with I2C, but it's still interesting to read about your experiences.
I'd heard of i2c but until earlier this year I'd never really looked into it. But am a bit besotted with it now (mainly because I don't have the knowledge to design/build any expansions myself!)
Many thanks
Tony
Re: Adventures with I2C & Minerva Mk2
Posted: Fri Sep 05, 2025 6:00 pm
by t0nyt
To save swapping connection harnesses around (or making new ones as it's fiddly work) I've attached one of these breakout boards
It also saves me having to look up my colour codes every time I swap things around too
Will also allow adding more than 2 x i2c devices when playing around (assuming QL can supply enough power!?)
Board with connector to Minerva Mk2 i2c with HTU21D attached