-
Notifications
You must be signed in to change notification settings - Fork 8
Description
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.
attiny85 transmittrer 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();
}
}