Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 16:55 19 May 2024 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 : Q: RP2040-LCD-0.96-M and PicoMite?

     Page 3 of 4    
Author Message
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 187
Posted: 06:57pm 07 Jun 2023
Copy link to clipboard 
Print this post

Hi Martin, thank you for the code!

I copied the program text out of your posting and pasted it in to the text file "maze.bas" - then I fired up MMEdit, loaded "maze.bas" and pressed F2 for "Deploy". After 5.3 seconds it was loaded into the RP2040. After that I take PuTTY to connect again and RUN the program.

It feels like DOOM but where is the gun?  



-andreas
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 187
Posted: 07:07pm 07 Jun 2023
Copy link to clipboard 
Print this post

  stanleyella said  Mine arrived today. From Andreas I used his
OPTION SYSTEM SPI GP10,GP11,GP12
OPTION LCDPANEL ST7735S, LANDSCAPE,GP8,GP0,GP9,GP25
It does graphics fine. Thanks all. Do I use above or
SYSTEM SPI GP10, GP11, GP12
LCDPANEL ST7735S, L, GP8, GP12, GP9, GP25


Hello Stan,

as Mick told you there is a even better configuration.
Currently I'm using this.

> option list
PicoMite MMBasic Version 5.07.07
OPTION SYSTEM SPI GP10,GP11,GP28
OPTION AUTORUN ON
OPTION COLOURCODE ON
OPTION HEARTBEAT OFF
OPTION DISPLAY 50, 100
OPTION LCDPANEL ST7735S, LANDSCAPE,GP8,GP12,GP9,GP25


Micks procedure to get there:

OPTION RESET
OPTION SYSTEM SPI DISABLE
SETPIN GP28 OFF
OPTION SYSTEM SPI GP10,GP11,GP28
OPTION HEARTBEAT OFF
OPTION LCDPANEL ST7735S, LANDSCAPE,GP8,GP12,GP9,GP25

-andreas
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1655
Posted: 10:33pm 07 Jun 2023
Copy link to clipboard 
Print this post

Thanks Andreas, that worked ok and overclocking works ok.
This would be nice for a beginner as there is no wiring for a display.


Edited 2023-06-08 10:10 by stanleyella
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 923
Posted: 06:43am 08 Jun 2023
Copy link to clipboard 
Print this post

still testing  


'Mandelbrot
' for 160x80 LCD
'inspired by Matt Heffernan s 8-BIT BATTLE
'https://www.youtube.com/watch?v=DC5wi6iv9io
dim col(16) as integer
Restore colors:For f%=1 To 15:Read col(f%):Next f%
CLS
' max x and max y
DX=160:DY=80
For py=0 To DY-1
For px=0 To DX-1
 xz=px*3.5/DX-2.5
 yz=py*2/DY-1
 x=0
 y=0
 For i=0 To 15
   If x*x+y*y>4 Then Exit For
   xt = x*x - y*y + xz
   y= 2 * x * y + yz
   x=xt
 Next i
Pixel px,py,col(i)
Next px
Next py
colors:
'--Colorscheme accordung to matherp
Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED)
Data RGB(MAGENTA),RGB(YELLOW),RGB(WHITE),RGB(MYRTLE)
Data RGB(COBALT) ,RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST)
Data RGB(FUCHSIA),RGB(BROWN),RGB(LILAC)


actually the picture looks better than in the photo



Speed:
  Quote  
> option cpuspeed 127000
> RUN
22918.171
> option cpuspeed 252000
> RUN
11496.921
> option cpuspeed 378000
> RUN
7655.455

Edited 2023-06-08 16:55 by Martin H.
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3865
Posted: 06:55am 08 Jun 2023
Copy link to clipboard 
Print this post

Didn't want to be left out, but rather bigger (100mmx100mm) - don't need the keyboard though:



Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 923
Posted: 06:58am 08 Jun 2023
Copy link to clipboard 
Print this post

  thwill said  Didn't want to be left out, but rather bigger (100mmx100mm) - don't need the keyboard though:



Best wishes,

Tom

and much nicer
With the 320x240 LCD you could keep the Original Resolution so the map remained readable    
good work Tom
Edited 2023-06-08 17:00 by Martin H.
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3865
Posted: 07:15am 08 Jun 2023
Copy link to clipboard 
Print this post

  Martin H. said  With the 320x240 LCD you could keep the Original Resolution so the map remained readable.


Yes, this is a descendant of the version that I had running on the PicoGAME VGA.

