Difference between revisions of "PiPicoMite01"

From Land Boards Wiki
Jump to navigation Jump to search
 
(467 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[file:PiPicoMite01_FRONT_3D.png]]
+
[[File:tindie-mediums.png|link=https://www.tindie.com/products/26931/]]
 +
 
 +
[[file:PiPicoMite01_Rev2_P18315-720px.jpg]]
 +
 
 +
<video type="youtube">5dcnrLDzjdU</video>
 +
 
 +
== Card Versions ==
 +
 
 +
* There are three versions of this card
 +
** [[PiPicoMite01]] (this version)
 +
*** Has 16-bit port I/O expander
 +
*** 120x70mm with (4) 6-32 mounting holes
 +
** [[PiPicoMite02]]
 +
*** Has 32-bit port I/O expander(s)
 +
*** 95x95mm with (4) 6-32 mounting holes
 +
** [[PiPicoMite03]]
 +
*** 99.5x69.5mm - Fits into extruded Aluminum Enclosure
 +
*** Fully functional, reduced cost
  
 
== Features ==
 
== Features ==
  
 
* [[Raspberry Pi Pico]]
 
* [[Raspberry Pi Pico]]
** All pins brought to header
+
** All Pico pins brought to headers
** Pin marking on rear
+
** Pico pin marking on rear
* VGA (1:2:1 - R:G:B)
+
* VGA
* PS/2 Keyboard
+
** [http://www.tinyvga.com/vga-timing/640x480@60Hz 640x480] monochrome resolution
 +
** 320x240 colour resolution
 +
** 1:2:1 - R:G:B - 16 colours
 +
* [https://wiki.osdev.org/PS/2_Keyboard PS/2 Keyboard]
 
** 5V to keyboard with voltage translator
 
** 5V to keyboard with voltage translator
 +
** Does not require a keyboard that runs at 3.3V
 
* SD Card
 
* SD Card
 
** Full size card
 
** Full size card
 
** Up to 32GB
 
** Up to 32GB
 +
** FAT32 format
 +
** [https://www.amazon.com/SanDisk-3-Pack-Ultra-Memory-3x32GB/dp/B08GY9575R/ref=sr_1_3?keywords=sandisk%2B32gb%2Bsd%2Bcard&qid=1657457739&sprefix=sandisk%2B32GB%2Caps%2C85&sr=8-3&th=1 Tested/worked]
 
* Stereo audio
 
* Stereo audio
 +
** PWM with filter
 
** 3.5mm jack
 
** 3.5mm jack
* 16-bit GPIO
+
** [https://www.amazon.com/dp/B000R9AAJA?psc=1&ref=ppx_yo2ov_dt_b_product_details Cheap speakers]
** [https://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf MCP23017] port expander
+
* 16 bit Port Expander
** I2C
+
** [https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP23017-Data-Sheet-DS20001952.pdf MCP23017 Datasheet] - Rev D
** 2x20 0.1" pitch header
+
** [https://hackaday.com/2023/02/03/mcp23017-went-through-shortage-hell-lost-two-inputs/?fbclid=IwAR1ktG1CsU7ns5fmTYXdlpBLdqaJmBioXrVrG1_Lgqe8MTQr1AY4rp6IETU MCP23017... LOST TWO INPUTS]
 +
*** MCP23017 now a 14/16-bit expander, with two of the pins (GPA7 and GPB7) losing their input capabilities
 +
*** The chips look the same, are called the same, and act mostly the same — if you don’t download the latest version of the datasheet (Revision D), you’d never know that there’s been a change* 16-bit General Purpose I/O (GPIO)
 +
** On Pico I2C1 (I2C2 from MMBASIC)
 +
** 2x10 0.1" pitch header
 
** Jumper selectable terminators
 
** Jumper selectable terminators
 +
* I2C0 connector (Rev 2 and later)
 +
** Requires external I2C terminators
 
* Power options
 
* Power options
** 5V power input via USB B or 0.1" pitch header
+
** 5V power input  
 +
*** USB Micro on Pico card
 +
*** USB B
 +
*** 0.1" pitch header
 
** 3.3V output header
 
** 3.3V output header
 +
* 120mmx70mm outline
 +
* (4) 6-32 Mounting holes
 +
 +
=== BASIC Interpreter ===
 +
 +
The [https://geoffg.net/picomitevga.html PicoMiteVGA] boots straight into the MMBasic prompt. At which point you can enter, edit and save the program, test BASIC commands and run the program.
 +
 +
MMBasic is a Microsoft BASIC compatible implementation of the BASIC language, originally written by Geoff Graham and enhanced and ported to the Pico by Peter Mather, who also designed the original PicoMite on which this design is based. It is full featured with floating point, 64-bit integers and string variables, long variable names, arrays of floats, integers or strings with multiple dimensions, extensive string handling and user defined subroutines and functions. Typically it will execute a program up to 100,000 lines per second. Embedded compiled C programs can be used for even higher performance.
 +
 +
Using MMBasic you can use communications protocols such as I2C or SPI to get data from a variety of sensors. You can save data to an SD card, measure voltages, detect digital inputs and drive output pins to turn on lights, relays, etc.
 +
 +
The emphasis with MMBasic is on ease of use and development. The development cycle is very fast with the ability to instantly switch from edit to run. Errors are listed in plain English and when an error does occur a single keystroke will invoke the built in editor with the cursor positioned on the line that caused the error.
 +
 +
==== MMBASIC Credits ====
 +
 +
Peter Mather led the [https://geoffg.net/picomitevga.html project], ported the MMBasic interpreter to the Raspberry Pi Pico and wrote the hardware device drivers. Geoff Graham wrote the MMBasic interpreter and the manual.  Mick Ames wrote the PIO compiler and its corresponding documentation. The VGA driver code was derived from work by Miroslav Nemecek.
  
== Pin Marking on Rear ==
+
=== Raspberry Pi Pico Pinout (Reference) ===
 +
 
 +
[[File:PiPico_Pins.PNG]]
 +
 
 +
== Pin Marking on Rear (Rev 2) ==
  
 
[[file:PiPicoMite01_REAR_3D.png]]
 
[[file:PiPicoMite01_REAR_3D.png]]
Line 29: Line 82:
 
== Schematic ==
 
== Schematic ==
  
* [https://github.com/land-boards/lb-boards/blob/master/Raspberry%20Pi%20Cards/PiPicoMite01/PiPicoMite01_Rev1_Schematic.pdf PiPicoMite01 Rev 1 Schematic]
+
* [http://land-boards.com/PiPicoMite01/PiPicoMite01_Rev1_Schematic.pdf PiPicoMite01 Rev 1 Schematic]
 +
* [http://land-boards.com/PiPicoMite01/PiPicoMite01_Rev2_Schematic.pdf PiPicoMite01 Rev 2 Schematic]
 +
 
 +
== Rev 1 Connectors ==
 +
 
 +
* [[PiPicoMite01 Rev 1 Connectors]] - Note the Rev 1 connectors are in different sequence orders than the Rev 2 and later cards
 +
 
 +
== Rev 2 Connectors ==
 +
 
 +
* The following are for Rev 2 and later boards
 +
 
 +
[[file:PicoMite01_Rev2_CAD.PNG]]
 +
 
 +
=== J1 - MCP23017 - 16-bit GPIO ===
 +
 
 +
* [https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP23017-Data-Sheet-DS20001952.pdf MCP23017 Datasheet] - Rev D
 +
** [https://hackaday.com/2023/02/03/mcp23017-went-through-shortage-hell-lost-two-inputs/?fbclid=IwAR1ktG1CsU7ns5fmTYXdlpBLdqaJmBioXrVrG1_Lgqe8MTQr1AY4rp6IETU MCP23017... LOST TWO INPUTS]
 +
*** MCP23017 now a 14/16-bit expander, with two of the pins (GPA7 and GPB7) losing their input capabilities
 +
*** The chips look the same, are called the same, and act mostly the same — if you don’t download the latest version of the datasheet (Revision D), you’d never know that there’s been a change
 +
* 2x10 header
 +
** 16 bits of Digital I/O
 +
*** A0 silkscreen marking = GPA0, etc.
 +
** (2) Power
 +
** (2) Ground
 +
* On I2C2 pins (I2C1 on Pico)
 +
** SetPin BASIC code
 +
 
 +
<pre>
 +
SetPin GP14, GP15, I2C2
 +
</pre>
 +
 
 +
[[file:PiPicoMite01_J1_GPIO.PNG]]
 +
 
 +
* Initialization code
 +
* Set all pins to outputs
 +
 
 +
<pre>
 +
MCP23017_I2CADR  = &H20
 +
MCP23017_IODIRA  = &H00
 +
MCP23017_IODIRB  = &H01
 +
MCP23017_IPOLA    = &H02
 +
MCP23017_IPOLB    = &H03
 +
MCP23017_GPINTENA = &H04
 +
MCP23017_GPINTENB = &H05
 +
MCP23017_DEFVALA  = &H06
 +
MCP23017_DEFVALB  = &H07
 +
MCP23017_INTCONA  = &H08
 +
MCP23017_INTCONB  = &H09
 +
MCP23017_IOCON    = &H0A
 +
MCP23017_GPPUA    = &H0C
 +
MCP23017_GPPUB    = &H0D
 +
MCP23017_INTFA    = &H0E
 +
MCP23017_INTFB    = &H0F
 +
MCP23017_INTCAPA  = &H10
 +
MCP23017_INTCAPB  = &H11
 +
MCP23017_GPIOA    = &H12
 +
MCP23017_GPIOB    = &H13
 +
MCP23017_OLATA    = &H14
 +
MCP23017_OLATB    = &H15
 +
 
 +
SetPin GP14, GP15, I2C2
 +
I2C2 OPEN 400, 100
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_IODIRA, &H00
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_IODIRB, &H00
 +
</pre>
 +
 
 +
* Write alternating patterns on output pins
 +
 
 +
<pre>
 +
' Alternating patterns
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &H55
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &HAA
 +
Pause 1000
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &HAA
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &H55
 +
Pause 200
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &H00
 +
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &H00
 +
</pre>
 +
 
 +
=== J2 - VGA ===
 +
 
 +
The VGA output is 640 x 480 pixels in monochrome mode or 320 x 240 pixels in colour mode with 16 colours (1 bit for red, 2 bits for green and 1 bit for blue). The VGA output is generated using the second CPU on the RP2040 processor plus one PIO channel so it does not affect the BASIC interpreter which runs at full speed on the first CPU. A handfull of components (resistors and a couple of diodes) is all that is required to connect the VGA monitor.
 +
 
 +
From within your BASIC program you can turn pixels on/off and draw lines, boxes and circles in any colour. Text can be positioned anywhere on the screen and displayed in any colour in a variety of fonts.
 +
 
 +
The built-in editor within MMBasic works perfectly with the VGA monitor and PS2 keyboard to allow programs to be edited (with colour coded text) and saved to an SD card.
 +
 
 +
Mode 1 (640x480 monochrome) and mode 2 (320x240 16-colours).
 +
 
 +
<pre>
 +
OPTION COLOURCODE ON
 +
</pre>
 +
 
 +
[[file:PiPicoMite01_J2_VGA.PNG]]
 +
 
 +
=== J3 - 3.3V Power Out ===
 +
 
 +
* Power external interfaces
 +
* Limits of the [https://www.richtek.com/Products/Switching%20Regulators/Buck-Boost%20Converter/RT6150ART6150B?sc_lang=en&specid=RT6150A/RT6150B RT6150 regulator] on the Pico
 +
** [https://components101.com/development-boards/raspberry-pi-pico-pinout-datasheet-specifications Max permissible current is 300mA]
 +
 
 +
[[file:PiPicoMite01_J3_3p3V.PNG]]
 +
 
 +
=== J4 - Audio ===
 +
 
 +
* Low Pass filter
 +
* Resistive voltage divider to get to line level
 +
** [https://en.wikipedia.org/wiki/Line_level Line Level Audio information]
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/testtone.bas Two Tone Test]
 +
* Can get rid of noise using
 +
 
 +
<pre>
 +
OPTION POWER PWM
 +
</pre>
 +
 
 +
* Play a WAV file
 +
 
 +
<pre>
 +
OPTION AUDIO GP6, GP7
 +
PLAY WAV "file.wav"
 +
PLAY STOP
 +
</pre>
 +
 
 +
[[file:PiPicoMite01_J4_Audio.PNG]]
 +
 
 +
=== J5 - USB B Power Connector ===
 +
 
 +
* In parallel with J6
 +
 
 +
[[file:PiPicoMite01_J5_5V-Power.PNG]]
 +
 
 +
* Full size USB B connector
 +
* No USB signal connections, just used for power
 +
 
 +
=== J6 - 5V Input ===
 +
 
 +
[[file:PiPicoMite01_J6-5V.PNG]]
 +
 
 +
* Useful to power the card from external 5V
 +
* Use in place of J5
 +
 
 +
=== J7 - PS/2 Keyboard ===
 +
 
 +
The PS2 keyboard connects to the Raspberry Pi Pico via a level shifter and works as a normal keyboard with the function keys and arrow keys fully operational. It can be configured for the standard US layout used in the USA, Australia and New Zealand or specialised layouts used in the United Kingdom, Germany, France and Spain.
 +
 
 +
* 5V keyboard
 +
 
 +
[[file:PiPicoMite01_J7_PS2-Keyboard.PNG]]
 +
 
 +
=== J8 - I2C0, UART0 (RTC, etc.) ===
 +
 
 +
[[FILE:PiPicoMite01_J8_I2C.PNG]]
 +
 
 +
# I2C0SCL. UART0_TX (GP1)
 +
# I2C0SDA. UART0_RX (GP0)
 +
# VCC
 +
# GND
 +
 
 +
Can use Real Time Clocks using the PCF8563, DS1307, DS3231 or DS3232 chips means that the time is always accurately known.
 +
 
 +
<pre>
 +
option system i2c gp0, gp1
 +
</pre>
 +
 
 +
=== J9, J10 Pico Connectors ===
 +
 
 +
* Pico pins are brought out to 1x20 pin headers J9, J10
  
== Connectors ==
+
[[file:PiPicoMite01_J9-10_PiPico.PNG]]
 +
 
 +
==== Pico Function Mapping ====
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 37: Line 259:
 
! FUNCTION
 
! FUNCTION
 
! PICO PIN
 
! PICO PIN
 +
!
 +
! GP
 +
! FUNCTION
 +
! PICO PIN
 +
|-
 +
| GP0
 +
| J8-2 (I2C0_SDA)
 +
| 1
 +
|
 +
| GP16
 +
| VGA_HSYNC
 +
| 21
 +
|-
 +
| GP1
 +
| J8-1 (I2C0_SCL)
 +
| 2
 +
|
 +
| GP17
 +
| VGA_VSYNC
 +
| 22
 +
|-
 +
| GND
 +
|
 +
| 3
 +
|
 +
| GND
 +
|
 +
| 23
 +
|-
 +
| GP2
 +
| MCP23017_INTA (H2)
 +
| 4
 +
|
 +
| GP18
 +
| VGA_BLU
 +
| 24
 +
|-
 +
| GP3
 +
| SPARE GPIO
 +
| 5
 +
|
 +
| GP19
 +
| VGA_GRN_LO
 +
| 25
 +
|-
 +
| GP4
 +
| SPARE GPIO
 +
| 6
 +
|
 +
| GP20
 +
| VGA_GRN_HI
 +
| 26
 +
|-
 +
| GP5
 +
| SPARE GPIO
 +
| 7
 +
|
 +
| GP21
 +
| VGA_RED
 +
| 27
 +
|-
 +
| GND
 +
|
 +
| 8
 +
|
 +
| GND
 +
|
 +
| 28
 
|-
 
|-
 
| GP6
 
| GP6
 
| AUDIO-L
 
| AUDIO-L
 
| 9
 
| 9
 +
|
 +
| GP22
 +
| SPARE GPIO
 +
| 29
 
|-
 
|-
 
| GP7
 
| GP7
 
| AUDIO-R
 
| AUDIO-R
 
| 10
 
| 10
|-
 
| GND
 
| AUDIO-GND
 
| 8
 
|-
 
| 3.3V
 
| PS2_3.3V
 
 
|  
 
|  
|-
+
| RUN
| VSYS
+
|  
| PS2_5V
+
| 30
| 39
 
 
|-
 
|-
 
| GP8
 
| GP8
 
| PS2_CLK
 
| PS2_CLK
 
| 11
 
| 11
 +
|
 +
| GP26
 +
| SPARE GPIO
 +
| 31
 
|-
 
|-
 
| GP9
 
| GP9
 
| PS2_DATA
 
| PS2_DATA
 
| 12
 
| 12
 +
|
 +
| GP27
 +
| SPARE GPIO
 +
| 32
 
|-
 
|-
 
| GND
 
| GND
| PS2_GND
+
|  
 
| 13
 
| 13
 +
|
 +
| GND
 +
|
 +
| 33
 
|-
 
|-
| 3.3V
+
| GP10
| SD_3.3V
+
| SD_SCK
 +
| 14
 
|  
 
|  
|-
+
| GP28
| GP12
+
| SPARE GPIO
| SD_MISO
+
| 34
| 16
 
 
|-
 
|-
 
| GP11
 
| GP11
 
| SD_MOSI
 
| SD_MOSI
 
| 15
 
| 15
 +
|
 +
| ADCREF
 +
|
 +
| 35
 
|-
 
|-
| GP10
+
| GP12
| SD_SCK
+
| SD_MISO
| 14
+
| 16
 +
|
 +
| 3.3V
 +
| POWER_3.3V
 +
| 36
 
|-
 
|-
 
| GP13
 
| GP13
 
| SD_SLVSEL
 
| SD_SLVSEL
 
| 17
 
| 17
 +
|
 +
| VEN3
 +
|
 +
| 37
 
|-
 
|-
 
| GND
 
| GND
| SD_GND
+
|  
 
| 18
 
| 18
|-
+
|  
| GP18
 
| VGA_BLU
 
| 24
 
|-
 
 
| GND
 
| GND
| VGA_GND
+
|  
| 23
+
| 38
 
|-
 
|-
| GP20
+
| GP14
| VGA_GRN_HI
+
| I2C1_SDA (MCP23017)
| 26
+
| 19
 +
|
 +
| VSYS
 +
| PS2_5V
 +
| 39
 
|-
 
|-
| GP19
+
| GP15
| VGA_GRN_LO
+
| I2C1_SCL (MCP23017)
| 25
+
| 20
|-
+
|  
| GP16
+
| VBUS
| VGA_HSYNC
+
|  
| 21
+
| 40
|-
 
| GP21
 
| VGA_RED
 
| 27
 
|-
 
| GP17
 
| VGA_VSYNC
 
| 22
 
 
|-
 
|-
 
|}
 
|}
  
=== H1 - 3.3V Power ===
+
=== H1 - I2C Terminators ===
 +
 
 +
[[file:PiPicoMite01_H1_I2CTerms.PNG]]
 +
 
 +
* 2.2K terminators
 +
* Install shunts to terminate SDA, SCL signals that go to the on-board MCP23017 I2C Expander
 +
* Terminators are normally installed at the end of daisy-chained cards
 +
* I2C1 on Raspberry Pi Pico pins
 +
* I2C2 from MM BASIC
 +
* MM BASIC example commands
 +
<pre>
 +
DIM BUFF(1)
 +
SETPIN GP14, GP15, I2C2
 +
I2C2 OPEN 400, 100
 +
I2C2 WRITE &H20, OC, LEN, B0[, B1...]
 +
I2C2 READ &H20, OX, LEN, BUFF()
 +
</pre>
 +
* &H20 - I2C Address 0x20
 +
* OC: 0=terminate after, 1=chain next
 +
* len - Length of buffer (normally 1 for receive)
 +
* B0,B1... Bytes to send
 +
* BUFF() - receive buffer
 +
 
 +
=== H2 - MCP23017 - I2C Interrupt ===
 +
 
 +
[[file:PiPicoMite01_H2_I2C-Interrupt.PNG]]
 +
 
 +
* Install shunt to connect INTA interrupt from MCP23017 to GP2 on Pico
 +
* MCP23017 interrupts can be set to generate interrupts on INTA pins for both A abd B ports
 +
* No Pull-up on card
 +
 
 +
=== SD1 - SD Card ===
 +
 
 +
The PicoMiteVGA firmware reserves eight program storage "slots" in the Raspberry Pi Pico flash memory. Programs can be saved and retreived from these without the need for any additional storage.
 +
 
 +
For more storage SD cards can be connected with full support for these built into MMBasic including the ability to open files for reading, writing or random access and loading and saving programs. SD cards connect directly to the Raspberry Pi Pico and the firmware will work with cards up to 32GB formatted in FAT16 or FAT32. The files created can be read and written on personal computers running Windows, Linux or the Mac operating system.
 +
 
 +
The option values are:
 +
 
 +
<pre>
 +
OPTION SDCARD GP13, GP10, GP11, GP12
 +
</pre>
  
[[file:PiPicoMite01_H1_3p3V.PNG]]
+
After entering the OPTION, the card will re-boot and the SD card should be accessible.  
  
=== SD Card ===
+
[https://github.com/land-boards/RasPiPico/tree/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs Repository for SD Card files]
  
 
[[file:PiPicoMite01_J1_SD_Card.PNG]]
 
[[file:PiPicoMite01_J1_SD_Card.PNG]]
  
=== Pico Connectors ===
+
== Configuration Options ==
 +
 
 +
<pre>
 +
> OPTION LIST
 +
OPTION COLOURCODE ON
 +
OPTION KEYBOARD US
 +
OPTION SDCARD GP13, GP10, GP11, GP12
 +
OPTION AUDIO GP6,GP7, ON PWM CHANNEL 3
 +
option system i2c gp0, gp1
 +
</pre>
 +
 
 +
== PicoMiteVGA Software ==
 +
 
 +
=== Download MMBASIC ===
 +
 
 +
* Tested with "VGA only" versions
 +
** Released [https://geoffg.net/Downloads/picomite/PicoMiteVGA_Firmware.zip V5.07.04]
 +
** Beta [https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=14854#186644 V5.07.05b2]
 +
** [https://github.com/land-boards/RasPiPico/tree/main/PicoMite_MMBASIC/PicoMite_VGA/PicoMiteVGA_Firmware Copies of firmware versions] - some have unstable video mode 1
 +
* [https://www.thebackshed.com/forum/ViewTopic.php?TID=14854&P=1 TheBackShed MMBasic support forum]
 +
* [http://www.fruitoftheshed.com/MMBasic.AllPages.aspx Fruit Of The Shed] - _MMBasic Code Library
 +
* If the Pico does not already have MMBASIC installed
 +
* Hold button on Pico while plugging in USB Micro to PC
 +
* Drive will open
 +
* Drop VGA uf2 onto Drive
 +
* System will reboot
 +
 
 +
<pre>
 +
> print mm.ver
 +
5.070502
 +
</pre>
 +
 
 +
* Run TeraTerm
 +
** Connect to Serial
 +
 
 +
=== Configure MMBASIC ===
 +
 
 +
* Setups
 +
** Can copy-paste a line at a time into TeraTerm
 +
** First two will reboot card
 +
 
 +
<pre>
 +
OPTION SDCARD GP13, GP10, GP11, GP12
 +
OPTION AUDIO GP6, GP7
 +
OPTION COLOURCODE ON
 +
OPTION POWER PWM
 +
 
 +
</pre>
 +
 
 +
* If an external RTC is attached to J1
 +
 
 +
<pre>
 +
OPTION SYSTEM I2C GP0,GP1
 +
</pre>
 +
 
 +
* Remove USB power
 +
* Install SD card
 +
* Apply USB power
 +
 
 +
=== PicoMite Source code ===
 +
 
 +
* It's not necessary to build the source code since there are .uf2 files
 +
* [https://github.com/UKTailwind/PicoMite/tree/main/PicoMite PicoMite Source code]
 +
** [https://github.com/UKTailwind/PicoMite-VGA-Edition Extra/replacement files for VGA]
 +
 
 +
=== On-board 16-bit Port Expander Example Code ===
 +
 
 +
[https://github.com/land-boards/RasPiPico/tree/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01 Example code] that exercises the MCP23017 Port Expander on the PiPicoMite01 card.
 +
 
 +
* [https://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf MCP23017 Datasheet]
 +
 
 +
==== MCP23017_Blinkey.bas ====
 +
 
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01/MCP23017_Blinkey.bas MCP23017_Blinkey.bas]
 +
* Blink LED
 +
** Attach external LED
 +
*** LED with series resistor + side to PORTA bit 0 (marked as A0) to - side GND (ground)
 +
 
 +
==== MCP23017_Bits.bas ====
 +
 
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01/MCP23017_Bits.bas MCP23017_Bits.bas]
 +
* Good starting app to build Digital I/O apps on
 +
** Arduino-like, bit-wise control of on-board MCP23017
 +
** [https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/ DigitalRead], [https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/ DigitalWrite], [https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/ PinMode] functions
 +
* Application reads 8 switches and echos to 8 LEDs
 +
* Uses [[SWLEDX8]] card
 +
 
 +
[[file:PiPicoMite01_P1080361_720px.jpg]]
 +
 
 +
==== GPIO16-01.bas ====
 +
 
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01/GPIO16-01.bas GPIO16-01.bas]
 +
** Set all 16 GPIO pins as outputs
 +
** Write alternate patterns, bounce a 1 across the outputs
 +
* Use with [[LED-32]] card
 +
 
 +
[[file:LED-32-P426-720px.jpg]]
 +
 
 +
=== Land Boards Card Test Code ===
 +
 
 +
<video type="youtube">BFAmXNDGFA0</video>
 +
 
 +
==== MCP23017 on external cards ====
 +
 
 +
Code to test Land Boards cards which have MCP23017 parts.
 +
 
 +
* [http://land-boards.com/blwiki/index.php?title=PROTO16-I2C PROTO16-I2C card]
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/lbcards/GPIO16/GPIO16-02.bas GPIO16-02.bas]
 +
** Set all 16 GPIO pins as outputs
 +
** Write alternate patterns, bounce a 1 across the outputs
 +
* On [[SWLEDX8-I2C]] card
 +
** [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/lbcards/SWLEDX8/swledx8-03.bas swledx8-03.bas]
 +
** Read switches, write LEDs
 +
 
 +
==== MCP23008 Demo Code ====
 +
 
 +
* [https://ww1.microchip.com/downloads/en/DeviceDoc/MCP23008-MCP23S08-Data-Sheet-20001919F.pdf MCP23008 Datasheet]
 +
* [[I2CIO-8]] card
 +
* [https://github.com/land-boards/RasPiPico/tree/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/lbcards/I2CIO8 MMBASIC code] - GitHub repo
 +
** [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/lbcards/I2CIO8/I2CIO8_Test.bas I2CIO8_Test.bas] - Card Test program
 +
 
 +
=== Blocks (Tetris) ===
 +
 
 +
<pre>
 +
> memory
 +
Program:
 +
  13K (10%) Program (485 lines)
 +
  95K (90%) Free
 +
 
 +
RAM:
 +
  8K ( 5%) 31 Variables
 +
  0K ( 0%) General
 +
132K (95%) Free
 +
</pre>
 +
 
 +
[[file:Pico_Tetris.jpg]]
 +
 
 +
=== CP/M on Raspberry Pi Pico ===
 +
 
 +
* [https://github.com/ExtremeElectronics/RC2040 ExtremeElectronics GitHub] - Z80 RC2014 Emulation
 +
* [https://www.extremeelectronics.co.uk/emulating-a-z80-rc2014-with-cpm-and-ide-drives-via-an-sd-card/ EMULATING A Z80 RC2014 WITH CPM AND IDE DRIVES VIA AN SD CARD]
 +
 
 +
=== MMBASIC vs MicroPython Performance ===
 +
 
 +
<video type="youtube">VFdXTYLX6PU</video>
 +
 
 +
== CircuitPython on PiPicoMite0x Cards ==
 +
 
 +
* The PiPicoMite0x cards can run CircuitPython with some limitations
 +
* Card features for CircuitPython application
 +
** SD support
 +
** 1x MCP23017, 16-bit port expander
 +
*** 2x10 header
 +
** 5V input
 +
** External I2C
 +
* CircuitPython does not have built-in support for
 +
** VGA
 +
** PS/2
 +
** Audio
 +
 
 +
=== Thoughts on CircuitPython on PiPicoMite0x Cards ===
 +
 
 +
To my way of thinking PicoMiteVGA build is two things. The first is a software build/port of MMBASIC a powerful piece of software with a rich legacy onto the RP2040 core. The second part is the hardware baseline for the PicoMiteVGA build.
 +
 
 +
By way of contrast, the folks that came up with the RP2040 Hardware Reference design made a set of design choices and Pico pin assignments. These rippled into the C++ SDK code base. The differences are largely in 2 areas - the SD card and VGA. The PS/2 interface is a 3rd area of difference.
 +
 
 +
Each approach picked a different method accessing the SD card. PicoMite and PicoMiteVGA chose the SPI method to connect to the SD card. The Hardware Reference design used the other method which uses more pins but it ostensibly "faster" since it accesses the card in a nibble mode. I think the Hardware Reference design made a poor choice since it takes more pins. It's faster, but not "necessary" since SD card speed isn't critical for the vast majority of applications and it's certainly not minimal. In short, it takes up pins of the Pico that are better reserved for other functions.
 +
 
 +
Similarly, the Pico Hardware Reference design chose 16-bit video and PicoMiteVGA chose 4 -bit video. PicoMiteVGA will never do photo-realistic images but it can do "enough" for most applications, particularly "retro" games. Most importantly, the PiPicoMiteVGA hardware saves a whole lot of pins of the Pico. The evidence that the Hardware Reference design is overkill is their dual use of the least significant video bits as inputs which they say don't affect video quality when you use them. So why have them if they don;t matter? I think they were building a showcase design and unconcerned about applications which might want to use pins on the Pico - they didn't leave many/any free.
 +
 
 +
So back to the original question. I envision a use of the hardware design of the PicoMiteVGA where the card does what it does so well in MMBASIC but also can be used in either Micro or Circuit Python(s). The Python(s) build has/needs three features.
 +
 
 +
# The PS/2 keyboard which is missing in the Hardware Reference design is presen in the PicMiteVGA designt. After all, why have a display for output but no means of input other than USB? No way to have a standalone design and still be tethered to the USB port. The PS/2 keyboard then replaces the USB for input. Ie, the Hardware Reference design is all showy output but no input. They provide nice video but just a couple of dual use buttons for controls.
 +
# The SD card works just fine under the Python(s), It really just works under the Python(s) since that's the method they prefer anyway and they support it. I tried it, and it works. Again, it was another "showy" choice in the Reference design that allows boasting about SD performance but a poor choice for applications which want/need the extra pins.
 +
# The VGA replaces the USB for output, It comes with the stated compromises of the number of bits but that's just fine for most cases (at least most of the cases I care about). In the end the same PicoMiteVGA hardware can be used for standalone applications in either MMBASIC or the Python(s).
 +
 
 +
The pieces that are "missing" (the PS/2 and VGA code) already exist as C++ code which can be [https://docs.micropython.org/en/latest/develop/cmodules.html#basic-example made into precompiled Python modules] - essentially wrappers to the C++ code that can be called from Python. It would be more work, probably involving messing with the Python kernel itself - to get things like print() working. It involves the same things that video modes and fonts on MMBASIC entailed.
 +
 
 +
If someone wants to run MMBASIC or one of the Python(s) on the same PicoMiteVGA hardware baseline, why not? It's a perfectly good hardware baseline for either.
 +
 
 +
=== CircuitPython Digital I/O ===
 +
 
 +
* [https://github.com/land-boards/RasPiPico/blob/main/CircuitPython/CircuitPython_Code/digio16/Digio16Test.py PiPicoMite01_Digio16.py]
 +
** Control the MCP23017 part on the PiPicoMite01
 +
** Provides Arduino-like functions
 +
 
 +
<pre>
 +
# digitalWrite(bit,value)
 +
#    bit = 0-15
 +
#    value = 0, 1
 +
# digitalRead(bit)
 +
#    bit = 0-15
 +
#    returns 0, 1
 +
# pinMode(bit,value)
 +
#    bit = 0-15
 +
#    value = INPUT, OUTPUT, INPUT_PULLUP
 +
# pinMode(bit,value)
 +
</pre>
 +
 
 +
* [https://github.com/land-boards/RasPiPico/blob/main/CircuitPython/CircuitPython_Code/digio16/PiPicoMite01_Digio16.py PiPicoMite01_Digio16.py] - Example code uses the PiPicoMite01_Digio16 library
 +
 
 +
=== CircuitPython SD Card ===
 +
 
 +
* [https://learn.adafruit.com/micropython-hardware-sd-cards/tdicola-circuitpython Adafruit CircuitPython Module Install]
 +
* [https://learn.adafruit.com/micropython-hardware-sd-cards/code-storage-on-sd-card Code Storage on SD Card]
 +
* [https://github.com/land-boards/RasPiPico/blob/main/CircuitPython/CircuitPython_Code/SD_Card/SDCard_Dir.py SDCard_Dir.py] - List SD Card directory
 +
* Pins (from MMBASIC)
 +
 
 +
<pre>
 +
# OPTION SDCARD GP13, GP10, GP11, GP12
 +
# CS = GP13
 +
# SCK = GP10
 +
# MOSI = GP11
 +
# MISO = GP12
 +
 
 +
spi = busio.SPI(board.GP10, MOSI=board.GP11, MISO=board.GP12)
 +
cs = board.GP13
 +
 
 +
sdcard = sdcardio.SDCard(spi, cs)
 +
</pre>
 +
 
 +
* Make directories
 +
 
 +
<pre>
 +
>>> os.mkdir('/sd/CircuitPython/')
 +
>>> os.mkdir('/sd/CircuitPython/SD_Card')
 +
</pre>
 +
 
 +
* Add code to path
 +
 
 +
<pre>
 +
>>> import sys
 +
>>> sys.path
 +
['', '/', '.frozen', '/lib']
 +
>>> sys.path.append("/sd")
 +
>>> sys.path
 +
['', '/', '.frozen', '/lib', '/sd']
 +
>>> os.listdir('/sd/CircuitPython/SD_Card')
 +
[]
 +
</pre>
 +
 
 +
== Factory Test Procedure ==
 +
 
 +
* Test assembled cards using this procedure
 +
* MMBASIC is already set up on the card
 +
 
 +
=== Equipment ===
 +
 
 +
* Unit Under Test (UUT)
 +
* VGA monitor
 +
* Stereo amplified speakers
 +
* PS/2 keyboard
 +
* MMBASIC SD card with contents
 +
** [https://github.com/land-boards/RasPiPico/tree/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs Test Software repo]
 +
* Raspberry Pi Pico with MMBASIC installed
 +
* PC running [http://www.teraterm.org/ TeraTerm]
 +
* If optional port expander is installed
 +
** [[LED-32]] card
 +
** Cable from GPIO to [[LED-32]] card
 +
 
 +
=== Test SD card interface ===
 +
 
 +
* Type
 +
<pre>
 +
files
 +
</pre>
 +
* Returns
 +
<pre>
 +
A:/
 +
  <DIR>  basic
 +
  <DIR>  bmps
 +
  <DIR>  demos
 +
  <DIR>  games
 +
  <DIR>  jpegs
 +
  <DIR>  lbcards
 +
  <DIR>  performance
 +
  <DIR>  wave
 +
8 directories, 0 files
 +
</pre>
 +
 
 +
=== Test Sound ===
 +
 
 +
* Loads [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/wave/sample4.wav sample4.wav file]
 +
* Type
 +
<pre>
 +
chdir "/wave"
 +
play wav "sample4.wav"
 +
 
 +
</pre>
 +
* Verify sound comes out of both speakers
 +
* Stop with
 +
<pre>
 +
play stop
 +
 
 +
</pre>
 +
 
 +
=== Test Keyboard ===
 +
 
 +
* Type on keyboard
 +
* Verify keys show up on VGA
 +
 
 +
=== Test VGA ===
 +
 
 +
* Type
 +
 
 +
<pre>
 +
chdir "/demos"
 +
load "Colours.bas"
 +
run
 +
 
 +
</pre>
 +
 
 +
* Verify 16 distinct colors on VGA
 +
* Type
 +
 
 +
<pre>
 +
mode 1
 +
 
 +
</pre>
 +
 
 +
=== Test 5V in ===
 +
 
 +
* Connect USB B to 5V (or PC)
 +
* Remove USB Micro cable
 +
* Card should continue to run
 +
 
 +
=== Test GPIO (Rev 2 card) (if optional MCP23017 is installed) ===
 +
 
 +
* Connect [[LED-32]] card to J1
 +
* Runs [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01/GPIO16-01.bas GPIO16-01.bas]
 +
** Rev 1 card requires edit to reverse the following change
 +
 
 +
[[file:PiPicoMite_Rev1_vs_Rev2.PNG]]
 +
 
 +
* Type
 +
 
 +
<pre>
 +
chdir "/lbcards/GPIO16"
 +
load "gpio16-01.bas"
 +
run
 +
 
 +
</pre>
 +
 
 +
* Board will display
 +
 
 +
<pre>
 +
Looping through LEDs
 +
Hit a key to stop
 +
</pre>
 +
 
 +
* Verify that all LEDs blink
 +
* Any key will stop the program
 +
 
 +
=== Test I2C (Rev 2 card) ===
 +
 
 +
* Use DS1307 RTC ([https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2380057.m570.l2632&_nkw=ds1307+rtc&_sacat=92074 ebay search]) attached to I2C J1
 +
 
 +
[[file:PiPicoMite01_RTC_P1080357_Cropped_720px.jpg]]
 +
 
 +
[[FILE:PiPicoMite01_J8_I2C.PNG]]
 +
 
 +
# I2C0SCL wired to RTC SCL
 +
# I2C0SDA wired to RTC SDA
 +
# VCC wired to RTC VCC
 +
# GND wired to RTC GND
 +
 
 +
[[FILE:RTC_PartsSide.PNG]]
 +
 
 +
* If RTC is not configured, type
 +
 
 +
<pre>
 +
option system i2c gp0, gp1
 +
rtc settime YYYY, MM, DD, HH, MM, SS
 +
 
 +
</pre>
 +
 
 +
* Check time
 +
 
 +
<pre>
 +
rtc gettime
 +
print time$
 +
 
 +
</pre>
 +
 
 +
* Verify RTC time works
 +
 
 +
=== Combined Copy/Paste ===
 +
 
 +
* Above tests can be copy/pasted
 +
 
 +
<pre>
 +
files
 +
 
 +
chdir "/wave"
 +
play wav "sample4.wav"
 +
 
 +
play stop
 +
 
 +
chdir "/demos"
 +
load "Colours.bas"
 +
run
 +
 
 +
mode 1
 +
 
 +
flash load 5
 +
run
 +
 
 +
option system i2c gp0, gp1
 +
rtc gettime
 +
print time$
 +
</pre>
 +
 
 +
* If MCP23017 is installed
 +
* [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Land%20Boards%20BASIC%20Programs/On-Board_Digital_IO/PiPicoMite01/MCP23017_Bits.bas MCP23017_Bits.bas]
 +
* Stored in Flash 5
 +
 
 +
== Mechanicals ==
 +
 
 +
[[file:PicoMite01_Rev2_Mechs.PNG]]
 +
 
 +
== Issues ==
 +
 
 +
=== Rev 2 ===
 +
 
 +
* Re-sequenced jacks and capacitors reference designators to left-to-right/top-to-bottom order
 +
** In sequential order for easier finding during assembly
 +
* Fixed on-board MCP23017 I2C SDA/SCL pins order
 +
* Added I2C Interface Header
 +
* Moved Vcc to the end of the GPIO connector
 +
* Checkout showed card is fully functional with no rework
 +
 
 +
=== Rev 1 ===
 +
 
 +
* Tested and working
 +
** Pico boots and runs
 +
** VGA passes [https://github.com/land-boards/RasPiPico/blob/main/PicoMite_MMBASIC/PicoMite_VGA/Example%20BASIC%20Programs/Colours.bas Colours.bas] test
 +
** PS/2 can type
 +
** SD Card loads files
 +
** Audio plays wav files
 +
 
 +
==== Issue with I2C connections to MCP23017 - Rework ====
 +
 
 +
 
 +
* SDA, SCL swapped to MCP23017
 +
* Cut etch solder side Pico pin 19 (to U2-12)
 +
* Cut etch solder side Pico pin 20 (to U2-13)
 +
* Cuts are done on rear side (CAD)
 +
* Verify cuts with ohmmeter
  
[[file:PiPicoMite01_J4-5_PiPico.PNG]]
+
[[file:PicoMite01_X1_Rework_I2C2.PNG]]
  
=== GPIO ===
+
* Cuts shown on board (using sharp [https://www.amazon.com/Xacto-X3201-N0-Precision-Knife/dp/B00004Z2TQ Xacto knife])
  
[[file:PiPicoMite01_J6_GPIO.PNG]]
+
[[file:PiMicoMite01_P18202_Cuts_Jumpers.jpg]]
  
=== Audio ===
+
* Jumpers
 +
* Add wire Pico pin 19 to U2-13 (GP14)
 +
* Add wire Pico pin 20 to U2-12 (GP15)
 +
* Glue down wires with small dots of Superglue
  
[[file:PiPicoMite01_J7_Audio.PNG]]
+
[[file:PiMicoMite01_P18202_720px_Jumpers.jpg]]
  
=== PS/2 Keyboard ===
+
== Prototype Build ==
  
[[file:PiPicoMite01_J8_Keyboard.PNG]]
+
<video type="youtube">gIK1ujslHHI</video>
  
=== 5V Distribution ===
+
* [[Raspberry Pi Pico MM BASIC Build]]
 +
* Built from Land Boards cards
  
[[file:PiPicoMite01_J9_5V.PNG]]
+
[[file:PicoMite_Proto_P18159_720px.jpg]]
  
=== VGA ===
+
== Assembly Sheet ==
  
[[file:PiPicoMite01_P1_VGA.PNG]]
+
* Make sure you build with the current revision assembly sheet
 +
** Revision is marked on the rear of the card
 +
* [[PiPicoMite01 Rev2 Assembly Sheet]]
 +
* [http://land-boards.com/PiPicoMite01/PiPicoMite01_ibom_Rev2.html PiPicoMite01 Rev2 Interactive BOM]
 +
* [[PiPicoMite01 Rev1 Assembly Sheet]]

Latest revision as of 19:37, 8 February 2023

Tindie-mediums.png

PiPicoMite01 Rev2 P18315-720px.jpg

Card Versions

  • There are three versions of this card
    • PiPicoMite01 (this version)
      • Has 16-bit port I/O expander
      • 120x70mm with (4) 6-32 mounting holes
    • PiPicoMite02
      • Has 32-bit port I/O expander(s)
      • 95x95mm with (4) 6-32 mounting holes
    • PiPicoMite03
      • 99.5x69.5mm - Fits into extruded Aluminum Enclosure
      • Fully functional, reduced cost

Features

  • Raspberry Pi Pico
    • All Pico pins brought to headers
    • Pico pin marking on rear
  • VGA
    • 640x480 monochrome resolution
    • 320x240 colour resolution
    • 1:2:1 - R:G:B - 16 colours
  • PS/2 Keyboard
    • 5V to keyboard with voltage translator
    • Does not require a keyboard that runs at 3.3V
  • SD Card
  • Stereo audio
  • 16 bit Port Expander
    • MCP23017 Datasheet - Rev D
    • MCP23017... LOST TWO INPUTS
      • MCP23017 now a 14/16-bit expander, with two of the pins (GPA7 and GPB7) losing their input capabilities
      • The chips look the same, are called the same, and act mostly the same — if you don’t download the latest version of the datasheet (Revision D), you’d never know that there’s been a change* 16-bit General Purpose I/O (GPIO)
    • On Pico I2C1 (I2C2 from MMBASIC)
    • 2x10 0.1" pitch header
    • Jumper selectable terminators
  • I2C0 connector (Rev 2 and later)
    • Requires external I2C terminators
  • Power options
    • 5V power input
      • USB Micro on Pico card
      • USB B
      • 0.1" pitch header
    • 3.3V output header
  • 120mmx70mm outline
  • (4) 6-32 Mounting holes

BASIC Interpreter

The PicoMiteVGA boots straight into the MMBasic prompt. At which point you can enter, edit and save the program, test BASIC commands and run the program.

MMBasic is a Microsoft BASIC compatible implementation of the BASIC language, originally written by Geoff Graham and enhanced and ported to the Pico by Peter Mather, who also designed the original PicoMite on which this design is based. It is full featured with floating point, 64-bit integers and string variables, long variable names, arrays of floats, integers or strings with multiple dimensions, extensive string handling and user defined subroutines and functions. Typically it will execute a program up to 100,000 lines per second. Embedded compiled C programs can be used for even higher performance.

Using MMBasic you can use communications protocols such as I2C or SPI to get data from a variety of sensors. You can save data to an SD card, measure voltages, detect digital inputs and drive output pins to turn on lights, relays, etc.

The emphasis with MMBasic is on ease of use and development. The development cycle is very fast with the ability to instantly switch from edit to run. Errors are listed in plain English and when an error does occur a single keystroke will invoke the built in editor with the cursor positioned on the line that caused the error.

MMBASIC Credits

Peter Mather led the project, ported the MMBasic interpreter to the Raspberry Pi Pico and wrote the hardware device drivers. Geoff Graham wrote the MMBasic interpreter and the manual. Mick Ames wrote the PIO compiler and its corresponding documentation. The VGA driver code was derived from work by Miroslav Nemecek.

Raspberry Pi Pico Pinout (Reference)

PiPico Pins.PNG

Pin Marking on Rear (Rev 2)

PiPicoMite01 REAR 3D.png

Schematic

Rev 1 Connectors

Rev 2 Connectors

  • The following are for Rev 2 and later boards

PicoMite01 Rev2 CAD.PNG

J1 - MCP23017 - 16-bit GPIO

  • MCP23017 Datasheet - Rev D
    • MCP23017... LOST TWO INPUTS
      • MCP23017 now a 14/16-bit expander, with two of the pins (GPA7 and GPB7) losing their input capabilities
      • The chips look the same, are called the same, and act mostly the same — if you don’t download the latest version of the datasheet (Revision D), you’d never know that there’s been a change
  • 2x10 header
    • 16 bits of Digital I/O
      • A0 silkscreen marking = GPA0, etc.
    • (2) Power
    • (2) Ground
  • On I2C2 pins (I2C1 on Pico)
    • SetPin BASIC code
SetPin GP14, GP15, I2C2

PiPicoMite01 J1 GPIO.PNG

  • Initialization code
  • Set all pins to outputs
MCP23017_I2CADR   = &H20
MCP23017_IODIRA   = &H00
MCP23017_IODIRB   = &H01
MCP23017_IPOLA    = &H02
MCP23017_IPOLB    = &H03
MCP23017_GPINTENA = &H04
MCP23017_GPINTENB = &H05
MCP23017_DEFVALA  = &H06
MCP23017_DEFVALB  = &H07
MCP23017_INTCONA  = &H08
MCP23017_INTCONB  = &H09
MCP23017_IOCON    = &H0A
MCP23017_GPPUA    = &H0C
MCP23017_GPPUB    = &H0D
MCP23017_INTFA    = &H0E
MCP23017_INTFB    = &H0F
MCP23017_INTCAPA  = &H10
MCP23017_INTCAPB  = &H11
MCP23017_GPIOA    = &H12
MCP23017_GPIOB    = &H13
MCP23017_OLATA    = &H14
MCP23017_OLATB    = &H15

SetPin GP14, GP15, I2C2
I2C2 OPEN 400, 100
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_IODIRA, &H00
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_IODIRB, &H00
  • Write alternating patterns on output pins
' Alternating patterns
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &H55
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &HAA
Pause 1000
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &HAA
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &H55
Pause 200
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATA, &H00
I2C2 WRITE MCP23017_I2CADR, 0, 2, MCP23017_OLATB, &H00

J2 - VGA

The VGA output is 640 x 480 pixels in monochrome mode or 320 x 240 pixels in colour mode with 16 colours (1 bit for red, 2 bits for green and 1 bit for blue). The VGA output is generated using the second CPU on the RP2040 processor plus one PIO channel so it does not affect the BASIC interpreter which runs at full speed on the first CPU. A handfull of components (resistors and a couple of diodes) is all that is required to connect the VGA monitor.

From within your BASIC program you can turn pixels on/off and draw lines, boxes and circles in any colour. Text can be positioned anywhere on the screen and displayed in any colour in a variety of fonts.

The built-in editor within MMBasic works perfectly with the VGA monitor and PS2 keyboard to allow programs to be edited (with colour coded text) and saved to an SD card.

Mode 1 (640x480 monochrome) and mode 2 (320x240 16-colours).

OPTION COLOURCODE ON

PiPicoMite01 J2 VGA.PNG

J3 - 3.3V Power Out

PiPicoMite01 J3 3p3V.PNG

J4 - Audio

OPTION POWER PWM
  • Play a WAV file
OPTION AUDIO GP6, GP7
PLAY WAV "file.wav"
PLAY STOP

PiPicoMite01 J4 Audio.PNG

J5 - USB B Power Connector

  • In parallel with J6

PiPicoMite01 J5 5V-Power.PNG

  • Full size USB B connector
  • No USB signal connections, just used for power

J6 - 5V Input

PiPicoMite01 J6-5V.PNG

  • Useful to power the card from external 5V
  • Use in place of J5

J7 - PS/2 Keyboard

The PS2 keyboard connects to the Raspberry Pi Pico via a level shifter and works as a normal keyboard with the function keys and arrow keys fully operational. It can be configured for the standard US layout used in the USA, Australia and New Zealand or specialised layouts used in the United Kingdom, Germany, France and Spain.

  • 5V keyboard

PiPicoMite01 J7 PS2-Keyboard.PNG

J8 - I2C0, UART0 (RTC, etc.)

PiPicoMite01 J8 I2C.PNG

  1. I2C0SCL. UART0_TX (GP1)
  2. I2C0SDA. UART0_RX (GP0)
  3. VCC
  4. GND

Can use Real Time Clocks using the PCF8563, DS1307, DS3231 or DS3232 chips means that the time is always accurately known.

option system i2c gp0, gp1

J9, J10 Pico Connectors

  • Pico pins are brought out to 1x20 pin headers J9, J10

PiPicoMite01 J9-10 PiPico.PNG

Pico Function Mapping

GP FUNCTION PICO PIN GP FUNCTION PICO PIN
GP0 J8-2 (I2C0_SDA) 1 GP16 VGA_HSYNC 21
GP1 J8-1 (I2C0_SCL) 2 GP17 VGA_VSYNC 22
GND 3 GND 23
GP2 MCP23017_INTA (H2) 4 GP18 VGA_BLU 24
GP3 SPARE GPIO 5 GP19 VGA_GRN_LO 25
GP4 SPARE GPIO 6 GP20 VGA_GRN_HI 26
GP5 SPARE GPIO 7 GP21 VGA_RED 27
GND 8 GND 28
GP6 AUDIO-L 9 GP22 SPARE GPIO 29
GP7 AUDIO-R 10 RUN 30
GP8 PS2_CLK 11 GP26 SPARE GPIO 31
GP9 PS2_DATA 12 GP27 SPARE GPIO 32
GND 13 GND 33
GP10 SD_SCK 14 GP28 SPARE GPIO 34
GP11 SD_MOSI 15 ADCREF 35
GP12 SD_MISO 16 3.3V POWER_3.3V 36
GP13 SD_SLVSEL 17 VEN3 37
GND 18 GND 38
GP14 I2C1_SDA (MCP23017) 19 VSYS PS2_5V 39
GP15 I2C1_SCL (MCP23017) 20 VBUS 40

H1 - I2C Terminators

PiPicoMite01 H1 I2CTerms.PNG

  • 2.2K terminators
  • Install shunts to terminate SDA, SCL signals that go to the on-board MCP23017 I2C Expander
  • Terminators are normally installed at the end of daisy-chained cards
  • I2C1 on Raspberry Pi Pico pins
  • I2C2 from MM BASIC
  • MM BASIC example commands
DIM BUFF(1)
SETPIN GP14, GP15, I2C2
I2C2 OPEN 400, 100
I2C2 WRITE &H20, OC, LEN, B0[, B1...]
I2C2 READ &H20, OX, LEN, BUFF()
  • &H20 - I2C Address 0x20
  • OC: 0=terminate after, 1=chain next
  • len - Length of buffer (normally 1 for receive)
  • B0,B1... Bytes to send
  • BUFF() - receive buffer

H2 - MCP23017 - I2C Interrupt

PiPicoMite01 H2 I2C-Interrupt.PNG

  • Install shunt to connect INTA interrupt from MCP23017 to GP2 on Pico
  • MCP23017 interrupts can be set to generate interrupts on INTA pins for both A abd B ports
  • No Pull-up on card

SD1 - SD Card

The PicoMiteVGA firmware reserves eight program storage "slots" in the Raspberry Pi Pico flash memory. Programs can be saved and retreived from these without the need for any additional storage.

For more storage SD cards can be connected with full support for these built into MMBasic including the ability to open files for reading, writing or random access and loading and saving programs. SD cards connect directly to the Raspberry Pi Pico and the firmware will work with cards up to 32GB formatted in FAT16 or FAT32. The files created can be read and written on personal computers running Windows, Linux or the Mac operating system.

The option values are:

OPTION SDCARD GP13, GP10, GP11, GP12

After entering the OPTION, the card will re-boot and the SD card should be accessible.

Repository for SD Card files

PiPicoMite01 J1 SD Card.PNG

Configuration Options

> OPTION LIST
OPTION COLOURCODE ON
OPTION KEYBOARD US
OPTION SDCARD GP13, GP10, GP11, GP12
OPTION AUDIO GP6,GP7, ON PWM CHANNEL 3
option system i2c gp0, gp1

PicoMiteVGA Software

Download MMBASIC

> print mm.ver
 5.070502
  • Run TeraTerm
    • Connect to Serial

Configure MMBASIC

  • Setups
    • Can copy-paste a line at a time into TeraTerm
    • First two will reboot card
OPTION SDCARD GP13, GP10, GP11, GP12
OPTION AUDIO GP6, GP7
OPTION COLOURCODE ON
OPTION POWER PWM

  • If an external RTC is attached to J1
OPTION SYSTEM I2C GP0,GP1
  • Remove USB power
  • Install SD card
  • Apply USB power

PicoMite Source code

On-board 16-bit Port Expander Example Code

Example code that exercises the MCP23017 Port Expander on the PiPicoMite01 card.

MCP23017_Blinkey.bas

  • MCP23017_Blinkey.bas
  • Blink LED
    • Attach external LED
      • LED with series resistor + side to PORTA bit 0 (marked as A0) to - side GND (ground)

MCP23017_Bits.bas

PiPicoMite01 P1080361 720px.jpg

GPIO16-01.bas

  • GPIO16-01.bas
    • Set all 16 GPIO pins as outputs
    • Write alternate patterns, bounce a 1 across the outputs
  • Use with LED-32 card

LED-32-P426-720px.jpg

Land Boards Card Test Code

MCP23017 on external cards

Code to test Land Boards cards which have MCP23017 parts.

MCP23008 Demo Code

Blocks (Tetris)

> memory
Program:
  13K (10%) Program (485 lines)
  95K (90%) Free

RAM:
   8K ( 5%) 31 Variables
   0K ( 0%) General
 132K (95%) Free

Pico Tetris.jpg

CP/M on Raspberry Pi Pico

MMBASIC vs MicroPython Performance

CircuitPython on PiPicoMite0x Cards

  • The PiPicoMite0x cards can run CircuitPython with some limitations
  • Card features for CircuitPython application
    • SD support
    • 1x MCP23017, 16-bit port expander
      • 2x10 header
    • 5V input
    • External I2C
  • CircuitPython does not have built-in support for
    • VGA
    • PS/2
    • Audio

Thoughts on CircuitPython on PiPicoMite0x Cards

To my way of thinking PicoMiteVGA build is two things. The first is a software build/port of MMBASIC a powerful piece of software with a rich legacy onto the RP2040 core. The second part is the hardware baseline for the PicoMiteVGA build.

By way of contrast, the folks that came up with the RP2040 Hardware Reference design made a set of design choices and Pico pin assignments. These rippled into the C++ SDK code base. The differences are largely in 2 areas - the SD card and VGA. The PS/2 interface is a 3rd area of difference.

Each approach picked a different method accessing the SD card. PicoMite and PicoMiteVGA chose the SPI method to connect to the SD card. The Hardware Reference design used the other method which uses more pins but it ostensibly "faster" since it accesses the card in a nibble mode. I think the Hardware Reference design made a poor choice since it takes more pins. It's faster, but not "necessary" since SD card speed isn't critical for the vast majority of applications and it's certainly not minimal. In short, it takes up pins of the Pico that are better reserved for other functions.

Similarly, the Pico Hardware Reference design chose 16-bit video and PicoMiteVGA chose 4 -bit video. PicoMiteVGA will never do photo-realistic images but it can do "enough" for most applications, particularly "retro" games. Most importantly, the PiPicoMiteVGA hardware saves a whole lot of pins of the Pico. The evidence that the Hardware Reference design is overkill is their dual use of the least significant video bits as inputs which they say don't affect video quality when you use them. So why have them if they don;t matter? I think they were building a showcase design and unconcerned about applications which might want to use pins on the Pico - they didn't leave many/any free.

So back to the original question. I envision a use of the hardware design of the PicoMiteVGA where the card does what it does so well in MMBASIC but also can be used in either Micro or Circuit Python(s). The Python(s) build has/needs three features.

  1. The PS/2 keyboard which is missing in the Hardware Reference design is presen in the PicMiteVGA designt. After all, why have a display for output but no means of input other than USB? No way to have a standalone design and still be tethered to the USB port. The PS/2 keyboard then replaces the USB for input. Ie, the Hardware Reference design is all showy output but no input. They provide nice video but just a couple of dual use buttons for controls.
  2. The SD card works just fine under the Python(s), It really just works under the Python(s) since that's the method they prefer anyway and they support it. I tried it, and it works. Again, it was another "showy" choice in the Reference design that allows boasting about SD performance but a poor choice for applications which want/need the extra pins.
  3. The VGA replaces the USB for output, It comes with the stated compromises of the number of bits but that's just fine for most cases (at least most of the cases I care about). In the end the same PicoMiteVGA hardware can be used for standalone applications in either MMBASIC or the Python(s).

The pieces that are "missing" (the PS/2 and VGA code) already exist as C++ code which can be made into precompiled Python modules - essentially wrappers to the C++ code that can be called from Python. It would be more work, probably involving messing with the Python kernel itself - to get things like print() working. It involves the same things that video modes and fonts on MMBASIC entailed.

If someone wants to run MMBASIC or one of the Python(s) on the same PicoMiteVGA hardware baseline, why not? It's a perfectly good hardware baseline for either.

CircuitPython Digital I/O

# digitalWrite(bit,value)
#    bit = 0-15
#    value = 0, 1
# digitalRead(bit)
#    bit = 0-15
#    returns 0, 1
# pinMode(bit,value)
#    bit = 0-15
#    value = INPUT, OUTPUT, INPUT_PULLUP
# pinMode(bit,value)

CircuitPython SD Card

# OPTION SDCARD GP13, GP10, GP11, GP12
# CS = GP13
# SCK = GP10
# MOSI = GP11
# MISO = GP12

spi = busio.SPI(board.GP10, MOSI=board.GP11, MISO=board.GP12)
cs = board.GP13

sdcard = sdcardio.SDCard(spi, cs)
  • Make directories
>>> os.mkdir('/sd/CircuitPython/')
>>> os.mkdir('/sd/CircuitPython/SD_Card')
  • Add code to path
>>> import sys
>>> sys.path
['', '/', '.frozen', '/lib']
>>> sys.path.append("/sd")
>>> sys.path
['', '/', '.frozen', '/lib', '/sd']
>>> os.listdir('/sd/CircuitPython/SD_Card')
[]

Factory Test Procedure

  • Test assembled cards using this procedure
  • MMBASIC is already set up on the card

Equipment

  • Unit Under Test (UUT)
  • VGA monitor
  • Stereo amplified speakers
  • PS/2 keyboard
  • MMBASIC SD card with contents
  • Raspberry Pi Pico with MMBASIC installed
  • PC running TeraTerm
  • If optional port expander is installed

Test SD card interface

  • Type
files
  • Returns
A:/
   <DIR>  basic
   <DIR>  bmps
   <DIR>  demos
   <DIR>  games
   <DIR>  jpegs
   <DIR>  lbcards
   <DIR>  performance
   <DIR>  wave
8 directories, 0 files

Test Sound

chdir "/wave"
play wav "sample4.wav"

  • Verify sound comes out of both speakers
  • Stop with
play stop

Test Keyboard

  • Type on keyboard
  • Verify keys show up on VGA

Test VGA

  • Type
chdir "/demos"
load "Colours.bas"
run

  • Verify 16 distinct colors on VGA
  • Type
mode 1

Test 5V in

  • Connect USB B to 5V (or PC)
  • Remove USB Micro cable
  • Card should continue to run

Test GPIO (Rev 2 card) (if optional MCP23017 is installed)

  • Connect LED-32 card to J1
  • Runs GPIO16-01.bas
    • Rev 1 card requires edit to reverse the following change

PiPicoMite Rev1 vs Rev2.PNG

  • Type
chdir "/lbcards/GPIO16"
load "gpio16-01.bas"
run

  • Board will display
Looping through LEDs
Hit a key to stop
  • Verify that all LEDs blink
  • Any key will stop the program

Test I2C (Rev 2 card)

PiPicoMite01 RTC P1080357 Cropped 720px.jpg

PiPicoMite01 J8 I2C.PNG

  1. I2C0SCL wired to RTC SCL
  2. I2C0SDA wired to RTC SDA
  3. VCC wired to RTC VCC
  4. GND wired to RTC GND

RTC PartsSide.PNG

  • If RTC is not configured, type
option system i2c gp0, gp1
rtc settime YYYY, MM, DD, HH, MM, SS

  • Check time
rtc gettime
print time$

  • Verify RTC time works

Combined Copy/Paste

  • Above tests can be copy/pasted
files

chdir "/wave"
play wav "sample4.wav"

play stop

chdir "/demos"
load "Colours.bas"
run

mode 1

flash load 5
run

option system i2c gp0, gp1
rtc gettime
print time$

Mechanicals

PicoMite01 Rev2 Mechs.PNG

Issues

Rev 2

  • Re-sequenced jacks and capacitors reference designators to left-to-right/top-to-bottom order
    • In sequential order for easier finding during assembly
  • Fixed on-board MCP23017 I2C SDA/SCL pins order
  • Added I2C Interface Header
  • Moved Vcc to the end of the GPIO connector
  • Checkout showed card is fully functional with no rework

Rev 1

  • Tested and working
    • Pico boots and runs
    • VGA passes Colours.bas test
    • PS/2 can type
    • SD Card loads files
    • Audio plays wav files

Issue with I2C connections to MCP23017 - Rework

  • SDA, SCL swapped to MCP23017
  • Cut etch solder side Pico pin 19 (to U2-12)
  • Cut etch solder side Pico pin 20 (to U2-13)
  • Cuts are done on rear side (CAD)
  • Verify cuts with ohmmeter

PicoMite01 X1 Rework I2C2.PNG

PiMicoMite01 P18202 Cuts Jumpers.jpg

  • Jumpers
  • Add wire Pico pin 19 to U2-13 (GP14)
  • Add wire Pico pin 20 to U2-12 (GP15)
  • Glue down wires with small dots of Superglue

PiMicoMite01 P18202 720px Jumpers.jpg

Prototype Build

PicoMite Proto P18159 720px.jpg

Assembly Sheet