[Demo]TTB TinyBasic (USBSerial)

I gave it a go, but it seems I’ll have to set the drivers up, and I’ve had issues doing so because none of the drivers are properly signed and one of the tools won’t recognise the chip.

Looks like it’s only Windows 10 that works without drivers.

What OS r u trying?

Windows 8(.1)

Here’s what I’ve done so far:

I made some code using USBSerial.

The Code
#include <Pokitto.h>
#include <cstdint>
#include <USBSerial.h>

char buffer[255];

bool dataReceived = false;
int lastReceived = 0;

USBSerial * serialPointer;

void received(void)
{
	auto available = serialPointer->available();

	if(available> 0)
	{
		serialPointer->gets(buffer, available);
		dataReceived = true;
	}
}

bool dataSent = false;
int lastSent = 0;

int main ()
{
	using Pokitto::Display;
	using Pokitto::Core;
	using Pokitto::Buttons;

	Core::begin();
	
	USBSerial serial;

	serialPointer = &serial;

	while(Core::isRunning())
	{
		if(Core::update())
		{
			if(Buttons::pressed(BTN_UP))
			{
				serial.attach(received);
			}

			if(Buttons::pressed(BTN_A))
			{
				if(dataReceived)
				{
					serial.puts(buffer);
					dataSent = true;
				}
			}

			if(Buttons::pressed(BTN_B))
			{
				dataReceived = false;
				lastReceived = 0;
				dataSent = false;
				lastSent = 0;
			}

			if(serial.connected())
				Display::println("Connected");
			else
				Display::println("Not Conencted");

			Display::print("Data Received: ");
			Display::print(dataReceived);
			Display::print(" ");
			Display::println(lastReceived);

			Display::print("Data Sent: ");
			Display::print(dataSent);
			Display::print(" ");
			Display::println(lastSent);
		}
	}
}

I uploaded it to Pokitto and when the Pokitto ran it installed a driver labelled “CDC DEVICE” which appears in Device Manager under the ‘Other devices’ category.

So I looked at this page and grabbed the serial.inf the link on that page (this link).

Then I go onto CDC DEVICE in Device Manager and choose “Update Driver Software…” and point it at setup.inf, but instead of getting a warning that I can accept, I get an error saying:

Windows found driver software for your device but encountered an error while attempting to install it.
The third-party INF does not contain digital signature information.

And the only option I get is ‘close’, no option to accept or ignore.

Based on that message I’ve found out that I should be able to bcdedit /set loadoptions DDISABLE_INTEGRITY_CHECKS & bcdedit /set testsigning on to disable the checks, but I haven’t found the command to undo that yet, so I don’t want to try it until I know for definite that I can undo it.


I also found an .exe which was actually a self-extracting cab with some other files inside (you can tell because the icon is usually a specific icon and 7zip can peek inside), from this page, but that executable can’t detect the Pokitto.

It just says “The driver could not be installed. No mebed Microcontrollers were found”.

Oh. It appears I may hve pushed the wrong driver. Let me check

1 Like

@Pharap , yep wrong driver

I will push right one later tonight

1 Like

Small reminder about the driver.

1 Like

it’s here:

1 Like

Is it also available on the PokittoIO repo?

I’ll put it there, but: what is the best way to “refresh” the PokittoIO repo in the PIO registry? I have to put a new version number in the package JSON but was there something else that needs to be done?

1 Like

You should also make a release with a matching version number as the tag (typically prefixed with a ‘v’, e.g. v0.4.0).
https://help.github.com/articles/creating-releases/

An example of a repo following semver-tagged releases:

1 Like

I just attempted to add usb serial to something, but I end up with my pokitto white-screening and windows telling me it’s an unknown device.

Does any of the following look in any way wrong?

[spoiler]

#include <Pokitto.h>
#include <SPISlave.h>
#include <USBSerial.h>
#include "bitmaps.h" // font data
#include "buttons.h" // button handling