It's a pity you never added the T-Rex.

Thanks for the program.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 923
Posted: 06:59am 09 Jun 2023
Copy link to clipboard 
Print this post

  thwill said  
It's a pity you never added the T-Rex.

Feel free to add Rex  
But for "3d Monster Maze" you'll need another kind of maze with multible possible ways to the exit.
I have polished up the LCD version so that the maze is now displayed correctly.





'Maze Game by Mart!n Herhaus 2022
'Version for 160x80 LCD 2023
Font 1
cw%=RGB(white):WallC1%=0:WallC2%=RGB(RED):cP%=RGB(green)
'Read the XY-Coordinates of the Wall Elements Corners
Dim Wall%(6,4,2)
For N%=0 To 5 'Walls
For C%=0 To 3 '4 Corners
 For F%=0 To 1 '2 Coordinates (X,Y)
   Read Wall%(N%,C%,F%)
 Next
Next
Next
MazeW%=20:MazeH%=24
' create array and fill
Dim Maze$(MazeW%,MazeH%) length 1
restart:
For x% = 0 To MazeW%
For y% = 0 To MazeH%
 Maze$(x%, y%) = "#"
Next :Next
'generate random Maze
generator
MovDir$=Chr$(146)+Chr$(148)+Chr$(147)+Chr$(149)
Map%=0:CLS cw%
'place Player
PlrX%=MazeW%-1:PlrY%=MazeH%-1:PD%=3
'place Exit
Ex_X%=2:Ex_Y%=0:If Maze$(Ex_X%,1)="#" Then Inc Ex_X%
Maze$(Ex_X%,Ex_Y%)="E"
If map% Then Box 243+Ex_X%*3,3+Ex_Y%*3,3,3,,WallC2%,WallC2%
Colour 0,cw%
Text 122,58,"D  X "
'Text 244,130,"KEYS:"
'Text 244,140,"W:FORWARD"
'Text 244,150,"A:TURN L."
'Text 244,160,"D:TURN R."
'Text 244,190,"M:SHOW/ "
'Text 244,204," HIDE MAP"
' --- Game Loop ---
Do
Text 122,70,Mid$(MovDir$,PD%+1,1)
Text 136,58,"X"+Str$(PlrX%)+" "
Text 136,70,"Y"+Str$(PlrY%)+" "
Draw_3D
Select Case PD%
 Case 0:XS%=0 :YS%=-1
 Case 1:XS%=1 :YS%=0
 Case 2:XS%=0 :YS%=1
 Case 3:XS%=-1:YS%=0
End Select
If map% Then Box 119+PlrX%*2,3+PlrY%*2,2,2,,cp%,cp%
Key$=""
Do :Key$=Inkey$:Loop While Key$=""
 Key$=UCase$(Key$)
 Select Case Key$
 Case "A",Chr$(130)
   Inc PD%,-1:Inc PD%,4*(PD%=-1):Box 0,0,120,80,,cw%,cw%
 Case "D",Chr$(131)
   Inc PD%:PD%=PD% And 3:Box 0,0,120,80,,cw%,cw%
 Case "W",Chr$(128)
   OX%=PlrX%:OY%=PlrY%
   Inc PlrX%,XS%:Inc PlrY%,YS%
   If Maze$(PlrX%,PlrY%)="#" Then PlrX%=OX%:PlrY%=OY%
   If Map% Then Box 119+ox%*2,3+oy%*2,2,2,,cw%,cw%
   Case "M"
   Map%=1*(Map%=0)
   If Map% Then
     Box 120,3,38,25,,cw%,cw%
     Show_Maze
     Box 119+Ex_X%*2,3+Ex_Y%*2,2,2,,255.255
   Else
     Box 120,3,38,25,,cw%,cw%
   EndIf
End Select
If PlrX%=Ex_X% And PlrY%=Ex_Y% Then Exit
Loop
Box 10,15,99,48,,0,cw%
Font 7
Text 12,20,"   WELL DONE!   "
Text 12,28,"PRESS Q TO QUIT "
Text 12,36,"OR ANY OTHER KEY"
Text 12,44," TO TRY ANOTHER "
Text 12,52,"     MAZE       "
Do :Key$=Inkey$:Loop While Key$=""
Font 1

If Key$="q" Then CLS 0:End
GoTo restart
'----------------------------
Sub show_maze
For y% = 0 To MazeH%
 For x% = 1 To MazeW%
     If Maze$(x%,y%)="#" Then Box 119+x%*2,3+y%*2,2,2,,0,0
 Next x%
