Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:07 03 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 : PicoMite/PicoMiteVGA V5.07.04 betas

     Page 5 of 7    
Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3553
Posted: 03:43pm 24 Feb 2022
Copy link to clipboard 
Print this post

@Peter,

What solution do you propose for the setpin ? I tried it, and you cannot use string either.


a$="GP0"
b$="DOUT"

setpin a$,b$
Error : Expected a number

setpin GP0,b$
Error : Syntax


So both GP0 and DOUT are MMBasic internal defines that cannot be supplied from within the program, not as numbers, not as strings. Or am I doing something wrong ?
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3848
Posted: 03:46pm 24 Feb 2022
Copy link to clipboard 
Print this post

  Volhout said  @Peter,

What solution do you propose for the setpin ? I tried it, and you cannot use string either.

a$="GP0"
b$="DOUT"

setpin a$,b$
Error : Expected a number

setpin GP0,b$
Error : Syntax

So both GP0 and DOUT are MMBasic internal defines that cannot be supplied from within the program, not as numbers, not as strings. Or am I doing something wrong ?


If/when EXECUTE is implemented you should be able to construct the whole command as a string and do:
a$="GP0"
b$="DOUT"
cmd$ = "SetPin " + a$ + "," + b$
EXECUTE cmd$


Best wishes,

Tom
Edited 2022-02-25 01:46 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 04:09pm 24 Feb 2022
Copy link to clipboard 
Print this post

  Quote  What solution do you propose for the setpin ? I tried it, and you cannot use string either.


How about select case? Not exactly difficult

sub mysetpin(mode%, pin%)
select case mode%
case 1
setpin pin%,dout
case 2
setpin pin%,din
.......
end select
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3553
Posted: 04:13pm 24 Feb 2022
Copy link to clipboard 
Print this post

Hi Tom,

That may be a solution. The current picomite implementation seems quite strict.

There is no #define (or I missed it) so I can not
#define "ADC_Input","GP26"
Setpin ADC_Input,AIN


This is possible in CMM2.

It looks like the GP0 and DOUT are not "evaluated" first but directly but are compared to pre-defined lookup table(s) when the setpin command is parsed.
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3553
Posted: 04:15pm 24 Feb 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote  What solution do you propose for the setpin ? I tried it, and you cannot use string either.


How about select case? Not exactly difficult

sub mysetpin(mode%, pin%)
select case mode%
case 1
setpin pin%,dout
case 2
setpin pin%,din
.......
end select


Thanks, that will work.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5735
Posted: 04:22pm 24 Feb 2022
Copy link to clipboard 
Print this post

Eh?
PicoMite doesn't have #define. It's not a CMM2. :)  I think this is the PicoMite version:

CONST ADC_Input = 31
SETPIN ADC_Input, AIN

Note that you can't substitute GP26 for the 31. You have to use the absolute pin number.
Mick

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

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 10:43pm 24 Feb 2022
Copy link to clipboard 
Print this post

mm.info(pinno GP6) saves you remembering the pinno.




>
> const adc_input = mm.info(pinno gp6)
> print adc_input
9
>

Latest F4 Latest H7
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 03:15am 25 Feb 2022
Copy link to clipboard 
Print this post

Here's a Picomite client accessed via serial (but otherwise following Geoff's example of the MX170 as an I2C slave in "A More Complex I2C Example" in the "Getting Started With the Micromite" guide).

I put LEDs on all the left side pins (I/O pins between the pin numbers 1 and 20).

Here's the picomite:

Here's a youtube video: Picomite serial client

Here's the master/server code running on MMB4W:
dim pins(16)=(1,2,4,5,6,7,9,10,11,12,14,15,16,17,19,20,0)

open "com11:115200" as #1
for i=0 to 15: print #1,chr$(1)+chr$(pins(i))+chr$(8)+chr$(13): pause 100: next i
for i=0 to 15: print #1,chr$(1)+chr$(pins(i))+chr$(0)+chr$(13): pause 100: next i
do:p=pins(fix(rnd*16)):v=fix(rnd*2):print #1,chr$(2)+chr$(p)+chr$(v)+chr$(13):pause 500: loop

