Coder Social home page Coder Social logo

wireless_keyboard's Introduction

Arduino custom wireless keyboard

There is a video associated with this repo, I highly recommend you watch it if you are going to use this repo.

Video

How to use

Libraries needed

*Installed directly from the Arduino library manager.

  • RF24 by TMRh20.
  • Button by Michael Adams.

For the transmitter

  • This is the micro-controller (MC) that will be running on battery and where all the buttons will be connected to. This needs to be a low current consuming MC and one that ideally meets the number of inputs pins to match the number buttons you are going to have.
  • I highly recommend the Attiny MCs, such as the Attiny85 (8 pins), Attiny84 (14 pins), or the Attiny88 (28 pins).
  • Changes you need to make to the code (/transmitter):
    • The CE and CSN pin numbers to match your connections, these could be any GPIO pins in your MC.
    • MAX_SHORTCUT_KEYS, this is the maximum number of characters a keyboard shortcut/sequence can be. This is specified so only the required number of bytes are sent through the radio signal.
    • The BUTTONS_INFO array. Each button element is made up of two values, the first is the pin number the button is connected to your MC. The second is a string of characters seperated by spaces. The characters are represented by their decimal/int values, which can be found here and here. Make sure you don't go over your MAX_SHORTCUT_KEYS in the string of keys, if more keys are required, simply increase MAX_SHORTCUT_KEYS.

For the Receiver

  • Any MC can be used here with USB cable connection, and one that has HID support so you can easily use the Arduino Keyboard library with no issues. I recommend the Pro Micro MC.
  • Changes you need to make to the code (/receiver):
    • The only change you need to make is if you changed the MAX_SHORTCUT_KEYS in the transmitter side, if you did, make sure the MAX_SHORTCUT_KEYS matches.

For 3D printing

Please refer to the /3d_models directory.

Components

Wiring

Transmitter

Receiver

How to upload code to Attiny MCs

  • The Attiny MCs can be programmed just like any Arduino and it's very easy to upload code to them.
  • You just need a USBASP adapter, then simply make the connections as shown in the image below.

  • You will also need to install the Attiny boards using the AttinyCore board manager by placing this link http://drazzy.com/package_drazzy.com_index.json to your "Additional Boards Manager URLs", which can be accessed in File > Preferences.

  • From Tools > Board, choose your Attiny board with the no bootloader option.

  • Then go to Tools > Programmer and choose USBasp (ATTinyCore), and then press Tools > Burn Bootloader.

  • Then to simply upload code, use Sketch > Upload Using Programmer.

  • You can use stripboards with some wires to make uploading code to the Attiny MCs more convenient:

wireless_keyboard's People

Contributors

projectswithred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wireless_keyboard's Issues

Making smaller version of this wireless keyboard by ProjectsWithRed

Hello
So to summarize, I am attempting to make an identical keyboard to the one beautifully crafted by ProjectsWithRed, Mine however will feature only a single button and uses all the exact same components apart from the ATtiny84 as I am using the smaller ATtiny85 instead!

I have therefore used the same code and libraries and adjusted the wiring and code (pins and input commands) for my single button which I want to command an input of "LCTRL+e"repeated 3 times. when pressed once.

To my knowledge I followed as carefully as possible all steps involved however testing the button I had no luck.
As mentioned I have used all the same parts, apart from using the smaller Attiny85 and single button.

Included in my post here I have attached my circuit diagrams and my code which I uploaded to the transmitter and receiver.
also when uploading the code to the Attiny85 i used an Arduino uno as ISP, and followed online guides as to how to correctly upload code to the Attiny with this method. I believe I did this correctly.

Hopefully ProjectsWithRed can help me with this and anyone else looking to do similar can also see the fix.

