lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Hunt the Wumpus for Pico

Wed May 12, 2021 6:00 pm


ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Tue Jun 29, 2021 3:01 am

lurk101 wrote:
Wed May 12, 2021 6:00 pm
viewtopic.php?p=1864165#p1864165
After the modification described in

viewtopic.php?f=144&t=314736

I now have a Wumpus dongle that when plugged into any computer creates a USB serial port to which one can connect and hunt wumpi.

Could the next step in this pico adventure be a Colossal Cave dongle?

Would it be possible to use the Frotz Z code interpreter to make a general dongle for interactive fiction?

https://davidgriffith.gitlab.io/frotz/

How large can a Pico executable be?

hippy
Posts: 10924
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Hunt the Wumpus for Pico

Tue Jun 29, 2021 11:29 am

ejolson wrote:
Tue Jun 29, 2021 3:01 am
Would it be possible to use the Frotz Z code interpreter to make a general dongle for interactive fiction?
Any arbitrary C code should be usable with the Pico though one will have to add shims to provide functionality not directly provided by Pico-SDK.

It should also be possible to wrap that code as a MicroPython C Extension to provide easy access to a file system,
ejolson wrote:
Tue Jun 29, 2021 3:01 am
How large can a Pico executable be?
My understanding is; as large as the Flash, and one can go higher than that with compression.

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Tue Jun 29, 2021 3:39 pm

An updated version of Hunt the Wumpus for Pico that saves the cave across power cycles is available here.

hippy
Posts: 10924
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Hunt the Wumpus for Pico

Wed Jun 30, 2021 7:15 pm

hippy wrote:
Tue Jun 29, 2021 11:29 am
ejolson wrote:
Tue Jun 29, 2021 3:01 am
Would it be possible to use the Frotz Z code interpreter to make a general dongle for interactive fiction?
Any arbitrary C code should be usable with the Pico though one will have to add shims to provide functionality not directly provided by Pico-SDK.
I have 'cmake' built the dumb version for the Pico with just a dummy 'int main(void) {}' added. Someone who knows what they are doing better than me can probably take that further, make it do something.

https://github.com/DavidGriffith/frotz/blob/master/DUMB

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Thu Jul 01, 2021 5:37 pm

lurk101 wrote:
Tue Jun 29, 2021 3:39 pm
An updated version of Hunt the Wumpus for Pico that saves the cave across power cycles is available here.
As described in

https://kevinboone.me/picoflash.html

do you need to turn off interrupts when writing to flash?

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Thu Jul 01, 2021 8:45 pm

ejolson wrote:
Thu Jul 01, 2021 5:37 pm
lurk101 wrote:
Tue Jun 29, 2021 3:39 pm
An updated version of Hunt the Wumpus for Pico that saves the cave across power cycles is available here.
As described in

https://kevinboone.me/picoflash.html

do you need to turn off interrupts when writing to flash?
Probably would be safer, but I haven't encountered any issues. But then I haven't tries serial over USB. I'll update the repo.

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 3:46 pm

lurk101 wrote:
Thu Jul 01, 2021 8:45 pm
ejolson wrote:
Thu Jul 01, 2021 5:37 pm
lurk101 wrote:
Tue Jun 29, 2021 3:39 pm
An updated version of Hunt the Wumpus for Pico that saves the cave across power cycles is available here.
As described in

https://kevinboone.me/picoflash.html

do you need to turn off interrupts when writing to flash?
Probably would be safer, but I haven't encountered any issues. But then I haven't tries serial over USB. I'll update the repo.
Does anyone know how to build serial over USB and UART support into the same binary so the Pico autodetects which device receives input first and then uses that for all subsequent interaction?

This would facilitate building a universal Pico-based wumpus hunting device that could be accessed either from USB or UART without reflashing.

If it works I would also like to include the technique in this Basic interpreter.

viewtopic.php?p=1914739#p1914739

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 3:53 pm

This isn't sufficient?

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:08 pm

lurk101 wrote:
Fri Sep 17, 2021 3:53 pm
This isn't sufficient?
That requires recompiling and flashing a new binary to switch consoles. In order to distribute a fully self-contained wumpus hunting device, it's convenient if there is a single binary that autodetects which console is in use. That's even more the case with a Basic interpreter.

