Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:38 22 Jan 2022 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Pi-cromite Version 5.04.16

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5688
Posted: 09:27am 12 Jan 2018
Copy link to clipboard 
Print this post

Please find attached V5.04.16

for Stretch

2018-01-12_224620_mmbasicstretch.zip

and for Jessie

2018-01-12_224632_mmbasicjessie.zip

Manual

2018-01-13_192334_Pi-cromite_Manual.pdf

This fixes a bug in the PEEK command and also implements the USER display driver capability of Geoff's version 5.4.09. In addition it includes a new font #7 which is a small 6x8 font ideal for smaller displays. NB the Pi-cromite does not support loadable fonts.

This is a huge advantage on the Pi-cromite where we can't have CFunctions. MMBasic is very fast on the Pi-cromite and drivers in Basic perform well





The picture shows an ST7920 based 128x64 display (QC12864B) being driven by a SPI user driver on a Pi Zero-W. The code is attached below and will also work unchanged on any of the Micromites (other than adjusting the pin numbers)

userdisplayinit
Line 0,0,MM.HRes-1,MM.VRes-1
Line MM.HRes-1,0,0,MM.VRes-1
Box 0,0,MM.HRes,MM.VRes
Text MM.HRes/2,MM.VRes/2,"Hello World",CM
End
'
Sub userdisplayinit
Option explicit
Option default none
On error skip
'if OPTION is already set then ignore the error
Option LCDPANEL USER, 128,64
On error skip
'don't error if Global variables not yet defined
Erase S$(), tmaskarray(), bmaskarray(), LCD_RESET, LCD_CD, LCD_CMD, LCD_DATA
Dim S$(MM.VRes-1) length MM.HRes\4
Dim integer tmaskarray(3)=(240,112,48,16)
Dim integer bmaskarray(3)=(128,192,224,240)
Dim INTEGER LCD_RESET=22 ' pin for chip select
Dim INTEGER LCD_CD=24 ' pin for Reset
Dim INTEGER LCD_CMD=&B11111000
Dim INTEGER LCD_DATA=&B11111010
Local i%
On error skip
'don't error if SPI already open
SPI open 100000,3,8
Pin(LCD_RESET)=1
Pin(LCD_CD)=1
SetPin LCD_RESET,dout
SetPin LCD_CD,dout
Pin(LCD_RESET)=0
Pause 200
Pin(LCD_RESET)=1
Pause 200
Pin(LCD_CD)=1
' continuous enable for the moment
LCD.CMD(1) 'DISPLAY CLEAR
LCD.CMD(&B00001100) 'display on
LCD.CMD(1) 'DISPLAY CLEAR
LCD.CMD(&B00100110) 'graphic mode
For i% = 0 To MM.VRes-1
s$(i%)=String$(MM.HRes\4,Chr$(&H0))
Next i%
update 0, 0, ((MM.HRes-1)\16), MM.VRes-1
End Sub
'
Sub MM.USER_RECTANGLE(x1%, y1%, x2%, y2%, fcol%)
If x1%=0 And y1%=0 And x2%=MM.HRes-1 And y2%=MM.VRes-1 Then
Local b$, i%
If fcol% Then
b$=String$(MM.HRes\4,Chr$(&HF0))
Else
b$=String$(MM.HRes\4,Chr$(0))
EndIf
For i% = 0 To MM.VRes-1
s$(i%)=b$
Next i%
Else
Local integer i, j, k, l, t, left_x,right_x, mask,emask
Local b$
'print "userrectangle ", x1%, y1%, x2%, y2%, fcol%
If x2% <= x1% Then
t = x1%
x1% = x2%
x2% = t
EndIf
If y2% <= y1% Then
t = y1%
y1% = y2%
y2% = t
EndIf
If x1% < 0 Then x1% = 0
If x1% >= MM.HRes Then x1% = MM.HRes - 1
If x2% < 0 Then x2% = 0
If x2% >= MM.HRes Then x2% = MM.HRes - 1
If y1% < 0 Then y1% = 0
If y1% >= MM.VRes Then y1% = MM.VRes - 1
If y2% < 0 Then y2% = 0
If y2% >= MM.VRes Then y2% = MM.VRes - 1
left_x=x1%\4
right_x=x2%\4
If left_x=right_x Then
If (fcol%) Then
mask =(tmaskarray(x1% Mod 4) And bmaskarray(x2% Mod 4))
Else
mask = notmask%(tmaskarray(x1% Mod 4) And bmaskarray(x2% Mod 4))
EndIf
For t=y1% To y2%
l= Peek(var S$(t),left_x+1)
If (fcol%) Then
l=l Or mask
Else
l=l And mask
EndIf
Poke var S$(t),left_x+1, l
Next t
Else
If (fcol%) Then
mask =tmaskarray(x1% Mod 4)
emask=bmaskarray(x2% Mod 4)
Else
mask = notmask%(tmaskarray(x1% Mod 4))
emask= notmask%(bmaskarray(x2% Mod 4))
EndIf
For t=y1% To y2%
If fcol% Then
l=Peek(var S$(t),left_x+1)
l=l Or mask
Poke var S$(t),left_x+1, l
l=Peek(var S$(t),right_x+1)
l=l Or emask
Poke var S$(t),right_x+1, l
Else
l=Peek(var S$(t),left_x+1)
l=l And mask
Poke var S$(t),left_x+1, l
l=Peek(var S$(t),right_x+1)
l=l And emask
Poke var S$(t),right_x+1, l
EndIf
Next t
If left_x+1<=right_x-1 Then
If fcol% Then
b$=String$(right_x-left_x-1, Chr$(240))
Else
b$=String$(right_x-left_x-1, Chr$(0))
EndIf
For t=y1% To y2%
s$(t)=Left$(s$(t),left_x+1)+b$+Right$(s$(t),32-right_x)
Next t
EndIf
EndIf
EndIf
update x1%\16, y1%, x2%\16, y2%
End Sub
'
'
Sub MM.USER_BITMAP(x1%, y1%, width%, height%, scale%, fcol%, bcol%, bitmap%)'bitmap is in string bitmap$
' print "userbitmap ", x1%, y1%, width%, height%, scale%, fcol%, bcol%
Local INTEGER i, j, k, mask, m, l, ll, t, tt, vCd, hCd, x, y, a%=height% * width%, ln%, c2%, c3%, c4%
vCd = y1%
If y1% < 0 Then y1% = 0 ' the y coord is above the top of the screen
For i = 0 To height%-1 ' step thru the font scan line by line
ln%=i * width%
For j = 0 To scale%-1 ' repeat lines to scale the font
vCd=vCd+1
If vCd >= 0 Then ' we are above the top of the screen
y=vCd - 1
If vCd > MM.VRes Then GoTo D_UP ' we have extended beyond the bottom of the screen
hCd = x1%
For k = 0 To width%-1 ' step through each bit in a scan line
c2%=ln% + k
c4%=(a% - c2% - 1) Mod 8
t=Peek(BYTE bitmap% + c2%\8)
tt = (t >> c4%) And 1 'we now know if the pixel is on or off
For m = 0 To scale% -1 ' repeat pixels to scale in the x axis
hCd = hCd +1' we have not reached the left margin
If hCd >= 0 Then
If hCd <= MM.HRes Then ' check are we beyond the right margin
x=hCd -1
mask=1<<(7-(x Mod 4))
c3%=notmask%(mask)
ll= Peek(var S$(y),x\4+1)
If tt Then
If fcol% Then
ll = ll Or mask
Else
ll = ll And c3%
EndIf
Else
If bcol%<>-1 Then 'transparent text
If bcol% Then
ll = ll Or mask
Else
ll = ll And c3%
EndIf
EndIf
EndIf
Poke var S$(y), x\4+1, ll
EndIf
EndIf
Next m
Next k
EndIf
Next j
Next i
D_UP:
update x1%\16, y1%, x\16, y
End Sub
'
Sub LCD.CMD(databyte As integer)
Local integer i,J
SPI write 3,LCD_CMD, DATABYTE And &HF0, (DATABYTE And &H0F)<<4
Pause 2
End Sub
'
Sub SetXY(x As integer, y As integer)
Local integer xx=x<<4,yy=y
If yy>31 Then
xx=xx+128
yy=yy-32
EndIf
SPI write 5, LCD_CMD, (yy And &H10) Or &H80, yy<<4, &H80, xx
Pause 1
End Sub
'
Sub update(x1%, y1%, x2%, y2%)
Local b$, i%
Pin(LCD_CD)=1 ' enable
For i% = y1% To y2%
If i%<MM.VRes Then
SetXY(x1%,i%)
b$=Chr$(LCD_DATA)+Mid$(s$(i%),x1%*4 +1, (x2%-x1%+1)*4)
SPI WRITE Len(b$),b$
EndIf
Next i%
Pin(LCD_CD)=0 ' disable
End Sub
'
Function notmask%(x%)
notmask% = (-1 Xor x%) And &HFF
End Function




