Pi: MMBasic driving the Maker Pi Pico: SDcard etc (166.html)

[WARNING: Do NOT connect any of the Grove 3V3 power pins on the Maker Pi Pico to the 3V3 power on the Raspberry Pi.]

Keywords:
MMBasic "Raspberry Pi Pico" Raspberry Cytron Maker Pi Pico "Maker Pi Pico" PicoMite" ttyACM0 ICH180R2 "micro SDcard"
SDcard Basic D@CC wav tone "wind.wav" Grove MMEdit minicom GPIO led pushbutton buzzer "audio jack"


Click on the photo to enlarge it.

thumb: IMG_5162.JPG
Maker Pi Pico with RPi Pico and a micro SDcard

by David @ ColeCanada.com (c) ICH180R2

Introduction

This article describes how the MMBasic language can be used with a Maker Pi Pico to communicate with a micro SDcard. No video is yet available to describe this process. The video cited near the end of this article describes how to use MicroPython (not MMBasic) to access a micro SDcard attached to a Raspberry Pi Pico.





MMBasic driving the Maker Pi Pico: SDcard etc

                                       Click on the photo to enlarge it.

thumb: MakerPiPicoDiagram.jpg
                                       Maker Pi Pico Features and Functions
                                       by Cytron

This article describes the rebirth of the BASIC language (viz MMBasic) on the Raspberry Pi Pico. Couple this MMBasic interpreter with the Cytron Maker Pi Pico board and you have an inexpensive new computer that controls many electronic devices. Perhaps the most important device is the micro SDcard that can be plugged into the connector (socket) on the Maker Pi Pico. Note the label "1DB4" stuck near the bottom of the Pi Pico shown at the top of this article. Each Pi Pico can be identified by its unique ID. The "1DB4" is simply the rightmost 4 characters of the unique ID listed by MMBasic.

Cytron sells two versions of the Maker Pi Pico board. The two boards are almost identical. The version shown immediately above is manufactured with a Raspberry Pi Pico board permanently soldered to the Maker Pi Pico board. It provides a free male pin connected to each pin of the Raspberry Pi Pico. The other board has a socket where a Raspberry Pi Pico board can be inserted. This board has a free female pin connected to each pin of the Raspberry Pi Pico. On this board, the three "debug pins" at the bottom of the Raspberry Pi Pico board are not connected. Other than these minor differences, these two Cytron boards are essentially identical.

In order to load MMBasic, the Pico board plugged into the Maker Pi Pico board must be connected to a computer. This computer is normally a Raspberry Pi or an Apple or Microsoft computer. Any computer running Linux can also be used.

Most of the components on the Maker Pi Pico board can be controlled using MMBasic as initially configured. However the SDCard is not accessible when MMBasic is initially loaded. The components that WORK upon installation of MMBasic are: Using MMBasic, I have successfully tested all of the above except the multicolor LED, I2C, 1-wire, the Grove connectors and the ESPI Wifi connector.

In order to use the micro SDcard on the Maker Pi Pico board, a special option must be assigned using MMBasic. First, the micro SDcard must be formatted. This can easily be done using the SD Card Formatter on a MicroSoft laptop. Then MMBasic must be installed on the Raspberry Pi Pico. This can easily be done using any Raspberry Pi computer. I did this using a Raspberry Pi 400. An appropriate editor must also be installed onto the Raspberry Pi. I have successfully used the minicom editor.
Once these have been installed and the Pico is disconnected and reconnected, MMBasic will be operational.  The 
flashing green LED on the Raspberry Pi Pico indicates that MMBasic is operational.  To use MMBasic, a terminal
emulator is required.  Minicom is often used.  It is a simple matter to install minicom using the Raspberry 
Add Software program.  Then minicom can be found in the Raspberry menu system.  To test MMBasic using the 
minicom editor,  the following can be typed into the Terminal window on the Raspberry Pi:

 >>$ minicom --device /dev/ttyACM0 --color=on

The above will clear the "Terminal Window" and will permit the user to use MMBasic. Once minicom is running, do as the prompt says: 

Enter Ctrl-A Z , 
then dismiss the minicom commands window by hitting Enter
the simply hit Enter again to get the ">" prompt for MMBasic.

when sending messages to the Raspberry Pi Pico, do not be surprised when the Pico doesn't respond until an End-Of-Line
 e.g. a Line Feed (LF) is sent to the Pico.  The Pico usually responds to a whole message.  A whole message is terminated 