Is the problem there are too many serial ports that might be assigned to different GPIO pins and hardware configurations for autodetect to be practical?

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:14 pm

ejolson wrote:
Fri Sep 17, 2021 4:08 pm
lurk101 wrote:
Fri Sep 17, 2021 3:53 pm
This isn't sufficient?
That requires recompiling and flashing a new binary to switch consoles. In order to distribute a fully self-contained wumpus hunting device, it's convenient if there is a single binary that autodetects which console is in use. That's even more the case with a Basic interpreter.

Is the problem there are too many serial ports that might be assigned to different GPIO pins and hardware configurations for autodetect to be practical?
Don't know. I'm not sure how that would work? The serial pin assigned stays the same whether USB or SERIAL but you can't detect if a serial device is connected or not. Maybe you can detect a unconnected USB port but I wouldn't know how.

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:18 pm

lurk101 wrote:
Fri Sep 17, 2021 4:14 pm
ejolson wrote:
Fri Sep 17, 2021 4:08 pm
lurk101 wrote:
Fri Sep 17, 2021 3:53 pm
This isn't sufficient?
That requires recompiling and flashing a new binary to switch consoles. In order to distribute a fully self-contained wumpus hunting device, it's convenient if there is a single binary that autodetects which console is in use. That's even more the case with a Basic interpreter.

Is the problem there are too many serial ports that might be assigned to different GPIO pins and hardware configurations for autodetect to be practical?
Don't know. I'm not sure how that would work? The serial pin assigned stays the same whether USB or SERIAL but you can detect if a serial device is connected or not. Maybe you can detect a unconnected USB port but I wouldn't know how.
I think one cycles through plausible baud rates and checks for recognizable input. The user has to keep hitting return until the port is recognized.

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:23 pm

ejolson wrote:
Fri Sep 17, 2021 4:18 pm
lurk101 wrote:
Fri Sep 17, 2021 4:14 pm
ejolson wrote:
Fri Sep 17, 2021 4:08 pm

That requires recompiling and flashing a new binary to switch consoles. In order to distribute a fully self-contained wumpus hunting device, it's convenient if there is a single binary that autodetects which console is in use. That's even more the case with a Basic interpreter.

Is the problem there are too many serial ports that might be assigned to different GPIO pins and hardware configurations for autodetect to be practical?
Don't know. I'm not sure how that would work? The serial pin assigned stays the same whether USB or SERIAL but you can detect if a serial device is connected or not. Maybe you can detect a unconnected USB port but I wouldn't know how.
I think one cycles through plausible baud rates and checks for recognizable input. The user has to keep hitting return until the port is recognized.
Sorry, cross posted. had updated my post to 'can't detect' instead of 'can detect'. The USB driver should have a way to tell you whether its endpoint is connected.

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:29 pm

lurk101 wrote:
Fri Sep 17, 2021 4:23 pm
ejolson wrote:
Fri Sep 17, 2021 4:18 pm
lurk101 wrote:
Fri Sep 17, 2021 4:14 pm

Don't know. I'm not sure how that would work? The serial pin assigned stays the same whether USB or SERIAL but you can detect if a serial device is connected or not. Maybe you can detect a unconnected USB port but I wouldn't know how.
I think one cycles through plausible baud rates and checks for recognizable input. The user has to keep hitting return until the port is recognized.
Sorry, cross posted. had updated my post to 'can't detect' instead of 'can detect'. The USB driver should have a way to tell you whether its endpoint is connected.
That's right. I know how to wait until the USB device is connected. While waiting I think one needs to check if the UART is receiving carriage returns. If so, then one switches to the UART for the console.

From a theoretical point of view it should be simpler than finding a wumpus.

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Fri Sep 17, 2021 4:36 pm

ejolson wrote:
Fri Sep 17, 2021 4:29 pm
lurk101 wrote:
Fri Sep 17, 2021 4:23 pm
ejolson wrote:
Fri Sep 17, 2021 4:18 pm

I think one cycles through plausible baud rates and checks for recognizable input. The user has to keep hitting return until the port is recognized.
Sorry, cross posted. had updated my post to 'can't detect' instead of 'can detect'. The USB driver should have a way to tell you whether its endpoint is connected.
That's right. I know how to wait until the USB device is connected. While waiting I think one needs to check if the UART is receiving carriage returns. If so, then one switches to the UART for the console.