The first FOR loop sets the pins as DOUT and the second FOR loop turns off all pins. The DO loop randomly selects a pin every half second and randomly sets it to on or off (1 or 0). No checking is done to determine whether the pin is already in the selected state.

And the client code:

' serialClient.bas acts on serial messages
' e.g. PRINT #1,chr$(1)+chr$(1)+chr$(8)+chr$(13)
OPTION AUTORUN ON
DIM integer msg(254), tempPins(40) ' array used to hold the message
dim float temps(40)
DIM string cmd, s$
 pause 3000
 print "Picomite SerialClient starting"
' I2C SLAVE OPEN &H26, 0, 0, WriteD, ReadD ' slave's address is 26 (hex)
 SetPin 22,21,com1 ' setpin 21,uart0tx:SetPin 22,uart0rx
 open "com1:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters

DO ' the program loops forever
 WATCHDOG 2000 ' this will recover from errors
LOOP

SUB SerInt ' received a message
 msg(0)=asc(input$(1,#1))
 if chr$(msg(0)) = "!" then
   pause 30 ' allow all characters in command to arrive
   cmd=input$(255, $1)
   EXECUTE cmd
 else
   msg(1)=asc(input$(1,#1)): msg(2)=asc(input$(1,#1))
     print msg(0);" ",msg(1);" ";msg(2)
   IF msg(0) = 1 THEN ' command = 1
'    SETPIN msg(1), msg(2) ' configure the I/O pin
     SELECT CASE msg(2)
         CASE 1: SETPIN msg(1),AIN
         CASE 2: SETPIN msg(1),DIN
         CASE 3: SETPIN msg(1),FIN
         CASE 4: SETPIN msg(1),PIN
         CASE 5: SETPIN msg(1),CIN
'          CASE 6: SETPIN msg(1),AIN
'          CASE 7: SETPIN msg(1),AIN
         CASE 8: SETPIN msg(1),DOUT
'          CASE 9: SETPIN msg(1),SPIN
         CASE 10: TEMPR START msg(1) ' begin a temperature read
     end select
   ELSEIF msg(0) = 2 THEN ' command = 2
     PIN(msg(1)) = msg(2) ' set the I/O pin's output
   ELSEif msg(0) = 3 then ' the command must be 3
     if msg(3) = 10 then ' DS18B20
       s$ = mid$(str$(tempr(pin(msg(1)),3,3) + Space$(12),1,12) ' get the input on the I/O pin
       TEMPR START msg(1) ' begin a temperature read
     else
       s$ = mid$(str$(pin(msg(1))) + Space$(12),1,12) ' get the input on the I/O pin
     endif
     print s$
     print #1,s$
   ENDIF
 ENDIF
 do while loc(1)>0: cmd=input$(255,#1): loop ' flush the input buffer
END SUB ' return from the interrupt

' Note:
' 0 Not configured or inactive
' 1 Analog input
' 2 Digital input
' 3 Frequency input
' 4 Period input
' 5 Counting input
' 8 Digital output
' 9 Open collector digital output. In this mode SPIN() will also return the value on the output pin.
' 10 DS18B20


I tested only digital out, but the code is also set up for AIN, DIN, FIN, PIN, CIN. I added DS18B20 support, but have not yet tested that. I also included code to allow basic statements to be run with EXECUTE when that command is provided on the Picomite.

Untested, but this should also work on MMB4L and MMBasic DOS, and indeed for any processor with serial I/O
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
KD5ZXG
Regular Member

Joined: 21/01/2022
Location: United States
Posts: 53
Posted: 04:00am 25 Feb 2022
Copy link to clipboard 
Print this post

An obsolete client that once worked to give certain versions of FUZE for Windows tethered GPIO via an Arduino, for comparison sake only.  

Some old FUZE BASIC files

Download the archive named resources.zip

Unzip: \extras\Devices\fuzeBasicArduino.ino
Edited 2022-02-25 14:06 by KD5ZXG
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 03:42pm 25 Feb 2022
Copy link to clipboard 
Print this post

After some fiddling, this now gets readings from 4 DS18B20s on the client Picomite via serial:

dim integer i, p(4)=(0,24,25,26,27)
dim string s
font 1
open "com11:115200" as #1

for i=1 to 4:print #1,chr$(1)+chr$(p(i))+chr$(10)+chr$(13):pause 50:next
do
 for i=1 to 4
   print #1,chr$(3)+chr$(p(i))+chr$(10)+chr$(13):pause 100:line input #1,s: ?s
 next
 pause 2000
loop




Modified client code:

' serialClient.bas acts on serial messages
' e.g. PRINT #1,chr$(1)+chr$(1)+chr$(8)+chr$(13)
OPTION AUTORUN ON
DIM integer msg(254), tempPins(40) ' array used to hold the message
dim float temps(40)
DIM string cmd, s$
 pause 3000
 print "Picomite SerialClient starting"
' I2C SLAVE OPEN &H26, 0, 0, WriteD, ReadD ' slave's address is 26 (hex)
 SetPin 22,21,com1 ' setpin 21,uart0tx:SetPin 22,uart0rx
 open "com1:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters

DO ' the program loops forever
 WATCHDOG 2000 ' this will recover from errors
LOOP

SUB SerInt ' received a message
 msg(0)=asc(input$(1,#1))
 if chr$(msg(0)) = "!" then
   pause 30 ' allow all characters in command to arrive
   cmd=input$(255, $1)
   EXECUTE cmd
 else
   msg(1)=asc(input$(1,#1)): msg(2)=asc(input$(1,#1))
     print msg(0);" ",msg(1);" ";msg(2)
   IF msg(0) = 1 THEN ' command = 1
'    SETPIN msg(1), msg(2) ' configure the I/O pin
     SELECT CASE msg(2)
         CASE 1: SETPIN msg(1),AIN
         CASE 2: SETPIN msg(1),DIN
         CASE 3: SETPIN msg(1),FIN
         CASE 4: SETPIN msg(1),PIN
         CASE 5: SETPIN msg(1),CIN
'          CASE 6: SETPIN msg(1),AIN
'          CASE 7: SETPIN msg(1),AIN
         CASE 8: SETPIN msg(1),DOUT
'          CASE 9: SETPIN msg(1),SPIN
         CASE 10: TEMPR START msg(1) ' begin a temperature read (.25 degree default)
     end select
   ELSEIF msg(0) = 2 THEN ' command = 2
     PIN(msg(1)) = msg(2) ' set the I/O pin's output
   ELSEif msg(0) = 3 then ' the command must be 3
     if msg(2) = 10 then ' DS18B20
'        s$ = mid$(str$(tempr(pin(msg(1)),3,3) + Space$(12),1,12) ' get the input on the I/O pin
       s$ = str$(tempr(pin(msg(1)),3,3) ' get the input on the I/O pin
       print s$
       TEMPR START msg(1) ' begin a temperature read
     else
'        s$ = mid$(str$(pin(msg(1))) + Space$(12),1,12) ' get the input on the I/O pin
       s$ = str$(pin(msg(1))) ' get the input on the I/O pin
     endif
     print #1,s$
   ENDIF
 ENDIF
 do while loc(1)>0: cmd=input$(255,#1): loop ' flush the input buffer
END SUB ' return from the interrupt

' Note:
' 0 Not configured or inactive
' 1 Analog input
' 2 Digital input
' 3 Frequency input
' 4 Period input
' 5 Counting input
' 8 Digital output
' 9 Open collector digital output. In this mode SPIN() will also return the value on the output pin.
' 10 DS18B20


PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5735
Posted: 04:17pm 25 Feb 2022
Copy link to clipboard 
Print this post

Cool! This is coming along nicely. :)
Mick

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

Joined: 05/03/2018
Location: Netherlands
Posts: 3553
Posted: 06:28pm 25 Feb 2022
Copy link to clipboard 
Print this post

Mick,

The last project I did with the pico, I could copy and paste my program in autosave mode. With current software (5.07.0404) the code gets corrupted when I paste.
Is this my pico? Or do you experience similar. Does this have to do with running from RAM ?

Volhout
PicomiteVGA PETSCII ROBOTS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 06:55pm 25 Feb 2022
Copy link to clipboard 
Print this post

Autosave has worked for me with the latest firmware.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3661
Posted: 07:29pm 25 Feb 2022
Copy link to clipboard 
Print this post

  Volhout said  The last project I did with the pico, I could copy and paste my program in autosave mode. With current software (5.07.0404) the code gets corrupted when I paste.

Could it be pasting too fast for the pico MMBasic to accept?

John
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 08:57pm 25 Feb 2022
Copy link to clipboard 
Print this post

With latest firmware, 5.070404, SETPIN 29,DIN works, and ?pin(29) gives correct value with and without the pin connected to 5V with a 10K resistor.

But SETPIN 29,CIN and SETPIN 29,FIN and SETPIN 29,PIN give me "Error : Invalid configuration". Other pin numbers and GP numbers give the same error.

What am I missing?

(By the way, both DIN requests and AIN requests work with the above picomite serial client code, giving 0 and 1 appropriately for DIN on pin 29, and 0.636 and 3.3 with either nothing connected to pin 31 or 3V3 connected to pin 31 through a 10K resistor.)

~
Edited 2022-02-26 07:14 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 09:27pm 25 Feb 2022
Copy link to clipboard 
Print this post

The image under Picomite Hardware on page 10 of the Picomite manual assigns the PWMnx labels to specific pins, for instance, PWM0A is pin 1, GP0, and PWM7B is pin 20, GP15.

The text for the SETPIN pin,PWM command doesn't specify that a pwm number and channel is associated with a specific pin, but an assignment which doesn't correspond to the Picomite Hardware image doesn't work for me.

It will simplify things for me with the picomite client code if I can assume that pin 1 must always be PWM0A and pin 20 (for instance) must always be PWM7B. Is this actually the case, or can a pin be arbitrarily assigned to any PWM number and channel?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5735
Posted: 09:54pm 25 Feb 2022
Copy link to clipboard 
Print this post

Yes, it looks like the PWM outputs are associated with fixed pins. The RP2040 Datasheet  certainly makes it look that way.
Mick

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

Joined: 05/03/2018
Location: Netherlands
Posts: 3553
Posted: 10:09pm 25 Feb 2022
Copy link to clipboard 
Print this post

  JohnS said  
  Volhout said  The last project I did with the pico, I could copy and paste my program in autosave mode. With current software (5.07.0404) the code gets corrupted when I paste.

Could it be pasting too fast for the pico MMBasic to accept?

John


Yeah, that was when using Putty under linux. Too fast.... I remember.
And Putty did not support end of line delay ...
PicomiteVGA PETSCII ROBOTS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 09:54pm 26 Feb 2022
Copy link to clipboard 
Print this post

The current Picomite manual from Geoff's site is for MMBasic version 5.07.03. It doesn't include the FIELD$ function, which is provided in the current Picomite firmware, 5.070404. Is there an update to the manual in process?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3016
Posted: 11:11pm 26 Feb 2022
Copy link to clipboard 
Print this post

  lizby said  SETPIN 29,CIN and SETPIN 29,FIN and SETPIN 29,PIN give me "Error : Invalid configuration". Other pin numbers and GP numbers give the same error.


Explained in the Picomite manual (page 26 at present): SETPIN pin,CIN|FIN|PIN default to GP6, GP7, GP8 and GP9 (9,10,11,12); use OPTION COUNT to change.

It might be good to refer to this in the SETPIN command definition for CIN, etc., and also in the error message if possible.

GP28 (pin 34) is not permitted:
> OPTION COUNT GP6, GP7, GP8, GP28
Error : Invalid pin
> OPTION COUNT GP6, GP7, GP8, GP27


~
Edited 2022-02-27 09:28 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 5 of 7    
Print this page
© JAQ Software 2024