by an LF.  In fact, the Raspberry software functions most efficiently when it knows in advance how long each incoming message
will be.  For this reason, transmissions of specific-sized packets is the most efficient method of communicating with the Raspberry 
Pi Pico.
Test MMBasic by typing: > print 1/7 A response of 0.1428571429 confirms that MMBasic is operational To configure MMBasic to access the micro SD card, enter > option sdcard GP15,GP10,GP11,GP12 Ignore the response that says "error reading ttyACM0!" To read the directory of the microSD card, enter > files The response should be a listing of the directory on the SDcard. The Unique Identifier for the Pi Pico can be listed by MMBasic using the following statement: > print MM.INFO(ID) The response will be a multi-character string. It is a different string than seen using Python or Thonny. The two strings are probably related, although I do not know how to convert one to the other. Because neither the Raspberry Pi Pico nor the Maker Pi Pico has a real time clock, it is necessary to initialise the Date and Time whenever the Raspberry Pi Pico is powered up. This can be done by typing the following 2 statements into MMBasic. > time$="03:58:00" > date$="18-01-2022" AUDIO TONES AND TUNES Tones can be played using the buzzer (GP18) on the Maker Pi Pico board. The buzzer on/off switch must be to the right (away from the audio jack). Tunes can be played on the audio output jack on the Maker Pi Pico board, if headphones are plugged in. To play tones and music (".wav") files, the audio output pins on the Maker Pi Pico card must be set up using the following Option statement: > option audio GP18,GP19 The volume should be set to 100% using the following Play statement: > play volume 100,100 To play a tone (500Hz note) on the buzzer (and on the headphones), type: > play tone 500,500,1000 To play a tune (".wav") named "wind.wav" located on the SDcard type: > play wav "wind.wav" If the above statement doen't work, be sure to set the correct options for the micro SDcard. MMBasic is now ready to be used. Note that the serial number on the Pi Pico board containing MMBasic ends in ":1db4". My shortcut for starting MMBasic is "sh MMBasic.sh"

The Minicom Terminal Emulator

The Minicom Terminal Emulator is probably a very good VT100 terminal emulator. It has many special control commands that can be seen by hitting Ctrl-A then Z. However I have not tried to attach anything other that the Pi Pico board to a USB port before starting minicom.

photos of the Pi Pico board

Click on the photo to enlarge it.

thumb: NB-bottom-lq-800x800.png
pin labels on bottom of Maker Pi Pico

by David @ ColeCanada.com (c) ICH180R2

Click on the photo to enlarge it.

thumb: Raspberry-Pi-Pico-techatronic.png
pin labels for the Raspberry Pi Pico

by David @ ColeCanada.com (c) ICH180R2

Program to setup the pins to access the SDcard on the Maker Pi Pico

The program shown below, can be edited into MMBasic. If followed by the command "> OPTION AUTORUN ON", it will be automatically run whevever MMBasic is started on the Raspberry Pi Pico. This program is all that is necessary for MMBasic to use the Micro SD card.
Print "autorun program configuring for Maker Pi Pico SDcard"
Print "follow this program by OPTION AUTORUN ON then OPTION LIST"
Print " applied to PI Pico with Unique ID: 1DB4 by D@CC"
Option SDCARD GP15,GP10,GP11,GP12
'/MakerPiPico_Autorun.BAS by D@CC on 2022AJan10

Reading Voltages (Analog to Digital Conversion)

Pins GP27 and GP28 are configured by MMBasic to read the voltages applied to them. Pin GP29 is a constant voltage reference of 3.3v. The small program shown below reads and displays the voltage applied to the respective pin.


set pin GP27 AIN
print "GP27:", pin(GP27))." volts"
set pin GP28 AIN
print "GP28:", pin(GP28)." volts"
end

'/MakerPiPico_Autorun.BAS by D@CC on 2022AJan10

Small MMBasic test programs