From a theoretical point of view, it should be simpler than finding the wumous.
That should do the trick. Might not be necessary to poll the UART while waiting for a USB endpoint, It happen pretty quick.

Instead of calling stdio_init_all(), maybe

Code: Select all

stdio_usb_init();
if (no_usb_endpoint_connected_after_a_few_seconds())
    stdio_uart_init();

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Tue Sep 21, 2021 8:47 pm

Thinking about it a little longer, I don't think you need to do any special handling at all to get a Pico app to automatically handle USB console or UART console. With

Code: Select all

pico_enable_stdio_uart(test 1)
pico_enable_stdio_usb(test 1)
in the CMakeLists you add both USB and UART on the standard IO driver list. Output is sent to both drivers and input is accepted from either.

Works for USB or UART whichever is in use.

Code: Select all

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>

#include "pico/stdlib.h"

int main() {
    stdio_init_all();
    getchar_timeout_us(1000); // swallow the spurious EOF character???
    for (;;) {
        sleep_ms(10000);
        printf("Hit key ");
        getchar();
        printf("\nworks!\n");
    }
}

ejolson
Posts: 8600
Joined: Tue Mar 18, 2014 11:47 am

Re: Hunt the Wumpus for Pico

Thu Sep 23, 2021 2:33 pm

lurk101 wrote:
Tue Sep 21, 2021 8:47 pm
Thinking about it a little longer, I don't think you need to do any special handling at all to get a Pico app to automatically handle USB console or UART console. With

Code: Select all

pico_enable_stdio_uart(test 1)
pico_enable_stdio_usb(test 1)
in the CMakeLists you add both USB and UART on the standard IO driver list. Output is sent to both drivers and input is accepted from either.

Works for USB or UART whichever is in use.

Code: Select all

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>

#include "pico/stdlib.h"

int main() {
    stdio_init_all();
    getchar_timeout_us(1000); // swallow the spurious EOF character???
    for (;;) {
        sleep_ms(10000);
        printf("Hit key ");
        getchar();
        printf("\nworks!\n");
    }
}
That's interesting. Would the speed of output be significantly slower by having two devices active? Is the baud rate of the UART much slower than USB?

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Thu Sep 23, 2021 3:20 pm

ejolson wrote:
Thu Sep 23, 2021 2:33 pm
That's interesting. Would the speed of output be significantly slower by having two devices active? Is the baud rate of the UART much slower than USB?
Hard to say. The default serial baud rate is 115200 baud. For interactive use I perceive no difference.

User avatar
RichardRussell
Posts: 1112
Joined: Thu Jun 21, 2012 10:48 am

Re: Hunt the Wumpus for Pico

Thu Sep 23, 2021 10:53 pm

lurk101 wrote:
Thu Sep 23, 2021 3:20 pm
The default serial baud rate is 115200 baud. For interactive use I perceive no difference.
A better test would be the BBC BASIC 'pseudo graphics' demos such as hanoi.bbc, snake.bbc sortdemo.bbc, sudoku.bbc etc. If their screen updates don't get noticeably slower through being capped at 115200 baud you'll probably be OK outputting to both serial and USB.

lurk101
Posts: 1053
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Hunt the Wumpus for Pico

Thu Sep 23, 2021 11:58 pm

RichardRussell wrote:
Thu Sep 23, 2021 10:53 pm
lurk101 wrote:
Thu Sep 23, 2021 3:20 pm
The default serial baud rate is 115200 baud. For interactive use I perceive no difference.
A better test would be the BBC BASIC 'pseudo graphics' demos such as hanoi.bbc, snake.bbc sortdemo.bbc, sudoku.bbc etc. If their screen updates don't get noticeably slower through being capped at 115200 baud you'll probably be OK outputting to both serial and USB.
I did run the hanoi demo, in fact it's the only one I ran, and it looked normal. In any case, I've found a technique that works by detecting the presence of a driven UART RX pin and allows me to initialize the correct driver without user intervention.

viewtopic.php?f=144&t=319577&start=125#p1916980

Return to “General”