[Home]AutoTyping

HomePage | RecentChanges | Preferences

Difference (from prior major revision) (no other diffs)
No diff available.

AutoType Graph Plotter

Use the Raspberry Pi Pico to Type into the DUT.

Paste call log into the text box on the link below to plot a graph.

http://dougrice.co.uk/AutoType/AutoTypeAnalysisScript.htm - Paste call log into text box.

Raspberry Pi PICO using Arduino IDE

With "Arduino MBED OS RP2040 Boards 3.3.0" installed you can generate .uf2 files for upload.

https://github.com/arduino/ArduinoCore-mbed

https://github.com/arduino/ArduinoCore-mbed/tree/master/libraries/USBHID/examples

There is a USBHID keyboard example.

 #include "PluggableUSBHID?.h"
 #include "USBKeyboard.h"

 USBKeyboard Keyboard;

 void setup() {
  // put your setup code here, to run once:
 }

 void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Keyboard.printf("Hello world\n\r");
 }

https://www.dougrice.co.uk/www/dev/DigiSpark/KeyboardRP2_min/KeyboardRP2_min.ino is my AutoType ported for an RP2 PICO

https://www.dougrice.co.uk/www/dev/DigiSpark/KeyboardRP2/KeyboardRP2.ino is my AutoType ported for an RP2 PICO, Digispark and Arduiono Leonardos

https://wokwi.com/projects/346791883892064850 - wokwi simulation using serial port instead of the the keyboard.

Auto Typing using The Raspberry Pi Pico - Circuit Python

It is possible to use a a raspberry Pi Pico as HID The code below can be run and it types in to the source code. You would need to add a switch and save the code in code.py to auto run it.

#
# Circuit Python HID kbd POC
# https://circuitpython.org/board/raspberry_pi_pico/
#
#
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
import time
import digitalio
import board

kbd = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS( kbd ) 
keyboard_layout.write("Doug")

kbd.press( 20 )
# Wiki needed sleep() 
time.sle ep(0.1)
kbd.release( 20 )

kbd.release_all()
keyboard_layout.write('D ')

keyboard_layout.write("The quick brown fox\n jumps over the lazy Doug\n")


# DougqDThe quick brown fox jumps over the lazy DougDougqD
# DougqDThe quick brown fox jumps over the lazy Doug
# DougqDThe quick brown fox
#
# DougqD The quick brown fox
# jumps over the lazy Doug
 

Code - Raspberry Pi PICO using Arduino IDE

/*
   AutoType Keyboard for the Raspberry PICO

   Overview:-
   I needed to automate typing a conversation, between two people over an App like a Chat Bot session.
   The App needed a slow stream of repeatable text to soak test it and fill up scroll buffers, over many minutes.
   It needed a trickle of characters as if typed on the App's keyboard(s).

   I can plug in an external keyboard at each end. 
   The Arduino IDE has Keyboard examples.
   
   Raspberry PICO were available from Farnell for about 6 GBP.
   There are examples using them as USB Keyboards.
    
   It is impractical to read the display, but a wire can be used between two of these devices, so they can type in turn.

   Typically, Person A: types to Person B: and B: types back.

   Raspberry PICO were available from Farnell for about 6 GBP.
   There are examples using them as USB Keyboards.

   See: https://wwwi.dougrice.co.uk/cgi-bin/wiki.pl?AutoType

   It is easy to get the Arduino IDE to work.

   https://www.arduino.cc/
   https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
   https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardMessage

   Add Arduino "MBED OS RP2040 boards"
   Based on Keyboard example
   With "Arduino MBED OS RP2040 Boards 3.3.0" installed you can generate .uf2 files for upload to the PICO
   https://github.com/arduino/ArduinoCore-mbed
   https://github.com/arduino/ArduinoCore-mbed/tree/master/libraries/USBHID/examples

   Example:

  #include "PluggableUSBHID.h"
  #include "USBKeyboard.h"

  USBKeyboard Keyboard;
  void setup() {
  // put your setup code here, to run once:
  }

  void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Keyboard.printf("Hello world\n\r");
  }



  ========================================================
   SEC: 1.0 -  Design Brainstorm and thoughts:-
  ========================================================
  I needed to automate typing a conversation, between two people over an App like a Chat Bot session.
  
  The App needed a slow stream of repeatable text to soak test it and fill up scroll buffers, over many minutes.

  It needed a trickle of characters as if typed on the App's keyboard(s).

  I can plug an external keyboard at each end, which could be two of these PICOs. This is not essential. 
  It is impracticle to read the display, but a wire can be used between two of these devices, so they can type in turn.

  Typically, Person A: types to Person B: and B: types back.

  * timeline:-
  * A:   | typing |GA| waiting   | typing    |GA| waiting   | typing           
  * B:   | waiting   | typing |GA| waiting      | typing |GA| waiting        
  *  
  * A: types pressing keys on a keyboard, at up to 10 characters a second or slower
  * A: hands over to B: by sending "GA" to Go Ahead, then waits 
  * B: reads the typing and can type but should wait until A: stops typing, before starting.
  * B: types and A: waits til B: stops.
  * 
  * Typing on a smart phone soft keyboard is slower.
  *
  * some devices display both conversations in a single line of text, making it difficult to read.
  *

   Use a one PIN Wired Or BUS wire to communicate between two of these PICOs.
   
   * Assert Low when Typing, 
   * Stop typing when "\n" found - Users send GA for Go Ahead 
   * Wait for it to go high, before sarting to type.

             pull up
              |
   -----+-----+-----+----------+--- Wired OR buss - Assert low when typing.
        |           |          |
      [ A ]       [ B ]     [ SW ]

     [ A ] and [ B ] Wait for high to start typing and assert a low

     [SW] is a switch which can pull low to inhibit typing.

     on start up hold off typing.
     
   When waiting look for ----____ before starting typing.

*/


