Hi, I decided to do wireless button box with using attiny88 development board as a transmitter, arduino pro micro as a receiver. Both of them use NRF24L01 for communication. I also use breakout adapter for NRF24L01. I saw the project from this video. I found 16 differents pins on the attiny88 board for my 16 buttons. I tested, each of them work properly one by one but when I write the code for 16 pins, somethings wrong. None of them work. The codes I mentioned are like this in the code, {4, "97"}, {5, "98"}, {6, "99"}, {7, "100"}. It works fine when I reduce the number of buttons in the code to 9 or less. I do not understand what is wrong. I used attinycore micronucleus mh-et t88 board manager. I cannot try different board manager like attinycore no bootloader or optiboot version because they do not see attiny88 board. Could you help me? What should I do?
Code for receiver
#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(20);
Keyboard.releaseAll();
}
}
Code for transmitter
#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 3
#define CSN_PIN 7
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[] = {{4, "97"},
{5, "98"},
{6, "99"},
{8, "100"},
{9, "101"},
{14, "102"},
{15, "103"},
{16, "104"},
{17, "105"},
{18, "106"},
{19, "107"},
{20, "108"},
{21, "109"},
{22, "110"},
{23, "111"},
{24, "112"},
};
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] = new Button(btnInfo.btnPin, DEBOUNCE_MS);
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;
}
}
}