Edited by matherp 2018-01-14
 
Micro-80
Newbie

Joined: 03/03/2017
Location: Russian Federation
Posts: 26
Posted: 07:52am 01 Feb 2018
Copy link to clipboard 
Print this post

The manual says that there are two serial ports COM1 and COM2. COM2 on the 7-Tx and 11-Rx pins. Can I reassign COM2Rx to a different PIN? The project needs COM2, and pin 11 is occupied by HAT.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 831
Posted: 07:58pm 01 Feb 2018
Copy link to clipboard 
Print this post

In your sample code, you have the following:

Line 0,0,MM.HRes-1,MM.VRes-1
<skip>
Box 0,0,MM.HRes,MM.VRes

It appears the bottom right corner of the screen is in different places for the Line and Box commands. Why is that?
Visit Vegipete's *Mite Library for cool programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5688
Posted: 10:09am 02 Feb 2018
Copy link to clipboard 
Print this post

  Quote  It appears the bottom right corner of the screen is in different places for the Line and Box commands. Why is that?


Check the MM+ manual
line x1,y1,x2,y2
box x,y,w,h

  Quote  The manual says that there are two serial ports COM1 and COM2. COM2 on the 7-Tx and 11-Rx pins. Can I reassign COM2Rx to a different PIN? The project needs COM2, and pin 11 is occupied by HAT.