/*========================================================
   SEC: 1.0 - Configuration
  ======================================================*/
#define TYPING_INTER_KEY_DELAY 20
//
// there was a bug with the SmartPhone App
// Pressing ENTER looses focus, so suppress ENTER
// select if "\n" presses ENTER key
//
#define nNOENTER true
#define NOENTER false

/*
   This code can use a Raspberry PICO or RP2
   Arduino IDE Tools configuration

   RP2 PICO
    Board: Raspberry Pi Pico
    Programmer: N/A - ensure  bootsel button is pressed when you plug in PICO
*/
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"

USBKeyboard Keyboard;
#define IP 9
#define TYPING 10
/*
  PICO pins:-

  USB
  (GP0)(GP1)[GND](GP2)(GP3)(GP4)(GP5)[GND](GP6)(GP7)(GP8)(GP9)[GND](GP10)(GP11)(GP12)(GP13)[GND](GP14)(GP15)
*/

/*========================================================
   SEC: 2.0 - Typing Text
  ======================================================*/

/* Phone User typing - The \n indicate end of sentence.*/
int phone = true;

// send space followed by a space.
// The phone lost focus when the  ENTER key is pressed.
// if using the Smartphone keyboard just touch input area.
// It buffers text and waits for a pause. send some single spaces or double spaces.
// \n means end of sentence , and hand over typing or Go Ahead - GA. 

char myString[] = "  This is BeeTea Engineer, DHR, making a test call.\n "
                  " Please hang up the B-leg \n "
                  " I am testing  the new Relay UK app  \n "
                  " Hello Doug here  \n "
                  " Can   you see my typing?  \n "
                  " The Quick brown fox jumps over the lazy dog  \n "
                  " I am testing the    new Relay UK app \n "
                  //" 1 2 3 4 5 6 7 8 9 ! £ $ % ^ & * ( ) _- + = { } [ ] ~ # : ; @ ' < > , . / ?"
                  ;


/*========================================================
   SEC: 3.0 - Variables
  ======================================================*/

int slowSpeed = true;
int waiting = true;

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTs = 0;  // the last timestamp

char * ptr;

/*========================================================
   SEC: 4.0 - Functions
  ======================================================*/

void setup() {
  // don't need to set anything up to use DigiKeyboard
  ptr = myString;

  pinMode(  0 , INPUT_PULLUP );
  pinMode( IP , INPUT_PULLUP );
  pinMode( TYPING , INPUT_PULLUP ); // used for WiredOR
  pinMode( LED_BUILTIN , OUTPUT );

  waiting = true;
}