Pokitto::Core game;
#include "drawing.h" // drawing routines for mixed mode

// create SPI instance
//SPISlave myDevice(P1_21, P1_22, P1_20, P1_5); // mosi, miso, sclk, ssel
//Virtual serial port over USB
USBSerial serial;

// Golbals
char tempText[32];
long int frameNumber=0;


void updateScreen(){
}

void startup(){
    game.begin();
    game.display.persistence=1;
    game.setFrameRate(255); // max out the frame rate so that it doesn't get used
    game.display.setInvisibleColor(-1);
    load2bitPalette(pal_2bit_pal);
    // set Draw mode to hires 4 colour
    for(int t=0; t<88; t++){
        game.display.scanType[t]=2; // 2bit
    }
//    myDevice.frequency(4000000);

}


 int main(){

    startup();
    int lineNum=0;
    int tX=0;

    while (game.isRunning()) {

    //    int v = myDevice.read();

        if(game.update()){
            frameNumber++;
            // update buttons
            myPad = updateButtons(myPad);
            UpdatePad(myPad);

            if(_A[NEW]){
                serial.printf("I am a virtual serial port\r\n");
            }

            game.update();
        } // update

    } // game running

return 1;
}

[/spoiler]

If there is no USB connection, the startup declaration of USB serial instance will freeze you in a white screen because there is no timeout

Spoiler tags aren’t supported here for some reason.

I remember having the same problem.
I remember there being some issue with the driver,
but I can’t remember exactly how it was fixed.

I’ll look in a minute to see if any of my PMs give a hint as to whether the fix was manually installing the driver or Jonne fixing the driver code in the library.

If you haven’t updated your library in a while, try that first just in case.

I think USBSerial has been phased out by the way,
I remember submitting a PR to fix one of the template functions and the guy accepting the PR mentioned it’s no longer supported (but they accepted the PR anyway because it was a simple fix).

Instead Serial should be used (I think that’s OS5 documentation, but I don’t it’s changed).
Edit: Actually I can’t get regular Serial working at the moment.
I think that was on my todo list but I never got round to it.
USBSerial works fine though, as long as I specify 0x04D8, 0x000A as the construction parameters.
Serial might work if you’re doing it over PEX rather than USB though.

Quick question, does this work for you?[/s]
Serial.bin (53.0 KB)

This uses dynamic allocation to create the link when you press Up on the dpad,
and resends the last data received when you press A.

This one is easier to use:
USBSerial.bin (52.9 KB)

Just turn your Pokitto on, plug in the USB (or vice versa),
you should hear a USB connect launch a serial monitor.
When the Pokitto gets past the launch screen(s),
output something over the serial monitor and then press A on the Pokitto to echo it back.


@jonne, this isn’t the case.

Nevermind, I see what you mean.
I forgot I had the USB cable plugged in.


Sorry for all the edits, it’s been a while since I’ve played around with serial communication on Pokitto.

TLDR:
For USBSerial, specify USBSerial serialDevice { 0x04D8, 0x000A } to get it working properly.
I don’t know of any way to avoid the program hanging when the object is created.
Presumably there’s a way to time it out, but I don’t know how yet.

I tried the above, it didn’t make a difference.
Your USBSerial.bin works perfectly though. is the source online anywhere?

It is now:

1 Like

hmmm, nope. doesn’t work for me. Just white screen. Perhaps my pokittolib is the wrong version.

With the USB plugged in?

Yup, I rarely unplug it.

It works for me using PokittoIO.
Try updating your PokittoLib.

I am new to Pokitto and wanted to try this USBSerial example

I am using the onlnie mbed environment and after success with the ‘helloworld’ example I now find the USBSerial doesn’t seem to be part of the PokittoLib.

Are there different versions of the PokittoLib?

Did the mbed version fall behind and there is some other preferred development path.

2 Likes