Raspberry Pi RP2040: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 59: Line 59:
Get the adafruit circuit python for your version of CP. Unzip it and put adafruit_gps.mpy in lib/ on the device.
Get the adafruit circuit python for your version of CP. Unzip it and put adafruit_gps.mpy in lib/ on the device.


<code>
<pre>
# Write your code here :-)
import board
import board
import busio
import busio
Line 81: Line 80:
     print(gps.satellites, gps.pdop, gps.hdop)
     print(gps.satellites, gps.pdop, gps.hdop)
     t = now
     t = now
</code>
</pre>


==== Crash recovery ====
==== Crash recovery ====

Revision as of 04:02, 1 April 2024

Inventory

These are RP2040 boards that I have right now.

  • 2x RPi PicoEdit
  • Adafruit Feather RP2040
  • Seeed Studio SenseCAP Indicator
  • Wiznet EVB hat for a Pico (ethernet)
  • Wiznet Pico WS5100S which is the Pico and ethernet on one board

Development

Using a Pi as the dev platform is described here, RPI "getting started" doc Setting up on Windows is not the same. See the C/C++ section below.

Arduino

Seeed Studio suggests using Arduino to program the RP2040 in the Sensecap D1, but, meh, not an Arduino fan so I have not tried it yet.

C/C++ in Windows + Visual Studio Code

Tracking the official instructions, I ran their installer for Windows.

The examples end up in Documents/Pico*. Examples for the Pico board are in Github.

FreeRTOS

Since FreeRTOS can be used on the ESP32 (on the SenseCap D1), I should look at it for the RP2040 too.

Python

Micropython

See also the Micropython page for now.

CircuitPython

Download from CircuitPython -- make sure you download the correct version, for example, the Rpi Pico version does not work on the Feather (but does work on SenseCap). Adafruit recommends you use the latest beta image, not the stable one.

General notes on VSCode. At one point I gave up on using VSCode with Micropython but last time I tried, it was fine. Maybe I can get Pymakr extension going now that I have figured out CircuitPython.

When you fire up a CP board (any, regardless of who made it, if it runs CP), it will mount a drive and set up a serial port. If you edit files it will automatically restart. Micropython uses a REPL instead of a drive so it's not as easy.

  1. Install CircuitPython on the board. (Power cycle with BOOT button held down then drag the UF2 file onto the drive.) It will reboot itself.
  2. Start Visual Studio Code.
  3. Select the board. There should be a way to do that from the bottom bar.
  4. Open a serial console, also in the bottom bar. You should see it's CircuitPython in the window.
  5. Open the folder.
  6. Edit the file code.py and save it. Saving will force reload the script and that should be visible in the console.
GPS AT6558

This is an M5 Grove module. (You can tell it's M5 because of the fine little enclosure, Seeed boards tend to be naked.) I put the Pico on a Grove interface board and plugged in the GPS to the UART0 port. There is a crossbar so any port can do anything on the RP2040 so I have to initialize the port, it's marked UART0 on the board so I went with that (GP0,GP1)

Get the adafruit circuit python for your version of CP. Unzip it and put adafruit_gps.mpy in lib/ on the device.

import board
import busio
import time
import adafruit_gps
uart = busio.UART(tx=board.GP0, rx=board.GP1, baudrate=9600, timeout=10)
gps = adafruit_gps.GPS(uart, debug=False)  # Use UART/pyserial
t = time.monotonic()
while True:
    gps.update()
    now = time.monotonic()
    if now - t < 1.0:
        continue
    if not gps.has_fix:
        print("no fix")
        time.sleep(.5)
        continue
    print(gps.datetime)
    print("{0:.6f}".format(gps.latitude),"{0:.6f}".format(gps.longitude), gps.altitude_m)
    print(gps.satellites, gps.pdop, gps.hdop)
    t = now

Crash recovery

I wrote a CircuitPython script that my SenseCap did not like, and it stopped mounting the storage device so I could not edit it. I reflashed it with "flash_nuke.uf2".

(Hold down the hidden reset button + power up to get a "root" storage device then drag and drop). This will put it back in a pristine state, wiping out your code.py file and forcing you to reinstall CircuitPython. Flash_nuke.uf2 has been added to my tool kit.

The errant program was one that tries to play an MP3 piano sample on the internal buzzer. It almost works. Lots of buzzing and clicking though.

Projects

Power management

The idea for this project is to manage a power strip or other interface that can control other equipment including load shedding and watchdog restarts. I want to define an API and talk to it exclusively via MQTT pub/sub messages.

  • Track the Ubiquiti link, and reset the link if the remote sites go offline. Can the UBNT do that on its own?
  • Bring up power to the other components and shut down when not needed to save power.
  • Real time clock calibrated via SNTP
  • Use hardware WDT to reset the Pico if it gets stuck.
  • Monitor a UPS over the USB port.
  • Monitor and reset the onboard ethernet hardware if it gets stuck.
  • Configure IP settings in flash. Initial address is 192.168.100.1.
  • OTA flash updates

The "other components" under control include a FlexRadio and a Windows computer. Incidentally -- both the full Raspberry Pi and the Intel NUC have built in hardware WDT.

Power - Need a regulated clean supply to feed it 3v3 from 12v power.

Resources

Wiznet

https://www.hackster.io/news/wiznet-s-w5100s-evb-pico-clones-the-raspberry-pi-pico-but-adds-a-handy-ethernet-port-too-11125e568928

Wiznet did a WiFi + Pico EVB, too, but I can't find it for sale anywhere. https://github.com/Wiznet/WizFi360-EVB-Pico-C/blob/main/getting_started.md

The CircuitPython page for the Wiznet Pico is here https://circuitpython.org/board/wiznet_w5100s_evb_pico/

Sample code: https://github.com/Wiznet/RP2040-HAT-CircuitPython