*sidenote, my code for the buttons command is currently set as {{5, "128 101"}, (pin 5, LCTRL e) I am aware this currently does not include the repeat function i wish to add so that the single press of the button will cause it to loop/repeat 'LCTRL +e' 3 times. I am unsure of how to do that and so need help with this. But for now the problem stands, I cannot get it to show any command.
It could be a wiring issue --perhaps I've made an error with the ATtiny pins I've used for the button and transmitter, or perhaps my code adjustments are incorrect.

Your help is greatly appreciated.

my transmitter attiny85

attiny85 transmittrer code.txt

Promiccro reciever code.txt

### Attiny transmitter code:

#include "SPI.h"
#include "RF24.h"

#include <Button.h>*


// Radio, choose any pins on your micro-controller to use as the CE and CSN pins.
#define CE_PIN 2
#define CSN_PIN 3

const uint8_t ADDRESS[6] = "CKeyB";


// Maximum number of keys a shortcut can be, or max number of keys to send through the NRF24L01 per button.
// This needs to match with the receiver side.
const int MAX_SHORTCUT_KEYS = 4;


const int BTN_SHORTCUT_SIZE = (3 * MAX_SHORTCUT_KEYS) + (MAX_SHORTCUT_KEYS - 1) + 1;

struct ButtonInfo {
    int btnPin;
    char btnShortcut[BTN_SHORTCUT_SIZE];
};


// All keys are represented using their ASCII decimal/int value. This can be found here: www.asciitable.com
// First specify the pin number, then seperate each key for that button in a string by a space.
const ButtonInfo BUTTONS_INFO[] = {{5, "128 101"},
                                   };


const int N_BUTTONS = sizeof(BUTTONS_INFO) / sizeof(BUTTONS_INFO[0]);

const uint16_t DEBOUNCE_MS = 10;


RF24 radio(CE_PIN, CSN_PIN);


Button *buttonObjs[N_BUTTONS];



void initRadio() {
    
    if (!radio.begin()) {
        while (1) {}
    }

    radio.setPALevel(RF24_PA_LOW);
    radio.setPayloadSize(BTN_SHORTCUT_SIZE);
    radio.openWritingPipe(ADDRESS);
    radio.setDataRate(RF24_1MBPS);
    
    radio.stopListening();
}

void initButtons() {
    for(int i = 0; i < N_BUTTONS; i++) {
        ButtonInfo btnInfo = BUTTONS_INFO[i];
        buttonObjs[i] -> begin();
    }
}


void setup() {

    initRadio();
    initButtons();
    
}

void loop() {

    // If any button pressed, then send the button keys through radio using the nRF24L01.
    for(int i = 0; i < N_BUTTONS; i++) {
        if(buttonObjs[i] -> pressed()) {
            ButtonInfo btnInfo = BUTTONS_INFO[i];
            
            radio.write(&btnInfo.btnShortcut, sizeof(btnInfo.btnShortcut));
            
            break;
        }
    }
}

Pro-micro receiver code:

#include "SPI.h"
#include "RF24.h"

#include <Keyboard.h>

#define CE_PIN 5
#define CSN_PIN 6

RF24 radio(CE_PIN, CSN_PIN);


uint8_t ADDRESS[6] = "CKeyB";


// Maximum number of keys a shortcut can be, or max number of keys to send through the NRF24L01 per button.
// This needs to match with the transmitter side.
const int MAX_SHORTCUT_KEYS = 4;


const int BTN_SHORTCUT_SIZE = (3 * MAX_SHORTCUT_KEYS) + (MAX_SHORTCUT_KEYS - 1) + 1;

char btnShortcut[BTN_SHORTCUT_SIZE];

char * key;
int keyInt;



void initRadio() {
    if (!radio.begin()) {
        while (1) {}
    }
    
    radio.setPALevel(RF24_PA_LOW);
    radio.setPayloadSize(BTN_SHORTCUT_SIZE);
    radio.openReadingPipe(1, ADDRESS);
    radio.setDataRate(RF24_1MBPS);
    
    radio.startListening();
}



void setup() {
    Keyboard.begin();
    
    initRadio();
}



void loop() {
    if (radio.available()) {
        radio.read(&btnShortcut, sizeof(btnShortcut));
        
        // Excract each key integer value from the incoming string and press each button.
        key = strtok(btnShortcut, " ");
        
        while(key != NULL) {
            keyInt = atoi(key);    
            Keyboard.press(keyInt);
            
            key = strtok(NULL, " ");
        }
        
        delay(10);
        Keyboard.releaseAll();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.