Next y%
End Sub


Sub draw_3d
'Box 0,0,120,80,,cw%,cw%
Select Case PD%
Case 0
  For f%=0 To 5
    If PlrY%-f%<0 Then Exit For
    If Maze$(PlrX%-1,PlrY%-f%)="#" Then Draw_Element f%,0,0 Else Draw_Element f%,0,1
    If Maze$(PlrX%+1,PlrY%-f%)="#" Then Draw_Element f%,1,0 Else Draw_Element f%,1,1
    If Maze$(PlrX%,PlrY%-f%)="#" Then Draw_Element f%,1,2:Exit For
  Next f%
 Case 1
   For f%=0 To 5
     If PlrX%+f%>MazeW% Then Exit For
     If Maze$(PlrX%+f%,PlrY%-1)="#" Then Draw_Element f%,0,0 Else Draw_Element f%,0,1
     If Maze$(PlrX%+f%,PlrY%+1)="#" Then Draw_Element f%,1,0 Else Draw_Element f%,1,1
     If Maze$(PlrX%+f%,PlrY%)="#" Then Draw_Element f%,1,2:Exit For
     Next f%
 Case 2
   For f%=0 To 5
    If PlrY%+f%>MazeH% Then Exit For
    If Maze$(PlrX%+1,PlrY%+f%)="#" Then Draw_Element f%,0,0 Else Draw_Element f%,0,1
    If Maze$(PlrX%-1,PlrY%+f%)="#" Then Draw_Element f%,1,0 Else Draw_Element f%,1,1
    If Maze$(PlrX%,PlrY%+f%)="#" Then Draw_Element f%,1,2:Exit For
  Next f%
Case 3
  For f%=0 To 5
    If PlrX%-f%<0 Then Exit For
    If Maze$(PlrX%-f%,PlrY%+1)="#" Then Draw_Element f%,0,0 Else Draw_Element f%,0,1
    If Maze$(PlrX%-f%,PlrY%-1)="#" Then Draw_Element f%,1,0 Else Draw_Element f%,1,1
    If Maze$(PlrX%-f%,PlrY%)="#" Then Draw_Element f%,1,2:Exit For
  Next f%
End Select
End Sub
'draw the elements
Sub Draw_Element nr%,mir%,Gap%
Local x1%,y1%,x2%,y2%,x3%,y3%,x4%,y4%
x1%=Wall%(nr%,0,0):y1%=Wall%(nr%,0,1)
x2%=Wall%(nr%,1,0):y2%=Wall%(nr%,1,1)
x3%=Wall%(nr%,2,0):y3%=Wall%(nr%,2,1)
x4%=Wall%(nr%,3,0):y4%=Wall%(nr%,3,1)
If mir% Then x1%=120-x1%:x2%=120-x2%:x3%=120-x3%:x4%=120-x4%
WallC1%=RGB(0,64,0):WallC2%=RGB(0,128,0)
If Not Gap% Then
 'Wall
 Triangle x1%,y1%,x2%,y2%,x4%,y4%,WallC1%,WallC1%
 Triangle x1%,y1%,x3%,y3%,x4%,y4%,WallC1%,WallC1%
 ElseIf Gap%=1 Then
     'Gap
     Triangle x1%,y1%,x2%,y2%,x4%,y4%,cw%,cw%
     Triangle x1%,y1%,x3%,y3%,x4%,y4%,cw%,cw%

     Triangle x1%,y3%,x3%,y3%,x4%,y4%,WallC2%,WallC2%
     Triangle x1%,y4%,x1%,y3%,x4%,y4%,WallC2%,WallC2%
   Else
    'Blocker
     Triangle x1%,y1%,120-x1%,y1%,120-x1%,y2%,WallC2%,WallC2%
     Triangle x1%,y1%,120-x1%,y2%,x1%,y2%,WallC2%,WallC2%
   EndIf
EndIf
End Sub