MMBasic programs can be stored in 10 flash memory areas (located on every RPi Pico board or stored on a micro SDcard plugged into the Maker Pi Pico board. To store programs on a micro SDcard, the GPIO pins must be correctly setup. The programs named "flash_#.BAS" were initially stored in flash memory (before the micro SDcard was usable). For this reason, they contain the "flash_" prefix in their names. The "current" program area can be loaded from any one of the 10 flash memory areas or from any "BAS" program stored by name on the micro SDcard. The 32 Gigabyte micro SDcard that I used provided an almost limitless storage area. Furthermore, I was able to plug the SDcard into a laptop to access them using Linux, IOS or MicroSoft.

Useful MMBasic Statements

MMBasic Useful Statements
by D@CC as of 2022AJan10

option reset
   clears all option settings                     p72
option list
  prints current option settings                  p72
option sdcard GP15,GP10,GP11,GP12
                       CS   SCK   SDin SDout
  hardware pins 20   14     15   16
  settings for the sdcard on Maker Pi Pico        p73
option system spi GP10,GP11,GP12
  to read sdcard on Maker Pi Pico                 p73
print MM.Info(DISK SIZE)
  prints size of SDcard                           p68
print mm.info(SDCARD)
  prints status of SDCARD eg ready                p68
files
  lists the files stored on the SD card           p37
pin diagram for the PicoMite                      p 9
pins as defined on MMBasic startup                p36
save "MakerPiPico_Autorun.BAS"
  save program to init MakerPiPico SDCard  p
flash save 1                                       p82
flash overwrite 1                                  p82
flash list 1                                       p82
flash load 1                                       p82
flash run 1                                        p82
date$ = "28-01-2022"                               p82


Documentation by D@CC
  01 MMBasic .txt
  02 MMBasic_Use.txt
  03 MMBasic_to_MakerPiPicoA.odt/jpg

MMBasic Programs
  flash_1.BAS
    plays a tone then rapidly flashes GP21 LED
  flash_2.BAS
    prints ID then rapidly flashes GP21 LED
  flash_3.BAS
    writes fox txt to SDcard
  flash_4.BAS
    manually  assign Maker Pi Pico GP pins
  flash_5.BAS
    shows how to use SDcard on Maker Pi Pico
  MakerPiPico_Autorun.BAS
   Autorun Program for Maker Pi Pico SDcard

Temperature Logging Program

Open "TemperatureLog.xls" for Output as #1
Do While Inkey$ = ""
  Print #1, Date$ "," Time$ "," TEMPR(GP0) "," TEMPR(GP1) "," TEMPR(GP2)
  Pause 400
Loop 
Close #1

Naming my Flash Drives

Usually, to uniquely identify each of my flash drives, I glue a small adhesive label to house the name of each SDcard. I also create a empty directory on each microSDcard containing this name. I try to use this name as the volume name of the "flash" drive. The naming convention that I use is:

"_Fla70S032G"

"_" The "_" usually causes this directory to be at the top of the directory listing
"Fla" identifies it as a "flash" drive
"70" is the unique identifier for "flash" drive #70 in my collection
The second hundred "flash" drives will be prefixed with "_Flb"
"D" is the format (S is usually micro SDcard) of "flash" drive
                             D is a normal USB format) of "flash" drive
                             M contains music or unusual data
"032G" is the size (in Gigabytes) of this "flash Drive
To document each of my "flash" drives, I keep a photograph (a jpg image) of each and I keep a list describing the main use of each of my flash drives. A backup copy of each of my flash drives is kept on an external back-up drive. My intention is to keep the names and images of all my flash drives in Source 21 which is ePC Article 167.

Hardware Support

MMBasic supports all the hardware features of the Raspberry Pi Pico (serial, I2C, SPI, CPU clock, ADC, etc) and adds support for:

All these features are built into the BASIC interpreter, there is no need to load libraries or write special code.

Known Bugs in PicoMite MMBasic 5.07.01 (as of 2022AJan18)

This is a list of known bugs and issues in PicoMite MMBasic 5.07.01.  
These should be fixed in later versions.

==================================================================================
If "ON KEY keyno, int" is used with Ctrl-C and not closed with "ON KEY keyno, 0" then XMODEM won't work correctly. Fixed in V5.07.02b1
When editing files with REM command an additional space will be added after REM after each edit. Fixed in V5.07.02b2
Bug where writing text to an SPI LCD that overlapped the bottom of the screen would fail to de-assert LCD_CS. Fixed in V5.07.02b2
Bug in day$(now) function. Fixed in V5.07.02b2
Bug in using SYSTEM I2C or I2C2 for general I2C use if I2C READ does not use a string as the variable. Fixed in V5.07.03b0.
BUG in BACKLIGHT 0. Fixed in V5.07.03b3
Bug in load user function definitions F6-F9. Fixed in V5.07.03RC2
Bug in GUI BITMAP when using monchrome displays not updating the screen. Fixed in V5.07.03RC6. Workaround issue a REFRESH command after GUI BITMAP

Directory of micro SDcard _Fla70S032G (Web Source 23)

as of 2022AJan29

 Volume in drive E is PICO_66
 Volume Serial Number is 585A-E83D

 Directory of E:\

