# Android GBoard Morse Code Control with Circuit Playground Express

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/058/023/medium800thumb/circuitpython_gboardmorse.jpg?1532461632)

[GBoard is an alternate keyboard for Android Devices](https://support.google.com/accessibility/android/answer/9011881?hl=en) that lets you type using Morse code. This has seen use for people with limited mobility, but it can also be useful for practicing your morse code skills.

The goal of this project is to build a simple input device for GBoard that doesn't require soldering or elaborate construction techniques.

We'll be using a Circuit Playground Express to build this project. We have a few different versions we'll be demonstrating - from the simplest using the two onboard buttons, to using capacitive touch inputs, to connecting up some alligator clips to big-and-easy-to-press arcade buttons.

**Using alligator clip pads lets us avoid avoid soldering altogether and makes this a quick, easy project to build by anyone!**

If you're not familiar with the Circuit Playground Express and all it has to offer, see [our introductory guide](https://learn.adafruit.com/adafruit-circuit-playground-express). This guide will be using CircuitPython.

## Parts
### Part: Circuit Playground Express
quantity: 1
CircuitPython ATSAMD21 based educational microcontrolelr board with an abundance of sensors and output devices.
[Circuit Playground Express](https://www.adafruit.com/product/3333)

### Part: Small alligator clip leads
quantity: 1
15" cables with alligator clip on each end, color coded.
[Small alligator clip leads](https://www.adafruit.com/product/1008)

### Part: 30mm Arcade Button
quantity: 2
1.5" deep, translucent, snap in arcade button. Available in various colors.
[30mm Arcade Button](https://www.adafruit.com/product/476)

### Part: Micro USB to Micro USB OTG Cable
quantity: 1
10" / 25mm, for connecting a board like CPX to a phone with USB OTG capability
[Micro USB to Micro USB OTG Cable](https://www.adafruit.com/product/3610)

## Materials for the box
### Part: Makedo Toolkit for Cardboard Construction
quantity: 1
The Makedo Toolkit is a starter kit of cardboard construction tools that's a great introduction to Makedo.
[Makedo Toolkit for Cardboard Construction](https://www.adafruit.com/product/3285)

You'll also need some corrugated cardboard from a typical shipping box. You'll need a smooth, flat piece big enough for the box you want to make.

# Android GBoard Morse Code Control with Circuit Playground Express

## Installing GBoard

GBoard is an alternate keyboard for Android Devices. It has flexibility not found in the keyboard that came with your phone as most Android devices come with keyboard software by the phone manufacturer unless, perhaps, if you are on a Google brand phone.

You can install GBoard by going to the Google Play Store. The icon in your phone should be similar to the one below.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/733/medium800/circuitpython_playstore.jpg?1532006549)

Search for GBoard. Make sure it is the app by Google and not some third party app. Select Get.

When the app is downloaded, click Install.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/735/medium800/circuitpython_aid7600114-v4-728px-Glide-Type-with-Gboard-on-iPhone-or-iPad-Step-7.jpg?1532006801 source: wikihow, marked "fair use")

Launch/Run the app after it is installed. It will go through some configuration settings. Allow GBoard to be your keyboard and make it the default keyboard.

It will go to settings, you can set it up for your preferences.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/736/medium800/circuitpython_accept.png?1532006924 credit: wikihow, marked "fair use")

## Changing Keyboards to add GBoard and the Morse Option

Google has a standard guide on how to configure your Android device to accept both a regular keyboard in your language and a Morse keyboard.

[Read the Google Configuration Guide for GBoard and Morse](https://support.google.com/accessibility/android/answer/9011881?hl=en)
When you have your regular keyboard up and you wish to switch to the Morse keyboard, press and hold the Globe icon ![](https://lh3.googleusercontent.com/Z96hYrx0miB1rh7dXsGSWJg5YPaqDYQoUMIxEsU01b_yV0fZW_jdcI65WM37GQ=w18)&nbsp;on the GBoard keyboard. That is Google's method of allowing to switch back & forth.

# Android GBoard Morse Code Control with Circuit Playground Express

## Connecting Your Phone to the Board

![](https://cdn-learn.adafruit.com/assets/assets/000/057/824/medium800/circuitpython_1200px-USB_OTG_Log-sm.svg?1532093720 source: Wikipedia, marked "Fair Use")

Android phones typically come with a micro-B USB connection. This USB connection follows the USB on-the-go (OTG) specification so peripherals can be plugged in to the port and be used by the phone.&nbsp;

This project is going to use the capabilities of Circuit Playground Express to act as a human interface device (HID), _namely a keyboard_. When the user wants the Express to send a key, they'll use a button, the board will translate this to some keyboard character, and the phone will believe a keyboard was used to enter the character.

This type of behavior is useful for a great many projects. Control of devices using alternative interfaces is the most popular. This can be in manufacturing, at home, or in assistive technology (AT) situations where traditional keyboards cannot be conveniently used.

## Making the Connection
For this project you will need a micro-B male to micro-B male connection that conforms to the OTG specification. Both the phone and the Circuit Playground Express have a micro-B female connector.

&nbsp;

The cable at left is the most direct connection. Some electronics stores carry these - [Adafruit sells them as product #3610](https://www.adafruit.com/product/3610).

&nbsp;

There are also a number of other OTG to regular USB connector devices including [Adafruit Tiny OTG Adapter](https://www.adafruit.com/product/2910)&nbsp;and the short [USB OTG Host Cable - MicroB OTG male to A female](https://www.adafruit.com/product/1099).

![circuitpython_2910-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/979/medium640/circuitpython_2910-01.jpg?1532440032)

![circuitpython_1099-00.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/980/medium640/circuitpython_1099-00.jpg?1532440042)

![circuitpython_3610-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/820/medium640/circuitpython_3610-01.jpg?1532092772)

### Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long

[Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long](https://www.adafruit.com/product/3610)
This cable is a little unusual, rather than having a USB A plug on one end, it has _two_ Micro B USB connections! What is this for? It's for when you have a "USB On-The-Go (OTG)" device, and you want to plug in another USB device. For example, a Pi Zero or Pi Zero W has a...

In Stock
[Buy Now](https://www.adafruit.com/product/3610)
[Related Guides to the Product](https://learn.adafruit.com/products/3610/guides)
![Micro USB to Micro USB OTG Cable](https://cdn-shop.adafruit.com/640x480/3610-01.jpg)

# The Final Phone Setup
Here is a picture of the connections with a USB OTG adapter rather than the micro-micro cable as I did not have the cable at hand. The connections would be identical - connect the phone micro-B USB to the Circuit Playground Express micro-USB connector.

![circuitpython_P1000013.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/994/medium640/circuitpython_P1000013.jpg?1532444723)

# Android GBoard Morse Code Control with Circuit Playground Express

## Buttons and Buzzers

![](https://cdn-learn.adafruit.com/assets/assets/000/057/826/medium800/circuitpython_blinka-small.png?1532093840)

We'll be using CircuitPython for this project. Are you new to using CircuitPython? No worries, [there is a full getting started guide here](https://learn.adafruit.com/welcome-to-circuitpython).

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython. [You can learn about Mu and its installation in this tutorial](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

In this first iteration, all we need is the Circuit Playground Express. We'll use the A and B buttons on it's face to trigger events, and in response we'll play a short (dot) or long (dash) tone on the onboard speaker.

The code is pretty simple. It continuously checks the two buttons and if one has been pressed it plays a tone for the appropriate length of time. After either tone plays, there's a short delay so the tones don't blur together. After that, the code makes sure the button has been released, or waits until it has. This avoids accidentally generating multiple triggers.

Save the code below as `code.py` on your Circuit Playground Express.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_GBoard/button_beeps/code.py

Now, when you press button A a short tone will sound, and when you press button B a longer tone will sound.&nbsp; The `while cpx.button_X: pass` code causes it to wait until you release the button before playing the tone again.

# Android GBoard Morse Code Control with Circuit Playground Express

## Adding Touch

In this next step, we'll replace the buttons with capacitive touch. That way we don't have to click the button, just tap the pads with our fingertips

All that's needed is to replace the button checks with checks for the capacitive touch inputs. The code uses the top touch pad on each side as a replacement for the button on that side.&nbsp;

Info: 

As before, save the code below as `code.py` on your Circuit Playground Express.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_GBoard/touch_beeps/code.py

Now, when you touch the **A4** pad a short tone will sound, and when you touch the **A3** pad a longer tone will sound.&nbsp; As before, the `while cpx.touch_X: pass` code causes it to wait until you release the button before playing the tone again. This prevents you triggering it multiple times accidentally.

Be careful how you hold the board so that you don't accidentally touch the **A3** and **A4** touch pads.

# Android GBoard Morse Code Control with Circuit Playground Express

## Sending Keys

Warning: 

Our next step is to pull in the HID library and send keys instead of beeping. The GBoard app accepts '.' (period) and '-' (minus sign), for dots and dashes, respectively, so that's what we'll send.

The changes are that we import the `Keyboard` and `Keycode` modules from the HID library, and initialize a keyboard object that is then used to send keys to the connected device.

For setting up the keyboard we need to add:

`from adafruit_hid.keyboard import Keyboard`  
`from adafruit_hid.keycode import Keycode`  
`import usb_hid`  
`kbd = Keyboard(usb_hid.devices)`

To actually send keys, we replace the dot and dash tone generation with&nbsp;`kbd.send(Keycode.PERIOD)` and&nbsp;`kbd.send(Keycode.MINUS)`

The code is below, copy it to `code.py` on your Circuit Playground Express.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_GBoard/touch_hid/code.py

Open up an app that accepts text. It can be a word processor like Google Docs or just be a text input box like the SMS/phone message app or a Twitter message input box.

Now, when you touch the **A4** pad a **dot** will be sent, and when you touch the **A3** pad a **dash** will be. The GBoard keyboard replacement will convert those dots and dashes into conventional characters and send them to the app.

![](https://cdn-learn.adafruit.com/assets/assets/000/058/007/medium800thumb/circuitpython_gboardmorse.jpg?1532457299)

You can refer to the table below for International and American Morse Code ([via Wikipedia](https://en.wikipedia.org/wiki/American_Morse_code "Morse Code")).

![](https://cdn-learn.adafruit.com/assets/assets/000/058/040/medium800/circuitpython_Capture.png?1532482280 credit: Wikipedia)

# Android GBoard Morse Code Control with Circuit Playground Express

## Using External Buttons

One final iteration before we build something physical will replace touch input with large external buttons. This is where we step beyond just the Circuit Playground Express and add those alligator clip wires and arcade buttons that were listed in the parts list. The diagram below shows how to connect the buttons. Use the alligator clip wires to do this.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/981/medium800/circuitpython_arcadebuttons_bb.png?1532440699)

The code is below. Copy it to `code.py` on your Circuit Playground Express. A few things change due to using external buttons. The first is the import from the `digitalio` module:

`from digitalio import DigitalInOut, Direction, Pull`

the next is initialization of the input connections:

`button_a = DigitalInOut(board.A4)`  
`button_a.direction = Direction.INPUT`  
`button_a.pull = Pull.UP`

`button_b = DigitalInOut(board.A3)`  
`button_b.direction = Direction.INPUT`  
`button_b.pull = Pull.UP`

The three lines for each button:

1. create the interface object for a specific I/O pad on the Circuit Playground Express
2. set it to input (as opposed to using it for output), and
3. enable the internal pullup resistor. The pullup keeps the input HIGH when the button isn't pressed.

Not all microcontrollers have an internal pulldown resistor so the standard has become to use a pullup and have the button connect the input to ground when it's pushed. You can see this in the wiring diagram: one side of each button is connected to ground.

Notice that this change is limited to changing the two touch functions to use digital inputs in place of touch inputs; the main loop didn't change in this iteration.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_GBoard/arcade_hid/code.py

As before, open up an app that accepts text. It can be a word processor like Google Docs or just be a text input box like the SMS/phone message app or a Twitter message input box.

Now, when you press the button connected to **A4** a dot will be sent to the app, and when you press the button connected to **A3** a dash will be.

# Android GBoard Morse Code Control with Circuit Playground Express

## Final Code

Here's the final version of the code. By uncommenting specific lines as indicated by the comments you can customize it for the various combinations of input and output methods we've explored.

The input and output functionality have been moved to separate functions so that the core code in the loop doesn't have to be changed when the input and output options change.

This is a common, and recommended approach in program design! We put things that can change in their own functions. This allows you to avoid changing the core algorithm. That means there's less opportunity to make a mistake and break it.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_GBoard/universal/code.py

# Android GBoard Morse Code Control with Circuit Playground Express

## Physical Build

![](https://cdn-learn.adafruit.com/assets/assets/000/057/999/medium800thumb/circuitpython_demo.jpg?1532448849)

Now that we have the electronics and code figured out, let's built a box to put it all in. Inspired by [John Park's recent guides](https://learn.adafruit.com/cardboard-fundamentals), we'll use cardboard.

We can start with [this Instructable](https://www.instructables.com/id/Cardboard-Box-Template/) on making custom cardboard shipping boxes. We need a much smaller box, but it works well enough. After some quick measurements of the arcade switches and Circuit Playground Express we can see that a 6cm x 9cm x 4cm box will fit everything, snuggly but well enough.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/803/medium800/circuitpython_template.jpg?1532038362)

For such a small box, the small flaps in the middle are overkill, and actually get in the way. They can be removed. Once measured, cut, and the bend lines (shown as dashed lines in the template) are partially cut, we're ready to add the required openings. You can see the holes marked and poked through for the Makedo Scru connectors.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/804/medium800/circuitpython_box_outside.jpg?1532038606)

Flipping it over, you can mark center lines on the top and bottom sections that will be used to position the Circuit Playground Express and the arcade buttons. 30mm dia. circles are marked for the buttons.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/805/medium800/circuitpython_box_inside.jpg?1532038909)

You can mount the Circuit Playground Express using double sided tape and a scrap piece of cardboard to raise it so as to give some room for the alligator clips.

![circuitpython_spacer_on_cpx.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/806/medium640/circuitpython_spacer_on_cpx.jpg?1532482695)

Using a spacer also provides a bit of space around the USB connector.

![circuitpython_cpx_in_place.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/807/medium640/circuitpython_cpx_in_place.jpg?1532482712)

Make sure you have clearance for your USB cable or OTG adapter

![circuitpython_cpx_connector.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/808/medium640/circuitpython_cpx_connector.jpg?1532482743)

The buttons get pushed through their holes carefully; their snap-in wings should pop out and secure them in place.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/811/medium800/circuitpython_buttons_in_place.jpg?1532040114)

The button connections have been bend to give a bit more clearance between the buttons and the Circuit Playground.

![circuitpython_inside_fit.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/812/medium640/circuitpython_inside_fit.jpg?1532482772)

Now it's time to connect the alligator clips and carefully fold the box together. Put the Scrus in the two ends and check that it works.

![circuitpython_wires.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/813/medium640/circuitpython_wires.jpg?1532482790)

If it doesn't work, open it again and check/fix the connections. Once it works put in the final Scru.

![](https://cdn-learn.adafruit.com/assets/assets/000/057/814/medium800/circuitpython_final.jpg?1532040381)

A set of plastic eyes completes it. It won't win any engineering awards, but it works.

If you want to use it with sound rather than the USB keycodes, you'll need to make the box a bit bigger so you can fit a LiPo battery inside. Be sure to place the batter in a way that you can easily disconnect the cable from the Circuit Playground Express so that it can be recharged.


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long

[Micro USB to Micro USB OTG Cable - 10-12" / 25-30cm long](https://www.adafruit.com/product/3610)
This cable is a little unusual, rather than having a USB A plug on one end, it has _two_ Micro B USB connections! What is this for? It's for when you have a "USB On-The-Go (OTG)" device, and you want to plug in another USB device. For example, a Pi Zero or Pi Zero W has a...

In Stock
[Buy Now](https://www.adafruit.com/product/3610)
[Related Guides to the Product](https://learn.adafruit.com/products/3610/guides)
### Arcade Button - 30mm Translucent Blue

[Arcade Button - 30mm Translucent Blue](https://www.adafruit.com/product/476)
A button is a button, and a switch is a switch, but these translucent arcade buttons are in a class of their own. They're the same size as common arcade controls (often referred to as 30mm diameter) but have some nice things going for them that justify the extra dollar.  
  
First,...

In Stock
[Buy Now](https://www.adafruit.com/product/476)
[Related Guides to the Product](https://learn.adafruit.com/products/476/guides)
### Arcade Button - 30mm Translucent Yellow

[Arcade Button - 30mm Translucent Yellow](https://www.adafruit.com/product/474)
A button is a button, and a switch is a switch, but these translucent arcade buttons are in a class of their own. They're the same size as common arcade controls (often referred to as 30mm diameter) but have some nice things going for them that justify the extra dollar.  
  
First,...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/474)
[Related Guides to the Product](https://learn.adafruit.com/products/474/guides)
### Small Alligator Clip Test Lead (set of 12)

[Small Alligator Clip Test Lead (set of 12)](https://www.adafruit.com/product/1008)
Connect this to that without soldering using these handy mini alligator clip test leads. 15" cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a multimeter so we...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1008)
[Related Guides to the Product](https://learn.adafruit.com/products/1008/guides)
### Makedo Toolkit for Cardboard Construction

[Makedo Toolkit for Cardboard Construction](https://www.adafruit.com/product/3285)
Discontinued - [**you can grab&nbsp;** Makedo Cardboard Construction Mini-Kit - 6 Scrus and Mini-Tool&nbsp; **instead!&nbsp;**](https://www.adafruit.com/product/4476)

&nbsp;

Looking for something for the little engineer in your life? The...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3285)
[Related Guides to the Product](https://learn.adafruit.com/products/3285/guides)
### Circuit Playground Express - Base Kit

[Circuit Playground Express - Base Kit](https://www.adafruit.com/product/3517)
It's the **Circuit Playground Express Base Kit!** &nbsp;It provides&nbsp;the few things you'll need to get started with the new [Circuit Playground Express](https://www.adafruit.com/product/3333).&nbsp;This version of Circuit Playground is super powered, and will...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3517)
[Related Guides to the Product](https://learn.adafruit.com/products/3517/guides)
### Circuit Playground Express Advanced Pack

[Circuit Playground Express Advanced Pack](https://www.adafruit.com/product/2769)
 **Circuit Playground Express** &nbsp;is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to program....

Out of Stock
[Buy Now](https://www.adafruit.com/product/2769)
[Related Guides to the Product](https://learn.adafruit.com/products/2769/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [CircuitPython Hardware: Charlieplex LED Matrix](https://learn.adafruit.com/micropython-hardware-charlieplex-led-matrix.md)
- [3D Print Ratcatcher 2 Controller Device](https://learn.adafruit.com/3d-print-ratcatcher-2-controller-device-wand.md)
- [Glowing Slime Lunchbox](https://learn.adafruit.com/glowing-slime-lunchbox.md)
- [Drama Piñata](https://learn.adafruit.com/customizable-reusable-pinata.md)
- [Using the Android CircuitPython Editor](https://learn.adafruit.com/using-the-android-circuitpython-editor.md)
- [Hammer Time Mini Golf Hazard with Crickit](https://learn.adafruit.com/mini-golf-hammer-time-circuit-playground-crickit.md)
- [Circuit Playground Express Perk-up Ears](https://learn.adafruit.com/perk-up-ears.md)
- [AdaBox 006](https://learn.adafruit.com/adabox006.md)
- [Pushrod Garage](https://learn.adafruit.com/pushrod-garage.md)
- [Esenciales para CircuitPython](https://learn.adafruit.com/esenciales-para-circuitpython.md)
- [Infrared Transmit and Receive on Circuit Playground Express in C++](https://learn.adafruit.com/infrared-transmit-and-receive-on-circuit-playground-express-in-c-plus-plus-2.md)
- [Mason Jar Snow Globe](https://learn.adafruit.com/snow-globe-makecode.md)
- [Circuit Playground Bluefruit Automatic Bike Brake Light](https://learn.adafruit.com/circuit-playground-bluefruit-brake-light.md)
- [LEGO Head Lamp with Audio](https://learn.adafruit.com/lego-head-lamp-with-audio.md)
- [Xenomorph Halloween Candy Bucket](https://learn.adafruit.com/xenomorph-halloween-candy-bucket.md)