' --- 2D Maze generator ---
' algorithmen based on
' https://rosettacode.org/wiki/Maze_generation#BASIC256
' --------------------------
Sub generator
Local done%,i%,CurX%,CurY%,OldX%,OldY%,x%,y%
' initial start location
CurX%=Int(Rnd * (MazeW% - 1))
CurY%=Int(Rnd * (MazeH% - 1))
' value must be odd
If CurX% Mod 2=0 Then Inc CurX%
If CurY% Mod 2=0 Then Inc CurY%
Maze$(CurX%, CurY%) = " "
' generate maze
done%=0
Do While done%=0
   For i% = 0 To 99
     OldX%=CurX%
     OldY%=CurY%
     ' move in random direction
     Select Case Int(Rnd*4)
         Case 0
             If CurX%+2<MazeW% Then Inc CurX%,2
         Case 1
             If CurY%+2<MazeH% Then Inc CurY%,2
         Case 2
             If CurX%-2>0 Then Inc CurX%,-2
         Case 3
             If CurY%-2>0 Then Inc CurY%,-2
     End Select
     ' if cell is unvisited then connect it
     If Maze$(CurX%,CurY%)="#" Then
         Maze$(CurX%,CurY%)=" "
         Maze$(Int((CurX%+OldX%)/2),((CurY%+OldY%)/2))=" "
     EndIf
 Next i%
 ' check if all cells are visited
 done%=1
 For x%=1 To MazeW%-1 Step 2
     For y%=1 To MazeH%-1 Step 2
         If Maze$(x%,y%)="#" Then done%=0
     Next y%
 Next x%
Loop
End Sub
' --- WallData (160x80)---
Data  0, 0, 0, 80, 5, 3, 5, 76
Data  6, 4, 6, 76, 25, 17, 25, 63
Data  26, 17, 26, 63, 40, 27, 40, 53
Data  41, 27, 41, 53, 50, 33, 50, 46
Data  51, 34, 51, 46, 55, 37, 55, 43
Data  56, 37, 56, 43, 60, 40, 60, 40
                                 


cheers

 Mart!n
'no comment
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 187
Posted: 07:22am 09 Jun 2023
Copy link to clipboard 
Print this post

  stanleyella said  Thanks Andreas, that worked ok and overclocking works ok.
This would be nice for a beginner as there is no wiring for a display.



Yes! The only thing I'm missing is wireless on the RP2040-LCD chip. So I'm using a second pico w as interface to the world. It starts to become a little computer in a matchbox :-)

-andreas
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 187
Posted: 07:26am 09 Jun 2023
Copy link to clipboard 
Print this post

Thanks for the new version  

-andreas
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 923
Posted: 07:53am 17 Jun 2023
Copy link to clipboard 
Print this post

a little firey treat.  

as it is able to Display more than 16 Colors

also runs on MM Basic for Windows or with other LCD types

H=80:W=160
Dim C(101) As integer
Dim Lne$(h,w) length 1
R=0:G=0:B=0
'Flamecolors
For f=0 To 100
C(f)=RGB(R,G,B)
Inc R,8*(R<247)
Inc G,4*(f>32)*(G<250)
Inc B,12*(F>80)
Next
CLS
Do
'For f=0 To 159:Lne$(H,f)=Chr$(0):Next
 For f=1 To 50
 px=Int(Rnd*w):CL=Int(100-(Rnd*30))
 Pixel px,h-1,c(CL)
 Lne$(H,px)=Chr$(CL)
 Next
 For f=h-1 To h/2 Step -1
   For n=1 To 158
       cl=Asc(Lne$(f+1,n-1))+Asc(Lne$(f+1,n))+Asc(Lne$(f+1,n+1))
  cl=cl/3: cl=cl-(Rnd*5):If cl<=0 Then cl=0
  lne$(f,n)=Chr$(cl):Pixel n,f-1,c(cl)
  Next
Next
Loop

have a nice Weekend
Edited 2023-06-17 17:55 by Martin H.
'no comment
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1655
Posted: 06:08pm 17 Jun 2023
Copy link to clipboard 
Print this post

I tried to write simple scope code for waveshare 2040 with lcd but it's rubbish. Had better results with 328.
Searched for scope code and not much.
How many samples could I expect at 378000 ?
Anyone made a picomite scope? This works... sort of, no sync.
 dim count%
 Dim samples!(160)
 Dim old_samples!(160)
'
 SETPIN GP26, AIN
 cls
 for count%=0 to 159
   samples!(count%)=PIN(GP26)'get new samples
 next count%
 
 for count%=0 to 159
   samples!(count%)=(samples!(count%)*20)+10 'scale 3V samples to 0 to 79 pixels
 next count%
 
 for count%=0 to 159
   old_samples!(count%)=samples!(count%) 'copy samples to old_samples
 next count%

 for count%=0 to 158
   line count%,samples!(count%),count%+1,samples!(count%)+1,1,rgb(white) 'draw first samples
 next count%