01/15/2022  02:20 PM              DKC
01/18/2022  11:54 AM              _Fla70S032G
01/01/2000  12:02 AM               340 flash_2.BAS
01/01/2000  12:26 AM               481 flash_1.BAS
01/01/2000  12:23 AM               216 flash_3.BAS
01/01/2000  07:28 AM                47 fox.txt
01/01/2000  12:10 AM               341 flash_4.BAS
01/01/2000  02:06 AM               426 flash_5.BAS
01/01/2000  10:03 AM               271 MakerPiPico_Autorun.BAS
01/01/2000  12:19 AM             1,107 MMBASIC_Installation.txt
01/18/2022  09:03 PM               187 MProgA.BAS
01/02/2000  12:09 AM               830 MProgB.BAS
01/10/2022  01:22 PM             2,173 MMBasicUsefulStatements.txt
01/02/2000  07:32 PM                 0 TempLog.xls
01/01/2000  11:39 PM               119 ProgC.BAS
01/27/2022  01:22 PM             1,015 MProgD.BAS
01/10/2022  01:34 PM                11 Prog01.BAS
05/31/2007  01:49 PM         3,228,374 Jennifer Warrens - Ain't No Cure for Love.mp3
01/27/2022  01:06 PM               150 VRC_1.643288778e+09.csv
01/27/2022  01:17 PM                70 VRC_1.643289467e+09.csv
01/27/2022  01:18 PM               150 VRC_1.643289523e+09.csv
01/16/2022  12:09 PM         8,586,184 WINDDsgn_Wind (ID 0595)_BSB.wav
01/27/2022  01:19 PM               150 VRC_1.643289562e+09.csv
01/16/2022  12:09 PM         8,586,184 wind.wav
01/27/2022  01:20 PM               150 VRC_1.6432896e+09.csv
01/27/2022  01:22 PM               150 VRC_1.643289746e+09.csv
              24 File(s)     20,409,126 bytes
               2 Dir(s)  30,982,963,200 bytes free

End of Article (Sources follow)

This article, by D@CC is of course, a work-in-progress as of 2022AJan11.

External Sources

Video Sources

Video Source 01:www RPi Pico with an SDcard (using MicroPython) by DigiKey on 2021GJul 26

Web Sources

Web Source S166:01:www RPi beginners GUide by
Web Source S166:02:www Micromite / MMBasic 5.1 Advanced Features (Not Raspberry Pi Pico) by Geoff G as of 2021FJun22
Web Source S166:03:www PicoMite User Manual (MMBasic 5.07.01 for the Raspberry Pi Pico) by Geoff Graham as of 2021FJun22
Web Source S166:04:www PicoMite (MMBasic) for the Raspberry Pi Pico (uf2) firmware to load
Web Source S166:05:www Maker Pi Pico Datasheet by Cytron
Web Source S166:06:www MMBasicUsefulStatements.txt
Web Source S166:07:www MMBasic_Use.txt
Web Source S166:08:www MakerPiPico_Autorun.BAS
Web Source S166:09:www https://www.c-com.com.au/MMedit.htm
Web Source S166:10:www by Joseph SARDIN at bigsoundbank.com Howling Wind tune (.wav)
Web Source S166:11:www flash_1.BAS
Web Source S166:12:www flash_2.BAS
Web Source S166:13:www flash_3.BAS
Web Source S166:14:www flash_4.BAS
Web Source S166:15:www flash_5.BAS
Web Source S166:16:www Toms Hardware review of MakerPiPico
Web Source S166:17:www Toms Hardware review of the Raspberry Pi Pico
Web Source S166:18:www sdcard reader using picomite at Hackaday.com by Elliot Williams (no longer available)
Web Source S166:19:www PicoMite gives your pico a deluxe basic by Elliot Williams on 2021KNov24
Web Source S166:20:www Raspberry Pi Pico RP2040 Manual
Web Source S166:21:www 167 Flash Drive Library (for D@CC) by David Cole
Web Source S166:22:www Current MMBasic Bug List by Geoff Graham
Web Source S166:23:www Zipped MMBasic SDcard # Fla70 (VName:PICO 66) by David KC Cole on 2022AJan29
     

thumb: IMG_4910.JPG
.
Contact: email: David @ ColeCanada.com or phone: 613-822-7767



WebMaster: Ye Old King Cole

Click here to return to ePC Articles by Old King Cole

Date Written: 2022 A Jan 11
Last Updated: 2022 B Feb 18
Backed Up On: 2022 A Jan 16 as 166_2022AJan16.html
(c) ICH180R2 Corp.

/166.html