At the moment this is hardwired. I'll look at it in a future release
 
Micro-80
Newbie

Joined: 03/03/2017
Location: Russian Federation
Posts: 26
Posted: 08:47am 03 Feb 2018
Copy link to clipboard 
Print this post

Thank you Peter!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1511
Posted: 06:06pm 11 May 2018
Copy link to clipboard 
Print this post

Peter I've been reading the manual as well as all the pages I can find about using a Pi on here
I only have 1 question (at the moment)
IF I wanted to make an interface board for an SDD1963 I know you've put the pin numbers in the manual but it doesn't say if you can use the SD card on there that I can see

Can you? and if you can is there specific pin numbers to use?

Or am I going stupid and you actually just use the SPI pins?

(I know nothing about how SD cards work in reading/writing yet but I plan on learning)

By the way, Amazing work, it's prompted me to buy a Raspberry Pi Zero W today/

EDIT:

Can you use the SD card on the Pi to store pictures to be used with Pi-cromite?
And Can you use touch if you use a HDMI display with touch built in?
Edited by lew247 2018-05-13
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5688
Posted: 09:34pm 11 May 2018
Copy link to clipboard 
Print this post

  Quote  but it doesn't say if you can use the SD card on there that I can see


No, you just use the SDcard that is on the Pi

  Quote  Can you use the SD card on the Pi to store pictures to be used with Pi-cromite?


Yes

  Quote  And Can you use touch if you use a HDMI display with touch built in?


No
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 1856
Posted: 02:57am 26 Nov 2018
Copy link to clipboard 
Print this post

As of now, the link in the manual (v5.4.16) for installing pigpio software version 64 is timing out: http://abyz.co.uk/rpi/pigpio/download.html

I've just loaded the latest raspbian stretch lite and I think the latest mmbasic (11/17). How do I install the right version of pigpio?

Never mind. I found it here: http://abyz.me.uk/rpi/pigpio/download.html
Edited by lizby 2018-11-27
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 560
Posted: 03:08am 26 Nov 2018
Copy link to clipboard 
Print this post

Last time I installed Raspbian it was already included.
You can check with the command below to see if its already installed

pigpiod -v


Not sure if you have seen this one.
This thread has latest versions of MMBasic for Pi Edited by disco4now 2018-11-27
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2022