'--------  
 do
   for count%=0 to 159
     samples!(count%)=PIN(GP26)'get new samples
   next count%
   
   for count%=0 to 159
     samples!(count%)=(samples!(count%)*20)+10 'scale 3V samples to 0 to 79 pixels
   next count%
   
   for count%=0 to 158
     line count%,old_samples!(count%),count%+1,old_samples!(count%)+1,1,rgb(black) 'erase old_sample
     line count%,samples!(count%),count%+1,samples!(count%)+1,1,rgb(white) 'draw new sample
   next count%

   for count%=0 to 159
     old_samples!(count%)=samples!(count%) 'copy samples to old_samples
   next count%
 loop
end
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8606
Posted: 06:59pm 17 Jun 2023
Copy link to clipboard 
Print this post

Use the ADC command and you will get up to 500,000 samples per second
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 114
Posted: 07:16pm 17 Jun 2023
Copy link to clipboard 
Print this post

to martin h:

this is the look alike on picomiteVGA:


 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1655
Posted: 08:00pm 17 Jun 2023
Copy link to clipboard 
Print this post

  matherp said  Use the ADC command and you will get up to 500,000 samples per second

Hi Mathew. Thanks but replaced reading pin for command and NOT the same, if it does anything.
 'SETPIN GP26, AIN

adc open 1000,1

 cls
 'for count%=0 to 159
   'samples!(count%)=PIN(GP26)'get new samples
   adc start samples!(160)
 'next count%

I tried adc start samples!() and no display
"The size of the arrays defines the number of
conversions." so dim samples!(160) is 161 samples
Edited 2023-06-18 06:52 by stanleyella
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8606
Posted: 09:48pm 17 Jun 2023
Copy link to clipboard 
Print this post

  Quote  I tried adc start samples!() and no display


Look at Volhout's posthere
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1655
Posted: 10:12pm 17 Jun 2023
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I tried adc start samples!() and no display


Look at Volhout's posthere

Cheers but I don't see the relevance. From the manual it should fill the array with samples, or maybe not.
To add joy I can't get pwm working
setpin gp2, pwm 1
pwm 1,1000,50,50

RUN
[8] PWM 1,1000,50,50
Error : Pin not set for PWM

I'm using gp0, gp1 for sound.
I wanted to drive the scope with a wave from tone then try from pwm.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5771
Posted: 06:06am 18 Jun 2023
Copy link to clipboard 
Print this post

You can always recover a pin before doing something else with it:
SETPIN GP0, OFF

ADC keeps reading the pin and putting it into the array, at the speed you set. It does it in the background so it's very fast. Once the array is full it stops running, so you can plot that array then restart the ADC for the next set of points.

Follow Volhout's code for the ADC:

Set the ADC frequency (he's used  formula because of what he's doing. You don't need to)
Dimension a float array for the number of samples.
ADC open adc_freq, 1, ready_int opens the ADC for 1 channels and trigger interrupt when array is full.
ADC start array!() starts the ADC run and stores the values.

DO:LOOP We do nothing here, just wait for the ADC.
END

At the end of the scan the interrupt routine runs. You plot the values here.
Sub ready_int
ADC close
....
....
End Sub

You'll have to tweak things a bit because you want to keep re-trigggering the ADC after each plot, I suppose. For a scope you would often use a Trigger input to start the scan. Or you can keep triggering it automatically after each plot.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1655
Posted: 02:49pm 18 Jun 2023
Copy link to clipboard 
Print this post

Thanks Mick,it's working better.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 923
Posted: 03:40pm 18 Jun 2023
Copy link to clipboard 
Print this post

tiny little Program for DigiClock

CLS
Font 6:bl=0
Gr=RGB(128,128,128):DG=RGB(64,64,64):LG=RGB(192,192,192)
If Date$="01-01-2001" Then
 Input "Time Houre";h:Input "Time Minute";m:Date$="01-01-2023"
 Time$=Str$(h)+":"+Str$(m)
EndIf
Box 0,4,160,72,,Dg,Dg:Line 1,12,160,12,,LG:Line 1,13,160,13,,Gr
Line 1,68,160,68,,Gr:Line 1,67,160,67,,LG
Do
 Text 1,14,Left$(Time$,5):bl=Not(bl)
 If bl Then Box 78,14,8,40,,0,0
 Pause 1000:If Asc(Inkey$)=27 Then Exit
Loop

'no comment
 
     Page 3 of 4    
Print this page
© JAQ Software 2024