void polledTimeSlice() {
  unsigned long now = millis();  // the last timestamp

  // using unsigned so be caureful.
  if ( now - lastTs > 300 ) {
    // 0.1 second tick
    lastTs = now;

    //
    // payload - run every 300 ticks.
    //

    // if typing TYPING asserted Low, wait for it to go high
    // If input goes low turn off waiting
    //if ( ! digitalRead( IP ) ){
    if ( digitalRead( TYPING ) ) {
      waiting = false;
    }
  }
}

void LED( int on ) {
  /* IF on == TRUE then Typing. Assest TYPING LOW using Wired OR */

  if ( on ) {
    // ASSERT LOW
    pinMode( LED_BUILTIN , OUTPUT );
    pinMode( TYPING      , OUTPUT );
    // Wired OR
    digitalWrite( LED_BUILTIN , on );
    digitalWrite( TYPING      , LOW );
  } else {
    pinMode( LED_BUILTIN , OUTPUT );
    // to turn on a PULLUP make pin input
    pinMode( TYPING      , INPUT_PULLUP );
    digitalWrite( LED_BUILTIN , on );
  }
}

/*========================================================
   SEC: 5.0 - Functions -  delay
  ======================================================*/

void delay_( unsigned long ms ) {
  delay( ms );
}

void wait() {
  // pick a random delay and square it to make it more like real typing?
  delay(random( 0, TYPING_INTER_KEY_DELAY )*random( 0, TYPING_INTER_KEY_DELAY ));
}

void waitLong() {
  int count;
  delay( random( 1000, 2000 ) );
}

/*========================================================
   SEC: 6.0 - Functions Increment  & Type Key
  ======================================================*/

void incStringPtr() {
  unsigned long ts = 0;

  /* end of string return to start.*/
  ptr ++ ;

  // if space end of word.
  if ( ptr[0] == ' ') {
  }

  // END OF LOOP
  if ( ptr[0] == '\0') {
    ptr = myString;
    if ( slowSpeed ) {
      slowSpeed = false;
    } else {
      slowSpeed = true;
    }
    ts = millis();
    Keyboard.printf( "%s", " ts: " );
    Keyboard.printf( "%d", ts / 1000 );
    Keyboard.printf( "%s", " seconds " );
  }
}

void typeKey( char letter ) {
  // enable typing in HALT is high in this version.
  if ( digitalRead( 0 ) ) {
    // this is generally not necessary but with some older systems it seems to
    // prevent missing the first character after a delay:
    //DigiKeyboard.sendKeyStroke(0);
    if ( NOENTER && isControl( letter ) ) {
      Keyboard.printf( "%c", ' ' );
    } else {
      Keyboard.printf( "%c", letter );
    }
    incStringPtr();
  }
}

/*========================================================
   SEC: 7.0 - Functions Main Loop
  ======================================================*/

void loop() {
  polledTimeSlice();
  /* work through string and print character by character */
  /* check if input low and enable typing. */
  if ( waiting ) {
    return;
  }

  // look for end of sentence,
  if ( isControl( ptr[0] ) ) {

    // turn off LED at end of sentence
    // This is used to tell other end as well.
    LED( LOW );

    // end of sentence turn os Waiting flag
    // so loop waits for other end to finish sentence.
    waiting = true;

    typeKey( ptr[0] );
    wait();
  } else {
    LED( HIGH );

    /* type character */
    typeKey( ptr[0] );
    if ( slowSpeed ) {
      wait();
    }
    wait();
  }

  if ( isWhitespace( ptr[0] ) ) {
    wait();
  }
}

/*========================================================
   SEC: 8.0 - Examples
  ======================================================*/
/*
  This is BeeTea Engineer, DHR, making a test call.
    Please hang up the B-leg
      I am testing  the new Relay UK app
        Hello Doug here
          Can   you see my typing?
            The Quick brown fox jumps over the lazy dog
              I am testing the    new Relay UK app
                ts: 60 seconds   This is BeeTea Engineer, DHR, making a test call.
                  Please hang up the B-leg
                    I am testing  the new Relay UK app
                      Hello Doug here

*/
/*========================================================
   SEC: 9.0 - End
  ======================================================*/


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited 2026-08-20 12:32 pm by dougrice.plus.com (diff)
Search:
home page